comparison python/c3/codegenerator.py @ 255:7416c923a02a

Added more logging
author Windel Bouwman
date Sun, 04 Aug 2013 15:10:10 +0200
parents c4370696ccc7
children ac603eb66b63
comparison
equal deleted inserted replaced
254:bd26dc13f270 255:7416c923a02a
1 import logging
1 import ir 2 import ir
2 from . import astnodes 3 from . import astnodes
3 from .scope import boolType, intType 4 from .scope import boolType, intType
4 from ppci import CompilerError 5 from ppci import CompilerError
5 from .typecheck import theType 6 from .typecheck import theType
6 7
7 tmpnames = {'+':'add', '-':'sub', '*': 'mul', '/':'div', '|':'or', \ 8 tmpnames = {'+':'add', '-':'sub', '*': 'mul', '/':'div', '|':'or', \
8 '&':'and', '>>':'shl', '<<':'shr'} 9 '&':'and', '>>':'shl', '<<':'shr'}
9 10
10 class CodeGenerator: 11 class CodeGenerator:
12 def __init__(self):
13 self.logger = logging.getLogger('c3')
11 """ Generates intermediate code from a package """ 14 """ Generates intermediate code from a package """
12 def gencode(self, pkg): 15 def gencode(self, pkg):
13 assert type(pkg) is astnodes.Package 16 assert type(pkg) is astnodes.Package
17 self.logger.info('Generating ir-code for {}'.format(pkg.name))
14 self.varMap = {} # Maps variables to storage locations. 18 self.varMap = {} # Maps variables to storage locations.
15 self.funcMap = {} 19 self.funcMap = {}
16 self.builder = ir.Builder() 20 self.builder = ir.Builder()
17 m = ir.Module(pkg.name) 21 m = ir.Module(pkg.name)
18 self.builder.setModule(m) 22 self.builder.setModule(m)