Mercurial > lcfOS
view python/ppci/ir2tree.py @ 322:44f336460c2a
Half of use of burg spec for arm
author | Windel Bouwman |
---|---|
date | Mon, 27 Jan 2014 19:58:07 +0100 |
parents | |
children | e9fe6988497c |
line wrap: on
line source
from tree import Tree from . import ir f_map = {} # Mapping from types to tree creation functions def register(tp): """ Register a function for type tp """ def reg_f(f): f_map[tp] = f return f return reg_f @register(ir.Binop) def binop_to_tree(e): names = {'+':'ADDI32', '-':'SUBI32', '|':'ORI32', '<<':'SHLI32', '*':'MULI32'} op = names[e.operation] return Tree(op, makeTree(e.a), makeTree(e.b)) @register(ir.Temp) def temp_to_tree(e): t = Tree('REGI32') t.value = e return t @register(ir.Const) def const_to_tree(e): t = Tree('CONSTI32') t.value = e.value return t @register(ir.Mem) def mem_to_tree(e): return Tree('MEMI32', makeTree(e.e)) @register(ir.Call) def call_to_tree(e): return Tree('CALL') def makeTree(ir_node): """ Transform an ir node into a tree usable for matching """ return f_map[type(ir_node)](ir_node)