summaryrefslogtreecommitdiff
path: root/pp2cc.py
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2011-12-02 15:06:40 +0000
committerPeter Wu <lekensteyn@gmail.com>2011-12-02 15:06:40 +0000
commit45f82a1acf465c8420690a578192cdabf4bc7c04 (patch)
tree7f982ae8811fc3f797a201c2a018a18387fe22a0 /pp2cc.py
parent83d06610b8c070759598a0bb2bd4dca4d61973f0 (diff)
downloadpp2cc-45f82a1acf465c8420690a578192cdabf4bc7c04.tar.gz
Add WIP for supporting existing asm files
Diffstat (limited to 'pp2cc.py')
-rwxr-xr-xpp2cc.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/pp2cc.py b/pp2cc.py
index 95809e3..6370613 100755
--- a/pp2cc.py
+++ b/pp2cc.py
@@ -17,6 +17,7 @@ from Registers import Registers
from LinkedNode import LinkedNode
from Function import Function
from Variables import Variables, GlobalVariables
+from AsmParser import AsmParser
__author__ = "Peter Wu"
__copyright__ = "Copyright 2011, Peter Wu"
@@ -91,7 +92,21 @@ class Parse(object):
self.registers = Registers()
def loadFile(self, filename, use_cpp=True, cpp_args=[]):
"""Loads a file and parses the contents of it"""
- self.node = parse_file(filename, use_cpp=use_cpp, cpp_args=cpp_args);
+ # reset state
+ self.asm_node = self.node = None
+
+ ext = os.path.splitext(filename)[1].lower()
+ if ext:
+ ext = ext[1:]
+ if ext == "i":
+ # C source code which should not be preprocessed
+ self.node = parse_file(filename, use_cpp=False)
+ elif ext in ("c", "h"):
+ self.node = parse_file(filename, use_cpp=use_cpp, cpp_args=cpp_args)
+ elif ext == "asm":
+ self.asm_node = AsmParser(filename)
+ else:
+ self.logger.error("Unrecognized file extension '{}'".format(ext))
def show(self):
self.node.show(showcoord=True)
def uniqLbl(self, labelname):
@@ -111,6 +126,15 @@ class Parse(object):
self.logger.error("Redefinition of label '{}'".format(labelname))
self.labels.add(labelname)
def compile(self):
+ """Processes a loaded file and adds it to the assembly output"""
+ if self.node is not None:
+ self.compileAST()
+ elif self.asm_node is not None:
+ self.compileASM()
+ else:
+ self.logger.error("No AST node nor assembly lines found to be"
+ " processed")
+ def compileAST(self):
"""Loops through the nodes in an AST syntax tree and generates ASM"""
root_node = LinkedNode(self.node)
variables = GlobalVariables(self.varNames)
@@ -123,6 +147,9 @@ class Parse(object):
" node, but also found " +
str(thing), linked_node=linked_node)
self.codeSegment += self.parseStatement(thing, root_node)
+ def compileASM(self):
+ """Processes lines of assembly and merge it into the output"""
+ pass
def getSource(self):
"""Retrieves the ASM source. You need to compile it first"""
output = []