Mercurial > lcfOS
diff python/irmach.py @ 280:02385f62f250
Rework from str interface to Instruction interface
author | Windel Bouwman |
---|---|
date | Sat, 02 Nov 2013 10:03:26 +0100 |
parents | 046017431c6a |
children | 534b94b40aa8 |
line wrap: on
line diff
--- a/python/irmach.py Sat Oct 12 09:56:23 2013 +0200 +++ b/python/irmach.py Sat Nov 02 10:03:26 2013 +0100 @@ -8,6 +8,8 @@ """ import ir +import target + class Frame: """ @@ -23,22 +25,29 @@ def __repr__(self): return 'Frame {}'.format(self.name) -def makeIns(*args, **kwargs): - return AbstractInstruction(*args, **kwargs) + def lower_to(self, outs): + for im in self.instructions: + if isinstance(im.assem, target.Instruction): + outs.emit(im.assem) + else: + outs.emit(im.assem.fromim(im)) + class AbstractInstruction: """ Abstract machine instruction class. This is a very simple abstraction of machine instructions. """ - def __init__(self, cls, ops=(), src=(), dst=(), jumps=()): + def __init__(self, cls, ops=(), src=(), dst=(), jumps=(), others=(), ismove=False): + assert type(cls) is type or isinstance(cls, target.Instruction) self.assem = cls - self.ops = ops + self.ops = tuple(ops) self.src = tuple(src) self.dst = tuple(dst) self.jumps = tuple(jumps) + self.others = tuple(others) c = lambda s: tuple(map(type, s)) == (ir.Temp, ) - self.ismove = c(src) and c(dst) and cls.lower().startswith('mov') + self.ismove = ismove def __repr__(self): return self.render()