diff python/c3/codegenerator.py @ 176:5fd02aa38b42

Added while loop code generation
author Windel Bouwman
date Sat, 20 Apr 2013 12:00:51 +0200
parents a51b3c956386
children 460db5669efa
line wrap: on
line diff
--- a/python/c3/codegenerator.py	Fri Apr 19 22:15:54 2013 +0200
+++ b/python/c3/codegenerator.py	Sat Apr 20 12:00:51 2013 +0200
@@ -69,6 +69,7 @@
          self.builder.addIns(ir.Branch(te))
          self.builder.setBB(te)
       elif type(code) is astnodes.FunctionCall:
+         print('TODO')
          pass
       elif type(code) is astnodes.EmptyStatement:
          pass
@@ -78,6 +79,17 @@
             self.builder.addIns(ir.Return(re))
          else:
             self.builder.addIns(ir.Return())
+      elif type(code) is astnodes.WhileStatement:
+         bbdo = self.builder.newBB()
+         bbtest = self.builder.newBB()
+         te = self.builder.newBB()
+         self.builder.addIns(ir.Branch(bbtest))
+         self.builder.setBB(bbtest)
+         self.genCondCode(code.condition, bbdo, te)
+         self.builder.setBB(bbdo)
+         self.genCode(code.dostatement)
+         self.builder.addIns(ir.Branch(bbtest))
+         self.builder.setBB(te)
       else:
          print('Unknown stmt:', code)
    def genCondCode(self, expr, bbtrue, bbfalse):