From a6f9617bd891074bba20cc1fc220e60a226e7fb4 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 2 Dec 2011 18:43:48 +0000 Subject: WIP for supporting ASM parsing and initialization of variables in @DATA --- pp2cc.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'pp2cc.py') diff --git a/pp2cc.py b/pp2cc.py index 6370613..ffe9ee4 100755 --- a/pp2cc.py +++ b/pp2cc.py @@ -30,6 +30,8 @@ __email__ = "uwretep@gmail.com" class Logger(object): def __init__(self): pass + def info(self, message, linked_node=None): + self.log(message, linked_node=linked_node, type="info") def warning(self, message, linked_node=None): self.log(message, linked_node=linked_node, type="warning") def error(self, message, linked_node=None): @@ -149,14 +151,23 @@ class Parse(object): self.codeSegment += self.parseStatement(thing, root_node) def compileASM(self): """Processes lines of assembly and merge it into the output""" - pass + for label in self.asm_node.labels: + new_label = label + # rename existing names + if label in self.labels: + new_label = self.uniqLbl(label) + self.asm_node.renameId(label, new_label) + self.labels.add(new_label) + self.codeSegment += self.asm_node.getCodeLines() def getSource(self): """Retrieves the ASM source. You need to compile it first""" output = [] output.append("@DATA") for varName, size in self.varNames.iteritems(): padding = " " * (16 - len(varName) - 1) - output.append(varName + padding + " DS " + str(size)) + assert size > 0, "Size of '{}' must be at least 1".format(varName) + initializers = "0,".repeat(size)[0:-1] + output.append(varName + padding + " DW " + initializers) output.append("") output.append("@CODE") # initialization of global variables -- cgit v1.2.1