Mercurial > lcfOS
comparison python/ppci/ir2tree.py @ 323:e9fe6988497c
Used burg for generating expressions
author | Windel Bouwman |
---|---|
date | Thu, 30 Jan 2014 19:03:24 +0100 |
parents | 44f336460c2a |
children | 5477e499b039 |
comparison
equal
deleted
inserted
replaced
322:44f336460c2a | 323:e9fe6988497c |
---|---|
1 from tree import Tree | 1 from tree import Tree |
2 from . import ir | 2 from . import ir |
3 | |
4 """ Create a tree from ir code. """ | |
3 | 5 |
4 f_map = {} # Mapping from types to tree creation functions | 6 f_map = {} # Mapping from types to tree creation functions |
5 | 7 |
6 def register(tp): | 8 def register(tp): |
7 """ Register a function for type tp """ | 9 """ Register a function for type tp """ |
33 def mem_to_tree(e): | 35 def mem_to_tree(e): |
34 return Tree('MEMI32', makeTree(e.e)) | 36 return Tree('MEMI32', makeTree(e.e)) |
35 | 37 |
36 @register(ir.Call) | 38 @register(ir.Call) |
37 def call_to_tree(e): | 39 def call_to_tree(e): |
38 return Tree('CALL') | 40 t = Tree('CALL') |
41 t.value = e | |
42 return t | |
39 | 43 |
40 def makeTree(ir_node): | 44 def makeTree(ir_node): |
41 """ Transform an ir node into a tree usable for matching """ | 45 """ Transform an ir node into a tree usable for matching """ |
42 return f_map[type(ir_node)](ir_node) | 46 return f_map[type(ir_node)](ir_node) |