diff options
Diffstat (limited to 'test/analysis')
| -rw-r--r-- | test/analysis/data_flow.py | 362 | ||||
| -rw-r--r-- | test/analysis/depgraph.py | 654 | ||||
| -rw-r--r-- | test/analysis/dg_test_02_implicit_expected.json | 2 | ||||
| -rw-r--r-- | test/analysis/dg_test_04_expected.json | 2 | ||||
| -rw-r--r-- | test/analysis/dg_test_04_implicit_expected.json | 2 | ||||
| -rw-r--r-- | test/analysis/dg_test_06_implicit_expected.json | 2 | ||||
| -rw-r--r-- | test/analysis/dg_test_10_implicit_expected.json | 2 | ||||
| -rw-r--r-- | test/analysis/dse.py | 11 |
8 files changed, 583 insertions, 454 deletions
diff --git a/test/analysis/data_flow.py b/test/analysis/data_flow.py index d0a85e13..d0dbbd8d 100644 --- a/test/analysis/data_flow.py +++ b/test/analysis/data_flow.py @@ -1,10 +1,12 @@ """ Test cases for dead code elimination""" from miasm2.expression.expression import ExprId, ExprInt, ExprAff, ExprMem -from miasm2.core.asmblock import AsmLabel +from miasm2.core.locationdb import LocationDB from miasm2.analysis.data_flow import * from miasm2.ir.analysis import ira from miasm2.ir.ir import IRBlock, AssignBlock +loc_db = LocationDB() + a = ExprId("a", 32) b = ExprId("b", 32) c = ExprId("c", 32) @@ -24,13 +26,13 @@ CST1 = ExprInt(0x11, 32) CST2 = ExprInt(0x12, 32) CST3 = ExprInt(0x13, 32) -LBL0 = AsmLabel("lbl0") -LBL1 = AsmLabel("lbl1") -LBL2 = AsmLabel("lbl2") -LBL3 = AsmLabel("lbl3") -LBL4 = AsmLabel("lbl4") -LBL5 = AsmLabel("lbl5") -LBL6 = AsmLabel("lbl6") +LBL0 = loc_db.add_location("lbl0", 0) +LBL1 = loc_db.add_location("lbl1", 1) +LBL2 = loc_db.add_location("lbl2", 2) +LBL3 = loc_db.add_location("lbl3", 3) +LBL4 = loc_db.add_location("lbl4", 4) +LBL5 = loc_db.add_location("lbl5", 5) +LBL6 = loc_db.add_location("lbl6", 6) IRDst = ExprId('IRDst', 32) dummy = ExprId('dummy', 32) @@ -66,117 +68,122 @@ class IRATest(ira): """Fake IRA class for tests""" - def __init__(self, symbol_pool=None): + def __init__(self, loc_db=None): arch = Arch() - super(IRATest, self).__init__(arch, 32, symbol_pool) + super(IRATest, self).__init__(arch, 32, loc_db) self.IRDst = IRDst self.ret_reg = r def get_out_regs(self, _): return set([self.ret_reg, self.sp]) +IRA = IRATest(loc_db) + # graph 1 : Simple graph with dead and alive variables -G1_IRA = IRATest() +G1_IRA = IRA.new_ircfg() G1_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST2)]]) G1_IRB1 = gen_irblock(LBL1, [[ExprAff(a, b)]]) G1_IRB2 = gen_irblock(LBL2, [[ExprAff(r, a)]]) -G1_IRA.blocks = {irb.label : irb for irb in [G1_IRB0, G1_IRB1, G1_IRB2]} +for irb in [G1_IRB0, G1_IRB1, G1_IRB2]: + G1_IRA.add_irblock(irb) -G1_IRA.graph.add_uniq_edge(G1_IRB0.label, G1_IRB1.label) -G1_IRA.graph.add_uniq_edge(G1_IRB1.label, G1_IRB2.label) +G1_IRA.add_uniq_edge(G1_IRB0.loc_key, G1_IRB1.loc_key) +G1_IRA.add_uniq_edge(G1_IRB1.loc_key, G1_IRB2.loc_key) # Expected output for graph 1 -G1_EXP_IRA = IRATest() +G1_EXP_IRA = IRA.new_ircfg() G1_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(b, CST2)]]) G1_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(a, b)]]) G1_EXP_IRB2 = gen_irblock(LBL2, [[ExprAff(r, a)]]) -G1_EXP_IRA.blocks = {irb.label : irb for irb in [G1_EXP_IRB0, G1_EXP_IRB1, - G1_EXP_IRB2]} +for irb in [G1_EXP_IRB0, G1_EXP_IRB1, G1_EXP_IRB2]: + G1_EXP_IRA.add_irblock(irb) # graph 2 : Natural loop with dead variable -G2_IRA = IRATest() +G2_IRA = IRA.new_ircfg() G2_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(r, CST1)]]) G2_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]]) G2_IRB2 = gen_irblock(LBL2, [[ExprAff(a, r)]]) -G2_IRA.blocks = {irb.label : irb for irb in [G2_IRB0, G2_IRB1, G2_IRB2]} +for irb in [G2_IRB0, G2_IRB1, G2_IRB2]: + G2_IRA.add_irblock(irb) -G2_IRA.graph.add_uniq_edge(G2_IRB0.label, G2_IRB1.label) -G2_IRA.graph.add_uniq_edge(G2_IRB1.label, G2_IRB2.label) -G2_IRA.graph.add_uniq_edge(G2_IRB1.label, G2_IRB1.label) +G2_IRA.add_uniq_edge(G2_IRB0.loc_key, G2_IRB1.loc_key) +G2_IRA.add_uniq_edge(G2_IRB1.loc_key, G2_IRB2.loc_key) +G2_IRA.add_uniq_edge(G2_IRB1.loc_key, G2_IRB1.loc_key) # Expected output for graph 2 -G2_EXP_IRA = IRATest() +G2_EXP_IRA = IRA.new_ircfg() G2_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(r, CST1)]]) G2_EXP_IRB1 = gen_irblock(LBL1, [[]]) G2_EXP_IRB2 = gen_irblock(LBL2, [[]]) -G2_EXP_IRA.blocks = {irb.label : irb for irb in [G2_EXP_IRB0, G2_EXP_IRB1, - G2_EXP_IRB2]} +for irb in [G2_EXP_IRB0, G2_EXP_IRB1, G2_EXP_IRB2]: + G2_EXP_IRA.add_irblock(irb) # graph 3 : Natural loop with alive variables -G3_IRA = IRATest() +G3_IRA = IRA.new_ircfg() G3_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]]) G3_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]]) G3_IRB2 = gen_irblock(LBL2, [[ExprAff(r, a)]]) -G3_IRA.blocks = {irb.label : irb for irb in [G3_IRB0, G3_IRB1, G3_IRB2]} +for irb in [G3_IRB0, G3_IRB1, G3_IRB2]: + G3_IRA.add_irblock(irb) -G3_IRA.graph.add_uniq_edge(G3_IRB0.label, G3_IRB1.label) -G3_IRA.graph.add_uniq_edge(G3_IRB1.label, G3_IRB2.label) -G3_IRA.graph.add_uniq_edge(G3_IRB1.label, G3_IRB1.label) +G3_IRA.add_uniq_edge(G3_IRB0.loc_key, G3_IRB1.loc_key) +G3_IRA.add_uniq_edge(G3_IRB1.loc_key, G3_IRB2.loc_key) +G3_IRA.add_uniq_edge(G3_IRB1.loc_key, G3_IRB1.loc_key) # Expected output for graph 3 -G3_EXP_IRA = IRATest() +G3_EXP_IRA = IRA.new_ircfg() G3_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]]) G3_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]]) G3_EXP_IRB2 = gen_irblock(LBL2, [[ExprAff(r, a)]]) -G3_EXP_IRA.blocks = {irb.label : irb for irb in [G3_EXP_IRB0, G3_EXP_IRB1, - G3_EXP_IRB2]} +for irb in [G3_EXP_IRB0, G3_EXP_IRB1, G3_EXP_IRB2]: + G3_EXP_IRA.add_irblock(irb) # graph 4 : If/else with dead variables -G4_IRA = IRATest() +G4_IRA = IRA.new_ircfg() G4_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]]) G4_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]]) G4_IRB2 = gen_irblock(LBL2, [[ExprAff(a, a+CST2)]]) G4_IRB3 = gen_irblock(LBL3, [[ExprAff(a, CST3)], [ExprAff(r, a)]]) -G4_IRA.blocks = {irb.label : irb for irb in [G4_IRB0, G4_IRB1, G4_IRB2, - G4_IRB3]} +for irb in [G4_IRB0, G4_IRB1, G4_IRB2, G4_IRB3]: + G4_IRA.add_irblock(irb) -G4_IRA.graph.add_uniq_edge(G4_IRB0.label, G4_IRB1.label) -G4_IRA.graph.add_uniq_edge(G4_IRB0.label, G4_IRB2.label) -G4_IRA.graph.add_uniq_edge(G4_IRB1.label, G4_IRB3.label) -G4_IRA.graph.add_uniq_edge(G4_IRB2.label, G4_IRB3.label) +G4_IRA.add_uniq_edge(G4_IRB0.loc_key, G4_IRB1.loc_key) +G4_IRA.add_uniq_edge(G4_IRB0.loc_key, G4_IRB2.loc_key) +G4_IRA.add_uniq_edge(G4_IRB1.loc_key, G4_IRB3.loc_key) +G4_IRA.add_uniq_edge(G4_IRB2.loc_key, G4_IRB3.loc_key) # Expected output for graph 4 -G4_EXP_IRA = IRATest() +G4_EXP_IRA = IRA.new_ircfg() G4_EXP_IRB0 = gen_irblock(LBL0, [[]]) G4_EXP_IRB1 = gen_irblock(LBL1, [[]]) G4_EXP_IRB2 = gen_irblock(LBL2, [[]]) G4_EXP_IRB3 = gen_irblock(LBL3, [[ExprAff(a, CST3)], [ExprAff(r, a)]]) -G4_EXP_IRA.blocks = {irb.label : irb for irb in [G4_EXP_IRB0, G4_EXP_IRB1, - G4_EXP_IRB2, G4_EXP_IRB3]} +for irb in [G4_EXP_IRB0, G4_EXP_IRB1, G4_EXP_IRB2, G4_EXP_IRB3]: + G4_EXP_IRA.add_irblock(irb) # graph 5 : Loop and If/else with dead variables -G5_IRA = IRATest() +G5_IRA = IRA.new_ircfg() G5_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]]) G5_IRB1 = gen_irblock(LBL1, [[ExprAff(r, CST2)]]) @@ -185,19 +192,19 @@ G5_IRB3 = gen_irblock(LBL3, [[ExprAff(a, a+CST3)]]) G5_IRB4 = gen_irblock(LBL4, [[ExprAff(a, a+CST1)]]) G5_IRB5 = gen_irblock(LBL5, [[ExprAff(a, r)]]) -G5_IRA.blocks = {irb.label : irb for irb in [G5_IRB0, G5_IRB1, G5_IRB2, G5_IRB3, - G5_IRB4, G5_IRB5]} +for irb in [G5_IRB0, G5_IRB1, G5_IRB2, G5_IRB3, G5_IRB4, G5_IRB5]: + G5_IRA.add_irblock(irb) -G5_IRA.graph.add_uniq_edge(G5_IRB0.label, G5_IRB1.label) -G5_IRA.graph.add_uniq_edge(G5_IRB1.label, G5_IRB2.label) -G5_IRA.graph.add_uniq_edge(G5_IRB1.label, G5_IRB3.label) -G5_IRA.graph.add_uniq_edge(G5_IRB2.label, G5_IRB4.label) -G5_IRA.graph.add_uniq_edge(G5_IRB3.label, G5_IRB4.label) -G5_IRA.graph.add_uniq_edge(G5_IRB4.label, G5_IRB5.label) -G5_IRA.graph.add_uniq_edge(G5_IRB4.label, G5_IRB1.label) +G5_IRA.add_uniq_edge(G5_IRB0.loc_key, G5_IRB1.loc_key) +G5_IRA.add_uniq_edge(G5_IRB1.loc_key, G5_IRB2.loc_key) +G5_IRA.add_uniq_edge(G5_IRB1.loc_key, G5_IRB3.loc_key) +G5_IRA.add_uniq_edge(G5_IRB2.loc_key, G5_IRB4.loc_key) +G5_IRA.add_uniq_edge(G5_IRB3.loc_key, G5_IRB4.loc_key) +G5_IRA.add_uniq_edge(G5_IRB4.loc_key, G5_IRB5.loc_key) +G5_IRA.add_uniq_edge(G5_IRB4.loc_key, G5_IRB1.loc_key) # Expected output for graph 5 -G5_EXP_IRA = IRATest() +G5_EXP_IRA = IRA.new_ircfg() G5_EXP_IRB0 = gen_irblock(LBL0, [[]]) G5_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, CST2)]]) @@ -206,72 +213,72 @@ G5_EXP_IRB3 = gen_irblock(LBL3, [[]]) G5_EXP_IRB4 = gen_irblock(LBL4, [[]]) G5_EXP_IRB5 = gen_irblock(LBL5, [[]]) -G5_EXP_IRA.blocks = {irb.label : irb for irb in [G5_EXP_IRB0, G5_EXP_IRB1, - G5_EXP_IRB2, G5_EXP_IRB3, - G5_EXP_IRB4, G5_EXP_IRB5]} +for irb in [G5_EXP_IRB0, G5_EXP_IRB1, G5_EXP_IRB2, + G5_EXP_IRB3, G5_EXP_IRB4, G5_EXP_IRB5]: + G5_EXP_IRA.add_irblock(irb) # graph 6 : Natural loop with dead variables symetric affectation # (a = b <-> b = a ) -G6_IRA = IRATest() +G6_IRA = IRA.new_ircfg() G6_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]]) G6_IRB1 = gen_irblock(LBL1, [[ExprAff(b, a)]]) G6_IRB2 = gen_irblock(LBL2, [[ExprAff(a, b)]]) G6_IRB3 = gen_irblock(LBL3, [[ExprAff(r, CST2)]]) -G6_IRA.blocks = {irb.label : irb for irb in [G6_IRB0, G6_IRB1, G6_IRB2, - G6_IRB3]} +for irb in [G6_IRB0, G6_IRB1, G6_IRB2, G6_IRB3]: + G6_IRA.add_irblock(irb) -G6_IRA.graph.add_uniq_edge(G6_IRB0.label, G6_IRB1.label) -G6_IRA.graph.add_uniq_edge(G6_IRB1.label, G6_IRB2.label) -G6_IRA.graph.add_uniq_edge(G6_IRB2.label, G6_IRB1.label) -G6_IRA.graph.add_uniq_edge(G6_IRB2.label, G6_IRB3.label) +G6_IRA.add_uniq_edge(G6_IRB0.loc_key, G6_IRB1.loc_key) +G6_IRA.add_uniq_edge(G6_IRB1.loc_key, G6_IRB2.loc_key) +G6_IRA.add_uniq_edge(G6_IRB2.loc_key, G6_IRB1.loc_key) +G6_IRA.add_uniq_edge(G6_IRB2.loc_key, G6_IRB3.loc_key) # Expected output for graph 6 -G6_EXP_IRA = IRATest() +G6_EXP_IRA = IRA.new_ircfg() G6_EXP_IRB0 = gen_irblock(LBL0, [[]]) G6_EXP_IRB1 = gen_irblock(LBL1, [[]]) G6_EXP_IRB2 = gen_irblock(LBL2, [[]]) G6_EXP_IRB3 = gen_irblock(LBL3, [[ExprAff(r, CST2)]]) -G6_EXP_IRA.blocks = {irb.label : irb for irb in [G6_EXP_IRB0, G6_EXP_IRB1, - G6_EXP_IRB2, G6_EXP_IRB3]} +for irb in [G6_EXP_IRB0, G6_EXP_IRB1, G6_EXP_IRB2, G6_EXP_IRB3]: + G6_EXP_IRA.add_irblock(irb) # graph 7 : Double entry loop with dead variables -G7_IRA = IRATest() +G7_IRA = IRA.new_ircfg() G7_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(r, CST1)]]) G7_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]]) G7_IRB2 = gen_irblock(LBL2, [[ExprAff(a, a+CST2)]]) G7_IRB3 = gen_irblock(LBL3, [[ExprAff(a, r)]]) -G7_IRA.blocks = {irb.label : irb for irb in [G7_IRB0, G7_IRB1, G7_IRB2, - G7_IRB3]} +for irb in [G7_IRB0, G7_IRB1, G7_IRB2, G7_IRB3]: + G7_IRA.add_irblock(irb) -G7_IRA.graph.add_uniq_edge(G7_IRB0.label, G7_IRB1.label) -G7_IRA.graph.add_uniq_edge(G7_IRB1.label, G7_IRB2.label) -G7_IRA.graph.add_uniq_edge(G7_IRB2.label, G7_IRB1.label) -G7_IRA.graph.add_uniq_edge(G7_IRB2.label, G7_IRB3.label) -G7_IRA.graph.add_uniq_edge(G7_IRB0.label, G7_IRB2.label) +G7_IRA.add_uniq_edge(G7_IRB0.loc_key, G7_IRB1.loc_key) +G7_IRA.add_uniq_edge(G7_IRB1.loc_key, G7_IRB2.loc_key) +G7_IRA.add_uniq_edge(G7_IRB2.loc_key, G7_IRB1.loc_key) +G7_IRA.add_uniq_edge(G7_IRB2.loc_key, G7_IRB3.loc_key) +G7_IRA.add_uniq_edge(G7_IRB0.loc_key, G7_IRB2.loc_key) # Expected output for graph 7 -G7_EXP_IRA = IRATest() +G7_EXP_IRA = IRA.new_ircfg() G7_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(r, CST1)]]) G7_EXP_IRB1 = gen_irblock(LBL1, [[]]) G7_EXP_IRB2 = gen_irblock(LBL2, [[]]) G7_EXP_IRB3 = gen_irblock(LBL3, [[]]) -G7_EXP_IRA.blocks = {irb.label : irb for irb in [G7_EXP_IRB0, G7_EXP_IRB1, - G7_EXP_IRB2, G7_EXP_IRB3]} +for irb in [G7_EXP_IRB0, G7_EXP_IRB1, G7_EXP_IRB2, G7_EXP_IRB3]: + G7_EXP_IRA.add_irblock(irb) # graph 8 : Nested loops with dead variables -G8_IRA = IRATest() +G8_IRA = IRA.new_ircfg() G8_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST1)]]) G8_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]]) @@ -279,31 +286,31 @@ G8_IRB2 = gen_irblock(LBL2, [[ExprAff(b, b+CST2)]]) G8_IRB3 = gen_irblock(LBL3, [[ExprAff(a, b)]]) -G8_IRA.blocks = {irb.label : irb for irb in [G8_IRB0, G8_IRB1, G8_IRB2, - G8_IRB3]} +for irb in [G8_IRB0, G8_IRB1, G8_IRB2, G8_IRB3]: + G8_IRA.add_irblock(irb) -G8_IRA.graph.add_uniq_edge(G8_IRB0.label, G8_IRB1.label) -G8_IRA.graph.add_uniq_edge(G8_IRB1.label, G8_IRB2.label) -G8_IRA.graph.add_uniq_edge(G8_IRB2.label, G8_IRB1.label) -G8_IRA.graph.add_uniq_edge(G8_IRB2.label, G8_IRB3.label) -G8_IRA.graph.add_uniq_edge(G8_IRB3.label, G8_IRB2.label) +G8_IRA.add_uniq_edge(G8_IRB0.loc_key, G8_IRB1.loc_key) +G8_IRA.add_uniq_edge(G8_IRB1.loc_key, G8_IRB2.loc_key) +G8_IRA.add_uniq_edge(G8_IRB2.loc_key, G8_IRB1.loc_key) +G8_IRA.add_uniq_edge(G8_IRB2.loc_key, G8_IRB3.loc_key) +G8_IRA.add_uniq_edge(G8_IRB3.loc_key, G8_IRB2.loc_key) # Expected output for graph 8 -G8_EXP_IRA = IRATest() +G8_EXP_IRA = IRA.new_ircfg() G8_EXP_IRB0 = gen_irblock(LBL0, [[], []]) G8_EXP_IRB1 = gen_irblock(LBL1, [[]]) G8_EXP_IRB2 = gen_irblock(LBL2, [[]]) G8_EXP_IRB3 = gen_irblock(LBL3, [[]]) -G8_EXP_IRA.blocks = {irb.label : irb for irb in [G8_EXP_IRB0, G8_EXP_IRB1, - G8_EXP_IRB2, G8_EXP_IRB3]} +for irb in [G8_EXP_IRB0, G8_EXP_IRB1, G8_EXP_IRB2, G8_EXP_IRB3]: + G8_EXP_IRA.add_irblock(irb) # graph 9 : Miultiple-exits loops with dead variables -G9_IRA = IRATest() +G9_IRA = IRA.new_ircfg() G9_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST1)]]) G9_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)], [ExprAff(b, b+CST1)]]) @@ -311,22 +318,22 @@ G9_IRB2 = gen_irblock(LBL2, [[ExprAff(a, a+CST2)], [ExprAff(b, b+CST2)]]) G9_IRB3 = gen_irblock(LBL3, [[ExprAff(a, b)]]) G9_IRB4 = gen_irblock(LBL4, [[ExprAff(r, a)], [ExprAff(r, b)]]) -G9_IRA.blocks = {irb.label : irb for irb in [G9_IRB0, G9_IRB1, G9_IRB2, - G9_IRB3, G9_IRB4]} +for irb in [G9_IRB0, G9_IRB1, G9_IRB2, G9_IRB3, G9_IRB4]: + G9_IRA.add_irblock(irb) -G9_IRA.graph.add_uniq_edge(G9_IRB0.label, G9_IRB4.label) -G9_IRA.graph.add_uniq_edge(G9_IRB0.label, G9_IRB1.label) -G9_IRA.graph.add_uniq_edge(G9_IRB1.label, G9_IRB0.label) -G9_IRA.graph.add_uniq_edge(G9_IRB1.label, G9_IRB4.label) -G9_IRA.graph.add_uniq_edge(G9_IRB1.label, G9_IRB2.label) -G9_IRA.graph.add_uniq_edge(G9_IRB2.label, G9_IRB0.label) -G9_IRA.graph.add_uniq_edge(G9_IRB2.label, G9_IRB3.label) -G9_IRA.graph.add_uniq_edge(G9_IRB3.label, G9_IRB4.label) +G9_IRA.add_uniq_edge(G9_IRB0.loc_key, G9_IRB4.loc_key) +G9_IRA.add_uniq_edge(G9_IRB0.loc_key, G9_IRB1.loc_key) +G9_IRA.add_uniq_edge(G9_IRB1.loc_key, G9_IRB0.loc_key) +G9_IRA.add_uniq_edge(G9_IRB1.loc_key, G9_IRB4.loc_key) +G9_IRA.add_uniq_edge(G9_IRB1.loc_key, G9_IRB2.loc_key) +G9_IRA.add_uniq_edge(G9_IRB2.loc_key, G9_IRB0.loc_key) +G9_IRA.add_uniq_edge(G9_IRB2.loc_key, G9_IRB3.loc_key) +G9_IRA.add_uniq_edge(G9_IRB3.loc_key, G9_IRB4.loc_key) # Expected output for graph 9 -G9_EXP_IRA = IRATest() +G9_EXP_IRA = IRA.new_ircfg() G9_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(b, CST1)]]) G9_EXP_IRB1 = gen_irblock(LBL1, [[], [ExprAff(b, b+CST1)]]) @@ -334,42 +341,42 @@ G9_EXP_IRB2 = gen_irblock(LBL2, [[], [ExprAff(b, b+CST2)]]) G9_EXP_IRB3 = gen_irblock(LBL3, [[]]) G9_EXP_IRB4 = gen_irblock(LBL4, [[], [ExprAff(r, b)]]) -G9_EXP_IRA.blocks = {irb.label : irb for irb in [G9_EXP_IRB0, G9_EXP_IRB1, - G9_EXP_IRB2, G9_EXP_IRB3, - G9_EXP_IRB4]} +for irb in [G9_EXP_IRB0, G9_EXP_IRB1, G9_EXP_IRB2, G9_EXP_IRB3, G9_EXP_IRB4]: + G9_EXP_IRA.add_irblock(irb) # graph 10 : Natural loop with alive variables symetric affectation # (a = b <-> b = a ) -G10_IRA = IRATest() +G10_IRA = IRA.new_ircfg() G10_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]]) G10_IRB1 = gen_irblock(LBL1, [[ExprAff(b, a)]]) G10_IRB2 = gen_irblock(LBL2, [[ExprAff(a, b)]]) G10_IRB3 = gen_irblock(LBL3, [[ExprAff(r, CST1)]]) -G10_IRA.blocks = {irb.label : irb for irb in [G10_IRB0, G10_IRB1, - G10_IRB2, G10_IRB3]} +for irb in [G10_IRB0, G10_IRB1, G10_IRB2, G10_IRB3]: + G10_IRA.add_irblock(irb) + -G10_IRA.graph.add_uniq_edge(G10_IRB0.label, G10_IRB1.label) -G10_IRA.graph.add_uniq_edge(G10_IRB1.label, G10_IRB2.label) -G10_IRA.graph.add_uniq_edge(G10_IRB2.label, G10_IRB1.label) -G10_IRA.graph.add_uniq_edge(G10_IRB2.label, G10_IRB3.label) +G10_IRA.add_uniq_edge(G10_IRB0.loc_key, G10_IRB1.loc_key) +G10_IRA.add_uniq_edge(G10_IRB1.loc_key, G10_IRB2.loc_key) +G10_IRA.add_uniq_edge(G10_IRB2.loc_key, G10_IRB1.loc_key) +G10_IRA.add_uniq_edge(G10_IRB2.loc_key, G10_IRB3.loc_key) # Expected output for graph 10 -G10_EXP_IRA = IRATest() +G10_EXP_IRA = IRA.new_ircfg() G10_EXP_IRB0 = gen_irblock(LBL0, [[]]) G10_EXP_IRB1 = gen_irblock(LBL1, [[]]) G10_EXP_IRB2 = gen_irblock(LBL2, [[]]) G10_EXP_IRB3 = gen_irblock(LBL3, [[ExprAff(r, CST1)]]) -G10_EXP_IRA.blocks = {irb.label : irb for irb in [G10_EXP_IRB0, G10_EXP_IRB1, - G10_EXP_IRB2, G10_EXP_IRB3]} +for irb in [G10_EXP_IRB0, G10_EXP_IRB1, G10_EXP_IRB2, G10_EXP_IRB3]: + G10_EXP_IRA.add_irblock(irb) # graph 11 : If/Else conditions with alive variables -G11_IRA = IRATest() +G11_IRA = IRA.new_ircfg() G11_IRB0 = gen_irblock(LBL0, [[ExprAff(a, b)]]) G11_IRB1 = gen_irblock(LBL1, [[ExprAff(b, a)]]) @@ -378,17 +385,18 @@ G11_IRB3 = gen_irblock(LBL3, [[ExprAff(a, a+CST1)]]) G11_IRB4 = gen_irblock(LBL4, [[ExprAff(b, b+CST1)]]) -G11_IRA.blocks = {irb.label : irb for irb in [G11_IRB0, G11_IRB1, G11_IRB2]} +for irb in [G11_IRB0, G11_IRB1, G11_IRB2]: + G11_IRA.add_irblock(irb) -G11_IRA.graph.add_uniq_edge(G11_IRB0.label, G11_IRB1.label) -#G11_IRA.graph.add_uniq_edge(G11_IRB3.label, G11_IRB1.label) -G11_IRA.graph.add_uniq_edge(G11_IRB1.label, G11_IRB0.label) -#G11_IRA.graph.add_uniq_edge(G11_IRB4.label, G11_IRB0.label) -G11_IRA.graph.add_uniq_edge(G11_IRB1.label, G11_IRB2.label) +G11_IRA.add_uniq_edge(G11_IRB0.loc_key, G11_IRB1.loc_key) +#G11_IRA.add_uniq_edge(G11_IRB3.loc_key, G11_IRB1.loc_key) +G11_IRA.add_uniq_edge(G11_IRB1.loc_key, G11_IRB0.loc_key) +#G11_IRA.add_uniq_edge(G11_IRB4.loc_key, G11_IRB0.loc_key) +G11_IRA.add_uniq_edge(G11_IRB1.loc_key, G11_IRB2.loc_key) # Expected output for graph 11 -G11_EXP_IRA = IRATest() +G11_EXP_IRA = IRA.new_ircfg() G11_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(a, b)]]) G11_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(b, a)]]) @@ -396,13 +404,14 @@ G11_EXP_IRB2 = gen_irblock(LBL2, [[ExprAff(r, a)]]) #G11_EXP_IRB3 = gen_irblock(LBL3, [[ExprAff(a, a+CST1)]]) #G11_EXP_IRB4 = gen_irblock(LBL4, [[ExprAff(b, b+CST1)]]) -G11_EXP_IRA.blocks = {irb.label : irb for irb in [G11_EXP_IRB0, G11_EXP_IRB1, - G11_EXP_IRB2]} +for irb in [G11_EXP_IRB0, G11_EXP_IRB1, + G11_EXP_IRB2]: + G11_EXP_IRA.add_irblock(irb) # graph 12 : Graph with multiple out points and useless definitions # of return register -G12_IRA = IRATest() +G12_IRA = IRA.new_ircfg() G12_IRB0 = gen_irblock(LBL0, [[ExprAff(r, CST1)], [ExprAff(a, CST2)]]) G12_IRB1 = gen_irblock(LBL1, [[ExprAff(r, CST2)]]) @@ -411,17 +420,17 @@ G12_IRB3 = gen_irblock(LBL3, [[ExprAff(r, CST3)]]) G12_IRB4 = gen_irblock(LBL4, [[ExprAff(r, CST2)]]) G12_IRB5 = gen_irblock(LBL5, [[ExprAff(r, b)]]) -G12_IRA.blocks = {irb.label : irb for irb in [G12_IRB0, G12_IRB1, G12_IRB2, - G12_IRB3, G12_IRB4, G12_IRB5]} +for irb in [G12_IRB0, G12_IRB1, G12_IRB2, G12_IRB3, G12_IRB4, G12_IRB5]: + G12_IRA.add_irblock(irb) -G12_IRA.graph.add_uniq_edge(G12_IRB0.label, G12_IRB1.label) -G12_IRA.graph.add_uniq_edge(G12_IRB0.label, G12_IRB2.label) -G12_IRA.graph.add_uniq_edge(G12_IRB2.label, G12_IRB3.label) -G12_IRA.graph.add_uniq_edge(G12_IRB2.label, G12_IRB4.label) -G12_IRA.graph.add_uniq_edge(G12_IRB4.label, G12_IRB5.label) +G12_IRA.add_uniq_edge(G12_IRB0.loc_key, G12_IRB1.loc_key) +G12_IRA.add_uniq_edge(G12_IRB0.loc_key, G12_IRB2.loc_key) +G12_IRA.add_uniq_edge(G12_IRB2.loc_key, G12_IRB3.loc_key) +G12_IRA.add_uniq_edge(G12_IRB2.loc_key, G12_IRB4.loc_key) +G12_IRA.add_uniq_edge(G12_IRB4.loc_key, G12_IRB5.loc_key) # Expected output for graph 12 -G12_EXP_IRA = IRATest() +G12_EXP_IRA = IRA.new_ircfg() G12_EXP_IRB0 = gen_irblock(LBL0, [[], []]) G12_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, CST2)]]) @@ -431,13 +440,14 @@ G12_EXP_IRB4 = gen_irblock(LBL4, [[]]) G12_EXP_IRB5 = gen_irblock(LBL5, [[ExprAff(r, b)]]) -G12_EXP_IRA.blocks = {irb.label : irb for irb in [G12_EXP_IRB0, G12_EXP_IRB1, - G12_EXP_IRB2, G12_EXP_IRB3, - G12_EXP_IRB4, G12_EXP_IRB5]} +for irb in [G12_EXP_IRB0, G12_EXP_IRB1, + G12_EXP_IRB2, G12_EXP_IRB3, + G12_EXP_IRB4, G12_EXP_IRB5]: + G12_EXP_IRA.add_irblock(irb) # graph 13 : Graph where a leaf has lost its son -G13_IRA = IRATest() +G13_IRA = IRA.new_ircfg() G13_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST2)]]) G13_IRB1 = gen_irblock(LBL1, [[ExprAff(r, b)]]) @@ -446,16 +456,16 @@ G13_IRB2 = gen_irblock(LBL2, [[ExprAff(d, CST2)], [ExprAff(a, b+CST1), G13_IRB3 = gen_irblock(LBL3, [[]]) # lost son G13_IRB4 = gen_irblock(LBL4, [[ExprAff(b, CST2)]]) -G13_IRA.blocks = {irb.label : irb for irb in [G13_IRB0, G13_IRB1, G13_IRB2, - G13_IRB4]} +for irb in [G13_IRB0, G13_IRB1, G13_IRB2, G13_IRB4]: + G13_IRA.add_irblock(irb) -G13_IRA.graph.add_uniq_edge(G13_IRB0.label, G13_IRB1.label) -G13_IRA.graph.add_uniq_edge(G13_IRB0.label, G13_IRB4.label) -G13_IRA.graph.add_uniq_edge(G13_IRB2.label, G13_IRB3.label) -G13_IRA.graph.add_uniq_edge(G13_IRB4.label, G13_IRB2.label) +G13_IRA.add_uniq_edge(G13_IRB0.loc_key, G13_IRB1.loc_key) +G13_IRA.add_uniq_edge(G13_IRB0.loc_key, G13_IRB4.loc_key) +G13_IRA.add_uniq_edge(G13_IRB2.loc_key, G13_IRB3.loc_key) +G13_IRA.add_uniq_edge(G13_IRB4.loc_key, G13_IRB2.loc_key) # Expected output for graph 13 -G13_EXP_IRA = IRATest() +G13_EXP_IRA = IRA.new_ircfg() G13_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST2)]]) G13_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, b)]]) @@ -464,58 +474,62 @@ G13_EXP_IRB2 = gen_irblock(LBL2, [[ExprAff(d, CST2)], [ExprAff(a, b+CST1), G13_EXP_IRB3 = gen_irblock(LBL3, [[]]) G13_EXP_IRB4 = gen_irblock(LBL4, [[ExprAff(b, CST2)]]) -G13_EXP_IRA.blocks = {irb.label: irb for irb in [G13_EXP_IRB0, G13_EXP_IRB1, - G13_EXP_IRB2, G13_EXP_IRB4]} +for irb in [G13_EXP_IRB0, G13_EXP_IRB1, G13_EXP_IRB2, G13_EXP_IRB4]: + G13_EXP_IRA.add_irblock(irb) #G13_EXP_IRA = G13_IRA # graph 14 : Graph where variable assigned multiple times in a block but still # useful in the end -G14_IRA = IRATest() +G14_IRA = IRA.new_ircfg() G14_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(c, a)], [ExprAff(a, CST2)]]) G14_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a+c)]]) -G14_IRA.blocks = {irb.label : irb for irb in [G14_IRB0, G14_IRB1]} +for irb in [G14_IRB0, G14_IRB1]: + G14_IRA.add_irblock(irb) -G14_IRA.graph.add_uniq_edge(G14_IRB0.label, G14_IRB1.label) +G14_IRA.add_uniq_edge(G14_IRB0.loc_key, G14_IRB1.loc_key) # Expected output for graph 1 -G14_EXP_IRA = IRATest() +G14_EXP_IRA = IRA.new_ircfg() G14_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(c, a)], [ExprAff(a, CST2)]]) G14_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a+c)]]) -G14_EXP_IRA.blocks = {irb.label: irb for irb in [G14_EXP_IRB0, G14_EXP_IRB1]} +for irb in [G14_EXP_IRB0, G14_EXP_IRB1]: + G14_EXP_IRA.add_irblock(irb) # graph 15 : Graph where variable assigned multiple and read at the same time, # but useless -G15_IRA = IRATest() +G15_IRA = IRA.new_ircfg() G15_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST2)], [ExprAff(a, CST1), ExprAff(b, a+CST2), ExprAff(c, CST1)]]) G15_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a)]]) -G15_IRA.blocks = {irb.label : irb for irb in [G15_IRB0, G15_IRB1]} +for irb in [G15_IRB0, G15_IRB1]: + G15_IRA.add_irblock(irb) -G15_IRA.graph.add_uniq_edge(G15_IRB0.label, G15_IRB1.label) +G15_IRA.add_uniq_edge(G15_IRB0.loc_key, G15_IRB1.loc_key) # Expected output for graph 1 -G15_EXP_IRA = IRATest() +G15_EXP_IRA = IRA.new_ircfg() G15_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(a, CST1)]]) G15_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a)]]) -G15_EXP_IRA.blocks = {irb.label: irb for irb in [G15_EXP_IRB0, G15_EXP_IRB1]} +for irb in [G15_EXP_IRB0, G15_EXP_IRB1]: + G15_EXP_IRA.add_irblock(irb) # graph 16 : Graph where variable assigned multiple times in the same bloc -G16_IRA = IRATest() +G16_IRA = IRA.new_ircfg() G16_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1), ExprAff(b, CST2), ExprAff(c, CST3)], [ExprAff(a, c+CST1), @@ -523,25 +537,28 @@ G16_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1), ExprAff(b, CST2), G16_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a+b)], [ExprAff(r, c+r)]]) G16_IRB2 = gen_irblock(LBL2, [[]]) -G16_IRA.blocks = {irb.label : irb for irb in [G16_IRB0, G16_IRB1]} +for irb in [G16_IRB0, G16_IRB1]: + G16_IRA.add_irblock(irb) -G16_IRA.graph.add_uniq_edge(G16_IRB0.label, G16_IRB1.label) -G16_IRA.graph.add_uniq_edge(G16_IRB1.label, G16_IRB2.label) +G16_IRA.add_uniq_edge(G16_IRB0.loc_key, G16_IRB1.loc_key) +G16_IRA.add_uniq_edge(G16_IRB1.loc_key, G16_IRB2.loc_key) -G16_IRA.blocks = {irb.label : irb for irb in [G16_IRB0, G16_IRB1]} +for irb in [G16_IRB0, G16_IRB1]: + G16_IRA.add_irblock(irb) # Expected output for graph 1 -G16_EXP_IRA = IRATest() +G16_EXP_IRA = IRA.new_ircfg() G16_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(c, CST3)], [ExprAff(a, c + CST1), ExprAff(b, c + CST2)]]) G16_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a+b)], [ExprAff(r, c+r)]]) -G16_EXP_IRA.blocks = {irb.label: irb for irb in [G16_EXP_IRB0, G16_EXP_IRB1]} +for irb in [G16_EXP_IRB0, G16_EXP_IRB1]: + G16_EXP_IRA.add_irblock(irb) # graph 17 : parallel ir -G17_IRA = IRATest() +G17_IRA = IRA.new_ircfg() G17_IRB0 = gen_irblock(LBL0, [[ExprAff(a, a*b), ExprAff(b, c), @@ -597,12 +614,13 @@ G17_IRB0 = gen_irblock(LBL0, [[ExprAff(a, a*b), ]) -G17_IRA.blocks = {irb.label : irb for irb in [G17_IRB0]} +for irb in [G17_IRB0]: + G17_IRA.add_irblock(irb) -G17_IRA.graph.add_node(G17_IRB0.label) +#G17_IRA.graph.add_node(G17_IRB0.loc_key) # Expected output for graph 17 -G17_EXP_IRA = IRATest() +G17_EXP_IRA = IRA.new_ircfg() G17_EXP_IRB0 = gen_irblock(LBL0, [[], @@ -639,7 +657,8 @@ G17_EXP_IRB0 = gen_irblock(LBL0, [[], # Trick because a+b+c != ((a+b)+c) ]) -G17_EXP_IRA.blocks = {irb.label : irb for irb in [G17_EXP_IRB0]} +for irb in [G17_EXP_IRB0]: + G17_EXP_IRA.add_irblock(irb) # Begining of tests @@ -667,17 +686,16 @@ for test_nb, test in enumerate([(G1_IRA, G1_EXP_IRA), print "[+] Test", test_nb+1 # Print initial graph, for debug - open("graph_%02d.dot" % (test_nb+1), "w").write(g_ira.graph.dot()) + open("graph_%02d.dot" % (test_nb+1), "w").write(g_ira.dot()) reaching_defs = ReachingDefinitions(g_ira) defuse = DiGraphDefUse(reaching_defs, deref_mem=True) - #open("defuse_%02d.dot" % (test_nb+1), "w").write(defuse.dot()) # # Simplify graph - dead_simp(g_ira) + dead_simp(IRA, g_ira) # # Print simplified graph, for debug - open("simp_graph_%02d.dot" % (test_nb+1), "w").write(g_ira.graph.dot()) + open("simp_graph_%02d.dot" % (test_nb+1), "w").write(g_ira.dot()) # Same number of blocks assert len(g_ira.blocks) == len(g_exp_ira.blocks) diff --git a/test/analysis/depgraph.py b/test/analysis/depgraph.py index 9fb046d0..2ba5f044 100644 --- a/test/analysis/depgraph.py +++ b/test/analysis/depgraph.py @@ -1,6 +1,7 @@ """Regression test module for DependencyGraph""" -from miasm2.expression.expression import ExprId, ExprInt, ExprAff, ExprCond -from miasm2.core.asmblock import AsmLabel +from miasm2.expression.expression import ExprId, ExprInt, ExprAff, ExprCond, \ + ExprLoc, LocKey +from miasm2.core.locationdb import LocationDB from miasm2.ir.analysis import ira from miasm2.ir.ir import IRBlock, AssignBlock from miasm2.core.graph import DiGraph @@ -9,6 +10,8 @@ from itertools import count from pdb import pm import re +loc_db = LocationDB() + EMULATION = True try: import z3 @@ -21,6 +24,7 @@ B = ExprId("b", 32) C = ExprId("c", 32) D = ExprId("d", 32) R = ExprId("r", 32) +COND = ExprId("cond", 32) A_INIT = ExprId("a_init", 32) B_INIT = ExprId("b_init", 32) @@ -41,13 +45,13 @@ CST33 = ExprInt(0x33, 32) CST35 = ExprInt(0x35, 32) CST37 = ExprInt(0x37, 32) -LBL0 = AsmLabel("lbl0") -LBL1 = AsmLabel("lbl1") -LBL2 = AsmLabel("lbl2") -LBL3 = AsmLabel("lbl3") -LBL4 = AsmLabel("lbl4") -LBL5 = AsmLabel("lbl5") -LBL6 = AsmLabel("lbl6") +LBL0 = loc_db.add_location("lbl0", 0) +LBL1 = loc_db.add_location("lbl1", 1) +LBL2 = loc_db.add_location("lbl2", 2) +LBL3 = loc_db.add_location("lbl3", 3) +LBL4 = loc_db.add_location("lbl4", 4) +LBL5 = loc_db.add_location("lbl5", 5) +LBL6 = loc_db.add_location("lbl6", 6) def gen_irblock(label, exprs_list): """ Returns an IRBlock. @@ -87,10 +91,10 @@ class IRATest(ira): """Fake IRA class for tests""" - def __init__(self, symbol_pool=None): + def __init__(self, loc_db=None): arch = Arch() - super(IRATest, self).__init__(arch, 32, symbol_pool) - self.IRDst = PC + super(IRATest, self).__init__(arch, 32, loc_db) + self.IRDst = ExprId("IRDst", 32) self.ret_reg = R def get_out_regs(self, _): @@ -111,18 +115,17 @@ def bloc2graph(irgraph, label=False, lines=True): # Generate basic blocks out_blocks = [] - for label in irgraph.graph.nodes(): - if isinstance(label, AsmLabel): - label_name = label.name - else: - label_name = str(label) + for label in irgraph.nodes(): + assert isinstance(label, LocKey) + label_names = irgraph.loc_db.get_location_names(label) + label_name = list(label_names)[0] if hasattr(irgraph, 'blocks'): irblock = irgraph.blocks[label] else: irblock = None - if isinstance(label, AsmLabel): - out_block = '%s [\n' % label.name + if isinstance(label, LocKey): + out_block = '%s [\n' % label_name else: out_block = '%s [\n' % label out_block += "%s " % block_attr @@ -151,20 +154,19 @@ def bloc2graph(irgraph, label=False, lines=True): out += out_blocks # Generate links - for src, dst in irgraph.graph.edges(): - if isinstance(src, AsmLabel): - src_name = src.name - else: - src_name = str(src) - if isinstance(dst, AsmLabel): - dst_name = dst.name - else: - dst_name = str(dst) + for src, dst in irgraph.edges(): + assert isinstance(src, LocKey) + src_names = irgraph.loc_db.get_location_names(src) + assert isinstance(dst, LocKey) + dst_names = irgraph.loc_db.get_location_names(dst) - edge_color = "black" - out.append('%s -> %s' % (src_name, - dst_name) + - '[' + edge_attr % ("", edge_color) + '];') + src_name = list(src_names)[0] + dst_name = list(dst_names)[0] + + edge_color = "black" + out.append('%s -> %s' % (src_name, + dst_name) + + '[' + edge_attr % ("", edge_color) + '];') out.append("}") return '\n'.join(out) @@ -184,19 +186,20 @@ def dg2graph(graph, label=False, lines=True): # Generate basic blocks out_blocks = [] - for label in graph.nodes(): - if isinstance(label, DependencyNode): - label_name = "%s %s %s" % (label.label.name, - label.element, - label.line_nb) + for node in graph.nodes(): + if isinstance(node, DependencyNode): + name = loc_db.pretty_str(node.loc_key) + node_name = "%s %s %s" % (name, + node.element, + node.line_nb) else: - label_name = str(label) - out_block = '%s [\n' % hash(label) + node_name = str(node) + out_block = '%s [\n' % hash(node) out_block += "%s " % block_attr out_block += 'label =<<table border="0" cellborder="0" cellpadding="3">' block_label = '<tr><td %s>%s</td></tr>' % ( - label_attr, label_name) + label_attr, node_name) block_html_lines = [] block_html_lines = ('<tr><td %s>' % td_attr + ('</td></tr><tr><td %s>' % td_attr).join(block_html_lines) + @@ -226,370 +229,476 @@ DNC2 = DependencyNode(LBL1, C, 0) DNB3 = DependencyNode(LBL1, B, 1) DNC3 = DependencyNode(LBL1, C, 0) +IRA = IRATest(loc_db) +IRDst = IRA.IRDst +END = ExprId("END", IRDst.size) # graph 1 -G1_IRA = IRATest() - -G1_IRB0 = gen_irblock(LBL0, [[ExprAff(C, CST1)]]) -G1_IRB1 = gen_irblock(LBL1, [[ExprAff(B, C)]]) -G1_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B)]]) +G1_IRA = IRA.new_ircfg() -G1_IRA.graph.add_uniq_edge(G1_IRB0.label, G1_IRB1.label) -G1_IRA.graph.add_uniq_edge(G1_IRB1.label, G1_IRB2.label) +G1_IRB0 = gen_irblock(LBL0, [[ExprAff(C, CST1), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) +G1_IRB1 = gen_irblock(LBL1, [[ExprAff(B, C), ExprAff(IRDst, ExprLoc(LBL2, 32))]]) +G1_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B), ExprAff(IRDst, END)]]) -G1_IRA.blocks = dict([(irb.label, irb) for irb in [G1_IRB0, G1_IRB1, G1_IRB2]]) +for irb in [G1_IRB0, G1_IRB1, G1_IRB2]: + G1_IRA.add_irblock(irb) # graph 2 -G2_IRA = IRATest() +G2_IRA = IRA.new_ircfg() -G2_IRB0 = gen_irblock(LBL0, [[ExprAff(C, CST1)]]) -G2_IRB1 = gen_irblock(LBL1, [[ExprAff(B, CST2)]]) -G2_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B + C)]]) +G2_IRB0 = gen_irblock(LBL0, [[ExprAff(C, CST1), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) +G2_IRB1 = gen_irblock(LBL1, [[ExprAff(B, CST2), ExprAff(IRDst, ExprLoc(LBL2, 32))]]) +G2_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B + C), ExprAff(IRDst, END)]]) -G2_IRA.graph.add_uniq_edge(G2_IRB0.label, G2_IRB1.label) -G2_IRA.graph.add_uniq_edge(G2_IRB1.label, G2_IRB2.label) - -G2_IRA.blocks = dict([(irb.label, irb) for irb in [G2_IRB0, G2_IRB1, G2_IRB2]]) +for irb in [G2_IRB0, G2_IRB1, G2_IRB2]: + G2_IRA.add_irblock(irb) # graph 3 -G3_IRA = IRATest() - -G3_IRB0 = gen_irblock(LBL0, [[ExprAff(C, CST1)]]) -G3_IRB1 = gen_irblock(LBL1, [[ExprAff(B, CST2)]]) -G3_IRB2 = gen_irblock(LBL2, [[ExprAff(B, CST3)]]) -G3_IRB3 = gen_irblock(LBL3, [[ExprAff(A, B + C)]]) - -G3_IRA.graph.add_uniq_edge(G3_IRB0.label, G3_IRB1.label) -G3_IRA.graph.add_uniq_edge(G3_IRB0.label, G3_IRB2.label) -G3_IRA.graph.add_uniq_edge(G3_IRB1.label, G3_IRB3.label) -G3_IRA.graph.add_uniq_edge(G3_IRB2.label, G3_IRB3.label) - -G3_IRA.blocks = dict([(irb.label, irb) for irb in [G3_IRB0, G3_IRB1, - G3_IRB2, G3_IRB3]]) +G3_IRA = IRA.new_ircfg() + +G3_IRB0 = gen_irblock( + LBL0, + [ + [ExprAff(C, CST1), ExprAff( + IRDst, ExprCond( + COND, + ExprLoc(LBL1, 32), + ExprLoc(LBL2, 32) + ) + ) + ] + ] +) + +G3_IRB1 = gen_irblock(LBL1, [[ExprAff(B, CST2), ExprAff(IRDst, ExprLoc(LBL3, 32))]]) +G3_IRB2 = gen_irblock(LBL2, [[ExprAff(B, CST3), ExprAff(IRDst, ExprLoc(LBL3, 32))]]) +G3_IRB3 = gen_irblock(LBL3, [[ExprAff(A, B + C), ExprAff(IRDst, END)]]) + +for irb in [G3_IRB0, G3_IRB1, G3_IRB2, G3_IRB3]: + G3_IRA.add_irblock(irb) # graph 4 -G4_IRA = IRATest() - -G4_IRB0 = gen_irblock(LBL0, [[ExprAff(C, CST1)]]) -G4_IRB1 = gen_irblock(LBL1, [[ExprAff(C, C + CST2)], - [ExprAff(G4_IRA.IRDst, - ExprCond(C, ExprId(LBL2, 32), - ExprId(LBL1, 32)))]]) +G4_IRA = IRA.new_ircfg() -G4_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B)]]) +G4_IRB0 = gen_irblock(LBL0, [[ExprAff(C, CST1), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) +G4_IRB1 = gen_irblock( + LBL1, + [ + [ExprAff(C, C + CST2)], + [ExprAff(IRDst, + ExprCond( + C, + ExprLoc(LBL2, 32), + ExprLoc(LBL1, 32)) + ) + ]] +) -G4_IRA.graph.add_uniq_edge(G4_IRB0.label, G4_IRB1.label) -G4_IRA.graph.add_uniq_edge(G4_IRB1.label, G4_IRB2.label) -G4_IRA.graph.add_uniq_edge(G4_IRB1.label, G4_IRB1.label) +G4_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B), ExprAff(IRDst, END)]]) -G4_IRA.blocks = dict([(irb.label, irb) for irb in [G4_IRB0, G4_IRB1, G4_IRB2]]) +for irb in [G4_IRB0, G4_IRB1, G4_IRB2]: + G4_IRA.add_irblock(irb) # graph 5 -G5_IRA = IRATest() - -G5_IRB0 = gen_irblock(LBL0, [[ExprAff(B, CST1)]]) -G5_IRB1 = gen_irblock(LBL1, [[ExprAff(B, B + CST2)], - [ExprAff(G5_IRA.IRDst, - ExprCond(B, ExprId(LBL2, 32), - ExprId(LBL1, 32)))]]) - -G5_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B)]]) - -G5_IRA.graph.add_uniq_edge(G5_IRB0.label, G5_IRB1.label) -G5_IRA.graph.add_uniq_edge(G5_IRB1.label, G5_IRB2.label) -G5_IRA.graph.add_uniq_edge(G5_IRB1.label, G5_IRB1.label) - -G5_IRA.blocks = dict([(irb.label, irb) for irb in [G5_IRB0, G5_IRB1, G5_IRB2]]) +G5_IRA = IRA.new_ircfg() + +G5_IRB0 = gen_irblock(LBL0, [[ExprAff(B, CST1), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) +G5_IRB1 = gen_irblock( + LBL1, + [ + [ExprAff(B, B + CST2)], + [ExprAff( + IRDst, + ExprCond( + B, + ExprLoc(LBL2, 32), + ExprLoc(LBL1, 32) + ) + ) + ] + ] +) + +G5_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B), ExprAff(IRDst, END)]]) + +for irb in [G5_IRB0, G5_IRB1, G5_IRB2]: + G5_IRA.add_irblock(irb) # graph 6 -G6_IRA = IRATest() +G6_IRA = IRA.new_ircfg() -G6_IRB0 = gen_irblock(LBL0, [[ExprAff(B, CST1)]]) -G6_IRB1 = gen_irblock(LBL1, [[ExprAff(A, B)]]) +G6_IRB0 = gen_irblock(LBL0, [[ExprAff(B, CST1), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) +G6_IRB1 = gen_irblock(LBL1, [[ExprAff(A, B), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) -G6_IRA.graph.add_uniq_edge(G6_IRB0.label, G6_IRB1.label) -G6_IRA.graph.add_uniq_edge(G6_IRB1.label, G6_IRB1.label) - -G6_IRA.blocks = dict([(irb.label, irb) for irb in [G6_IRB0, G6_IRB1]]) +for irb in [G6_IRB0, G6_IRB1]: + G6_IRA.add_irblock(irb) # graph 7 -G7_IRA = IRATest() - -G7_IRB0 = gen_irblock(LBL0, [[ExprAff(C, CST1)]]) -G7_IRB1 = gen_irblock(LBL1, [[ExprAff(B, C)], [ExprAff(A, B)]]) -G7_IRB2 = gen_irblock(LBL2, [[ExprAff(D, A)]]) - -G7_IRA.graph.add_uniq_edge(G7_IRB0.label, G7_IRB1.label) -G7_IRA.graph.add_uniq_edge(G7_IRB1.label, G7_IRB1.label) -G7_IRA.graph.add_uniq_edge(G7_IRB1.label, G7_IRB2.label) - -G7_IRA.blocks = dict([(irb.label, irb) for irb in [G7_IRB0, G7_IRB1, G7_IRB2]]) +G7_IRA = IRA.new_ircfg() + +G7_IRB0 = gen_irblock(LBL0, [[ExprAff(C, CST1), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) +G7_IRB1 = gen_irblock( + LBL1, + [ + [ExprAff(B, C)], + [ExprAff(A, B)], + [ExprAff( + IRDst, + ExprCond( + COND, + ExprLoc(LBL1, 32), + ExprLoc(LBL2, 32) + ) + ) + ] + ] +) + +G7_IRB2 = gen_irblock(LBL2, [[ExprAff(D, A), ExprAff(IRDst, END)]]) + +for irb in [G7_IRB0, G7_IRB1, G7_IRB2]: + G7_IRA.add_irblock(irb) # graph 8 -G8_IRA = IRATest() - -G8_IRB0 = gen_irblock(LBL0, [[ExprAff(C, CST1)]]) -G8_IRB1 = gen_irblock(LBL1, [[ExprAff(B, C)], [ExprAff(C, D)]]) -G8_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B)]]) - -G8_IRA.graph.add_uniq_edge(G8_IRB0.label, G8_IRB1.label) -G8_IRA.graph.add_uniq_edge(G8_IRB1.label, G8_IRB1.label) -G8_IRA.graph.add_uniq_edge(G8_IRB1.label, G8_IRB2.label) - -G8_IRA.blocks = dict([(irb.label, irb) for irb in [G8_IRB0, G8_IRB1, G8_IRB2]]) +G8_IRA = IRA.new_ircfg() + +G8_IRB0 = gen_irblock(LBL0, [[ExprAff(C, CST1), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) +G8_IRB1 = gen_irblock( + LBL1, + [ + [ExprAff(B, C)], + [ExprAff(C, D), + ExprAff( + IRDst, + ExprCond( + COND, + ExprLoc(LBL1, 32), + ExprLoc(LBL2, 32) + ) + ) + ] + ] +) +G8_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B), ExprAff(IRDst, END)]]) + +for irb in [G8_IRB0, G8_IRB1, G8_IRB2]: + G8_IRA.add_irblock(irb) # graph 9 is graph 8 # graph 10 -G10_IRA = IRATest() - -G10_IRB1 = gen_irblock(LBL1, [[ExprAff(B, B + CST2)]]) -G10_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B)]]) - -G10_IRA.graph.add_uniq_edge(G10_IRB1.label, G10_IRB2.label) -G10_IRA.graph.add_uniq_edge(G10_IRB1.label, G10_IRB1.label) - -G10_IRA.blocks = dict([(irb.label, irb) for irb in [G10_IRB1, G10_IRB2]]) +G10_IRA = IRA.new_ircfg() + +G10_IRB1 = gen_irblock( + LBL1, + [ + [ExprAff(B, B + CST2), + ExprAff( + IRDst, + ExprCond( + COND, + ExprLoc(LBL1, 32), + ExprLoc(LBL2, 32) + ) + ) + ] + ] +) + +G10_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B), ExprAff(IRDst, END)]]) + +for irb in [G10_IRB1, G10_IRB2]: + G10_IRA.add_irblock(irb) # graph 11 -G11_IRA = IRATest() - -G11_IRB0 = gen_irblock(LBL0, [[ExprAff(A, CST1), - ExprAff(B, CST2)]]) -G11_IRB1 = gen_irblock(LBL1, [[ExprAff(A, B), - ExprAff(B, A)]]) -G11_IRB2 = gen_irblock(LBL2, [[ExprAff(A, A - B)]]) - -G11_IRA.graph.add_uniq_edge(G11_IRB0.label, G11_IRB1.label) -G11_IRA.graph.add_uniq_edge(G11_IRB1.label, G11_IRB2.label) - -G11_IRA.blocks = dict([(irb.label, irb) - for irb in [G11_IRB0, G11_IRB1, G11_IRB2]]) +G11_IRA = IRA.new_ircfg() + +G11_IRB0 = gen_irblock( + LBL0, + [ + [ExprAff(A, CST1), + ExprAff(B, CST2), + ExprAff(IRDst, ExprLoc(LBL1, 32)) + ] + ] +) + +G11_IRB1 = gen_irblock( + LBL1, + [ + [ExprAff(A, B), + ExprAff(B, A), + ExprAff(IRDst, ExprLoc(LBL2, 32)) + ] + ] +) + +G11_IRB2 = gen_irblock(LBL2, [[ExprAff(A, A - B), ExprAff(IRDst, END)]]) + +for irb in [G11_IRB0, G11_IRB1, G11_IRB2]: + G11_IRA.add_irblock(irb) # graph 12 -G12_IRA = IRATest() +G12_IRA = IRA.new_ircfg() -G12_IRB0 = gen_irblock(LBL0, [[ExprAff(B, CST1)]]) -G12_IRB1 = gen_irblock(LBL1, [[ExprAff(A, B)], [ExprAff(B, B + CST2)]]) -G12_IRB2 = gen_irblock(LBL2, [[ExprAff(B, A)]]) +G12_IRB0 = gen_irblock(LBL0, [[ExprAff(B, CST1), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) +G12_IRB1 = gen_irblock( + LBL1, + [ + [ExprAff(A, B)], + [ExprAff(B, B + CST2), + ExprAff( + IRDst, + ExprCond( + COND, + ExprLoc(LBL1, 32), + ExprLoc(LBL2, 32) + ) + ) + ] + ] +) -G12_IRA.graph.add_uniq_edge(G12_IRB0.label, G12_IRB1.label) -G12_IRA.graph.add_uniq_edge(G12_IRB1.label, G12_IRB2.label) -G12_IRA.graph.add_uniq_edge(G12_IRB1.label, G12_IRB1.label) +G12_IRB2 = gen_irblock(LBL2, [[ExprAff(B, A), ExprAff(IRDst, END)]]) -G12_IRA.blocks = dict([(irb.label, irb) for irb in [G12_IRB0, G12_IRB1, - G12_IRB2]]) +for irb in [G12_IRB0, G12_IRB1, G12_IRB2]: + G12_IRA.add_irblock(irb) # graph 13 -G13_IRA = IRATest() +G13_IRA = IRA.new_ircfg() G13_IRB0 = gen_irblock(LBL0, [[ExprAff(A, CST1)], #[ExprAff(B, A)], - [ExprAff(G13_IRA.IRDst, - ExprId(LBL1, 32))]]) + [ExprAff(IRDst, + ExprLoc(LBL1, 32))]]) G13_IRB1 = gen_irblock(LBL1, [[ExprAff(C, A)], #[ExprAff(A, A + CST1)], - [ExprAff(G13_IRA.IRDst, - ExprCond(R, ExprId(LBL2, 32), - ExprId(LBL1, 32)))]]) + [ExprAff(IRDst, + ExprCond( + R, + ExprLoc(LBL2, 32), + ExprLoc(LBL3, 32) + ) + )]]) G13_IRB2 = gen_irblock(LBL2, [[ExprAff(B, A + CST3)], [ExprAff(A, B + CST3)], - [ExprAff(G13_IRA.IRDst, - ExprId(LBL1, 32))]]) - -G13_IRB3 = gen_irblock(LBL3, [[ExprAff(R, C)]]) + [ExprAff(IRDst, + ExprLoc(LBL1, 32))]]) -G13_IRA.graph.add_uniq_edge(G13_IRB0.label, G13_IRB1.label) -G13_IRA.graph.add_uniq_edge(G13_IRB1.label, G13_IRB2.label) -G13_IRA.graph.add_uniq_edge(G13_IRB2.label, G13_IRB1.label) -G13_IRA.graph.add_uniq_edge(G13_IRB1.label, G13_IRB3.label) +G13_IRB3 = gen_irblock(LBL3, [[ExprAff(R, C), ExprAff(IRDst, END)]]) -G13_IRA.blocks = dict([(irb.label, irb) for irb in [G13_IRB0, G13_IRB1, - G13_IRB2, G13_IRB3]]) +for irb in [G13_IRB0, G13_IRB1, G13_IRB2, G13_IRB3]: + G13_IRA.add_irblock(irb) # graph 14 -G14_IRA = IRATest() +G14_IRA = IRA.new_ircfg() G14_IRB0 = gen_irblock(LBL0, [[ExprAff(A, CST1)], - [ExprAff(G14_IRA.IRDst, - ExprId(LBL1, 32))] + [ExprAff(IRDst, + ExprLoc(LBL1, 32))] ]) G14_IRB1 = gen_irblock(LBL1, [[ExprAff(B, A)], - [ExprAff(G14_IRA.IRDst, - ExprCond(C, ExprId(LBL2, 32), - ExprId(LBL3, 32)))] + [ExprAff(IRDst, + ExprCond( + C, + ExprLoc(LBL2, 32), + ExprLoc(LBL3, 32) + ) + ) + ] ]) G14_IRB2 = gen_irblock(LBL2, [[ExprAff(D, A)], [ExprAff(A, D + CST1)], - [ExprAff(G14_IRA.IRDst, - ExprId(LBL1, 32))] + [ExprAff(IRDst, + ExprLoc(LBL1, 32))] ]) -G14_IRB3 = gen_irblock(LBL3, [[ExprAff(R, D + B)]]) - -G14_IRA.graph.add_uniq_edge(G14_IRB0.label, G14_IRB1.label) -G14_IRA.graph.add_uniq_edge(G14_IRB1.label, G14_IRB2.label) -G14_IRA.graph.add_uniq_edge(G14_IRB2.label, G14_IRB1.label) -G14_IRA.graph.add_uniq_edge(G14_IRB1.label, G14_IRB3.label) +G14_IRB3 = gen_irblock(LBL3, [[ExprAff(R, D + B), ExprAff(IRDst, END)]]) -G14_IRA.blocks = dict([(irb.label, irb) for irb in [G14_IRB0, G14_IRB1, - G14_IRB2, G14_IRB3]]) +for irb in [G14_IRB0, G14_IRB1, G14_IRB2, G14_IRB3]: + G14_IRA.add_irblock(irb) # graph 16 -G15_IRA = IRATest() +G15_IRA = IRA.new_ircfg() -G15_IRB0 = gen_irblock(LBL0, [[ExprAff(A, CST1)]]) +G15_IRB0 = gen_irblock(LBL0, [[ExprAff(A, CST1), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) G15_IRB1 = gen_irblock(LBL1, [[ExprAff(D, A + B)], [ExprAff(C, D)], - [ExprAff(B, C)]]) -G15_IRB2 = gen_irblock(LBL2, [[ExprAff(R, B)]]) - -G15_IRA.graph.add_uniq_edge(G15_IRB0.label, G15_IRB1.label) -G15_IRA.graph.add_uniq_edge(G15_IRB1.label, G15_IRB2.label) -G15_IRA.graph.add_uniq_edge(G15_IRB1.label, G15_IRB1.label) - -G15_IRA.blocks = dict([(irb.label, irb) for irb in [G15_IRB0, G15_IRB1, - G15_IRB2]]) + [ExprAff(B, C), + ExprAff(IRDst, + ExprCond( + C, + ExprLoc(LBL1, 32), + ExprLoc(LBL2, 32) + ) + )]]) +G15_IRB2 = gen_irblock(LBL2, [[ExprAff(R, B), ExprAff(IRDst, END)]]) + +for irb in [G15_IRB0, G15_IRB1, G15_IRB2]: + G15_IRA.add_irblock(irb) # graph 16 -G16_IRA = IRATest() - -G16_IRB0 = gen_irblock(LBL0, [[ExprAff(A, CST1)]]) -G16_IRB1 = gen_irblock(LBL1, [[ExprAff(R, D)]]) -G16_IRB2 = gen_irblock(LBL2, [[ExprAff(D, A)]]) -G16_IRB3 = gen_irblock(LBL3, [[ExprAff(R, D)]]) -G16_IRB4 = gen_irblock(LBL4, [[ExprAff(R, A)]]) -G16_IRB5 = gen_irblock(LBL5, [[ExprAff(R, A)]]) - -G16_IRA.graph.add_uniq_edge(G16_IRB0.label, G16_IRB1.label) -G16_IRA.graph.add_uniq_edge(G16_IRB1.label, G16_IRB2.label) -G16_IRA.graph.add_uniq_edge(G16_IRB2.label, G16_IRB1.label) -G16_IRA.graph.add_uniq_edge(G16_IRB1.label, G16_IRB3.label) -G16_IRA.graph.add_uniq_edge(G16_IRB3.label, G16_IRB1.label) -G16_IRA.graph.add_uniq_edge(G16_IRB1.label, G16_IRB4.label) -G16_IRA.graph.add_uniq_edge(G16_IRB4.label, G16_IRB1.label) -G16_IRA.graph.add_uniq_edge(G16_IRB1.label, G16_IRB5.label) - -G16_IRA.blocks = dict([(irb.label, irb) for irb in [G16_IRB0, G16_IRB1, - G16_IRB2, G16_IRB3, - G16_IRB4, G16_IRB5]]) +G16_IRA = IRA.new_ircfg() + +G16_IRB0 = gen_irblock( + LBL0, [ + [ExprAff(A, CST1), ExprAff(IRDst, ExprLoc(LBL1, 32))] + ] +) + +G16_IRB1 = gen_irblock( + LBL1, + [ + [ExprAff(R, D), + ExprAff( + IRDst, + ExprCond( + C, + ExprCond( + C, + ExprCond( + C, + ExprLoc(LBL2, 32), + ExprLoc(LBL3, 32) + ), + ExprLoc(LBL4, 32) + ), + ExprLoc(LBL5, 32) + ) + ) + ] + ] +) + + + +G16_IRB2 = gen_irblock(LBL2, [[ExprAff(D, A), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) +G16_IRB3 = gen_irblock(LBL3, [[ExprAff(R, D), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) +G16_IRB4 = gen_irblock(LBL4, [[ExprAff(R, A), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) +G16_IRB5 = gen_irblock(LBL5, [[ExprAff(R, A), ExprAff(IRDst, ExprLoc(LBL1, 32))]]) + +for irb in [G16_IRB0, G16_IRB1, G16_IRB2, G16_IRB3, G16_IRB4, G16_IRB5]: + G16_IRA.add_irblock(irb) # graph 17 -G17_IRA = IRATest() +G17_IRA = IRA.new_ircfg() G17_IRB0 = gen_irblock(LBL0, [[ExprAff(A, CST1), - ExprAff(D, CST2)]]) + ExprAff(D, CST2), + ExprAff(IRDst, ExprLoc(LBL1, 32))]]) G17_IRB1 = gen_irblock(LBL1, [[ExprAff(A, D), - ExprAff(B, D)]]) -G17_IRB2 = gen_irblock(LBL2, [[ExprAff(A, A - B)]]) + ExprAff(B, D), + ExprAff(IRDst, ExprLoc(LBL2, 32))]]) +G17_IRB2 = gen_irblock(LBL2, [[ExprAff(A, A - B), + ExprAff(IRDst, END)]]) -G17_IRA.graph.add_uniq_edge(G17_IRB0.label, G17_IRB1.label) -G17_IRA.graph.add_uniq_edge(G17_IRB1.label, G17_IRB2.label) +G17_IRA.add_uniq_edge(G17_IRB0.loc_key, G17_IRB1.loc_key) +G17_IRA.add_uniq_edge(G17_IRB1.loc_key, G17_IRB2.loc_key) -G17_IRA.blocks = dict([(irb.label, irb) for irb in [G17_IRB0, G17_IRB1, - G17_IRB2]]) +for irb in [G17_IRB0, G17_IRB1, G17_IRB2]: + G17_IRA.add_irblock(irb) # Test graph 1 G1_TEST1_DN1 = DependencyNode( - G1_IRB2.label, A, len(G1_IRB2)) + G1_IRB2.loc_key, A, len(G1_IRB2)) -G1_INPUT = (set([G1_TEST1_DN1]), set([G1_IRB0.label])) +G1_INPUT = (set([G1_TEST1_DN1]), set([G1_IRB0.loc_key])) # Test graph 2 G2_TEST1_DN1 = DependencyNode( - G2_IRB2.label, A, len(G2_IRB2)) + G2_IRB2.loc_key, A, len(G2_IRB2)) -G2_INPUT = (set([G2_TEST1_DN1]), set([G2_IRB0.label])) +G2_INPUT = (set([G2_TEST1_DN1]), set([G2_IRB0.loc_key])) # Test graph 3 G3_TEST1_0_DN1 = DependencyNode( - G3_IRB3.label, A, len(G3_IRB3)) + G3_IRB3.loc_key, A, len(G3_IRB3)) -G3_INPUT = (set([G3_TEST1_0_DN1]), set([G3_IRB0.label])) +G3_INPUT = (set([G3_TEST1_0_DN1]), set([G3_IRB0.loc_key])) # Test graph 4 G4_TEST1_DN1 = DependencyNode( - G4_IRB2.label, A, len(G2_IRB0)) + G4_IRB2.loc_key, A, len(G2_IRB0)) -G4_INPUT = (set([G4_TEST1_DN1]), set([G4_IRB0.label])) +G4_INPUT = (set([G4_TEST1_DN1]), set([G4_IRB0.loc_key])) # Test graph 5 G5_TEST1_0_DN1 = DependencyNode( - G5_IRB2.label, A, len(G5_IRB2)) + G5_IRB2.loc_key, A, len(G5_IRB2)) -G5_INPUT = (set([G5_TEST1_0_DN1]), set([G5_IRB0.label])) +G5_INPUT = (set([G5_TEST1_0_DN1]), set([G5_IRB0.loc_key])) # Test graph 6 G6_TEST1_0_DN1 = DependencyNode( - G6_IRB1.label, A, len(G6_IRB1)) + G6_IRB1.loc_key, A, len(G6_IRB1)) -G6_INPUT = (set([G6_TEST1_0_DN1]), set([G6_IRB0.label])) +G6_INPUT = (set([G6_TEST1_0_DN1]), set([G6_IRB0.loc_key])) # Test graph 7 G7_TEST1_0_DN1 = DependencyNode( - G7_IRB2.label, D, len(G7_IRB2)) + G7_IRB2.loc_key, D, len(G7_IRB2)) -G7_INPUT = (set([G7_TEST1_0_DN1]), set([G7_IRB0.label])) +G7_INPUT = (set([G7_TEST1_0_DN1]), set([G7_IRB0.loc_key])) # Test graph 8 G8_TEST1_0_DN1 = DependencyNode( - G8_IRB2.label, A, len(G8_IRB2)) + G8_IRB2.loc_key, A, len(G8_IRB2)) -G8_INPUT = (set([G8_TEST1_0_DN1]), set([G3_IRB0.label])) +G8_INPUT = (set([G8_TEST1_0_DN1]), set([G3_IRB0.loc_key])) # Test 9: Multi elements G9_TEST1_0_DN1 = DependencyNode( - G8_IRB2.label, A, len(G8_IRB2)) + G8_IRB2.loc_key, A, len(G8_IRB2)) G9_TEST1_0_DN5 = DependencyNode( - G8_IRB2.label, C, len(G8_IRB2)) + G8_IRB2.loc_key, C, len(G8_IRB2)) -G9_INPUT = (set([G9_TEST1_0_DN1, G9_TEST1_0_DN5]), set([G8_IRB0.label])) +G9_INPUT = (set([G9_TEST1_0_DN1, G9_TEST1_0_DN5]), set([G8_IRB0.loc_key])) # Test 10: loop at beginning G10_TEST1_0_DN1 = DependencyNode( - G10_IRB2.label, A, len(G10_IRB2)) + G10_IRB2.loc_key, A, len(G10_IRB2)) -G10_INPUT = (set([G10_TEST1_0_DN1]), set([G10_IRB1.label])) +G10_INPUT = (set([G10_TEST1_0_DN1]), set([G10_IRB1.loc_key])) # Test 11: no dual bloc emulation G11_TEST1_DN1 = DependencyNode( - G11_IRB2.label, A, len(G11_IRB2)) + G11_IRB2.loc_key, A, len(G11_IRB2)) -G11_INPUT = (set([G11_TEST1_DN1]), set([G11_IRB0.label])) +G11_INPUT = (set([G11_TEST1_DN1]), set([G11_IRB0.loc_key])) # Test graph 12 -G12_TEST1_0_DN1 = DependencyNode(G12_IRB2.label, B, 1) +G12_TEST1_0_DN1 = DependencyNode(G12_IRB2.loc_key, B, 1) G12_INPUT = (set([G12_TEST1_0_DN1]), set([])) @@ -597,7 +706,7 @@ G12_INPUT = (set([G12_TEST1_0_DN1]), set([])) # All filters -G13_TEST1_0_DN4 = DependencyNode(G13_IRB3.label, R, 1) +G13_TEST1_0_DN4 = DependencyNode(G13_IRB3.loc_key, R, 1) G13_INPUT = (set([G13_TEST1_0_DN4]), set([])) @@ -605,24 +714,24 @@ G13_INPUT = (set([G13_TEST1_0_DN4]), set([])) # All filters -G14_TEST1_0_DN1 = DependencyNode(G14_IRB3.label, R, 1) +G14_TEST1_0_DN1 = DependencyNode(G14_IRB3.loc_key, R, 1) G14_INPUT = (set([G14_TEST1_0_DN1]), set([])) # Test graph 15 -G15_TEST1_0_DN1 = DependencyNode(G15_IRB2.label, R, 1) +G15_TEST1_0_DN1 = DependencyNode(G15_IRB2.loc_key, R, 1) G15_INPUT = (set([G15_TEST1_0_DN1]), set([])) # Test graph 16 -G16_TEST1_0_DN1 = DependencyNode(G16_IRB5.label, R, 1) +G16_TEST1_0_DN1 = DependencyNode(G16_IRB5.loc_key, R, 1) G16_INPUT = (set([G16_TEST1_0_DN1]), set([])) # Test graph 17 -G17_TEST1_DN1 = DependencyNode(G17_IRB2.label, A, 1) +G17_TEST1_DN1 = DependencyNode(G17_IRB2.loc_key, A, 1) G17_INPUT = (set([G17_TEST1_DN1]), set([])) @@ -638,7 +747,8 @@ def flatNode(node): element = int(node.element.arg) else: RuntimeError("Unsupported type '%s'" % type(enode.element)) - return (node.label.name, + name = loc_db.pretty_str(node.loc_key) + return (name, element, node.line_nb) else: @@ -736,7 +846,8 @@ def match_results(resultsA, resultsB, nodes): def get_flat_init_depnodes(depnodes): out = [] for node in depnodes: - out.append((node.label.name, + name = loc_db.pretty_str(node.loc_key) + out.append((name, node.element.name, node.line_nb, 0)) @@ -1017,21 +1128,23 @@ for test_nb, test in enumerate([(G1_IRA, G1_INPUT), # Extract test elements print "[+] Test", test_nb + 1 - g_ira, (depnodes, heads) = test + ircfg, (depnodes, heads) = test - open("graph_%02d.dot" % (test_nb + 1), "w").write(g_ira.graph.dot()) - open("graph_%02d.dot" % (test_nb + 1), "w").write(bloc2graph(g_ira)) + open("graph_%02d.dot" % (test_nb + 1), "w").write(ircfg.dot()) + open("graph_%02d.dot" % (test_nb + 1), "w").write(bloc2graph(ircfg)) # Different options suffix_key_list = ["", "_nosimp", "_nomem", "_nocall", "_implicit"] # Test classes - for g_ind, g_dep in enumerate([DependencyGraph(g_ira), - DependencyGraph(g_ira, apply_simp=False), - DependencyGraph(g_ira, follow_mem=False), - DependencyGraph(g_ira, follow_mem=False, - follow_call=False), - # DependencyGraph(g_ira, implicit=True), + for g_ind, g_dep in enumerate([DependencyGraph(ircfg), + DependencyGraph(ircfg, apply_simp=False), + DependencyGraph(ircfg, follow_mem=False), + DependencyGraph( + ircfg, follow_mem=False, + follow_call=False + ), + # DependencyGraph(ircfg, implicit=True), ]): # if g_ind == 4: # TODO: Implicit specifications @@ -1052,14 +1165,13 @@ for test_nb, test in enumerate([(G1_IRA, G1_INPUT), all_results.add(unflatGraph(flatGraph(result.graph))) open("graph_test_%02d_%02d.dot" % (test_nb + 1, i), "w").write(dg2graph(result.graph)) - # print all_flat + if g_ind == 0: all_flat = sorted(all_flat) all_flats.append(all_flat) flat_depnodes = get_flat_init_depnodes(depnodes) if not match_results(all_results, test_results[test_nb], flat_depnodes): FAILED.add(test_nb) - # fds continue if FAILED: diff --git a/test/analysis/dg_test_02_implicit_expected.json b/test/analysis/dg_test_02_implicit_expected.json index 9394f01d..cfcf7258 100644 --- a/test/analysis/dg_test_02_implicit_expected.json +++ b/test/analysis/dg_test_02_implicit_expected.json @@ -1 +1 @@ -[{"has_loop": false, "EAX": "0x4", "satisfiability": true, "constraints": {"zf_init": "0x1"}}, {"has_loop": false, "EAX": "0x3", "satisfiability": true, "constraints": {"zf_init": "0x0"}}] +[{"has_loop": false, "EAX": "0x4", "satisfiability": true, "constraints": {"zf": "0x1"}}, {"has_loop": false, "EAX": "0x3", "satisfiability": true, "constraints": {"zf": "0x0"}}] diff --git a/test/analysis/dg_test_04_expected.json b/test/analysis/dg_test_04_expected.json index fb115835..24687e4a 100644 --- a/test/analysis/dg_test_04_expected.json +++ b/test/analysis/dg_test_04_expected.json @@ -1 +1 @@ -[{"EAX": "EBX_init", "has_loop": false}] +[{"EAX": "EBX", "has_loop": false}] diff --git a/test/analysis/dg_test_04_implicit_expected.json b/test/analysis/dg_test_04_implicit_expected.json index 73e7209e..21dbfc96 100644 --- a/test/analysis/dg_test_04_implicit_expected.json +++ b/test/analysis/dg_test_04_implicit_expected.json @@ -1 +1 @@ -[{"has_loop": false, "EAX": "EBX_init", "satisfiability": true, "constraints": {}}, {"has_loop": true, "EAX": "EBX_init", "satisfiability": false, "constraints": {}}] +[{"has_loop": false, "EAX": "EBX", "satisfiability": true, "constraints": {}}, {"has_loop": true, "EAX": "EBX", "satisfiability": false, "constraints": {}}] diff --git a/test/analysis/dg_test_06_implicit_expected.json b/test/analysis/dg_test_06_implicit_expected.json index bda75296..be4e9afb 100644 --- a/test/analysis/dg_test_06_implicit_expected.json +++ b/test/analysis/dg_test_06_implicit_expected.json @@ -1 +1 @@ -[{"has_loop": false, "EAX": "0x1", "satisfiability": true, "constraints": {"EAX_init": "0xffffffff"}}, {"has_loop": false, "EAX": "0x2", "satisfiability": false, "constraints": {}}] +[{"has_loop": false, "EAX": "0x1", "satisfiability": true, "constraints": {"EAX": "0xffffffff"}}, {"has_loop": false, "EAX": "0x2", "satisfiability": false, "constraints": {}}] diff --git a/test/analysis/dg_test_10_implicit_expected.json b/test/analysis/dg_test_10_implicit_expected.json index 05b34918..36a84788 100644 --- a/test/analysis/dg_test_10_implicit_expected.json +++ b/test/analysis/dg_test_10_implicit_expected.json @@ -1 +1 @@ -[{"has_loop": false, "EAX": "0x1", "EBX": "0x3", "satisfiability": true, "constraints": {"zf_init": "0x0"}}, {"has_loop": false, "EAX": "0x2", "EBX": "0x3", "satisfiability": false, "constraints": {}}, {"has_loop": false, "EAX": "0x1", "EBX": "0x4", "satisfiability": false, "constraints": {}}, {"has_loop": false, "EAX": "0x2", "EBX": "0x4", "satisfiability": true, "constraints": {"zf_init": "0x1"}}] +[{"has_loop": false, "EAX": "0x1", "EBX": "0x3", "satisfiability": true, "constraints": {"zf": "0x0"}}, {"has_loop": false, "EAX": "0x2", "EBX": "0x3", "satisfiability": false, "constraints": {}}, {"has_loop": false, "EAX": "0x1", "EBX": "0x4", "satisfiability": false, "constraints": {}}, {"has_loop": false, "EAX": "0x2", "EBX": "0x4", "satisfiability": true, "constraints": {"zf": "0x1"}}] diff --git a/test/analysis/dse.py b/test/analysis/dse.py index 5a72db34..a05d8595 100644 --- a/test/analysis/dse.py +++ b/test/analysis/dse.py @@ -34,8 +34,7 @@ class DSETest(object): self.myjit = jitter(jitter_engine) self.myjit.init_stack() - self.myjit.jit.log_regs = True - self.myjit.jit.log_mn = True + self.myjit.set_trace_log() self.dse = None self.assembly = None @@ -70,17 +69,17 @@ class DSETest(object): def asm(self): mn_x86 = self.machine.mn - blocks, symbol_pool = parse_asm.parse_txt( + blocks, loc_db = parse_asm.parse_txt( mn_x86, self.arch_attrib, self.TXT, - symbol_pool=self.myjit.ir_arch.symbol_pool + loc_db=self.myjit.ir_arch.loc_db ) # fix shellcode addr - symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) + loc_db.set_location_offset(loc_db.get_name_location("main"), 0x0) output = StrPatchwork() - patches = asm_resolve_final(mn_x86, blocks, symbol_pool) + patches = asm_resolve_final(mn_x86, blocks, loc_db) for offset, raw in patches.items(): output[offset] = raw |