Mercurial > lcfOS
comparison python/irmach.py @ 277:046017431c6a
Started register allocator
author | Windel Bouwman |
---|---|
date | Thu, 26 Sep 2013 21:14:25 +0200 |
parents | 6f2423df0675 |
children | 02385f62f250 |
comparison
equal
deleted
inserted
replaced
276:56d37ed4b4d2 | 277:046017431c6a |
---|---|
4 | 4 |
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 | |
10 import ir | |
9 | 11 |
10 class Frame: | 12 class Frame: |
11 """ | 13 """ |
12 Activation record abstraction. This class contains a flattened | 14 Activation record abstraction. This class contains a flattened |
13 function. Instructions are selected and scheduled at this stage. | 15 function. Instructions are selected and scheduled at this stage. |
27 class AbstractInstruction: | 29 class AbstractInstruction: |
28 """ | 30 """ |
29 Abstract machine instruction class. This is a very simple | 31 Abstract machine instruction class. This is a very simple |
30 abstraction of machine instructions. | 32 abstraction of machine instructions. |
31 """ | 33 """ |
32 def __init__(self, assem, src=(), dst=(), jumps=()): | 34 def __init__(self, cls, ops=(), src=(), dst=(), jumps=()): |
33 self.assem = assem | 35 self.assem = cls |
36 self.ops = ops | |
34 self.src = tuple(src) | 37 self.src = tuple(src) |
35 self.dst = tuple(dst) | 38 self.dst = tuple(dst) |
36 self.jumps = tuple(jumps) | 39 self.jumps = tuple(jumps) |
40 c = lambda s: tuple(map(type, s)) == (ir.Temp, ) | |
41 self.ismove = c(src) and c(dst) and cls.lower().startswith('mov') | |
37 | 42 |
38 def __repr__(self): | 43 def __repr__(self): |
39 s = str(self.src) if self.src else '' | |
40 d = str(self.dst) if self.dst else '' | |
41 l = str(self.jumps) if self.jumps else '' | |
42 #return self.assem + s + d + l | |
43 return self.render() | 44 return self.render() |
44 | 45 |
45 def render(self): | 46 def render(self): |
46 """ | 47 """ |
47 Substitutes source, dst and labels in the string | 48 Substitutes source, dst and labels in the string |
48 """ | 49 """ |
49 x = self.assem | 50 x = str(self.assem) |
50 for i, s in enumerate(self.src): | 51 for i, s in enumerate(self.src): |
51 p = '%s{}'.format(i) | 52 p = '%s{}'.format(i) |
52 x = x.replace(p, str(s)) | 53 x = x.replace(p, str(s)) |
53 for i, d in enumerate(self.dst): | 54 for i, d in enumerate(self.dst): |
54 p = '%d{}'.format(i) | 55 p = '%d{}'.format(i) |
55 x = x.replace(p, str(d)) | 56 x = x.replace(p, str(d)) |
56 for i, j in enumerate(self.jumps): | 57 for i, j in enumerate(self.jumps): |
57 p = '%l{}'.format(i) | 58 p = '%l{}'.format(i) |
58 x = x.replace(p, str(j)) | 59 x = x.replace(p, str(j)) |
59 | |
60 return x | 60 return x |
61 | 61 |
62 | 62 |