comparison python/irmach.py @ 299:674789d9ff37

Added a doc
author Windel Bouwman
date Sun, 01 Dec 2013 18:37:23 +0100
parents 534b94b40aa8
children
comparison
equal deleted inserted replaced
298:f7c3d38d0a47 299:674789d9ff37
5 This is the second intermediate representation. 5 This is the second intermediate representation.
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 from target import Instruction
11 import target
12 11
13 12
14 class Frame: 13 class Frame:
15 """ 14 """
16 Activation record abstraction. This class contains a flattened 15 Activation record abstraction. This class contains a flattened
25 def __repr__(self): 24 def __repr__(self):
26 return 'Frame {}'.format(self.name) 25 return 'Frame {}'.format(self.name)
27 26
28 def lower_to(self, outs): 27 def lower_to(self, outs):
29 for im in self.instructions: 28 for im in self.instructions:
30 if isinstance(im.assem, target.Instruction): 29 if isinstance(im.assem, Instruction):
31 outs.emit(im.assem) 30 outs.emit(im.assem)
32 else: 31 else:
33 outs.emit(im.assem.fromim(im)) 32 outs.emit(im.assem.fromim(im))
34 33
35 34
37 """ 36 """
38 Abstract machine instruction class. This is a very simple 37 Abstract machine instruction class. This is a very simple
39 abstraction of machine instructions. 38 abstraction of machine instructions.
40 """ 39 """
41 def __init__(self, cls, ops=(), src=(), dst=(), jumps=(), others=(), ismove=False): 40 def __init__(self, cls, ops=(), src=(), dst=(), jumps=(), others=(), ismove=False):
42 assert type(cls) is type or isinstance(cls, target.Instruction) 41 assert type(cls) is type or isinstance(cls, Instruction)
43 self.assem = cls 42 self.assem = cls
44 self.ops = tuple(ops) 43 self.ops = tuple(ops)
45 self.src = tuple(src) 44 self.src = tuple(src)
46 self.dst = tuple(dst) 45 self.dst = tuple(dst)
47 self.jumps = tuple(jumps) 46 self.jumps = tuple(jumps)
48 self.others = tuple(others) 47 self.others = tuple(others)
49 c = lambda s: tuple(map(type, s)) == (ir.Temp, )
50 self.ismove = ismove 48 self.ismove = ismove
51 49
52 def __repr__(self): 50 def __repr__(self):
53 return self.render() 51 return self.render()
54 52
65 x = x.replace(p, str(d)) 63 x = x.replace(p, str(d))
66 for i, j in enumerate(self.jumps): 64 for i, j in enumerate(self.jumps):
67 p = '%l{}'.format(i) 65 p = '%l{}'.format(i)
68 x = x.replace(p, str(j)) 66 x = x.replace(p, str(j))
69 return x 67 return x
68
69
70 makeIns = AbstractInstruction