Mercurial > lcfOS
view python/ir/instruction.py @ 170:4348da5ca307
Cleanup of ir dir
author | Windel Bouwman |
---|---|
date | Fri, 29 Mar 2013 17:33:17 +0100 |
parents | 10330be89bc2 |
children | 3eb9b9e2958d |
line wrap: on
line source
class Instruction: """ Base class for all instructions. """ pass # Label: class LabelInstruction(Instruction): def __init__(self, labid): self.labid = labid def __repr__(self): return '{0}:'.format(self.labid) # 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 MoveInstruction(Instruction): def __init__(self, name, value): self.name = name self.value = value def __repr__(self): return '{0} = {1}'.format(self.name, self.value) class BinaryOperator(Instruction): def __init__(self, name, operation, value1, 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} = {2} {1} {3}'.format(self.name, self.operation, self.value1, self.value2) # Memory functions: class LoadInstruction(Instruction): def __init__(self, name, value): self.value = value self.name = name def __repr__(self): return '{1} = [{0}]'.format(self.name, self.value) class StoreInstruction(Instruction): def __init__(self, name, value): self.name = name self.value = value def __repr__(self): return '[{0}] = {1}'.format(self.name, self.value) class BranchInstruction(Instruction): def __init__(self, target): self.t1 = target def __repr__(self): return 'BRANCH {0}'.format(self.t1) class IfInstruction(Instruction): def __init__(self, cond, lab1, lab2): self.cond = cond self.lab1 = lab1 self.lab2 = lab2 def __repr__(self): return 'IF {0} THEN {1} ELSE {2}'.format(self.cond, self.lab1, self.lab2)