comparison python/ppci/frontends/ks/irgenerator.py @ 107:1544e7a4aa98

Improvements
author Windel Bouwman
date Tue, 01 Jan 2013 17:16:05 +0100
parents f2d980eef509
children 9e552d34bd60
comparison
equal deleted inserted replaced
106:f2d980eef509 107:1544e7a4aa98
73 else: 73 else:
74 pass 74 pass
75 # Get a register to store the integer value 75 # Get a register to store the integer value
76 else: 76 else:
77 Error('Cannot load variable type {0}'.format(node.typ)) 77 Error('Cannot load variable type {0}'.format(node.typ))
78
79 elif isinstance(node, Relop):
80 # Create a boolean from operands
81 # TODO create an alternative for expressions used as conditions.
82 self.genexprcode(node.a)
83 self.genexprcode(node.b)
84
85 if node.a.typ.isType(integer):
86 self.freereg(node.b)
87 else:
88 Error('Relop not implemented for {0}'.format(node.a.typ))
89
90 elif type(node) is Constant: 78 elif type(node) is Constant:
91 print('TODO: constant') 79 print('TODO: constant')
92
93 elif type(node) is ProcedureCall:
94 Error('TODO: proc call')
95 else: 80 else:
96 Error('Cannot generate expression code for: {0}'.format(node)) 81 Error('Cannot generate expression code for: {0}'.format(node))
97 82
98 def gencode(self, node): 83 def gencode(self, node):
99 """ Code generation function for AST nodes """ 84 """ Code generation function for AST nodes """
100 if isinstance(node, Module): 85 if isinstance(node, Module):
101 # TODO: recurse! 86 # TODO: recurse!
87
88 print(node.symtable)
89 node.symtable.printTable()
90 funcs = node.symtable.getAllLocal(Procedure)
91 for f in funcs:
92 print('function', f)
93 ftype = f.typ.coreType()
94 ftype = core.FunctionType(retType)
102 95
103 self.mod = core.Module() 96 self.mod = core.Module(node.name)
104 # Create a function called init for this module: 97 # Create a function called init for this module:
105 ftype = core.FunctionType(self.context.VoidType, []) 98 ftype = core.FunctionType(self.context.VoidType, [])
106 func = core.Function(ftype, "init", self.mod) 99 func = core.Function(ftype, "init", self.mod)
107 bb = self.gencode(node.initcode) 100 bb = self.gencode(node.initcode)
108 self.mod.dump() 101 self.mod.dump()