summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/back/tac.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/back/tac.py b/src/back/tac.py
new file mode 100644
index 0000000..2b288f8
--- /dev/null
+++ b/src/back/tac.py
@@ -0,0 +1,50 @@
+class Op(object):
+ __slots__ = ["name"]
+
+ def __init__(self, name):
+ self.name = name
+
+ def __str__(self):
+ return self.name
+
+ def __repr__(self):
+ return "<Tag: %s>" % self
+
+
+Op.ADD = Op("ADD") # x = y + z -> y z x
+Op.SUB = Op("SUB") # x = y - z -> y z x
+Op.MUL = Op("MUL") # x = y * z -> y z x
+Op.DIV = Op("DIV") # x = y / z -> y z x
+Op.MOD = Op("MOD") # x = y % z -> y z x
+Op.AND = Op("AND") # x = y AND z -> y z x
+Op.OR = Op("OR") # x = y OR z -> y z x
+
+Op.NOT = Op("NOT") # x = !y -> y None x
+Op.MINUS = Op("MINUS") # x = - y -> y None x
+
+Op.ASSIGN = Op("ASSIGN") # x = y -> y None x
+
+Op.JMP = Op("JMP") # "goto" x -> x
+Op.BEQ = Op("BEQ") # "if y == z" goto x -> y z x
+Op.BNE = Op("BNE") # "if y != z" goto x -> y z x
+Op.BLE = Op("BLE") # ...
+Op.BGE = Op("BGE")
+Op.BLT = Op("BLT")
+Op.BGT = Op("BGT")
+
+Op.PARAM = Op("PARAM") # param x -> x
+Op.CALL = Op("CALL") # fun y (z-args..) -> y z
+Op.RETURN = Op("RETURN") # return x -> x
+
+Op.ARRAYGET = Op("ARRAYGET") # x = y[i] -> y i x
+Op.ARRAYSET = Op("ARRAYSET") # x[i] = y -> y i x
+
+
+class ThreeAddressCode:
+
+ def __init__(self,op,arg1=None,arg2=None,result=None):
+ self.op = op
+ self.arg1 = arg1
+ self.arg2 = arg2
+ self.result = result
+