blob: fc072d943ad3b8c59b11e9ef3ef4c4183dc95643 (
plain) (
tree)
|
|
class Op(object):
__slots__ = ["name"]
def __init__(self, name):
self.name = name
def __str__(self):
return self.name
def __repr__(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.NOT = Op("NOT") # !x -> x
Op.MINUS = Op("MINUS") # -x -> x
Op.ASSIGN = Op("ASSIGN") # x = y -> x y
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.LE = Op("LE") # ...
Op.GE = Op("GE")
Op.LT = Op("LT")
Op.GT = Op("GT")
Op.PARAM = Op("PARAM") # param x -> x
Op.CALL = Op("CALL") # fun x (y-args..) -> x y
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
class TacElem:
def __init__(self,op,arg1=None,arg2=None):
self.op = op
self.arg1 = arg1
self.arg2 = arg2
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 = 1
output = ""
for item in self.liste:
print "%08d | %s\t%s\t%s" % (i,item.op,item.arg1,item.arg2)
i = i+1
|