diff python/c3/codegenerator.py @ 217:8b2e5f3cd579

Removed some stale python source files
author Windel Bouwman
date Fri, 05 Jul 2013 14:13:59 +0200
parents d77cb5962cc5
children 3f6c30a5d234
line wrap: on
line diff
--- a/python/c3/codegenerator.py	Fri Jul 05 13:26:51 2013 +0200
+++ b/python/c3/codegenerator.py	Fri Jul 05 14:13:59 2013 +0200
@@ -3,25 +3,24 @@
 from .scope import boolType
    
 class CodeGenerator:
-   """ Generates intermediate code from a package """
-   def gencode(self, pkg):
-      assert type(pkg) is astnodes.Package
-      self.varMap = {} # Maps variables to storage locations.
-      self.funcMap = {}
-      self.builder = ir.Builder()
-      m = ir.Module(pkg.name)
-      self.builder.setModule(m)
-      self.genModule(pkg)
-      return m
+    """ Generates intermediate code from a package """
+    def gencode(self, pkg):
+        assert type(pkg) is astnodes.Package
+        self.varMap = {} # Maps variables to storage locations.
+        self.funcMap = {}
+        self.builder = ir.Builder()
+        m = ir.Module(pkg.name)
+        self.builder.setModule(m)
+        self.genModule(pkg)
+        return m
 
-   # inner helpers:
-   def genModule(self, pkg):
+    # inner helpers:
+    def genModule(self, pkg):
       # Take care of forward declarations:
-      for s in pkg.scope:
-         if type(s) is astnodes.Function:
+      for s in pkg.innerScope.Functions:
             f = self.builder.newFunction(s.name)
             self.funcMap[s] = f
-      for s in pkg.scope:
+      for s in pkg.innerScope:
          if type(s) is astnodes.Variable:
               v = self.builder.newVariable(s.name)
               #self.builder.addIns(ir.Alloc(v))
@@ -35,7 +34,7 @@
             self.builder.setBB(bb)
             # generate room for locals:
 
-            for sym in s.scope:
+            for sym in s.innerScope:
                #print(sym, sym.isParameter)
                # TODO: handle parameters different
                v = self.builder.newTmp(sym.name)
@@ -49,7 +48,7 @@
          else:
             print(s)
 
-   def genCode(self, code):
+    def genCode(self, code):
       if type(code) is astnodes.CompoundStatement:
          for s in code.statements:
             self.genCode(s)
@@ -88,12 +87,12 @@
          self.builder.setBB(bbtest)
          self.genCondCode(code.condition, bbdo, te)
          self.builder.setBB(bbdo)
-         self.genCode(code.dostatement)
+         self.genCode(code.statement)
          self.builder.addIns(ir.Branch(bbtest))
          self.builder.setBB(te)
       else:
          print('Unknown stmt:', code)
-   def genCondCode(self, expr, bbtrue, bbfalse):
+    def genCondCode(self, expr, bbtrue, bbfalse):
       # Implement sequential logical operators
       assert expr.typ == boolType
       if type(expr) is astnodes.Binop:
@@ -121,7 +120,7 @@
             self.builder.addIns(ir.Branch(bbfalse))
       else:
          print('Unknown cond', expr)
-   def genExprCode(self, expr):
+    def genExprCode(self, expr):
       if type(expr) is astnodes.Binop:
          ra = self.genExprCode(expr.a)
          rb = self.genExprCode(expr.b)