diff 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
line wrap: on
line diff
--- a/python/ppci/c3/codegenerator.py	Sun Mar 16 11:28:47 2014 +0100
+++ b/python/ppci/c3/codegenerator.py	Wed Mar 19 20:24:03 2014 +0100
@@ -41,11 +41,11 @@
         try:
             # Only generate function if function contains a body:
             real_functions = list(filter(lambda f: f.body, pkg.innerScope.Functions))
-            #real_functions = list(filter(None, pkg.innerScope.Functions))
             for v in pkg.innerScope.Variables:
-                self.varMap[v] = self.newTemp()
+                v2 = ir.GlobalVariable(v.name)
+                self.varMap[v] = v2
                 if not v.isLocal:
-                    self.m.add_variable(v.name)
+                    self.m.add_variable(v2)
             for s in real_functions:
                 self.gen_function(s)
         except SemanticError as e:
@@ -322,10 +322,14 @@
         if isinstance(from_type, ast.PointerType) and isinstance(to_type, ast.PointerType):
             expr.typ = expr.to_type
             return ar
-        elif type(from_type) is ast.BaseType and from_type.name == 'int' and \
+        elif self.equalTypes(self.intType, from_type) and \
                 isinstance(to_type, ast.PointerType):
             expr.typ = expr.to_type
             return ar
+        elif self.equalTypes(self.intType, to_type) \
+                and isinstance(from_type, ast.PointerType):
+            expr.typ = expr.to_type
+            return ar
         elif type(from_type) is ast.BaseType and from_type.name == 'byte' and \
                 type(to_type) is ast.BaseType and to_type.name == 'int':
             expr.typ = expr.to_type