-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathanalyze_test.py
More file actions
executable file
·37 lines (26 loc) · 1.23 KB
/
analyze_test.py
File metadata and controls
executable file
·37 lines (26 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
import pyc_var_analyzer
from pyc_asm_nodes import *
import pyc_reg_allocator
asm_list = [
Mov(Immed(Int(4)), Var("z")),
Mov(Immed(Int(0)), Var("w")),
Mov(Immed(Int(1)), Var("z")),
Mov(Var("w"), Var("x")),
Add(Var("z"), Var("x")),
Mov(Var("w"), Var("y")),
Add(Var("x"), Var("y")),
Mov(Var("y"), Var("w")),
Add(Var("x"), Var("w"))
]
live_list = pyc_var_analyzer.to_live_list(asm_list)
print ""
print "live_list:\n\t%s" % "\n\t".join([repr(x) for x in reversed(live_list)])
graph = pyc_var_analyzer.to_intf_graph(live_list)
print "graph:\n\t%s" % "\n\t".join(["%s: %s" % (repr(k), repr(v)) for (k,v) in graph.items()])
memallocs = pyc_reg_allocator.alloc(live_list, graph)
print "mem allocation offsets:\n\t%s" % "\n\t".join(["%s: %s" % (repr(k), repr(v)) for (k,v) in memallocs.items()])
print "mem allocations:\n\t%s" % "\n\t".join(["%s: %s" % (repr(k), repr(pyc_reg_allocator.index_to_loc(v))) for (k,v) in memallocs.items()])
(has_alts, patched_asm_list) = pyc_reg_allocator.patch(asm_list, memallocs)
print "patched asm list (has_alts = %d):\n\t%s" % (has_alts, "\n\t".join([("%s" % repr(x) ) for x in patched_asm_list]))
print "final asm code: \n\t%s" % "\n\t".join([str(ins) for ins in patched_asm_list])