diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/analysis/depgraph.py | 246 | ||||
| -rw-r--r-- | test/arch/aarch64/unit/asm_test.py | 8 | ||||
| -rwxr-xr-x | test/arch/arm/sem.py | 4 | ||||
| -rw-r--r-- | test/arch/mips32/unit/asm_test.py | 8 | ||||
| -rwxr-xr-x | test/arch/msp430/sem.py | 4 | ||||
| -rwxr-xr-x | test/arch/x86/sem.py | 12 | ||||
| -rw-r--r-- | test/arch/x86/unit/asm_test.py | 8 | ||||
| -rw-r--r-- | test/core/asmblock.py (renamed from test/core/asmbloc.py) | 52 | ||||
| -rwxr-xr-x | test/core/parse_asm.py | 2 | ||||
| -rw-r--r-- | test/core/sembuilder.py | 8 | ||||
| -rw-r--r-- | test/ir/analysis.py | 456 | ||||
| -rwxr-xr-x | test/ir/symbexec.py | 10 | ||||
| -rw-r--r-- | test/ir/translators/z3_ir.py | 6 | ||||
| -rwxr-xr-x | test/test_all.py | 2 |
14 files changed, 413 insertions, 413 deletions
diff --git a/test/analysis/depgraph.py b/test/analysis/depgraph.py index 0b8d97b6..24095c7b 100644 --- a/test/analysis/depgraph.py +++ b/test/analysis/depgraph.py @@ -1,9 +1,9 @@ """Regression test module for DependencyGraph""" from miasm2.expression.expression import ExprId, ExprInt32, ExprAff, ExprCond, \ ExprInt -from miasm2.core.asmbloc import asm_label +from miasm2.core.asmblock import AsmLabel from miasm2.ir.analysis import ira -from miasm2.ir.ir import ir, irbloc, AssignBlock +from miasm2.ir.ir import IRBlock, AssignBlock from miasm2.core.graph import DiGraph from miasm2.analysis.depgraph import DependencyNode, DependencyGraph from itertools import count @@ -42,15 +42,15 @@ CST33 = ExprInt32(0x33) CST35 = ExprInt32(0x35) CST37 = ExprInt32(0x37) -LBL0 = asm_label("lbl0") -LBL1 = asm_label("lbl1") -LBL2 = asm_label("lbl2") -LBL3 = asm_label("lbl3") -LBL4 = asm_label("lbl4") -LBL5 = asm_label("lbl5") -LBL6 = asm_label("lbl6") +LBL0 = AsmLabel("lbl0") +LBL1 = AsmLabel("lbl1") +LBL2 = AsmLabel("lbl2") +LBL3 = AsmLabel("lbl3") +LBL4 = AsmLabel("lbl4") +LBL5 = AsmLabel("lbl5") +LBL6 = AsmLabel("lbl6") -def gen_irbloc(label, exprs_list): +def gen_irblock(label, exprs_list): """ Returns an IRBlock with empty lines. Used only for tests purpose """ @@ -62,7 +62,7 @@ def gen_irbloc(label, exprs_list): else: irs.append(AssignBlock(exprs)) - irbl = irbloc(label, irs, lines) + irbl = IRBlock(label, irs, lines) return irbl @@ -114,16 +114,16 @@ def bloc2graph(irgraph, label=False, lines=True): # Generate basic blocks out_blocks = [] for label in irgraph.graph.nodes(): - if isinstance(label, asm_label): + if isinstance(label, AsmLabel): label_name = label.name else: label_name = str(label) - if hasattr(irgraph, 'blocs'): - irblock = irgraph.blocs[label] + if hasattr(irgraph, 'blocks'): + irblock = irgraph.blocks[label] else: irblock = None - if isinstance(label, asm_label): + if isinstance(label, AsmLabel): out_block = '%s [\n' % label.name else: out_block = '%s [\n' % label @@ -154,11 +154,11 @@ def bloc2graph(irgraph, label=False, lines=True): out += out_blocks # Generate links for src, dst in irgraph.graph.edges(): - if isinstance(src, asm_label): + if isinstance(src, AsmLabel): src_name = src.name else: src_name = str(src) - if isinstance(dst, asm_label): + if isinstance(dst, AsmLabel): dst_name = dst.name else: dst_name = str(dst) @@ -232,122 +232,122 @@ DNC3 = DependencyNode(LBL1, C, 0) G1_IRA = IRATest() -G1_IRB0 = gen_irbloc(LBL0, [[ExprAff(C, CST1)]]) -G1_IRB1 = gen_irbloc(LBL1, [[ExprAff(B, C)]]) -G1_IRB2 = gen_irbloc(LBL2, [[ExprAff(A, B)]]) +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.graph.add_uniq_edge(G1_IRB0.label, G1_IRB1.label) G1_IRA.graph.add_uniq_edge(G1_IRB1.label, G1_IRB2.label) -G1_IRA.blocs = dict([(irb.label, irb) for irb in [G1_IRB0, G1_IRB1, G1_IRB2]]) +G1_IRA.blocks = dict([(irb.label, irb) for irb in [G1_IRB0, G1_IRB1, G1_IRB2]]) # graph 2 G2_IRA = IRATest() -G2_IRB0 = gen_irbloc(LBL0, [[ExprAff(C, CST1)]]) -G2_IRB1 = gen_irbloc(LBL1, [[ExprAff(B, CST2)]]) -G2_IRB2 = gen_irbloc(LBL2, [[ExprAff(A, B + C)]]) +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_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.blocs = dict([(irb.label, irb) for irb in [G2_IRB0, G2_IRB1, G2_IRB2]]) +G2_IRA.blocks = dict([(irb.label, irb) for irb in [G2_IRB0, G2_IRB1, G2_IRB2]]) # graph 3 G3_IRA = IRATest() -G3_IRB0 = gen_irbloc(LBL0, [[ExprAff(C, CST1)]]) -G3_IRB1 = gen_irbloc(LBL1, [[ExprAff(B, CST2)]]) -G3_IRB2 = gen_irbloc(LBL2, [[ExprAff(B, CST3)]]) -G3_IRB3 = gen_irbloc(LBL3, [[ExprAff(A, B + C)]]) +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.blocs = dict([(irb.label, irb) for irb in [G3_IRB0, G3_IRB1, - G3_IRB2, G3_IRB3]]) +G3_IRA.blocks = dict([(irb.label, irb) for irb in [G3_IRB0, G3_IRB1, + G3_IRB2, G3_IRB3]]) # graph 4 G4_IRA = IRATest() -G4_IRB0 = gen_irbloc(LBL0, [[ExprAff(C, CST1)]]) -G4_IRB1 = gen_irbloc(LBL1, [[ExprAff(C, C + CST2)], - [ExprAff(G4_IRA.IRDst, - ExprCond(C, ExprId(LBL2), - ExprId(LBL1)))]]) +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), + ExprId(LBL1)))]]) -G4_IRB2 = gen_irbloc(LBL2, [[ExprAff(A, B)]]) +G4_IRB2 = gen_irblock(LBL2, [[ExprAff(A, B)]]) 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_IRA.blocs = dict([(irb.label, irb) for irb in [G4_IRB0, G4_IRB1, G4_IRB2]]) +G4_IRA.blocks = dict([(irb.label, irb) for irb in [G4_IRB0, G4_IRB1, G4_IRB2]]) # graph 5 G5_IRA = IRATest() -G5_IRB0 = gen_irbloc(LBL0, [[ExprAff(B, CST1)]]) -G5_IRB1 = gen_irbloc(LBL1, [[ExprAff(B, B + CST2)], - [ExprAff(G5_IRA.IRDst, - ExprCond(B, ExprId(LBL2), - ExprId(LBL1)))]]) +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), + ExprId(LBL1)))]]) -G5_IRB2 = gen_irbloc(LBL2, [[ExprAff(A, B)]]) +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.blocs = dict([(irb.label, irb) for irb in [G5_IRB0, G5_IRB1, G5_IRB2]]) +G5_IRA.blocks = dict([(irb.label, irb) for irb in [G5_IRB0, G5_IRB1, G5_IRB2]]) # graph 6 G6_IRA = IRATest() -G6_IRB0 = gen_irbloc(LBL0, [[ExprAff(B, CST1)]]) -G6_IRB1 = gen_irbloc(LBL1, [[ExprAff(A, B)]]) +G6_IRB0 = gen_irblock(LBL0, [[ExprAff(B, CST1)]]) +G6_IRB1 = gen_irblock(LBL1, [[ExprAff(A, B)]]) 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.blocs = dict([(irb.label, irb) for irb in [G6_IRB0, G6_IRB1]]) +G6_IRA.blocks = dict([(irb.label, irb) for irb in [G6_IRB0, G6_IRB1]]) # graph 7 G7_IRA = IRATest() -G7_IRB0 = gen_irbloc(LBL0, [[ExprAff(C, CST1)]]) -G7_IRB1 = gen_irbloc(LBL1, [[ExprAff(B, C)], [ExprAff(A, B)]]) -G7_IRB2 = gen_irbloc(LBL2, [[ExprAff(D, A)]]) +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.blocs = dict([(irb.label, irb) for irb in [G7_IRB0, G7_IRB1, G7_IRB2]]) +G7_IRA.blocks = dict([(irb.label, irb) for irb in [G7_IRB0, G7_IRB1, G7_IRB2]]) # graph 8 G8_IRA = IRATest() -G8_IRB0 = gen_irbloc(LBL0, [[ExprAff(C, CST1)]]) -G8_IRB1 = gen_irbloc(LBL1, [[ExprAff(B, C)], [ExprAff(C, D)]]) -G8_IRB2 = gen_irbloc(LBL2, [[ExprAff(A, B)]]) +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.blocs = dict([(irb.label, irb) for irb in [G8_IRB0, G8_IRB1, G8_IRB2]]) +G8_IRA.blocks = dict([(irb.label, irb) for irb in [G8_IRB0, G8_IRB1, G8_IRB2]]) # graph 9 is graph 8 @@ -355,131 +355,131 @@ G8_IRA.blocs = dict([(irb.label, irb) for irb in [G8_IRB0, G8_IRB1, G8_IRB2]]) G10_IRA = IRATest() -G10_IRB1 = gen_irbloc(LBL1, [[ExprAff(B, B + CST2)]]) -G10_IRB2 = gen_irbloc(LBL2, [[ExprAff(A, B)]]) +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.blocs = dict([(irb.label, irb) for irb in [G10_IRB1, G10_IRB2]]) +G10_IRA.blocks = dict([(irb.label, irb) for irb in [G10_IRB1, G10_IRB2]]) # graph 11 G11_IRA = IRATest() -G11_IRB0 = gen_irbloc(LBL0, [[ExprAff(A, CST1), - ExprAff(B, CST2)]]) -G11_IRB1 = gen_irbloc(LBL1, [[ExprAff(A, B), - ExprAff(B, A)]]) -G11_IRB2 = gen_irbloc(LBL2, [[ExprAff(A, A - B)]]) +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.blocs = dict([(irb.label, irb) - for irb in [G11_IRB0, G11_IRB1, G11_IRB2]]) +G11_IRA.blocks = dict([(irb.label, irb) + for irb in [G11_IRB0, G11_IRB1, G11_IRB2]]) # graph 12 G12_IRA = IRATest() -G12_IRB0 = gen_irbloc(LBL0, [[ExprAff(B, CST1)]]) -G12_IRB1 = gen_irbloc(LBL1, [[ExprAff(A, B)], [ExprAff(B, B + CST2)]]) -G12_IRB2 = gen_irbloc(LBL2, [[ExprAff(B, A)]]) +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_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_IRA.blocs = dict([(irb.label, irb) for irb in [G12_IRB0, G12_IRB1, - G12_IRB2]]) +G12_IRA.blocks = dict([(irb.label, irb) for irb in [G12_IRB0, G12_IRB1, + G12_IRB2]]) # graph 13 G13_IRA = IRATest() -G13_IRB0 = gen_irbloc(LBL0, [[ExprAff(A, CST1)], - #[ExprAff(B, A)], - [ExprAff(G13_IRA.IRDst, - ExprId(LBL1))]]) -G13_IRB1 = gen_irbloc(LBL1, [[ExprAff(C, A)], - #[ExprAff(A, A + CST1)], - [ExprAff(G13_IRA.IRDst, - ExprCond(R, ExprId(LBL2), - ExprId(LBL1)))]]) +G13_IRB0 = gen_irblock(LBL0, [[ExprAff(A, CST1)], + #[ExprAff(B, A)], + [ExprAff(G13_IRA.IRDst, + ExprId(LBL1))]]) +G13_IRB1 = gen_irblock(LBL1, [[ExprAff(C, A)], + #[ExprAff(A, A + CST1)], + [ExprAff(G13_IRA.IRDst, + ExprCond(R, ExprId(LBL2), + ExprId(LBL1)))]]) -G13_IRB2 = gen_irbloc(LBL2, [[ExprAff(B, A + CST3)], [ExprAff(A, B + CST3)], - [ExprAff(G13_IRA.IRDst, - ExprId(LBL1))]]) +G13_IRB2 = gen_irblock(LBL2, [[ExprAff(B, A + CST3)], [ExprAff(A, B + CST3)], + [ExprAff(G13_IRA.IRDst, + ExprId(LBL1))]]) -G13_IRB3 = gen_irbloc(LBL3, [[ExprAff(R, C)]]) +G13_IRB3 = gen_irblock(LBL3, [[ExprAff(R, C)]]) 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_IRA.blocs = dict([(irb.label, irb) for irb in [G13_IRB0, G13_IRB1, - G13_IRB2, G13_IRB3]]) +G13_IRA.blocks = dict([(irb.label, irb) for irb in [G13_IRB0, G13_IRB1, + G13_IRB2, G13_IRB3]]) # graph 14 G14_IRA = IRATest() -G14_IRB0 = gen_irbloc(LBL0, [[ExprAff(A, CST1)], - [ExprAff(G14_IRA.IRDst, - ExprId(LBL1))] +G14_IRB0 = gen_irblock(LBL0, [[ExprAff(A, CST1)], + [ExprAff(G14_IRA.IRDst, + ExprId(LBL1))] ]) -G14_IRB1 = gen_irbloc(LBL1, [[ExprAff(B, A)], - [ExprAff(G14_IRA.IRDst, - ExprCond(C, ExprId(LBL2), - ExprId(LBL3)))] +G14_IRB1 = gen_irblock(LBL1, [[ExprAff(B, A)], + [ExprAff(G14_IRA.IRDst, + ExprCond(C, ExprId(LBL2), + ExprId(LBL3)))] ]) -G14_IRB2 = gen_irbloc(LBL2, [[ExprAff(D, A)], - [ExprAff(A, D + CST1)], - [ExprAff(G14_IRA.IRDst, - ExprId(LBL1))] +G14_IRB2 = gen_irblock(LBL2, [[ExprAff(D, A)], + [ExprAff(A, D + CST1)], + [ExprAff(G14_IRA.IRDst, + ExprId(LBL1))] ]) -G14_IRB3 = gen_irbloc(LBL3, [[ExprAff(R, D + B)]]) +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_IRA.blocs = dict([(irb.label, irb) for irb in [G14_IRB0, G14_IRB1, - G14_IRB2, G14_IRB3]]) +G14_IRA.blocks = dict([(irb.label, irb) for irb in [G14_IRB0, G14_IRB1, + G14_IRB2, G14_IRB3]]) # graph 16 G15_IRA = IRATest() -G15_IRB0 = gen_irbloc(LBL0, [[ExprAff(A, CST1)]]) -G15_IRB1 = gen_irbloc(LBL1, [[ExprAff(D, A + B)], - [ExprAff(C, D)], - [ExprAff(B, C)]]) -G15_IRB2 = gen_irbloc(LBL2, [[ExprAff(R, B)]]) +G15_IRB0 = gen_irblock(LBL0, [[ExprAff(A, CST1)]]) +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.blocs = dict([(irb.label, irb) for irb in [G15_IRB0, G15_IRB1, - G15_IRB2]]) +G15_IRA.blocks = dict([(irb.label, irb) for irb in [G15_IRB0, G15_IRB1, + G15_IRB2]]) # graph 16 G16_IRA = IRATest() -G16_IRB0 = gen_irbloc(LBL0, [[ExprAff(A, CST1)]]) -G16_IRB1 = gen_irbloc(LBL1, [[ExprAff(R, D)]]) -G16_IRB2 = gen_irbloc(LBL2, [[ExprAff(D, A)]]) -G16_IRB3 = gen_irbloc(LBL3, [[ExprAff(R, D)]]) -G16_IRB4 = gen_irbloc(LBL4, [[ExprAff(R, A)]]) -G16_IRB5 = gen_irbloc(LBL5, [[ExprAff(R, A)]]) +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) @@ -490,25 +490,25 @@ 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.blocs = dict([(irb.label, irb) for irb in [G16_IRB0, G16_IRB1, - G16_IRB2, G16_IRB3, - G16_IRB4, G16_IRB5]]) +G16_IRA.blocks = dict([(irb.label, irb) for irb in [G16_IRB0, G16_IRB1, + G16_IRB2, G16_IRB3, + G16_IRB4, G16_IRB5]]) # graph 17 G17_IRA = IRATest() -G17_IRB0 = gen_irbloc(LBL0, [[ExprAff(A, CST1), - ExprAff(D, CST2)]]) -G17_IRB1 = gen_irbloc(LBL1, [[ExprAff(A, D), - ExprAff(B, D)]]) -G17_IRB2 = gen_irbloc(LBL2, [[ExprAff(A, A - B)]]) +G17_IRB0 = gen_irblock(LBL0, [[ExprAff(A, CST1), + ExprAff(D, CST2)]]) +G17_IRB1 = gen_irblock(LBL1, [[ExprAff(A, D), + ExprAff(B, D)]]) +G17_IRB2 = gen_irblock(LBL2, [[ExprAff(A, A - B)]]) 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.blocs = dict([(irb.label, irb) for irb in [G17_IRB0, G17_IRB1, - G17_IRB2]]) +G17_IRA.blocks = dict([(irb.label, irb) for irb in [G17_IRB0, G17_IRB1, + G17_IRB2]]) # Test graph 1 G1_TEST1_DN1 = DependencyNode( diff --git a/test/arch/aarch64/unit/asm_test.py b/test/arch/aarch64/unit/asm_test.py index 54ab476d..ddb8a08c 100644 --- a/test/arch/aarch64/unit/asm_test.py +++ b/test/arch/aarch64/unit/asm_test.py @@ -5,7 +5,7 @@ from miasm2.core.cpu import ParseAst from miasm2.arch.aarch64.arch import mn_aarch64, base_expr, variable from miasm2.core import parse_asm from miasm2.expression.expression import * -from miasm2.core import asmbloc +from miasm2.core import asmblock from elfesteem.strpatchwork import StrPatchwork from miasm2.analysis.machine import Machine from miasm2.jitter.csts import * @@ -28,12 +28,12 @@ class Asm_Test(object): def asm(self): - blocs, symbol_pool = parse_asm.parse_txt(mn_aarch64, 'l', self.TXT, - symbol_pool = self.myjit.ir_arch.symbol_pool) + blocks, symbol_pool = parse_asm.parse_txt(mn_aarch64, 'l', self.TXT, + symbol_pool = self.myjit.ir_arch.symbol_pool) # fix shellcode addr symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) s = StrPatchwork() - patches = asmbloc.asm_resolve_final(mn_aarch64, blocs, symbol_pool) + patches = asmblock.asm_resolve_final(mn_aarch64, blocks, symbol_pool) for offset, raw in patches.items(): s[offset] = raw diff --git a/test/arch/arm/sem.py b/test/arch/arm/sem.py index 3695fd29..01c536cd 100755 --- a/test/arch/arm/sem.py +++ b/test/arch/arm/sem.py @@ -4,7 +4,7 @@ import unittest import logging -from miasm2.ir.symbexec import symbexec +from miasm2.ir.symbexec import SymbolicExecutionEngine from miasm2.arch.arm.arch import mn_arm as mn from miasm2.arch.arm.sem import ir_arml as ir_arch from miasm2.arch.arm.regs import * @@ -23,7 +23,7 @@ def compute(asm, inputstate={}, debug=False): sympool = dict(regs_init) sympool.update({k: ExprInt(v, k.size) for k, v in inputstate.iteritems()}) interm = ir_arch() - symexec = symbexec(interm, sympool) + symexec = SymbolicExecutionEngine(interm, sympool) instr = mn.fromstring(asm, "l") code = mn.asm(instr)[0] instr = mn.dis(code, "l") diff --git a/test/arch/mips32/unit/asm_test.py b/test/arch/mips32/unit/asm_test.py index 4425bb65..9281f1b6 100644 --- a/test/arch/mips32/unit/asm_test.py +++ b/test/arch/mips32/unit/asm_test.py @@ -5,7 +5,7 @@ from miasm2.core.cpu import ParseAst from miasm2.arch.mips32.arch import mn_mips32, base_expr, variable from miasm2.core import parse_asm from miasm2.expression.expression import * -from miasm2.core import asmbloc +from miasm2.core import asmblock from elfesteem.strpatchwork import StrPatchwork from miasm2.analysis.machine import Machine from miasm2.jitter.csts import * @@ -28,12 +28,12 @@ class Asm_Test(object): self.check() def asm(self): - blocs, symbol_pool = parse_asm.parse_txt(mn_mips32, 'l', self.TXT, - symbol_pool=self.myjit.ir_arch.symbol_pool) + blocks, symbol_pool = parse_asm.parse_txt(mn_mips32, 'l', self.TXT, + symbol_pool=self.myjit.ir_arch.symbol_pool) # fix shellcode addr symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) s = StrPatchwork() - patches = asmbloc.asm_resolve_final(mn_mips32, blocs, symbol_pool) + patches = asmblock.asm_resolve_final(mn_mips32, blocks, symbol_pool) for offset, raw in patches.items(): s[offset] = raw diff --git a/test/arch/msp430/sem.py b/test/arch/msp430/sem.py index 433055e0..4b5b0c7d 100755 --- a/test/arch/msp430/sem.py +++ b/test/arch/msp430/sem.py @@ -4,7 +4,7 @@ import unittest import logging -from miasm2.ir.symbexec import symbexec +from miasm2.ir.symbexec import SymbolicExecutionEngine from miasm2.arch.msp430.arch import mn_msp430 as mn, mode_msp430 as mode from miasm2.arch.msp430.sem import ir_msp430 as ir_arch from miasm2.arch.msp430.regs import * @@ -21,7 +21,7 @@ def compute(asm, inputstate={}, debug=False): sympool = dict(regs_init) sympool.update({k: ExprInt(v, k.size) for k, v in inputstate.iteritems()}) interm = ir_arch() - symexec = symbexec(interm, sympool) + symexec = SymbolicExecutionEngine(interm, sympool) instr = mn.fromstring(asm, mode) code = mn.asm(instr)[0] instr = mn.dis(code, mode) diff --git a/test/arch/x86/sem.py b/test/arch/x86/sem.py index d2198847..7b6a20b7 100755 --- a/test/arch/x86/sem.py +++ b/test/arch/x86/sem.py @@ -7,13 +7,13 @@ import unittest import logging import copy -from miasm2.ir.symbexec import symbexec +from miasm2.ir.symbexec import SymbolicExecutionEngine from miasm2.arch.x86.arch import mn_x86 as mn from miasm2.arch.x86.sem import ir_x86_32 as ir_32, ir_x86_64 as ir_64 from miasm2.arch.x86.regs import * from miasm2.expression.expression import * from miasm2.expression.simplifications import expr_simp -from miasm2.core import parse_asm, asmbloc +from miasm2.core import parse_asm, asmblock logging.getLogger('cpuhelper').setLevel(logging.ERROR) @@ -25,7 +25,7 @@ m64 = 64 def symb_exec(interm, inputstate, debug): sympool = dict(regs_init) sympool.update(inputstate) - symexec = symbexec(interm, sympool) + symexec = SymbolicExecutionEngine(interm, sympool) symexec.emul_ir_blocks(0) if debug: for k, v in symexec.symbols.items(): @@ -45,11 +45,11 @@ def compute(ir, mode, asm, inputstate={}, debug=False): def compute_txt(ir, mode, txt, inputstate={}, debug=False): - blocs, symbol_pool = parse_asm.parse_txt(mn, mode, txt) + blocks, symbol_pool = parse_asm.parse_txt(mn, mode, txt) symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) - patches = asmbloc.asm_resolve_final(mn, blocs, symbol_pool) + patches = asmblock.asm_resolve_final(mn, blocks, symbol_pool) interm = ir(symbol_pool) - for bbl in blocs: + for bbl in blocks: interm.add_bloc(bbl) return symb_exec(interm, inputstate, debug) diff --git a/test/arch/x86/unit/asm_test.py b/test/arch/x86/unit/asm_test.py index 524791ce..aba47df1 100644 --- a/test/arch/x86/unit/asm_test.py +++ b/test/arch/x86/unit/asm_test.py @@ -5,7 +5,7 @@ from miasm2.core.cpu import ParseAst from miasm2.arch.x86.arch import mn_x86, base_expr, variable from miasm2.core import parse_asm from miasm2.expression.expression import * -from miasm2.core import asmbloc +from miasm2.core import asmblock from elfesteem.strpatchwork import StrPatchwork from miasm2.analysis.machine import Machine from miasm2.jitter.csts import * @@ -44,12 +44,12 @@ class Asm_Test(object): assert(self.myjit.pc == self.ret_addr) def asm(self): - blocs, symbol_pool = parse_asm.parse_txt(mn_x86, self.arch_attrib, self.TXT, - symbol_pool = self.myjit.ir_arch.symbol_pool) + blocks, symbol_pool = parse_asm.parse_txt(mn_x86, self.arch_attrib, self.TXT, + symbol_pool = self.myjit.ir_arch.symbol_pool) # fix shellcode addr symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0) s = StrPatchwork() - patches = asmbloc.asm_resolve_final(mn_x86, blocs, symbol_pool) + patches = asmblock.asm_resolve_final(mn_x86, blocks, symbol_pool) for offset, raw in patches.items(): s[offset] = raw diff --git a/test/core/asmbloc.py b/test/core/asmblock.py index 5fbdca3e..79bf47be 100644 --- a/test/core/asmbloc.py +++ b/test/core/asmblock.py @@ -2,8 +2,8 @@ from pdb import pm from miasm2.arch.x86.disasm import dis_x86_32 from miasm2.analysis.binary import Container -from miasm2.core.asmbloc import AsmCFG, asm_constraint, asm_bloc, \ - asm_label, asm_block_bad, asm_constraint_to, asm_constraint_next, \ +from miasm2.core.asmblock import AsmCFG, AsmConstraint, AsmBlock, \ + AsmLabel, AsmBlockBad, AsmConstraintTo, AsmConstraintNext, \ bbl_simplifier from miasm2.core.graph import DiGraphSimplifier, MatchGraphJoker from miasm2.expression.expression import ExprId @@ -60,10 +60,10 @@ assert last_block in blocks for pred in blocks.predecessors(last_block): blocks.del_edge(pred, last_block) ### Link first and last block -blocks.add_edge(first_block, last_block, asm_constraint.c_next) +blocks.add_edge(first_block, last_block, AsmConstraint.c_next) ### Only one link between two blocks try: - blocks.add_edge(first_block, last_block, asm_constraint.c_to) + blocks.add_edge(first_block, last_block, AsmConstraint.c_to) good = False except AssertionError: good = True @@ -71,7 +71,7 @@ assert good ### Check final state assert len(first_block.bto) == 1 -assert list(first_block.bto)[0].c_t == asm_constraint.c_next +assert list(first_block.bto)[0].c_t == AsmConstraint.c_next ## Simplify the obtained graph to keep only blocks which reach a block ## finnishing with RET @@ -98,7 +98,7 @@ open("graph2.dot", "w").write(blocks.dot()) # Test helper methods ## Label2block should always be updated assert blocks.label2block(first_block.label) == first_block -my_block = asm_bloc(asm_label("testlabel")) +my_block = AsmBlock(AsmLabel("testlabel")) blocks.add_node(my_block) assert len(blocks) == 3 assert blocks.label2block(first_block.label) == first_block @@ -108,17 +108,17 @@ assert blocks.label2block(my_block.label) == my_block assert len(list(blocks.get_bad_blocks())) == 0 assert len(list(blocks.get_bad_blocks_predecessors())) == 0 ### Add a bad block, not linked -my_bad_block = asm_block_bad(asm_label("testlabel_bad")) +my_bad_block = AsmBlockBad(AsmLabel("testlabel_bad")) blocks.add_node(my_bad_block) assert list(blocks.get_bad_blocks()) == [my_bad_block] assert len(list(blocks.get_bad_blocks_predecessors())) == 0 ### Link the bad block and update edges ### Indeed, a sub-element has been modified (bto from a block from blocks) -my_block.bto.add(asm_constraint_to(my_bad_block.label)) +my_block.bto.add(AsmConstraintTo(my_bad_block.label)) blocks.rebuild_edges() assert list(blocks.get_bad_blocks_predecessors()) == [my_block] ### Test strict option -my_block.bto.add(asm_constraint_to(my_block.label)) +my_block.bto.add(AsmConstraintTo(my_block.label)) blocks.rebuild_edges() assert list(blocks.get_bad_blocks_predecessors(strict=False)) == [my_block] assert len(list(blocks.get_bad_blocks_predecessors(strict=True))) == 0 @@ -126,8 +126,8 @@ assert len(list(blocks.get_bad_blocks_predecessors(strict=True))) == 0 ## Sanity check blocks.sanity_check() ### Next on itself -my_block_ni = asm_bloc(asm_label("testlabel_nextitself")) -my_block_ni.bto.add(asm_constraint_next(my_block_ni.label)) +my_block_ni = AsmBlock(AsmLabel("testlabel_nextitself")) +my_block_ni.bto.add(AsmConstraintNext(my_block_ni.label)) blocks.add_node(my_block_ni) error_raised = False try: @@ -139,16 +139,16 @@ assert error_raised blocks.del_node(my_block_ni) blocks.sanity_check() ### Multiple next on the same node -my_block_target = asm_bloc(asm_label("testlabel_target")) +my_block_target = AsmBlock(AsmLabel("testlabel_target")) blocks.add_node(my_block_target) -my_block_src1 = asm_bloc(asm_label("testlabel_src1")) -my_block_src2 = asm_bloc(asm_label("testlabel_src2")) -my_block_src1.bto.add(asm_constraint_next(my_block_target.label)) +my_block_src1 = AsmBlock(AsmLabel("testlabel_src1")) +my_block_src2 = AsmBlock(AsmLabel("testlabel_src2")) +my_block_src1.bto.add(AsmConstraintNext(my_block_target.label)) blocks.add_node(my_block_src1) ### OK for now blocks.sanity_check() ### Add a second next from src2 to target (already src1 -> target) -my_block_src2.bto.add(asm_constraint_next(my_block_target.label)) +my_block_src2.bto.add(AsmConstraintNext(my_block_target.label)) blocks.add_node(my_block_src2) error_raised = False try: @@ -171,9 +171,9 @@ assert blocks.label2block(my_block_src1.label).max_size == 0 ## Check pendings ### Create a pending element -my_block_src = asm_bloc(asm_label("testlabel_pend_src")) -my_block_dst = asm_bloc(asm_label("testlabel_pend_dst")) -my_block_src.bto.add(asm_constraint_to(my_block_dst.label)) +my_block_src = AsmBlock(AsmLabel("testlabel_pend_src")) +my_block_dst = AsmBlock(AsmLabel("testlabel_pend_dst")) +my_block_src.bto.add(AsmConstraintTo(my_block_dst.label)) blocks.add_node(my_block_src) ### Check resulting state assert len(blocks) == 7 @@ -183,7 +183,7 @@ assert len(blocks.pendings[my_block_dst.label]) == 1 pending = list(blocks.pendings[my_block_dst.label])[0] assert isinstance(pending, blocks.AsmCFGPending) assert pending.waiter == my_block_src -assert pending.constraint == asm_constraint.c_to +assert pending.constraint == AsmConstraint.c_to ### Sanity check must fail error_raised = False try: @@ -219,7 +219,7 @@ assert len(list(blocks.get_bad_blocks())) == 1 ### Check "special" blocks entry_blocks = blocks.heads() bad_block = (block for block in entry_blocks - if isinstance(block, asm_block_bad)).next() + if isinstance(block, AsmBlockBad)).next() entry_blocks.remove(bad_block) alone_block = (block for block in entry_blocks if len(blocks.successors(block)) == 0).next() @@ -236,9 +236,9 @@ assert map(str, entry_block.lines) == ['XOR EAX, EAX', assert len(blocks.successors(entry_block)) == 2 assert len(entry_block.bto) == 2 nextb = blocks.label2block((cons.label for cons in entry_block.bto - if cons.c_t == asm_constraint.c_next).next()) + if cons.c_t == AsmConstraint.c_next).next()) tob = blocks.label2block((cons.label for cons in entry_block.bto - if cons.c_t == asm_constraint.c_to).next()) + if cons.c_t == AsmConstraint.c_to).next()) assert len(nextb.lines) == 4 assert map(str, nextb.lines) == ['XOR EDX, EDX', 'XOR ESI, ESI', @@ -257,7 +257,7 @@ blocks.apply_splitting(mdis.symbol_pool) assert blocks_bef == blocks ## Create conditions for a block split inside_firstbbl = mdis.symbol_pool.getby_offset(4) -tob.bto.add(asm_constraint_to(inside_firstbbl)) +tob.bto.add(AsmConstraintTo(inside_firstbbl)) blocks.rebuild_edges() assert len(blocks.pendings) == 1 assert inside_firstbbl in blocks.pendings @@ -277,8 +277,8 @@ preds = blocks.predecessors(newb) assert len(preds) == 2 assert entry_block in preds assert tob in preds -assert blocks.edges2constraint[(entry_block, newb)] == asm_constraint.c_next -assert blocks.edges2constraint[(tob, newb)] == asm_constraint.c_to +assert blocks.edges2constraint[(entry_block, newb)] == AsmConstraint.c_next +assert blocks.edges2constraint[(tob, newb)] == AsmConstraint.c_to # Check double block split diff --git a/test/core/parse_asm.py b/test/core/parse_asm.py index e91c8c8c..54f3be1d 100755 --- a/test/core/parse_asm.py +++ b/test/core/parse_asm.py @@ -38,7 +38,7 @@ class TestParseAsm(unittest.TestCase): def test_DirectiveDontSplit(self): from miasm2.arch.x86.arch import mn_x86 from miasm2.core.parse_asm import parse_txt - from miasm2.core.asmbloc import asm_resolve_final + from miasm2.core.asmblock import asm_resolve_final ASM0 = ''' lbl0: diff --git a/test/core/sembuilder.py b/test/core/sembuilder.py index 3a575727..d8fdb6c4 100644 --- a/test/core/sembuilder.py +++ b/test/core/sembuilder.py @@ -3,7 +3,7 @@ from pdb import pm from miasm2.core.sembuilder import SemBuilder import miasm2.expression.expression as m2_expr -from miasm2.core.asmbloc import asm_label +from miasm2.core.asmblock import AsmLabel # Test classes class IR(object): @@ -11,13 +11,13 @@ class IR(object): IRDst = m2_expr.ExprId("IRDst") def get_next_instr(self, _): - return asm_label("NEXT") + return AsmLabel("NEXT") def get_next_label(self, _): - return asm_label("NEXT") + return AsmLabel("NEXT") def gen_label(self): - return asm_label("GEN") + return AsmLabel("GEN") class Instr(object): mode = 32 diff --git a/test/ir/analysis.py b/test/ir/analysis.py index 913d9c56..6209b36b 100644 --- a/test/ir/analysis.py +++ b/test/ir/analysis.py @@ -1,8 +1,8 @@ """ Test cases for dead code elimination""" from miasm2.expression.expression import ExprId, ExprInt32, ExprAff, ExprMem -from miasm2.core.asmbloc import asm_label +from miasm2.core.asmblock import AsmLabel from miasm2.ir.analysis import ira -from miasm2.ir.ir import irbloc, AssignBlock +from miasm2.ir.ir import IRBlock, AssignBlock a = ExprId("a") b = ExprId("b") @@ -23,17 +23,17 @@ CST1 = ExprInt32(0x11) CST2 = ExprInt32(0x12) CST3 = ExprInt32(0x13) -LBL0 = asm_label("lbl0") -LBL1 = asm_label("lbl1") -LBL2 = asm_label("lbl2") -LBL3 = asm_label("lbl3") -LBL4 = asm_label("lbl4") -LBL5 = asm_label("lbl5") -LBL6 = asm_label("lbl6") +LBL0 = AsmLabel("lbl0") +LBL1 = AsmLabel("lbl1") +LBL2 = AsmLabel("lbl2") +LBL3 = AsmLabel("lbl3") +LBL4 = AsmLabel("lbl4") +LBL5 = AsmLabel("lbl5") +LBL6 = AsmLabel("lbl6") -def gen_irbloc(label, exprs_list): +def gen_irblock(label, exprs_list): lines = [None for _ in xrange(len(exprs_list))] irs = [] for exprs in exprs_list: @@ -42,7 +42,7 @@ def gen_irbloc(label, exprs_list): else: irs.append(AssignBlock(exprs)) - irbl = irbloc(label, irs, lines) + irbl = IRBlock(label, irs, lines) return irbl @@ -76,111 +76,111 @@ class IRATest(ira): G1_IRA = IRATest() -G1_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST2)]]) -G1_IRB1 = gen_irbloc(LBL1, [[ExprAff(a, b)]]) -G1_IRB2 = gen_irbloc(LBL2, [[ExprAff(r, a)]]) +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.graph.add_uniq_edge(G1_IRB0.label, G1_IRB1.label) G1_IRA.graph.add_uniq_edge(G1_IRB1.label, G1_IRB2.label) -G1_IRA.blocs = {irb.label : irb for irb in [G1_IRB0, G1_IRB1, G1_IRB2]} +G1_IRA.blocks = {irb.label : irb for irb in [G1_IRB0, G1_IRB1, G1_IRB2]} # Expected output for graph 1 G1_EXP_IRA = IRATest() -G1_EXP_IRB0 = gen_irbloc(LBL0, [[], [ExprAff(b, CST2)]]) -G1_EXP_IRB1 = gen_irbloc(LBL1, [[ExprAff(a, b)]]) -G1_EXP_IRB2 = gen_irbloc(LBL2, [[ExprAff(r, a)]]) +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.blocs = {irb.label : irb for irb in [G1_EXP_IRB0, G1_EXP_IRB1, - G1_EXP_IRB2]} +G1_EXP_IRA.blocks = {irb.label : irb for irb in [G1_EXP_IRB0, G1_EXP_IRB1, + G1_EXP_IRB2]} # graph 2 : Natural loop with dead variable G2_IRA = IRATest() -G2_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)], [ExprAff(r, CST1)]]) -G2_IRB1 = gen_irbloc(LBL1, [[ExprAff(a, a+CST1)]]) -G2_IRB2 = gen_irbloc(LBL2, [[ExprAff(a, r)]]) +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.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.blocs = {irb.label : irb for irb in [G2_IRB0, G2_IRB1, G2_IRB2]} +G2_IRA.blocks = {irb.label : irb for irb in [G2_IRB0, G2_IRB1, G2_IRB2]} # Expected output for graph 2 G2_EXP_IRA = IRATest() -G2_EXP_IRB0 = gen_irbloc(LBL0, [[], [ExprAff(r, CST1)]]) -G2_EXP_IRB1 = gen_irbloc(LBL1, [[]]) -G2_EXP_IRB2 = gen_irbloc(LBL2, [[]]) +G2_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(r, CST1)]]) +G2_EXP_IRB1 = gen_irblock(LBL1, [[]]) +G2_EXP_IRB2 = gen_irblock(LBL2, [[]]) -G2_EXP_IRA.blocs = {irb.label : irb for irb in [G2_EXP_IRB0, G2_EXP_IRB1, - G2_EXP_IRB2]} +G2_EXP_IRA.blocks = {irb.label : irb for irb in [G2_EXP_IRB0, G2_EXP_IRB1, + G2_EXP_IRB2]} # graph 3 : Natural loop with alive variables G3_IRA = IRATest() -G3_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)]]) -G3_IRB1 = gen_irbloc(LBL1, [[ExprAff(a, a+CST1)]]) -G3_IRB2 = gen_irbloc(LBL2, [[ExprAff(r, a)]]) +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.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.blocs = {irb.label : irb for irb in [G3_IRB0, G3_IRB1, G3_IRB2]} +G3_IRA.blocks = {irb.label : irb for irb in [G3_IRB0, G3_IRB1, G3_IRB2]} # Expected output for graph 3 G3_EXP_IRA = IRATest() -G3_EXP_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)]]) -G3_EXP_IRB1 = gen_irbloc(LBL1, [[ExprAff(a, a+CST1)]]) -G3_EXP_IRB2 = gen_irbloc(LBL2, [[ExprAff(r, a)]]) +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.blocs = {irb.label : irb for irb in [G3_EXP_IRB0, G3_EXP_IRB1, - G3_EXP_IRB2]} +G3_EXP_IRA.blocks = {irb.label : irb for irb in [G3_EXP_IRB0, G3_EXP_IRB1, + G3_EXP_IRB2]} # graph 4 : If/else with dead variables G4_IRA = IRATest() -G4_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)]]) -G4_IRB1 = gen_irbloc(LBL1, [[ExprAff(a, a+CST1)]]) -G4_IRB2 = gen_irbloc(LBL2, [[ExprAff(a, a+CST2)]]) -G4_IRB3 = gen_irbloc(LBL3, [[ExprAff(a, CST3)], [ExprAff(r, a)]]) +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.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.blocs = {irb.label : irb for irb in [G4_IRB0, G4_IRB1, G4_IRB2, - G4_IRB3]} +G4_IRA.blocks = {irb.label : irb for irb in [G4_IRB0, G4_IRB1, G4_IRB2, + G4_IRB3]} # Expected output for graph 4 G4_EXP_IRA = IRATest() -G4_EXP_IRB0 = gen_irbloc(LBL0, [[]]) -G4_EXP_IRB1 = gen_irbloc(LBL1, [[]]) -G4_EXP_IRB2 = gen_irbloc(LBL2, [[]]) -G4_EXP_IRB3 = gen_irbloc(LBL3, [[ExprAff(a, CST3)], [ExprAff(r, a)]]) +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.blocs = {irb.label : irb for irb in [G4_EXP_IRB0, G4_EXP_IRB1, - G4_EXP_IRB2, G4_EXP_IRB3]} +G4_EXP_IRA.blocks = {irb.label : irb for irb in [G4_EXP_IRB0, G4_EXP_IRB1, + G4_EXP_IRB2, G4_EXP_IRB3]} # graph 5 : Loop and If/else with dead variables G5_IRA = IRATest() -G5_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)]]) -G5_IRB1 = gen_irbloc(LBL1, [[ExprAff(r, CST2)]]) -G5_IRB2 = gen_irbloc(LBL2, [[ExprAff(a, a+CST2)]]) -G5_IRB3 = gen_irbloc(LBL3, [[ExprAff(a, a+CST3)]]) -G5_IRB4 = gen_irbloc(LBL4, [[ExprAff(a, a+CST1)]]) -G5_IRB5 = gen_irbloc(LBL5, [[ExprAff(a, r)]]) +G5_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]]) +G5_IRB1 = gen_irblock(LBL1, [[ExprAff(r, CST2)]]) +G5_IRB2 = gen_irblock(LBL2, [[ExprAff(a, a+CST2)]]) +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.graph.add_uniq_edge(G5_IRB0.label, G5_IRB1.label) G5_IRA.graph.add_uniq_edge(G5_IRB1.label, G5_IRB2.label) @@ -190,32 +190,32 @@ 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.blocs = {irb.label : irb for irb in [G5_IRB0, G5_IRB1, G5_IRB2, G5_IRB3, - G5_IRB4, G5_IRB5]} +G5_IRA.blocks = {irb.label : irb for irb in [G5_IRB0, G5_IRB1, G5_IRB2, G5_IRB3, + G5_IRB4, G5_IRB5]} # Expected output for graph 5 G5_EXP_IRA = IRATest() -G5_EXP_IRB0 = gen_irbloc(LBL0, [[]]) -G5_EXP_IRB1 = gen_irbloc(LBL1, [[ExprAff(r, CST2)]]) -G5_EXP_IRB2 = gen_irbloc(LBL2, [[]]) -G5_EXP_IRB3 = gen_irbloc(LBL3, [[]]) -G5_EXP_IRB4 = gen_irbloc(LBL4, [[]]) -G5_EXP_IRB5 = gen_irbloc(LBL5, [[]]) +G5_EXP_IRB0 = gen_irblock(LBL0, [[]]) +G5_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, CST2)]]) +G5_EXP_IRB2 = gen_irblock(LBL2, [[]]) +G5_EXP_IRB3 = gen_irblock(LBL3, [[]]) +G5_EXP_IRB4 = gen_irblock(LBL4, [[]]) +G5_EXP_IRB5 = gen_irblock(LBL5, [[]]) -G5_EXP_IRA.blocs = {irb.label : irb for irb in [G5_EXP_IRB0, G5_EXP_IRB1, - G5_EXP_IRB2, G5_EXP_IRB3, - G5_EXP_IRB4, G5_EXP_IRB5]} +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]} # graph 6 : Natural loop with dead variables symetric affectation # (a = b <-> b = a ) G6_IRA = IRATest() -G6_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)]]) -G6_IRB1 = gen_irbloc(LBL1, [[ExprAff(b, a)]]) -G6_IRB2 = gen_irbloc(LBL2, [[ExprAff(a, b)]]) -G6_IRB3 = gen_irbloc(LBL3, [[ExprAff(r, CST2)]]) +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.graph.add_uniq_edge(G6_IRB0.label, G6_IRB1.label) @@ -223,28 +223,28 @@ 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.blocs = {irb.label : irb for irb in [G6_IRB0, G6_IRB1, G6_IRB2, - G6_IRB3]} +G6_IRA.blocks = {irb.label : irb for irb in [G6_IRB0, G6_IRB1, G6_IRB2, + G6_IRB3]} # Expected output for graph 6 G6_EXP_IRA = IRATest() -G6_EXP_IRB0 = gen_irbloc(LBL0, [[]]) -G6_EXP_IRB1 = gen_irbloc(LBL1, [[]]) -G6_EXP_IRB2 = gen_irbloc(LBL2, [[]]) -G6_EXP_IRB3 = gen_irbloc(LBL3, [[ExprAff(r, CST2)]]) +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.blocs = {irb.label : irb for irb in [G6_EXP_IRB0, G6_EXP_IRB1, - G6_EXP_IRB2, G6_EXP_IRB3]} +G6_EXP_IRA.blocks = {irb.label : irb for irb in [G6_EXP_IRB0, G6_EXP_IRB1, + G6_EXP_IRB2, G6_EXP_IRB3]} # graph 7 : Double entry loop with dead variables G7_IRA = IRATest() -G7_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)], [ExprAff(r, CST1)]]) -G7_IRB1 = gen_irbloc(LBL1, [[ExprAff(a, a+CST1)]]) -G7_IRB2 = gen_irbloc(LBL2, [[ExprAff(a, a+CST2)]]) -G7_IRB3 = gen_irbloc(LBL3, [[ExprAff(a, r)]]) +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.graph.add_uniq_edge(G7_IRB0.label, G7_IRB1.label) @@ -254,28 +254,28 @@ 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.blocs = {irb.label : irb for irb in [G7_IRB0, G7_IRB1, G7_IRB2, - G7_IRB3]} +G7_IRA.blocks = {irb.label : irb for irb in [G7_IRB0, G7_IRB1, G7_IRB2, + G7_IRB3]} # Expected output for graph 7 G7_EXP_IRA = IRATest() -G7_EXP_IRB0 = gen_irbloc(LBL0, [[], [ExprAff(r, CST1)]]) -G7_EXP_IRB1 = gen_irbloc(LBL1, [[]]) -G7_EXP_IRB2 = gen_irbloc(LBL2, [[]]) -G7_EXP_IRB3 = gen_irbloc(LBL3, [[]]) +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.blocs = {irb.label : irb for irb in [G7_EXP_IRB0, G7_EXP_IRB1, - G7_EXP_IRB2, G7_EXP_IRB3]} +G7_EXP_IRA.blocks = {irb.label : irb for irb in [G7_EXP_IRB0, G7_EXP_IRB1, + G7_EXP_IRB2, G7_EXP_IRB3]} # graph 8 : Nested loops with dead variables G8_IRA = IRATest() -G8_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST1)]]) -G8_IRB1 = gen_irbloc(LBL1, [[ExprAff(a, a+CST1)]]) -G8_IRB2 = gen_irbloc(LBL2, [[ExprAff(b, b+CST2)]]) -G8_IRB3 = gen_irbloc(LBL3, [[ExprAff(a, b)]]) +G8_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST1)]]) +G8_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]]) +G8_IRB2 = gen_irblock(LBL2, [[ExprAff(b, b+CST2)]]) +G8_IRB3 = gen_irblock(LBL3, [[ExprAff(a, b)]]) G8_IRA.graph.add_uniq_edge(G8_IRB0.label, G8_IRB1.label) @@ -285,30 +285,30 @@ 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.blocs = {irb.label : irb for irb in [G8_IRB0, G8_IRB1, G8_IRB2, - G8_IRB3]} +G8_IRA.blocks = {irb.label : irb for irb in [G8_IRB0, G8_IRB1, G8_IRB2, + G8_IRB3]} # Expected output for graph 8 G8_EXP_IRA = IRATest() -G8_EXP_IRB0 = gen_irbloc(LBL0, [[], []]) -G8_EXP_IRB1 = gen_irbloc(LBL1, [[]]) -G8_EXP_IRB2 = gen_irbloc(LBL2, [[]]) -G8_EXP_IRB3 = gen_irbloc(LBL3, [[]]) +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.blocs = {irb.label : irb for irb in [G8_EXP_IRB0, G8_EXP_IRB1, - G8_EXP_IRB2, G8_EXP_IRB3]} +G8_EXP_IRA.blocks = {irb.label : irb for irb in [G8_EXP_IRB0, G8_EXP_IRB1, + G8_EXP_IRB2, G8_EXP_IRB3]} # graph 9 : Miultiple-exits loops with dead variables G9_IRA = IRATest() -G9_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST1)]]) -G9_IRB1 = gen_irbloc(LBL1, [[ExprAff(a, a+CST1)], [ExprAff(b, b+CST1)]]) -G9_IRB2 = gen_irbloc(LBL2, [[ExprAff(a, a+CST2)], [ExprAff(b, b+CST2)]]) -G9_IRB3 = gen_irbloc(LBL3, [[ExprAff(a, b)]]) -G9_IRB4 = gen_irbloc(LBL4, [[ExprAff(r, a)], [ExprAff(r, b)]]) +G9_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST1)]]) +G9_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)], [ExprAff(b, b+CST1)]]) +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.graph.add_uniq_edge(G9_IRB0.label, G9_IRB4.label) @@ -321,32 +321,32 @@ 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.blocs = {irb.label : irb for irb in [G9_IRB0, G9_IRB1, G9_IRB2, - G9_IRB3, G9_IRB4]} +G9_IRA.blocks = {irb.label : irb for irb in [G9_IRB0, G9_IRB1, G9_IRB2, + G9_IRB3, G9_IRB4]} # Expected output for graph 9 G9_EXP_IRA = IRATest() -G9_EXP_IRB0 = gen_irbloc(LBL0, [[], [ExprAff(b, CST1)]]) -G9_EXP_IRB1 = gen_irbloc(LBL1, [[], [ExprAff(b, b+CST1)]]) -G9_EXP_IRB2 = gen_irbloc(LBL2, [[], [ExprAff(b, b+CST2)]]) -G9_EXP_IRB3 = gen_irbloc(LBL3, [[]]) -G9_EXP_IRB4 = gen_irbloc(LBL4, [[], [ExprAff(r, b)]]) +G9_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(b, CST1)]]) +G9_EXP_IRB1 = gen_irblock(LBL1, [[], [ExprAff(b, b+CST1)]]) +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.blocs = {irb.label : irb for irb in [G9_EXP_IRB0, G9_EXP_IRB1, - G9_EXP_IRB2, G9_EXP_IRB3, - G9_EXP_IRB4]} +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]} # graph 10 : Natural loop with alive variables symetric affectation # (a = b <-> b = a ) G10_IRA = IRATest() -G10_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)]]) -G10_IRB1 = gen_irbloc(LBL1, [[ExprAff(b, a)]]) -G10_IRB2 = gen_irbloc(LBL2, [[ExprAff(a, b)]]) -G10_IRB3 = gen_irbloc(LBL3, [[ExprAff(r, CST1)]]) +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.graph.add_uniq_edge(G10_IRB0.label, G10_IRB1.label) @@ -354,29 +354,29 @@ 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.blocs = {irb.label : irb for irb in [G10_IRB0, G10_IRB1, - G10_IRB2, G10_IRB3]} +G10_IRA.blocks = {irb.label : irb for irb in [G10_IRB0, G10_IRB1, + G10_IRB2, G10_IRB3]} # Expected output for graph 10 G10_EXP_IRA = IRATest() -G10_EXP_IRB0 = gen_irbloc(LBL0, [[]]) -G10_EXP_IRB1 = gen_irbloc(LBL1, [[]]) -G10_EXP_IRB2 = gen_irbloc(LBL2, [[]]) -G10_EXP_IRB3 = gen_irbloc(LBL3, [[ExprAff(r, CST1)]]) +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.blocs = {irb.label : irb for irb in [G10_EXP_IRB0, G10_EXP_IRB1, - G10_EXP_IRB2, G10_EXP_IRB3]} +G10_EXP_IRA.blocks = {irb.label : irb for irb in [G10_EXP_IRB0, G10_EXP_IRB1, + G10_EXP_IRB2, G10_EXP_IRB3]} # graph 11 : If/Else conditions with alive variables G11_IRA = IRATest() -G11_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, b)]]) -G11_IRB1 = gen_irbloc(LBL1, [[ExprAff(b, a)]]) -G11_IRB2 = gen_irbloc(LBL2, [[ExprAff(r, a)]]) -G11_IRB3 = gen_irbloc(LBL3, [[ExprAff(a, a+CST1)]]) -G11_IRB4 = gen_irbloc(LBL4, [[ExprAff(b, b+CST1)]]) +G11_IRB0 = gen_irblock(LBL0, [[ExprAff(a, b)]]) +G11_IRB1 = gen_irblock(LBL1, [[ExprAff(b, a)]]) +G11_IRB2 = gen_irblock(LBL2, [[ExprAff(r, a)]]) +G11_IRB3 = gen_irblock(LBL3, [[ExprAff(a, a+CST1)]]) +G11_IRB4 = gen_irblock(LBL4, [[ExprAff(b, b+CST1)]]) G11_IRA.graph.add_uniq_edge(G11_IRB0.label, G11_IRB1.label) @@ -385,31 +385,31 @@ 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.blocs = {irb.label : irb for irb in [G11_IRB0, G11_IRB1, G11_IRB2]} +G11_IRA.blocks = {irb.label : irb for irb in [G11_IRB0, G11_IRB1, G11_IRB2]} # Expected output for graph 11 G11_EXP_IRA = IRATest() -G11_EXP_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, b)]]) -G11_EXP_IRB1 = gen_irbloc(LBL1, [[ExprAff(b, a)]]) -G11_EXP_IRB2 = gen_irbloc(LBL2, [[ExprAff(r, a)]]) -#G11_EXP_IRB3 = gen_irbloc(LBL3, [[ExprAff(a, a+CST1)]]) -#G11_EXP_IRB4 = gen_irbloc(LBL4, [[ExprAff(b, b+CST1)]]) +G11_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(a, b)]]) +G11_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(b, a)]]) +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.blocs = {irb.label : irb for irb in [G11_EXP_IRB0, G11_EXP_IRB1, - G11_EXP_IRB2]} +G11_EXP_IRA.blocks = {irb.label : irb for irb in [G11_EXP_IRB0, G11_EXP_IRB1, + G11_EXP_IRB2]} # graph 12 : Graph with multiple out points and useless definitions # of return register G12_IRA = IRATest() -G12_IRB0 = gen_irbloc(LBL0, [[ExprAff(r, CST1)], [ExprAff(a, CST2)]]) -G12_IRB1 = gen_irbloc(LBL1, [[ExprAff(r, CST2)]]) -G12_IRB2 = gen_irbloc(LBL2, [[ExprAff(r, a)], [ExprAff(b, CST3)]]) -G12_IRB3 = gen_irbloc(LBL3, [[ExprAff(r, CST3)]]) -G12_IRB4 = gen_irbloc(LBL4, [[ExprAff(r, CST2)]]) -G12_IRB5 = gen_irbloc(LBL5, [[ExprAff(r, b)]]) +G12_IRB0 = gen_irblock(LBL0, [[ExprAff(r, CST1)], [ExprAff(a, CST2)]]) +G12_IRB1 = gen_irblock(LBL1, [[ExprAff(r, CST2)]]) +G12_IRB2 = gen_irblock(LBL2, [[ExprAff(r, a)], [ExprAff(b, CST3)]]) +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.graph.add_uniq_edge(G12_IRB0.label, G12_IRB1.label) G12_IRA.graph.add_uniq_edge(G12_IRB0.label, G12_IRB2.label) @@ -417,55 +417,55 @@ 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.blocs = {irb.label : irb for irb in [G12_IRB0, G12_IRB1, G12_IRB2, - G12_IRB3, G12_IRB4, G12_IRB5]} +G12_IRA.blocks = {irb.label : irb for irb in [G12_IRB0, G12_IRB1, G12_IRB2, + G12_IRB3, G12_IRB4, G12_IRB5]} # Expected output for graph 12 G12_EXP_IRA = IRATest() -G12_EXP_IRB0 = gen_irbloc(LBL0, [[], []]) -G12_EXP_IRB1 = gen_irbloc(LBL1, [[ExprAff(r, CST2)]]) -G12_EXP_IRB2 = gen_irbloc(LBL2, [[], [ExprAff(b, CST3)]]) -G12_EXP_IRB3 = gen_irbloc(LBL3, [[ExprAff(r, CST3)]]) -G12_EXP_IRB4 = gen_irbloc(LBL4, [[]]) -G12_EXP_IRB5 = gen_irbloc(LBL5, [[ExprAff(r, b)]]) +G12_EXP_IRB0 = gen_irblock(LBL0, [[], []]) +G12_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, CST2)]]) +G12_EXP_IRB2 = gen_irblock(LBL2, [[], [ExprAff(b, CST3)]]) +G12_EXP_IRB3 = gen_irblock(LBL3, [[ExprAff(r, CST3)]]) +G12_EXP_IRB4 = gen_irblock(LBL4, [[]]) +G12_EXP_IRB5 = gen_irblock(LBL5, [[ExprAff(r, b)]]) -G12_EXP_IRA.blocs = {irb.label : irb for irb in [G12_EXP_IRB0, G12_EXP_IRB1, - G12_EXP_IRB2, G12_EXP_IRB3, - G12_EXP_IRB4, G12_EXP_IRB5]} +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]} # graph 13 : Graph where a leaf has lost its son G13_IRA = IRATest() -G13_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST2)]]) -G13_IRB1 = gen_irbloc(LBL1, [[ExprAff(r, b)]]) -G13_IRB2 = gen_irbloc(LBL2, [[ExprAff(d, CST2)], [ExprAff(a, b+CST1), +G13_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST2)]]) +G13_IRB1 = gen_irblock(LBL1, [[ExprAff(r, b)]]) +G13_IRB2 = gen_irblock(LBL2, [[ExprAff(d, CST2)], [ExprAff(a, b+CST1), ExprAff(c, a+b)]]) -G13_IRB3 = gen_irbloc(LBL3, [[]]) # lost son -G13_IRB4 = gen_irbloc(LBL4, [[ExprAff(b, CST2)]]) +G13_IRB3 = gen_irblock(LBL3, [[]]) # lost son +G13_IRB4 = gen_irblock(LBL4, [[ExprAff(b, CST2)]]) 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.blocs = {irb.label : irb for irb in [G13_IRB0, G13_IRB1, G13_IRB2, - G13_IRB4]} +G13_IRA.blocks = {irb.label : irb for irb in [G13_IRB0, G13_IRB1, G13_IRB2, + G13_IRB4]} # Expected output for graph 13 G13_EXP_IRA = IRATest() -G13_EXP_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST2)]]) -G13_EXP_IRB1 = gen_irbloc(LBL1, [[ExprAff(r, b)]]) -G13_EXP_IRB2 = gen_irbloc(LBL2, [[ExprAff(d, CST2)], [ExprAff(a, b+CST1), - ExprAff(c, a+b)]]) -G13_EXP_IRB3 = gen_irbloc(LBL3, [[]]) -G13_EXP_IRB4 = gen_irbloc(LBL4, [[ExprAff(b, CST2)]]) +G13_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST2)]]) +G13_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, b)]]) +G13_EXP_IRB2 = gen_irblock(LBL2, [[ExprAff(d, CST2)], [ExprAff(a, b+CST1), + ExprAff(c, a+b)]]) +G13_EXP_IRB3 = gen_irblock(LBL3, [[]]) +G13_EXP_IRB4 = gen_irblock(LBL4, [[ExprAff(b, CST2)]]) -G13_EXP_IRA.blocs = {irb.label: irb for irb in [G13_EXP_IRB0, G13_EXP_IRB1, - G13_EXP_IRB2, G13_EXP_IRB4]} +G13_EXP_IRA.blocks = {irb.label: irb for irb in [G13_EXP_IRB0, G13_EXP_IRB1, + G13_EXP_IRB2, G13_EXP_IRB4]} #G13_EXP_IRA = G13_IRA @@ -474,74 +474,74 @@ G13_EXP_IRA.blocs = {irb.label: irb for irb in [G13_EXP_IRB0, G13_EXP_IRB1, G14_IRA = IRATest() -G14_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)], [ExprAff(c, a)], - [ExprAff(a, CST2)]]) -G14_IRB1 = gen_irbloc(LBL1, [[ExprAff(r, a+c)]]) +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.graph.add_uniq_edge(G14_IRB0.label, G14_IRB1.label) -G14_IRA.blocs = {irb.label : irb for irb in [G14_IRB0, G14_IRB1]} +G14_IRA.blocks = {irb.label : irb for irb in [G14_IRB0, G14_IRB1]} # Expected output for graph 1 G14_EXP_IRA = IRATest() -G14_EXP_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1)], [ExprAff(c, a)], - [ExprAff(a, CST2)]]) -G14_EXP_IRB1 = gen_irbloc(LBL1, [[ExprAff(r, a+c)]]) +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.blocs = {irb.label: irb for irb in [G14_EXP_IRB0, G14_EXP_IRB1]} +G14_EXP_IRA.blocks = {irb.label: irb for irb in [G14_EXP_IRB0, G14_EXP_IRB1]} # graph 15 : Graph where variable assigned multiple and read at the same time, # but useless G15_IRA = IRATest() -G15_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST2)], [ExprAff(a, CST1), - ExprAff(b, a+CST2), - ExprAff(c, CST1)]]) -G15_IRB1 = gen_irbloc(LBL1, [[ExprAff(r, a)]]) +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.graph.add_uniq_edge(G15_IRB0.label, G15_IRB1.label) -G15_IRA.blocs = {irb.label : irb for irb in [G15_IRB0, G15_IRB1]} +G15_IRA.blocks = {irb.label : irb for irb in [G15_IRB0, G15_IRB1]} # Expected output for graph 1 G15_EXP_IRA = IRATest() -G15_EXP_IRB0 = gen_irbloc(LBL0, [[], [ExprAff(a, CST1)]]) -G15_EXP_IRB1 = gen_irbloc(LBL1, [[ExprAff(r, a)]]) +G15_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(a, CST1)]]) +G15_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a)]]) -G15_EXP_IRA.blocs = {irb.label: irb for irb in [G15_EXP_IRB0, G15_EXP_IRB1]} +G15_EXP_IRA.blocks = {irb.label: irb for irb in [G15_EXP_IRB0, G15_EXP_IRB1]} # graph 16 : Graph where variable assigned multiple times in the same bloc G16_IRA = IRATest() -G16_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, CST1), ExprAff(b, CST2), - ExprAff(c, CST3)], [ExprAff(a, c+CST1), - ExprAff(b, c+CST2)]]) -G16_IRB1 = gen_irbloc(LBL1, [[ExprAff(r, a+b)], [ExprAff(r, c+r)]]) -G16_IRB2 = gen_irbloc(LBL2, [[]]) +G16_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1), ExprAff(b, CST2), + ExprAff(c, CST3)], [ExprAff(a, c+CST1), + ExprAff(b, c+CST2)]]) +G16_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a+b)], [ExprAff(r, c+r)]]) +G16_IRB2 = gen_irblock(LBL2, [[]]) 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.blocs = {irb.label : irb for irb in [G16_IRB0, G16_IRB1]} +G16_IRA.blocks = {irb.label : irb for irb in [G16_IRB0, G16_IRB1]} # Expected output for graph 1 G16_EXP_IRA = IRATest() -G16_EXP_IRB0 = gen_irbloc(LBL0, [[ExprAff(c, CST3)], [ExprAff(a, c + CST1), - ExprAff(b, c + CST2)]]) -G16_EXP_IRB1 = gen_irbloc(LBL1, [[ExprAff(r, a+b)], [ExprAff(r, c+r)]]) +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.blocs = {irb.label: irb for irb in [G16_EXP_IRB0, G16_EXP_IRB1]} +G16_EXP_IRA.blocks = {irb.label: irb for irb in [G16_EXP_IRB0, G16_EXP_IRB1]} # graph 17 : parallel ir G17_IRA = IRATest() -G17_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, a*b), +G17_IRB0 = gen_irblock(LBL0, [[ExprAff(a, a*b), ExprAff(b, c), ExprAff(c, CST1)], @@ -595,49 +595,49 @@ G17_IRB0 = gen_irbloc(LBL0, [[ExprAff(a, a*b), ]) -G17_IRA.blocs = {irb.label : irb for irb in [G17_IRB0]} +G17_IRA.blocks = {irb.label : irb for irb in [G17_IRB0]} G17_IRA.graph.add_node(G17_IRB0.label) # Expected output for graph 17 G17_EXP_IRA = IRATest() -G17_EXP_IRB0 = gen_irbloc(LBL0, [[], +G17_EXP_IRB0 = gen_irblock(LBL0, [[], - [ExprAff(d, d+ CST2)], + [ExprAff(d, d+ CST2)], - [ExprAff(a, CST1)], + [ExprAff(a, CST1)], - [ExprAff(ExprMem(d+CST1), a)], + [ExprAff(ExprMem(d+CST1), a)], - [ExprAff(a, CST1)], + [ExprAff(a, CST1)], - [ExprAff(ExprMem(d+CST2), a)], + [ExprAff(ExprMem(d+CST2), a)], - [ExprAff(a, CST2)], + [ExprAff(a, CST2)], - [ExprAff(a, a+CST1)], + [ExprAff(a, a+CST1)], - [ExprAff(d, a)], + [ExprAff(d, a)], - [ExprAff(d, d+CST1)], + [ExprAff(d, d+CST1)], - [ExprAff(a, CST2)], + [ExprAff(a, CST2)], - [ExprAff(a, a+CST2)], + [ExprAff(a, a+CST2)], - [ExprAff(a, CST2), - ExprAff(b, a)], + [ExprAff(a, CST2), + ExprAff(b, a)], - [ExprAff(a, CST1), - ExprAff(b, a), - ExprAff(c, b)], + [ExprAff(a, CST1), + ExprAff(b, a), + ExprAff(c, b)], - G17_IRB0.irs[14] - # Trick because a+b+c != ((a+b)+c) - ]) + G17_IRB0.irs[14] + # Trick because a+b+c != ((a+b)+c) + ]) -G17_EXP_IRA.blocs = {irb.label : irb for irb in [G17_EXP_IRB0]} +G17_EXP_IRA.blocks = {irb.label : irb for irb in [G17_EXP_IRB0]} # Begining of tests @@ -674,8 +674,8 @@ for test_nb, test in enumerate([(G1_IRA, G1_EXP_IRA), open("simp_graph_%02d.dot" % (test_nb+1), "w").write(g_ira.graph.dot()) # Same number of blocks - assert len(g_ira.blocs) == len(g_exp_ira.blocs) - # Check that each expr in the blocs are the same - for lbl, irb in g_ira.blocs.iteritems(): - exp_irb = g_exp_ira.blocs[lbl] + assert len(g_ira.blocks) == len(g_exp_ira.blocks) + # Check that each expr in the blocks are the same + for lbl, irb in g_ira.blocks.iteritems(): + exp_irb = g_exp_ira.blocks[lbl] assert exp_irb.irs == irb.irs diff --git a/test/ir/symbexec.py b/test/ir/symbexec.py index 2e776f74..48de6573 100755 --- a/test/ir/symbexec.py +++ b/test/ir/symbexec.py @@ -10,7 +10,7 @@ class TestSymbExec(unittest.TestCase): from miasm2.expression.expression import ExprInt32, ExprId, ExprMem, \ ExprCompose, ExprAff from miasm2.arch.x86.sem import ir_x86_32 - from miasm2.ir.symbexec import symbexec + from miasm2.ir.symbexec import SymbolicExecutionEngine from miasm2.ir.ir import AssignBlock addrX = ExprInt32(-1) @@ -35,10 +35,10 @@ class TestSymbExec(unittest.TestCase): id_a = ExprId('a') id_eax = ExprId('eax_init') - e = symbexec(ir_x86_32(), - {mem0: id_x, mem1: id_y, mem9: id_x, - mem40w: id_x[:16], mem50v: id_y, - id_a: addr0, id_eax: addr0}) + e = SymbolicExecutionEngine(ir_x86_32(), + {mem0: id_x, mem1: id_y, mem9: id_x, + mem40w: id_x[:16], mem50v: id_y, + id_a: addr0, id_eax: addr0}) self.assertEqual(e.find_mem_by_addr(addr0), mem0) self.assertEqual(e.find_mem_by_addr(addrX), None) self.assertEqual(e.eval_expr(ExprMem(addr1 - addr1)), id_x) diff --git a/test/ir/translators/z3_ir.py b/test/ir/translators/z3_ir.py index 5fcfe25e..0251c2fe 100644 --- a/test/ir/translators/z3_ir.py +++ b/test/ir/translators/z3_ir.py @@ -1,6 +1,6 @@ import z3 -from miasm2.core.asmbloc import asm_label +from miasm2.core.asmblock import AsmLabel from miasm2.expression.expression import * from miasm2.ir.translators.translator import Translator from miasm2.ir.translators.z3_ir import Z3Mem @@ -139,13 +139,13 @@ for miasm_int, res in [(five, -5), (four, -4)]: assert equiv(ez3, z3_e6) # -------------------------------------------------------------------------- -e7 = ExprId(asm_label("label_histoire", 0xdeadbeef), 32) +e7 = ExprId(AsmLabel("label_histoire", 0xdeadbeef), 32) ez3 = Translator.to_language('z3').from_expr(e7) z3_e7 = z3.BitVecVal(0xdeadbeef, 32) assert equiv(ez3, z3_e7) # Should just not throw anything to pass -e8 = ExprId(asm_label("label_jambe"), 32) +e8 = ExprId(AsmLabel("label_jambe"), 32) ez3 = Translator.to_language('z3').from_expr(e8) assert not equiv(ez3, z3_e7) diff --git a/test/test_all.py b/test/test_all.py index 0c9a0c08..4f3ea760 100755 --- a/test/test_all.py +++ b/test/test_all.py @@ -230,7 +230,7 @@ for script in ["interval.py", "test_types.py", ]: testset += RegressionTest([script], base_dir="core") -testset += RegressionTest(["asmbloc.py"], base_dir="core", +testset += RegressionTest(["asmblock.py"], base_dir="core", products=["graph.dot", "graph2.dot", "graph3.dot", "graph4.dot"]) ## Expression |