Mercurial > lcfOS
comparison 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 |
comparison
equal
deleted
inserted
replaced
175:a51b3c956386 | 176:5fd02aa38b42 |
---|---|
67 self.builder.setBB(bbfalse) | 67 self.builder.setBB(bbfalse) |
68 self.genCode(code.falsestatement) | 68 self.genCode(code.falsestatement) |
69 self.builder.addIns(ir.Branch(te)) | 69 self.builder.addIns(ir.Branch(te)) |
70 self.builder.setBB(te) | 70 self.builder.setBB(te) |
71 elif type(code) is astnodes.FunctionCall: | 71 elif type(code) is astnodes.FunctionCall: |
72 print('TODO') | |
72 pass | 73 pass |
73 elif type(code) is astnodes.EmptyStatement: | 74 elif type(code) is astnodes.EmptyStatement: |
74 pass | 75 pass |
75 elif type(code) is astnodes.ReturnStatement: | 76 elif type(code) is astnodes.ReturnStatement: |
76 if code.expr: | 77 if code.expr: |
77 re = self.genExprCode(code.expr) | 78 re = self.genExprCode(code.expr) |
78 self.builder.addIns(ir.Return(re)) | 79 self.builder.addIns(ir.Return(re)) |
79 else: | 80 else: |
80 self.builder.addIns(ir.Return()) | 81 self.builder.addIns(ir.Return()) |
82 elif type(code) is astnodes.WhileStatement: | |
83 bbdo = self.builder.newBB() | |
84 bbtest = self.builder.newBB() | |
85 te = self.builder.newBB() | |
86 self.builder.addIns(ir.Branch(bbtest)) | |
87 self.builder.setBB(bbtest) | |
88 self.genCondCode(code.condition, bbdo, te) | |
89 self.builder.setBB(bbdo) | |
90 self.genCode(code.dostatement) | |
91 self.builder.addIns(ir.Branch(bbtest)) | |
92 self.builder.setBB(te) | |
81 else: | 93 else: |
82 print('Unknown stmt:', code) | 94 print('Unknown stmt:', code) |
83 def genCondCode(self, expr, bbtrue, bbfalse): | 95 def genCondCode(self, expr, bbtrue, bbfalse): |
84 # Implement sequential logical operators | 96 # Implement sequential logical operators |
85 assert expr.typ == boolType | 97 assert expr.typ == boolType |