Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pyc_var_analyzer: live_list computation

  • Loading branch information...
commit 162ac10691f28646d66c5b90405dc700d59a5047 1 parent 385293a
cantora authored
Showing with 73 additions and 4 deletions.
  1. +19 −0 analyze_test.py
  2. +10 −4 pyc
  3. +44 −0 pyc_var_analyzer.py
View
19 analyze_test.py
@@ -0,0 +1,19 @@
+import pyc_var_analyzer
+from pyc_asm_nodes import *
+
+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)])
View
14 pyc
@@ -4,6 +4,7 @@ import argparse
import sys
import pyc_ast
import pyc_asm_list
+import pyc_var_analyzer
from pyc_log import *
import os.path
@@ -60,6 +61,13 @@ def run(options):
asm_list = pyc_asm_list.from_ss_list(ss_list)
+ asm_list = reduce(lambda a,b: a + b, asm_list)
+ for n in asm_list:
+ log(repr(n))
+
+ pyc_var_analyzer.interference_graph(asm_list)
+
+ exit()
insns = []
insns.extend(asm_prefix())
@@ -67,10 +75,8 @@ def run(options):
# insns.append("subl\t$%s, %%esp" % sym_tbl.stack)
log("asm list:")
- for ins_list in asm_list:
- for ins in ins_list:
- log(repr(ins))
- insns.append(str(ins))
+ for ins in asm_list:
+ insns.append(str(ins))
insns.extend(asm_suffix())
View
44 pyc_var_analyzer.py
@@ -0,0 +1,44 @@
+from pyc_log import *
+from pyc_asm_nodes import VarOperandDesc
+
+def interference_graph(asm_list):
+ live_list = to_live_list(asm_list)
+ log(lambda: "live_list:\n\t%s" % "\n\t".join([repr(x) for x in reversed(live_list)]))
+
+ return None
+
+def is_read_op(op):
+ return isinstance(op, VarOperandDesc) \
+ and VarOperandDesc.READ in op.modes
+
+
+def is_write_op(op):
+ return isinstance(op, VarOperandDesc) \
+ and set([VarOperandDesc.WRITE]) == op.modes
+
+
+def to_live_list(asm_list):
+ result = []
+ live = set([])
+
+ log("process asm_list into live_list")
+ for ins in reversed(asm_list):
+ log("ins: %s" % ins)
+ #log("operands: %s" % repr(ins.operands()))
+ writes = []
+ reads = []
+ for op_desc in ins.operands():
+ if is_write_op(op_desc):
+ writes.append(op_desc.operand)
+ elif is_read_op(op_desc):
+ reads.append(op_desc.operand)
+
+ live = (live - set(writes) ) | set(reads)
+
+ result.append(set(live))
+ log("live: %s" % repr(live))
+
+ return result
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.