diff python/ppci/c3/codegenerator.py @ 306:b145f8e6050b

Start on c3 rewrite
author Windel Bouwman
date Mon, 09 Dec 2013 19:00:21 +0100
parents 0615b5308710
children e609d5296ee9
line wrap: on
line diff
--- a/python/ppci/c3/codegenerator.py	Fri Dec 06 13:50:38 2013 +0100
+++ b/python/ppci/c3/codegenerator.py	Mon Dec 09 19:00:21 2013 +0100
@@ -1,7 +1,6 @@
 import logging
 from .. import ir
 from . import astnodes
-from .scope import boolType, intType
 from ppci import CompilerError
 from .analyse import theType
 
@@ -43,7 +42,6 @@
         # TODO: handle arguments
         f = self.funcMap[fn]
         f.return_value = self.newTemp()
-        # TODO reserve room for stack, this can be done at later point?
         self.setFunction(f)
         l2 = self.newBlock()
         self.emit(ir.Jump(l2))
@@ -77,6 +75,8 @@
         if type(code) is astnodes.CompoundStatement:
             for s in code.statements:
                 self.genCode(s)
+        elif type(code) is astnodes.EmptyStatement:
+            pass
         elif type(code) is astnodes.Assignment:
             rval = self.genExprCode(code.rval)
             lval = self.genExprCode(code.lval)
@@ -92,12 +92,10 @@
             self.genCode(code.truestatement)
             self.emit(ir.Jump(te))
             self.setBlock(bbfalse)
-            if code.falsestatement:
-                self.genCode(code.falsestatement)
+            self.genCode(code.falsestatement)
             self.emit(ir.Jump(te))
             self.setBlock(te)
         elif type(code) is astnodes.ReturnStatement:
-            assert code.expr
             re = self.genExprCode(code.expr)
             self.emit(ir.Move(self.fn.return_value, re))
             self.emit(ir.Jump(self.fn.epiloog))
@@ -119,7 +117,6 @@
 
     def genCondCode(self, expr, bbtrue, bbfalse):
         # Implement sequential logical operators
-        assert expr.typ == boolType
         if type(expr) is astnodes.Binop:
             if expr.op == 'or':
                 l2 = self.newBlock()
@@ -180,7 +177,7 @@
             ar = self.genExprCode(expr.a)
             tt = theType(expr.to_type)
             if isinstance(tt, astnodes.PointerType):
-                if expr.a.typ is intType:
+                if expr.a.typ is expr.scope['int']:
                     return ar
                 elif isinstance(expr.a.typ, astnodes.PointerType):
                     return ar