diff options
author | Andreas Nüßlein <nutz@unfoog.de> | 2009-05-22 17:37:00 +0200 |
---|---|---|
committer | Andreas Nüßlein <nutz@unfoog.de> | 2009-05-22 17:37:00 +0200 |
commit | a200c7f8c51ace73295974cc07e9e4a9db38d3e1 (patch) | |
tree | 149366c005b9bedbefd75ccbc48d60340c2c0d57 /src/back | |
parent | 028a685f7c19dee1af0482cf5ed142e751d36a62 (diff) | |
download | swppy-a200c7f8c51ace73295974cc07e9e4a9db38d3e1.tar.gz swppy-a200c7f8c51ace73295974cc07e9e4a9db38d3e1.tar.xz swppy-a200c7f8c51ace73295974cc07e9e4a9db38d3e1.zip |
added ThreeAddressCode class
Diffstat (limited to '')
-rw-r--r-- | src/back/tac.py | 50 |
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 + |