about summary refs log tree commit diff stats
path: root/test/analysis/data_flow.py
diff options
context:
space:
mode:
authorFabrice Desclaux <fabrice.desclaux@cea.fr>2017-12-11 14:26:23 +0100
committerFabrice Desclaux <fabrice.desclaux@cea.fr>2018-06-08 17:35:05 +0200
commita2637cdf0b40df074865d23a7fd71f082ad7f40a (patch)
treef6c958ca8481e6e29760078e5d1bdc2d2b64da53 /test/analysis/data_flow.py
parentdadfaabc3fff5edb9bf4ef7e7e8c4cfc4baccb94 (diff)
downloadmiasm-a2637cdf0b40df074865d23a7fd71f082ad7f40a.tar.gz
miasm-a2637cdf0b40df074865d23a7fd71f082ad7f40a.zip
Expr: Add new word ExprLoc
This word represents a location in the binary.
Thus, the hack of ExprId containing an AsmLabel ends here.
Diffstat (limited to 'test/analysis/data_flow.py')
-rw-r--r--test/analysis/data_flow.py88
1 files changed, 45 insertions, 43 deletions
diff --git a/test/analysis/data_flow.py b/test/analysis/data_flow.py
index d0a85e13..24335f45 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.asmblock import AsmLabel, AsmSymbolPool
 from miasm2.analysis.data_flow import *
 from miasm2.ir.analysis import ira
 from miasm2.ir.ir import IRBlock, AssignBlock
 
+symbol_pool = AsmSymbolPool()
+
 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 = symbol_pool.add_label("lbl0", 0)
+LBL1 = symbol_pool.add_label("lbl1", 1)
+LBL2 = symbol_pool.add_label("lbl2", 2)
+LBL3 = symbol_pool.add_label("lbl3", 3)
+LBL4 = symbol_pool.add_label("lbl4", 4)
+LBL5 = symbol_pool.add_label("lbl5", 5)
+LBL6 = symbol_pool.add_label("lbl6", 6)
 
 IRDst = ExprId('IRDst', 32)
 dummy = ExprId('dummy', 32)
@@ -45,7 +47,7 @@ def gen_irblock(label, exprs_list):
             irs.append(AssignBlock(exprs))
 
     irs.append(AssignBlock({IRDst:dummy}))
-    irbl = IRBlock(label, irs)
+    irbl = IRBlock(label.loc_key, irs)
     return irbl
 
 
@@ -77,7 +79,7 @@ class IRATest(ira):
 
 # graph 1 : Simple graph with dead and alive variables
 
-G1_IRA = IRATest()
+G1_IRA = IRATest(symbol_pool)
 
 G1_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST2)]])
 G1_IRB1 = gen_irblock(LBL1, [[ExprAff(a, b)]])
@@ -89,7 +91,7 @@ G1_IRA.graph.add_uniq_edge(G1_IRB0.label, G1_IRB1.label)
 G1_IRA.graph.add_uniq_edge(G1_IRB1.label, G1_IRB2.label)
 
 # Expected output for graph 1
-G1_EXP_IRA = IRATest()
+G1_EXP_IRA = IRATest(symbol_pool)
 
 G1_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(b, CST2)]])
 G1_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(a, b)]])
@@ -100,7 +102,7 @@ G1_EXP_IRA.blocks = {irb.label : irb for irb in [G1_EXP_IRB0, G1_EXP_IRB1,
 
 # graph 2 : Natural loop with dead variable
 
-G2_IRA = IRATest()
+G2_IRA = IRATest(symbol_pool)
 
 G2_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(r, CST1)]])
 G2_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]])
@@ -113,7 +115,7 @@ G2_IRA.graph.add_uniq_edge(G2_IRB1.label, G2_IRB2.label)
 G2_IRA.graph.add_uniq_edge(G2_IRB1.label, G2_IRB1.label)
 
 # Expected output for graph 2
-G2_EXP_IRA = IRATest()
+G2_EXP_IRA = IRATest(symbol_pool)
 
 G2_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(r, CST1)]])
 G2_EXP_IRB1 = gen_irblock(LBL1, [[]])
@@ -124,7 +126,7 @@ G2_EXP_IRA.blocks = {irb.label : irb for irb in [G2_EXP_IRB0, G2_EXP_IRB1,
 
 # graph 3 : Natural loop with alive variables
 
-G3_IRA = IRATest()
+G3_IRA = IRATest(symbol_pool)
 
 G3_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]])
 G3_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]])
