diff options
author | Peter Wu <lekensteyn@gmail.com> | 2011-11-27 11:01:57 +0000 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2011-11-27 11:01:57 +0000 |
commit | ae6a72437d596112fc9ee38783088560d3fd5c8b (patch) | |
tree | 7728b229bbe79a9125574731ad6d67d70948d49a /pp2cc.py | |
parent | 2678ed888b39d27d4bace24d7fad584c5cc91a10 (diff) | |
download | pp2cc-ae6a72437d596112fc9ee38783088560d3fd5c8b.tar.gz |
Support do { .. } while (..), allow for empty compound statements (e.g. do{}while(1))
Diffstat (limited to 'pp2cc.py')
-rwxr-xr-x | pp2cc.py | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -320,8 +320,9 @@ class Parse(object): def parseCompound(self, linked_node): linked_node.incrementLevel() lines = [] - for cn in linked_node.node.block_items: - lines += self.parseStatement(cn, linked_node) + if linked_node.node.block_items: + for cn in linked_node.node.block_items: + lines += self.parseStatement(cn, linked_node) return lines def parseBinaryLogicalOp(self, linked_node): @@ -694,6 +695,17 @@ class Parse(object): def parseCast(self, linked_node): self.logger.warning("Found a type cast, but these are unsupported.", linked_node=linked_node) return self.parseStatement(linked_node.node.expr, linked_node) + def parseDoWhile(self, linked_node): + node = linked_node.node + lbl_do = self.uniqLbl("do") + # provides a way to redo the loop + lines = [self.asm.noop(lbl_do)] + # do { ... }, expect do{/*empty*/} as well + lines += self.parseStatement(node.stmt, linked_node) + # while (...) + lines += self.parseStatement(node.cond, linked_node) + lines.append(self.asm.branch_op("BNE", lbl_do)) + return lines def parseStatement(self, node, parent_linked_node, level_increment=False): linked_node = LinkedNode(node, parent_linked_node, level_increment=level_increment) self.asm.level = linked_node.level @@ -702,8 +714,6 @@ class Parse(object): raise RuntimeError("Not implemented for type " + repr(node)) elif isinstance(node, c_ast.Decl): self.defineGlobalVar(linked_node, parent_linked_node) - elif isinstance(node, c_ast.DoWhile): - raise RuntimeError("Not implemented for type " + repr(node)) elif isinstance(node, c_ast.ExprList): raise RuntimeError("Not implemented for type " + repr(node)) elif isinstance(node, c_ast.For): @@ -717,7 +727,7 @@ class Parse(object): else: for entry in ("Compound", "BinaryOp", "If", "Constant", "ID", "Return", "FuncCall", "UnaryOp", "Cast", - "TernaryOp"): + "TernaryOp", "DoWhile"): if isinstance(node, getattr(c_ast, entry)): lines += getattr(self, "parse" + entry)(linked_node) break |