diff options
author | Andreas Nüßlein <nutz@unfoog.de> | 2009-05-26 00:07:37 +0200 |
---|---|---|
committer | Andreas Nüßlein <nutz@unfoog.de> | 2009-05-26 00:07:37 +0200 |
commit | 3bf28deef216b5e795a782165eb7878ca36e80a8 (patch) | |
tree | 191135e8232e8194a82739fc3b5a584d71453f8d /src/back | |
parent | 23daaf1372863949e2fccebafd25a0d973716d54 (diff) | |
download | swppy-3bf28deef216b5e795a782165eb7878ca36e80a8.tar.gz swppy-3bf28deef216b5e795a782165eb7878ca36e80a8.tar.xz swppy-3bf28deef216b5e795a782165eb7878ca36e80a8.zip |
tac and ast updates - added eval to ast-elems
every ast-element now has a .eval-method that creates the
ThreeAddressCode for said element.
Also: tac-elements are stored linear in a list (, duh)
Diffstat (limited to 'src/back')
-rw-r--r-- | src/back/tac.py | 72 |
1 files changed, 45 insertions, 27 deletions
diff --git a/src/back/tac.py b/src/back/tac.py index 2b288f8..a875a7d 100644 --- a/src/back/tac.py +++ b/src/back/tac.py @@ -8,43 +8,61 @@ class Op(object): return self.name def __repr__(self): - return "<Tag: %s>" % self + return """<Operator: "%s">""" % self +# arg1 arg2 +Op.ADD = Op("ADD") # x + y -> x y +Op.SUB = Op("SUB") # x - y -> x y +Op.MUL = Op("MUL") # x * y -> x y +Op.DIV = Op("DIV") # x / y -> x y +Op.MOD = Op("MOD") # x % y -> x y +Op.AND = Op("AND") # x AND y -> x y +Op.OR = Op("OR") # x OR y -> x y -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 -> x +Op.MINUS = Op("MINUS") # -x -> 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 -> x y -Op.ASSIGN = Op("ASSIGN") # x = y -> y None x +Op.JMP = Op("JMP") # "goto" x -> x +Op.BEQ = Op("EQ") # "if x == y" -> x y +Op.BNE = Op("NE") # "if x != y" -> x y +Op.BLE = Op("LE") # ... +Op.BGE = Op("GE") +Op.BLT = Op("LT") +Op.BGT = Op("GT") -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 x (y-args..) -> x y +Op.RETURN = Op("RETURN") # return x -> x -Op.PARAM = Op("PARAM") # param x -> x -Op.CALL = Op("CALL") # fun y (z-args..) -> y z -Op.RETURN = Op("RETURN") # return x -> x +# maybe in the future +#Op.ARRAYGET = Op("ARRAYGET") # x = y[i] -> i +#Op.ARRAYSET = Op("ARRAYSET") # x[i] = y -> y i -Op.ARRAYGET = Op("ARRAYGET") # x = y[i] -> y i x -Op.ARRAYSET = Op("ARRAYSET") # x[i] = y -> y i x +class TacElem: -class ThreeAddressCode: - - def __init__(self,op,arg1=None,arg2=None,result=None): + def __init__(self,op,arg1=None,arg2=None): self.op = op self.arg1 = arg1 self.arg2 = arg2 - self.result = result + + def __repr__(self): + return "<TacElem, Op: %s, Arg1: %s, Arg2: %s>" % (self.op,self.arg1,self.arg2) + +class TacArray: + def __init__(self): + self.liste = [] + + def append(self,arg): + self.liste.append(arg) + return len(self.liste)-1 + + def createList(self): + i = 0 + output = "" + for item in self.liste: + print "%08d | %s\t%s\t%s" % (i,item.op,item.arg1,item.arg2) + |