Mercurial > lcfOS
annotate python/ppci/irmach.py @ 365:98ff43cfdd36
Nasty bug in adr instruction
author | Windel Bouwman |
---|---|
date | Wed, 19 Mar 2014 22:32:04 +0100 |
parents | 3bb7dcfe5529 |
children | 39bf68bf1891 |
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 |
43 def __repr__(self): | |
346 | 44 """ Substitutes source, dst and labels in the string """ |
323 | 45 if isinstance(self.assem, Instruction): |
46 x = str(self.assem) | |
47 else: | |
48 cn = self.assem.__name__ | |
49 x = '{}, def={}, use={}, other={}' | |
50 x = x.format(cn, self.dst, self.src, self.others) | |
275 | 51 return x |
299 | 52 |