Mercurial > lcfOS
view python/ir/instruction.py @ 163:8104fc8b5e90
Added visitor to c3
author | Windel Bouwman |
---|---|
date | Mon, 18 Mar 2013 20:13:57 +0100 |
parents | 10330be89bc2 |
children | 4348da5ca307 |
line wrap: on
line source
class Instruction: """ Base class for all instructions. """ pass # Function calling: class CallInstruction(Instruction): def __init__(self, callee, arguments): super().__init__() self.callee = callee self.arguments = arguments def __repr__(self): return 'CALL {0}'.format(self.callee) class RetInstruction(Instruction): def __repr__(self): return 'RET' class BinaryOperator(Instruction): def __init__(self, name, operation, value1, value2): assert value1 assert value2 #print('operation is in binops:', operation in BinOps) # Check types of the two operands: self.name = name self.value1 = value1 self.value2 = value2 self.operation = operation def __repr__(self): return '{0} = {1} {2}, {3}'.format(self.name, self.operation, self.value1, self.value2) class LoadInstruction(Instruction): def __init__(self, name, value): self.value = value self.name = name def __repr__(self): return 'load {0} = {1}'.format(self.name, self.value) class StoreInstruction(Instruction): def __init__(self, name, value): self.name = name self.value = value def __repr__(self): return 'store {0}'.format(self.name) class BranchInstruction(Instruction): def __init__(self, t1, t2): self.t1 = t1 self.t2 = t2 def __repr__(self): return 'BRANCH {0}'.format(self.t1)