Mercurial > lcfOS
annotate python/ppci/irmach.py @ 366:39bf68bf1891
Fix sample tests and deterministic build
author | Windel Bouwman |
---|---|
date | Fri, 21 Mar 2014 09:43:01 +0100 |
parents | 3bb7dcfe5529 |
children | 5d03c10fe19d |
rev | line source |
---|---|
261 | 1 |
269 | 2 """ |
270 | 3 Abstract assembly language instructions. |
4 | |
5 This is the second intermediate representation. | |
6 | |
7 Instructions are selected and scheduled at this stage. | |
269 | 8 """ |
261 | 9 |
342 | 10 from .target import Instruction |
280
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
277
diff
changeset
|
11 |
277 | 12 |
274 | 13 class Frame: |
323 | 14 """ |
274 | 15 Activation record abstraction. This class contains a flattened |
16 function. Instructions are selected and scheduled at this stage. | |
17 Frames differ per machine. | |
18 """ | |
19 def __init__(self, name): | |
20 self.name = name | |
21 self.instructions = [] | |
275 | 22 self.stacksize = 0 |
274 | 23 |
24 def __repr__(self): | |
275 | 25 return 'Frame {}'.format(self.name) |
274 | 26 |
261 | 27 |
268 | 28 class AbstractInstruction: |
274 | 29 """ |
30 Abstract machine instruction class. This is a very simple | |
31 abstraction of machine instructions. | |
32 """ | |
280
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
277
diff
changeset
|
33 def __init__(self, cls, ops=(), src=(), dst=(), jumps=(), others=(), ismove=False): |
342 | 34 assert type(cls) is type or isinstance(cls, Instruction), str(cls) |
277 | 35 self.assem = cls |
280
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
277
diff
changeset
|
36 self.ops = tuple(ops) |
268 | 37 self.src = tuple(src) |
38 self.dst = tuple(dst) | |
39 self.jumps = tuple(jumps) | |
280
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
277
diff
changeset
|
40 self.others = tuple(others) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
277
diff
changeset
|
41 self.ismove = ismove |
268 | 42 |
366 | 43 def __gt__(self, other): |
44 """ To make the class fit for sorting """ | |
45 return str(self) > str(other) | |
46 | |
268 | 47 def __repr__(self): |
346 | 48 """ Substitutes source, dst and labels in the string """ |
323 | 49 if isinstance(self.assem, Instruction): |
50 x = str(self.assem) | |
51 else: | |
52 cn = self.assem.__name__ | |
53 x = '{}, def={}, use={}, other={}' | |
54 x = x.format(cn, self.dst, self.src, self.others) | |
275 | 55 return x |
299 | 56 |