Mercurial > lcfOS
comparison python/irmach.py @ 275:6f2423df0675
Fixed serve arm-as
author | Windel Bouwman |
---|---|
date | Sat, 14 Sep 2013 17:29:10 +0200 |
parents | ea93e0a7a31e |
children | 046017431c6a |
comparison
equal
deleted
inserted
replaced
274:ea93e0a7a31e | 275:6f2423df0675 |
---|---|
14 Frames differ per machine. | 14 Frames differ per machine. |
15 """ | 15 """ |
16 def __init__(self, name): | 16 def __init__(self, name): |
17 self.name = name | 17 self.name = name |
18 self.instructions = [] | 18 self.instructions = [] |
19 self.stacksize = 0 | |
19 | 20 |
20 def __repr__(self): | 21 def __repr__(self): |
21 return 'Frame' | 22 return 'Frame {}'.format(self.name) |
22 | 23 |
24 def makeIns(*args, **kwargs): | |
25 return AbstractInstruction(*args, **kwargs) | |
23 | 26 |
24 class AbstractInstruction: | 27 class AbstractInstruction: |
25 """ | 28 """ |
26 Abstract machine instruction class. This is a very simple | 29 Abstract machine instruction class. This is a very simple |
27 abstraction of machine instructions. | 30 abstraction of machine instructions. |
34 | 37 |
35 def __repr__(self): | 38 def __repr__(self): |
36 s = str(self.src) if self.src else '' | 39 s = str(self.src) if self.src else '' |
37 d = str(self.dst) if self.dst else '' | 40 d = str(self.dst) if self.dst else '' |
38 l = str(self.jumps) if self.jumps else '' | 41 l = str(self.jumps) if self.jumps else '' |
39 return self.assem + s + d + l | 42 #return self.assem + s + d + l |
43 return self.render() | |
44 | |
45 def render(self): | |
46 """ | |
47 Substitutes source, dst and labels in the string | |
48 """ | |
49 x = self.assem | |
50 for i, s in enumerate(self.src): | |
51 p = '%s{}'.format(i) | |
52 x = x.replace(p, str(s)) | |
53 for i, d in enumerate(self.dst): | |
54 p = '%d{}'.format(i) | |
55 x = x.replace(p, str(d)) | |
56 for i, j in enumerate(self.jumps): | |
57 p = '%l{}'.format(i) | |
58 x = x.replace(p, str(j)) | |
59 | |
60 return x | |
40 | 61 |
41 | 62 |