annotate python/ppci/irmach.py @ 357:818be710e13d

Added acceptance function to burg
author Windel Bouwman
date Fri, 14 Mar 2014 15:14:29 +0100
parents 3bb7dcfe5529
children 39bf68bf1891
rev   line source
261
444b9df2ed99 try to split up code generation
Windel Bouwman
parents:
diff changeset
1
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents: 268
diff changeset
2 """
270
cdc76d183bcc first register allocator
Windel Bouwman
parents: 269
diff changeset
3 Abstract assembly language instructions.
cdc76d183bcc first register allocator
Windel Bouwman
parents: 269
diff changeset
4
cdc76d183bcc first register allocator
Windel Bouwman
parents: 269
diff changeset
5 This is the second intermediate representation.
cdc76d183bcc first register allocator
Windel Bouwman
parents: 269
diff changeset
6
cdc76d183bcc first register allocator
Windel Bouwman
parents: 269
diff changeset
7 Instructions are selected and scheduled at this stage.
269
5f8c04a8d26b Towards better modularity
Windel Bouwman
parents: 268
diff changeset
8 """
261
444b9df2ed99 try to split up code generation
Windel Bouwman
parents:
diff changeset
9
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 323
diff changeset
10 from .target import Instruction
280
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 277
diff changeset
11
277
046017431c6a Started register allocator
Windel Bouwman
parents: 275
diff changeset
12
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
13 class Frame:
323
e9fe6988497c Used burg for generating expressions
Windel Bouwman
parents: 301
diff changeset
14 """
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
15 Activation record abstraction. This class contains a flattened
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
16 function. Instructions are selected and scheduled at this stage.
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
17 Frames differ per machine.
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
18 """
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
19 def __init__(self, name):
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
20 self.name = name
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
21 self.instructions = []
275
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
22 self.stacksize = 0
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
23
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
24 def __repr__(self):
275
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
25 return 'Frame {}'.format(self.name)
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
26
261
444b9df2ed99 try to split up code generation
Windel Bouwman
parents:
diff changeset
27
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
28 class AbstractInstruction:
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
29 """
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
30 Abstract machine instruction class. This is a very simple
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
31 abstraction of machine instructions.
ea93e0a7a31e Move docs
Windel Bouwman
parents: 270
diff changeset
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
86b02c98a717 Moved target directory
Windel Bouwman
parents: 323
diff changeset
34 assert type(cls) is type or isinstance(cls, Instruction), str(cls)
277
046017431c6a Started register allocator
Windel Bouwman
parents: 275
diff changeset
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
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
37 self.src = tuple(src)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
38 self.dst = tuple(dst)
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
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
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
42
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 261
diff changeset
43 def __repr__(self):
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 342
diff changeset
44 """ Substitutes source, dst and labels in the string """
323
e9fe6988497c Used burg for generating expressions
Windel Bouwman
parents: 301
diff changeset
45 if isinstance(self.assem, Instruction):
e9fe6988497c Used burg for generating expressions
Windel Bouwman
parents: 301
diff changeset
46 x = str(self.assem)
e9fe6988497c Used burg for generating expressions
Windel Bouwman
parents: 301
diff changeset
47 else:
e9fe6988497c Used burg for generating expressions
Windel Bouwman
parents: 301
diff changeset
48 cn = self.assem.__name__
e9fe6988497c Used burg for generating expressions
Windel Bouwman
parents: 301
diff changeset
49 x = '{}, def={}, use={}, other={}'
e9fe6988497c Used burg for generating expressions
Windel Bouwman
parents: 301
diff changeset
50 x = x.format(cn, self.dst, self.src, self.others)
275
6f2423df0675 Fixed serve arm-as
Windel Bouwman
parents: 274
diff changeset
51 return x
299
674789d9ff37 Added a doc
Windel Bouwman
parents: 292
diff changeset
52