@@ -137,7 +139,7 @@ G3_IRA.graph.add_uniq_edge(G3_IRB1.label, G3_IRB2.label)
 G3_IRA.graph.add_uniq_edge(G3_IRB1.label, G3_IRB1.label)
 
 # Expected output for graph 3
-G3_EXP_IRA = IRATest()
+G3_EXP_IRA = IRATest(symbol_pool)
 
 G3_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]])
 G3_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]])
@@ -148,7 +150,7 @@ G3_EXP_IRA.blocks = {irb.label : irb for irb in [G3_EXP_IRB0, G3_EXP_IRB1,
 
 # graph 4 : If/else with dead variables
 
-G4_IRA = IRATest()
+G4_IRA = IRATest(symbol_pool)
 
 G4_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]])
 G4_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]])
@@ -164,7 +166,7 @@ G4_IRA.graph.add_uniq_edge(G4_IRB1.label, G4_IRB3.label)
 G4_IRA.graph.add_uniq_edge(G4_IRB2.label, G4_IRB3.label)
 
 # Expected output for graph 4
-G4_EXP_IRA = IRATest()
+G4_EXP_IRA = IRATest(symbol_pool)
 
 G4_EXP_IRB0 = gen_irblock(LBL0, [[]])
 G4_EXP_IRB1 = gen_irblock(LBL1, [[]])
@@ -176,7 +178,7 @@ G4_EXP_IRA.blocks = {irb.label : irb for irb in [G4_EXP_IRB0, G4_EXP_IRB1,
 
 # graph 5 : Loop and If/else with dead variables
 
-G5_IRA = IRATest()
+G5_IRA = IRATest(symbol_pool)
 
 G5_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]])
 G5_IRB1 = gen_irblock(LBL1, [[ExprAff(r, CST2)]])
@@ -197,7 +199,7 @@ G5_IRA.graph.add_uniq_edge(G5_IRB4.label, G5_IRB5.label)
 G5_IRA.graph.add_uniq_edge(G5_IRB4.label, G5_IRB1.label)
 
 # Expected output for graph 5
-G5_EXP_IRA = IRATest()
+G5_EXP_IRA = IRATest(symbol_pool)
 
 G5_EXP_IRB0 = gen_irblock(LBL0, [[]])
 G5_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, CST2)]])
@@ -213,7 +215,7 @@ G5_EXP_IRA.blocks = {irb.label : irb for irb in [G5_EXP_IRB0, G5_EXP_IRB1,
 # graph 6 : Natural loop with dead variables symetric affectation
 # (a = b <-> b = a )
 
-G6_IRA = IRATest()
+G6_IRA = IRATest(symbol_pool)
 
 G6_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]])
 G6_IRB1 = gen_irblock(LBL1, [[ExprAff(b, a)]])
@@ -229,7 +231,7 @@ G6_IRA.graph.add_uniq_edge(G6_IRB2.label, G6_IRB1.label)
 G6_IRA.graph.add_uniq_edge(G6_IRB2.label, G6_IRB3.label)
 
 # Expected output for graph 6
-G6_EXP_IRA = IRATest()
+G6_EXP_IRA = IRATest(symbol_pool)
 
 G6_EXP_IRB0 = gen_irblock(LBL0, [[]])
 G6_EXP_IRB1 = gen_irblock(LBL1, [[]])
@@ -241,7 +243,7 @@ G6_EXP_IRA.blocks = {irb.label : irb for irb in [G6_EXP_IRB0, G6_EXP_IRB1,
 
 # graph 7 : Double entry loop with dead variables
 
-G7_IRA = IRATest()
+G7_IRA = IRATest(symbol_pool)
 
 G7_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(r, CST1)]])
 G7_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]])
@@ -259,7 +261,7 @@ G7_IRA.graph.add_uniq_edge(G7_IRB0.label, G7_IRB2.label)
 
 
 # Expected output for graph 7
-G7_EXP_IRA = IRATest()
+G7_EXP_IRA = IRATest(symbol_pool)
 
 G7_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(r, CST1)]])
 G7_EXP_IRB1 = gen_irblock(LBL1, [[]])
