Mercurial > lcfOS
diff 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 |
line wrap: on
line diff
--- a/python/irmach.py Wed Sep 04 17:35:06 2013 +0200 +++ b/python/irmach.py Sat Sep 14 17:29:10 2013 +0200 @@ -16,10 +16,13 @@ def __init__(self, name): self.name = name self.instructions = [] + self.stacksize = 0 def __repr__(self): - return 'Frame' + return 'Frame {}'.format(self.name) +def makeIns(*args, **kwargs): + return AbstractInstruction(*args, **kwargs) class AbstractInstruction: """ @@ -36,6 +39,24 @@ s = str(self.src) if self.src else '' d = str(self.dst) if self.dst else '' l = str(self.jumps) if self.jumps else '' - return self.assem + s + d + l + #return self.assem + s + d + l + return self.render() + + def render(self): + """ + Substitutes source, dst and labels in the string + """ + x = self.assem + for i, s in enumerate(self.src): + p = '%s{}'.format(i) + x = x.replace(p, str(s)) + for i, d in enumerate(self.dst): + p = '%d{}'.format(i) + x = x.replace(p, str(d)) + for i, j in enumerate(self.jumps): + p = '%l{}'.format(i) + x = x.replace(p, str(j)) + + return x