about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAjax <commial@gmail.com>2015-04-21 09:43:49 +0200
committerAjax <commial@gmail.com>2015-04-24 08:11:36 +0200
commit44531d3b9a4fe31dfa70ae148acb7b04ae65b2c2 (patch)
treed12bb8d18042e6661cedffe3eba858bba6b9fbf5
parentd9368a5d5615af529d7bb08f542a1c32bded3861 (diff)
downloadmiasm-44531d3b9a4fe31dfa70ae148acb7b04ae65b2c2.tar.gz
miasm-44531d3b9a4fe31dfa70ae148acb7b04ae65b2c2.zip
IR: Introduce dst_linenb, factorize and comment code
-rw-r--r--miasm2/arch/arm/ira.py2
-rw-r--r--miasm2/ir/ir.py32
2 files changed, 21 insertions, 13 deletions
diff --git a/miasm2/arch/arm/ira.py b/miasm2/arch/arm/ira.py
index 74548f86..b918a2e6 100644
--- a/miasm2/arch/arm/ira.py
+++ b/miasm2/arch/arm/ira.py
@@ -69,7 +69,7 @@ class ir_a_arml(ir_a_arml_base):
             nbloc = irbloc(new_lbl, irs)
             nbloc.lines = [l]*len(irs)
             self.blocs[new_lbl] = nbloc
-            irb.set_dst(ExprId(new_lbl, size=self.pc.size))
+            irb.dst = ExprId(new_lbl, size=self.pc.size)
 
         """
         if not bloc.lines:
diff --git a/miasm2/ir/ir.py b/miasm2/ir/ir.py
index 252f0ab3..5d77c5a1 100644
--- a/miasm2/ir/ir.py
+++ b/miasm2/ir/ir.py
@@ -36,34 +36,42 @@ class irbloc(object):
         self.lines = lines
         self.except_automod = True
         self._dst = None
+        self._dst_linenb = None
 
 
-    def get_dst(self):
+    def _get_dst(self):
+        """Find the IRDst affectation and update dst, dst_linenb accordingly"""
         if self._dst is not None:
             return self._dst
         dst = None
-        for ir in self.irs:
+        for linenb, ir in enumerate(self.irs):
             for i in ir:
                 if isinstance(i.dst, m2_expr.ExprId) and i.dst.name == "IRDst":
                     if dst is not None:
                         raise ValueError('Multiple destinations!')
                     dst = i.src
+                    dst_linenb = linenb
         self._dst = dst
+        self._dst_linenb = linenb
         return dst
 
-    def set_dst(self, value):
+    def _set_dst(self, value):
         """Find and replace the IRDst affectation's source by @value"""
-        dst = None
-        for ir in self.irs:
-            for i, expr in enumerate(ir):
-                if isinstance(expr.dst, m2_expr.ExprId) and expr.dst.name == "IRDst":
-                    if dst is not None:
-                        raise ValueError('Multiple destinations!')
-                    dst = value
-                    ir[i] = m2_expr.ExprAff(expr.dst, value)
+        if self._dst_linenb is None:
+            self._get_dst()
+
+        ir = self.irs[self._dst_linenb]
+        for i, expr in enumerate(ir):
+            if isinstance(expr.dst, m2_expr.ExprId) and expr.dst.name == "IRDst":
+                ir[i] = m2_expr.ExprAff(expr.dst, value)
         self._dst = value
 
-    dst = property(get_dst, set_dst)
+    dst = property(_get_dst, _set_dst)
+
+    @property
+    def dst_linenb(self):
+        """Line number of the IRDst setting statement in the current irs"""
+        return self._dst_linenb
 
     def get_rw(self):
         self.r = []