@@ -271,7 +273,7 @@ G7_EXP_IRA.blocks = {irb.label : irb for irb in [G7_EXP_IRB0, G7_EXP_IRB1,
 
 # graph 8 : Nested loops with dead variables
 
-G8_IRA = IRATest()
+G8_IRA = IRATest(symbol_pool)
 
 G8_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST1)]])
 G8_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)]])
@@ -291,7 +293,7 @@ G8_IRA.graph.add_uniq_edge(G8_IRB3.label, G8_IRB2.label)
 
 # Expected output for graph 8
 
-G8_EXP_IRA = IRATest()
+G8_EXP_IRA = IRATest(symbol_pool)
 
 G8_EXP_IRB0 = gen_irblock(LBL0, [[], []])
 G8_EXP_IRB1 = gen_irblock(LBL1, [[]])
@@ -303,7 +305,7 @@ G8_EXP_IRA.blocks = {irb.label : irb for irb in [G8_EXP_IRB0, G8_EXP_IRB1,
 
 # graph 9 : Miultiple-exits loops with dead variables
 
-G9_IRA = IRATest()
+G9_IRA = IRATest(symbol_pool)
 
 G9_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST1)]])
 G9_IRB1 = gen_irblock(LBL1, [[ExprAff(a, a+CST1)], [ExprAff(b, b+CST1)]])
@@ -326,7 +328,7 @@ G9_IRA.graph.add_uniq_edge(G9_IRB3.label, G9_IRB4.label)
 
 # Expected output for graph 9
 
-G9_EXP_IRA = IRATest()
+G9_EXP_IRA = IRATest(symbol_pool)
 
 G9_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(b, CST1)]])
 G9_EXP_IRB1 = gen_irblock(LBL1, [[], [ExprAff(b, b+CST1)]])
@@ -341,7 +343,7 @@ G9_EXP_IRA.blocks = {irb.label : irb for irb in [G9_EXP_IRB0, G9_EXP_IRB1,
 # graph 10 : Natural loop with alive variables symetric affectation
 # (a = b <-> b = a )
 
-G10_IRA = IRATest()
+G10_IRA = IRATest(symbol_pool)
 
 G10_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)]])
 G10_IRB1 = gen_irblock(LBL1, [[ExprAff(b, a)]])
@@ -357,7 +359,7 @@ G10_IRA.graph.add_uniq_edge(G10_IRB2.label, G10_IRB1.label)
 G10_IRA.graph.add_uniq_edge(G10_IRB2.label, G10_IRB3.label)
 
 # Expected output for graph 10
-G10_EXP_IRA = IRATest()
+G10_EXP_IRA = IRATest(symbol_pool)
 
 G10_EXP_IRB0 = gen_irblock(LBL0, [[]])
 G10_EXP_IRB1 = gen_irblock(LBL1, [[]])
@@ -369,7 +371,7 @@ G10_EXP_IRA.blocks = {irb.label : irb for irb in [G10_EXP_IRB0, G10_EXP_IRB1,
 
 # graph 11 : If/Else conditions with alive variables
 
-G11_IRA = IRATest()
+G11_IRA = IRATest(symbol_pool)
 
 G11_IRB0 = gen_irblock(LBL0, [[ExprAff(a, b)]])
 G11_IRB1 = gen_irblock(LBL1, [[ExprAff(b, a)]])
@@ -388,7 +390,7 @@ G11_IRA.graph.add_uniq_edge(G11_IRB1.label, G11_IRB2.label)
 
 
 # Expected output for graph 11
-G11_EXP_IRA = IRATest()
+G11_EXP_IRA = IRATest(symbol_pool)
 
 G11_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(a, b)]])
 G11_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(b, a)]])
@@ -402,7 +404,7 @@ G11_EXP_IRA.blocks = {irb.label : irb for irb in [G11_EXP_IRB0, G11_EXP_IRB1,
 # graph 12 : Graph with multiple out points and useless definitions
 # of return register
 
-G12_IRA = IRATest()
+G12_IRA = IRATest(symbol_pool)
 
 G12_IRB0 = gen_irblock(LBL0, [[ExprAff(r, CST1)], [ExprAff(a, CST2)]])
 G12_IRB1 = gen_irblock(LBL1, [[ExprAff(r, CST2)]])
@@ -421,7 +423,7 @@ G12_IRA.graph.add_uniq_edge(G12_IRB2.label, G12_IRB4.label)
 G12_IRA.graph.add_uniq_edge(G12_IRB4.label, G12_IRB5.label)
 
 # Expected output for graph 12
-G12_EXP_IRA = IRATest()
+G12_EXP_IRA = IRATest(symbol_pool)
 
 G12_EXP_IRB0 = gen_irblock(LBL0, [[], []])
 G12_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, CST2)]])
