summaryrefslogtreecommitdiffstats
path: root/src/back
diff options
context:
space:
mode:
authorBenedikt Böhm <bb@xnull.de>2009-07-06 21:21:19 +0200
committerBenedikt Böhm <bb@xnull.de>2009-07-06 21:21:19 +0200
commitac4fb25412982447af2e718d3824e6acf7d3a2dd (patch)
tree4eb8d49be8363dda95e3e1851e8dc04e6c3cb4f5 /src/back
parent37aec7789434c3ade9a1df630b1eec6c997487b2 (diff)
downloadswppy-ac4fb25412982447af2e718d3824e6acf7d3a2dd.tar.gz
swppy-ac4fb25412982447af2e718d3824e6acf7d3a2dd.tar.xz
swppy-ac4fb25412982447af2e718d3824e6acf7d3a2dd.zip
implement print statement
Diffstat (limited to 'src/back')
-rw-r--r--src/back/generator.py8
-rw-r--r--src/back/tac.py2
2 files changed, 10 insertions, 0 deletions
diff --git a/src/back/generator.py b/src/back/generator.py
index 414cf7b..7ca2658 100644
--- a/src/back/generator.py
+++ b/src/back/generator.py
@@ -90,6 +90,14 @@ class Generator(object):
elif tac.op == Op.RETURN:
self.emit("ADD rv, r0, r%d" % tac.arg1)
self.emit(tac)
+ elif tac.op == Op.PRINT:
+ r = Register().new()
+ self.emit("PUSH r%d" % tac.arg1)
+ self.emit("MOV r%d, %d" % (r, 1))
+ self.emit("PUSH r%d" % r)
+ self.emit("SYS")
+ self.emit("POP r0")
+ self.emit("POP r0")
elif isinstance(tac, FunctionPrologue):
self.generate_prologue(tac.name)
elif isinstance(tac, FunctionEpilogue):
diff --git a/src/back/tac.py b/src/back/tac.py
index 03303cf..86ccd90 100644
--- a/src/back/tac.py
+++ b/src/back/tac.py
@@ -40,6 +40,8 @@ Op.JMP = Op("JMP") # goto x
Op.CALL = Op("CALL") # call x return in y
Op.RETURN = Op("RETURN") # return x
+Op.PRINT = Op("PRINT") # print x
+
class TAC(object):
def __init__(self,op,arg1=None,arg2=None):
self.op = op