From a200c7f8c51ace73295974cc07e9e4a9db38d3e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20N=C3=BC=C3=9Flein?= Date: Fri, 22 May 2009 17:37:00 +0200 Subject: added ThreeAddressCode class --- src/back/tac.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/back/tac.py (limited to 'src/back') 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 "" % 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 + -- cgit v1.2.3