comparison python/ppci/c3/codegenerator.py @ 364:c49459768aaa

Work on globals
author Windel Bouwman
date Wed, 19 Mar 2014 20:24:03 +0100
parents 396e5cefba13
children 2ec730e45ea1
comparison
equal deleted inserted replaced
363:396e5cefba13 364:c49459768aaa
39 self.varMap = {} # Maps variables to storage locations. 39 self.varMap = {} # Maps variables to storage locations.
40 self.m = ir.Module(pkg.name) 40 self.m = ir.Module(pkg.name)
41 try: 41 try:
42 # Only generate function if function contains a body: 42 # Only generate function if function contains a body:
43 real_functions = list(filter(lambda f: f.body, pkg.innerScope.Functions)) 43 real_functions = list(filter(lambda f: f.body, pkg.innerScope.Functions))
44 #real_functions = list(filter(None, pkg.innerScope.Functions))
45 for v in pkg.innerScope.Variables: 44 for v in pkg.innerScope.Variables:
46 self.varMap[v] = self.newTemp() 45 v2 = ir.GlobalVariable(v.name)
46 self.varMap[v] = v2
47 if not v.isLocal: 47 if not v.isLocal:
48 self.m.add_variable(v.name) 48 self.m.add_variable(v2)
49 for s in real_functions: 49 for s in real_functions:
50 self.gen_function(s) 50 self.gen_function(s)
51 except SemanticError as e: 51 except SemanticError as e:
52 self.error(e.msg, e.loc) 52 self.error(e.msg, e.loc)
53 if self.pkg.ok: 53 if self.pkg.ok:
320 from_type = self.the_type(expr.a.typ) 320 from_type = self.the_type(expr.a.typ)
321 to_type = self.the_type(expr.to_type) 321 to_type = self.the_type(expr.to_type)
322 if isinstance(from_type, ast.PointerType) and isinstance(to_type, ast.PointerType): 322 if isinstance(from_type, ast.PointerType) and isinstance(to_type, ast.PointerType):
323 expr.typ = expr.to_type 323 expr.typ = expr.to_type
324 return ar 324 return ar
325 elif type(from_type) is ast.BaseType and from_type.name == 'int' and \ 325 elif self.equalTypes(self.intType, from_type) and \
326 isinstance(to_type, ast.PointerType): 326 isinstance(to_type, ast.PointerType):
327 expr.typ = expr.to_type
328 return ar
329 elif self.equalTypes(self.intType, to_type) \
330 and isinstance(from_type, ast.PointerType):
327 expr.typ = expr.to_type 331 expr.typ = expr.to_type
328 return ar 332 return ar
329 elif type(from_type) is ast.BaseType and from_type.name == 'byte' and \ 333 elif type(from_type) is ast.BaseType and from_type.name == 'byte' and \
330 type(to_type) is ast.BaseType and to_type.name == 'int': 334 type(to_type) is ast.BaseType and to_type.name == 'int':
331 expr.typ = expr.to_type 335 expr.typ = expr.to_type