annotate 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
rev   line source
322
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
1 from tree import Tree
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
2 from . import ir
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
3
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
4 f_map = {} # Mapping from types to tree creation functions
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
5
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
6 def register(tp):
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
7 """ Register a function for type tp """
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
8 def reg_f(f):
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
9 f_map[tp] = f
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
10 return f
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
11 return reg_f
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
12
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
13 @register(ir.Binop)
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
14 def binop_to_tree(e):
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
15 names = {'+':'ADDI32', '-':'SUBI32', '|':'ORI32', '<<':'SHLI32',
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
16 '*':'MULI32'}
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
17 op = names[e.operation]
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
18 return Tree(op, makeTree(e.a), makeTree(e.b))
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
19
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
20 @register(ir.Temp)
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
21 def temp_to_tree(e):
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
22 t = Tree('REGI32')
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
23 t.value = e
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
24 return t
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
25
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
26 @register(ir.Const)
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
27 def const_to_tree(e):
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
28 t = Tree('CONSTI32')
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
29 t.value = e.value
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
30 return t
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
31
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
32 @register(ir.Mem)
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
33 def mem_to_tree(e):
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
34 return Tree('MEMI32', makeTree(e.e))
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
35
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
36 @register(ir.Call)
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
37 def call_to_tree(e):
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
38 return Tree('CALL')
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
39
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
40 def makeTree(ir_node):
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
41 """ Transform an ir node into a tree usable for matching """
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents:
diff changeset
42 return f_map[type(ir_node)](ir_node)