comparison python/irmach.py @ 280:02385f62f250

Rework from str interface to Instruction interface
author Windel Bouwman
date Sat, 02 Nov 2013 10:03:26 +0100
parents 046017431c6a
children 534b94b40aa8
comparison
equal deleted inserted replaced
279:2ccd57b1d78c 280:02385f62f250
6 6
7 Instructions are selected and scheduled at this stage. 7 Instructions are selected and scheduled at this stage.
8 """ 8 """
9 9
10 import ir 10 import ir
11 import target
12
11 13
12 class Frame: 14 class Frame:
13 """ 15 """
14 Activation record abstraction. This class contains a flattened 16 Activation record abstraction. This class contains a flattened
15 function. Instructions are selected and scheduled at this stage. 17 function. Instructions are selected and scheduled at this stage.
21 self.stacksize = 0 23 self.stacksize = 0
22 24
23 def __repr__(self): 25 def __repr__(self):
24 return 'Frame {}'.format(self.name) 26 return 'Frame {}'.format(self.name)
25 27
26 def makeIns(*args, **kwargs): 28 def lower_to(self, outs):
27 return AbstractInstruction(*args, **kwargs) 29 for im in self.instructions:
30 if isinstance(im.assem, target.Instruction):
31 outs.emit(im.assem)
32 else:
33 outs.emit(im.assem.fromim(im))
34
28 35
29 class AbstractInstruction: 36 class AbstractInstruction:
30 """ 37 """
31 Abstract machine instruction class. This is a very simple 38 Abstract machine instruction class. This is a very simple
32 abstraction of machine instructions. 39 abstraction of machine instructions.
33 """ 40 """
34 def __init__(self, cls, ops=(), src=(), dst=(), jumps=()): 41 def __init__(self, cls, ops=(), src=(), dst=(), jumps=(), others=(), ismove=False):
42 assert type(cls) is type or isinstance(cls, target.Instruction)
35 self.assem = cls 43 self.assem = cls
36 self.ops = ops 44 self.ops = tuple(ops)
37 self.src = tuple(src) 45 self.src = tuple(src)
38 self.dst = tuple(dst) 46 self.dst = tuple(dst)
39 self.jumps = tuple(jumps) 47 self.jumps = tuple(jumps)
48 self.others = tuple(others)
40 c = lambda s: tuple(map(type, s)) == (ir.Temp, ) 49 c = lambda s: tuple(map(type, s)) == (ir.Temp, )
41 self.ismove = c(src) and c(dst) and cls.lower().startswith('mov') 50 self.ismove = ismove
42 51
43 def __repr__(self): 52 def __repr__(self):
44 return self.render() 53 return self.render()
45 54
46 def render(self): 55 def render(self):