@@ -437,7 +439,7 @@ G12_EXP_IRA.blocks = {irb.label : irb for irb in [G12_EXP_IRB0, G12_EXP_IRB1,
 
 # graph 13 : Graph where a leaf has lost its son
 
-G13_IRA = IRATest()
+G13_IRA = IRATest(symbol_pool)
 
 G13_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST2)]])
 G13_IRB1 = gen_irblock(LBL1, [[ExprAff(r, b)]])
@@ -455,7 +457,7 @@ G13_IRA.graph.add_uniq_edge(G13_IRB2.label, G13_IRB3.label)
 G13_IRA.graph.add_uniq_edge(G13_IRB4.label, G13_IRB2.label)
 
 # Expected output for graph 13
-G13_EXP_IRA = IRATest()
+G13_EXP_IRA = IRATest(symbol_pool)
 
 G13_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(b, CST2)]])
 G13_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, b)]])
@@ -472,7 +474,7 @@ G13_EXP_IRA.blocks = {irb.label: irb for irb in [G13_EXP_IRB0, G13_EXP_IRB1,
 # graph 14 : Graph where variable assigned multiple times in a block but still
 # useful in the end
 
-G14_IRA = IRATest()
+G14_IRA = IRATest(symbol_pool)
 
 G14_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(c, a)],
                               [ExprAff(a, CST2)]])
@@ -483,7 +485,7 @@ G14_IRA.blocks = {irb.label : irb for irb in [G14_IRB0, G14_IRB1]}
 G14_IRA.graph.add_uniq_edge(G14_IRB0.label, G14_IRB1.label)
 
 # Expected output for graph 1
-G14_EXP_IRA = IRATest()
+G14_EXP_IRA = IRATest(symbol_pool)
 
 G14_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1)], [ExprAff(c, a)],
                                   [ExprAff(a, CST2)]])
@@ -494,7 +496,7 @@ 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_IRA = IRATest(symbol_pool)
 
 G15_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST2)], [ExprAff(a, CST1),
                                                    ExprAff(b, a+CST2),
@@ -506,7 +508,7 @@ G15_IRA.blocks = {irb.label : irb for irb in [G15_IRB0, G15_IRB1]}
 G15_IRA.graph.add_uniq_edge(G15_IRB0.label, G15_IRB1.label)
 
 # Expected output for graph 1
-G15_EXP_IRA = IRATest()
+G15_EXP_IRA = IRATest(symbol_pool)
 
 G15_EXP_IRB0 = gen_irblock(LBL0, [[], [ExprAff(a, CST1)]])
 G15_EXP_IRB1 = gen_irblock(LBL1, [[ExprAff(r, a)]])
@@ -515,7 +517,7 @@ 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_IRA = IRATest(symbol_pool)
 
 G16_IRB0 = gen_irblock(LBL0, [[ExprAff(a, CST1), ExprAff(b, CST2),
                                ExprAff(c, CST3)], [ExprAff(a, c+CST1),
@@ -531,7 +533,7 @@ G16_IRA.graph.add_uniq_edge(G16_IRB1.label, G16_IRB2.label)
 G16_IRA.blocks = {irb.label : irb for irb in [G16_IRB0, G16_IRB1]}
 
 # Expected output for graph 1
-G16_EXP_IRA = IRATest()
+G16_EXP_IRA = IRATest(symbol_pool)
 
 G16_EXP_IRB0 = gen_irblock(LBL0, [[ExprAff(c, CST3)], [ExprAff(a, c + CST1),
                                                        ExprAff(b, c + CST2)]])
@@ -541,7 +543,7 @@ G16_EXP_IRA.blocks = {irb.label: irb for irb in [G16_EXP_IRB0, G16_EXP_IRB1]}
 
 # graph 17 : parallel ir
 
-G17_IRA = IRATest()
+G17_IRA = IRATest(symbol_pool)
 
 G17_IRB0 = gen_irblock(LBL0, [[ExprAff(a, a*b),
                                ExprAff(b, c),
@@ -602,7 +604,7 @@ 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_IRA = IRATest(symbol_pool)
 
 G17_EXP_IRB0 = gen_irblock(LBL0, [[],