about summary refs log tree commit diff stats
path: root/miasm2/arch/sh4/arch.py
diff options
context:
space:
mode:
Diffstat (limited to 'miasm2/arch/sh4/arch.py')
-rw-r--r--miasm2/arch/sh4/arch.py67
1 files changed, 36 insertions, 31 deletions
diff --git a/miasm2/arch/sh4/arch.py b/miasm2/arch/sh4/arch.py
index 14f46265..d5e9820e 100644
--- a/miasm2/arch/sh4/arch.py
+++ b/miasm2/arch/sh4/arch.py
@@ -96,23 +96,23 @@ dgbr_reg = (DEREF + LPARENT + reg_info_gbr.parser + COMMA + gpregs.parser + RPAR
 
 
 class sh4_arg(m_arg):
-    def asm_ast_to_expr(self, arg, symbol_pool):
+    def asm_ast_to_expr(self, arg, loc_db):
         if isinstance(arg, AstId):
             if isinstance(arg.name, ExprId):
                 return arg.name
             if arg.name in gpregs.str:
                 return None
-            label = symbol_pool.getby_name_create(arg.name)
-            return ExprId(label, 32)
+            loc_key = loc_db.get_or_create_name_location(arg.name)
+            return ExprLoc(loc_key, 32)
         if isinstance(arg, AstOp):
-            args = [self.asm_ast_to_expr(tmp, symbol_pool) for tmp in arg.args]
+            args = [self.asm_ast_to_expr(tmp, loc_db) for tmp in arg.args]
             if None in args:
                 return None
             return ExprOp(arg.op, *args)
         if isinstance(arg, AstInt):
             return ExprInt(arg.value, 32)
         if isinstance(arg, AstMem):
-            ptr = self.asm_ast_to_expr(arg.ptr, symbol_pool)
+            ptr = self.asm_ast_to_expr(arg.ptr, loc_db)
             if ptr is None:
                 return None
             return ExprMem(ptr, arg.size)
@@ -165,8 +165,8 @@ class sh4_freg(sh4_reg):
 class sh4_dgpreg(sh4_arg):
     parser = dgpregs_base
 
-    def fromstring(self, text, symbol_pool, parser_result=None):
-        start, stop = super(sh4_dgpreg, self).fromstring(text, symbol_pool, parser_result)
+    def fromstring(self, text, loc_db, parser_result=None):
+        start, stop = super(sh4_dgpreg, self).fromstring(text, loc_db, parser_result)
         if start is None or self.expr == [None]:
             return start, stop
         self.expr = ExprMem(self.expr.arg, self.sz)
@@ -191,8 +191,8 @@ class sh4_dgpreg(sh4_arg):
 class sh4_dgpregpinc(sh4_arg):
     parser = dgpregs_p
 
-    def fromstring(self, text, symbol_pool, parser_result=None):
-        start, stop = super(sh4_dgpregpinc, self).fromstring(text, symbol_pool, parser_result)
+    def fromstring(self, text, loc_db, parser_result=None):
+        start, stop = super(sh4_dgpregpinc, self).fromstring(text, loc_db, parser_result)
         if self.expr == [None]:
             return None, None
         if not isinstance(self.expr.arg, ExprOp):
@@ -406,31 +406,36 @@ class instruction_sh4(instruction):
         return self.name.startswith('J')
 
     @staticmethod
-    def arg2str(e, pos = None):
-        if isinstance(e, ExprId) or isinstance(e, ExprInt):
-            return str(e)
-        assert(isinstance(e, ExprMem))
-        e = e.arg
-
-        if isinstance(e, ExprOp):
-            if e.op == "predec":
-                s = '-%s' % e.args[0]
-            elif e.op == "postinc":
-                s = '%s+' % e.args[0]
+    def arg2str(expr, index=None, loc_db=None):
+        if isinstance(expr, ExprId) or isinstance(expr, ExprInt):
+            return str(expr)
+        elif expr.is_loc():
+            if loc_db is not None:
+                return loc_db.pretty_str(expr.loc_key)
+            else:
+                return str(expr)
+        assert(isinstance(expr, ExprMem))
+        expr = expr.arg
+
+        if isinstance(expr, ExprOp):
+            if expr.op == "predec":
+                s = '-%s' % expr.args[0]
+            elif expr.op == "postinc":
+                s = '%s+' % expr.args[0]
             else:
                 s = ','.join([str(x).replace('(', '').replace(')', '')
-                              for x in e.args])
+                              for x in expr.args])
                 s = "(%s)"%s
             s = "@%s" % s
-        elif isinstance(e, ExprId):
-            s = "@%s" % e
+        elif isinstance(expr, ExprId):
+            s = "@%s" % expr
         else:
             raise NotImplementedError('zarb arg2str')
         return s
 
 
     """
-    def dstflow2label(self, symbol_pool):
+    def dstflow2label(self, loc_db):
         e = self.args[0]
         if not isinstance(e, ExprInt):
             return
@@ -438,7 +443,7 @@ class instruction_sh4(instruction):
             ad = e.arg+8+self.offset
         else:
             ad = e.arg+8+self.offset
-        l = symbol_pool.getby_offset_create(ad)
+        l = loc_db.get_or_create_offset_location(ad)
         s = ExprId(l, e.size)
         self.args[0] = s
     """
@@ -451,13 +456,13 @@ class instruction_sh4(instruction):
     def is_subcall(self):
         return self.name == 'JSR'
 
-    def getdstflow(self, symbol_pool):
+    def getdstflow(self, loc_db):
         return [self.args[0]]
 
     def splitflow(self):
         return self.name == 'JSR'
 
-    def get_symbol_size(self, symbol, symbol_pool):
+    def get_symbol_size(self, symbol, loc_db):
         return 32
 
     def fixDstOffset(self):
@@ -818,10 +823,10 @@ addop("bf", [bs('10001011'), s08imm])
         return True
     def dstflow(self):
         return True
-    def dstflow2label(self, symbol_pool):
+    def dstflow2label(self, loc_db):
         e = self.args[0].expr
         ad = e.arg*2+4+self.offset
-        l = symbol_pool.getby_offset_create(ad)
+        l = loc_db.get_or_create_offset_location(ad)
         s = ExprId(l, e.size)
         self.args[0].expr = s
 """
@@ -841,10 +846,10 @@ addop("bra", [bs('1010'), s12imm])
         return True
     def dstflow(self):
         return True
-    def dstflow2label(self, symbol_pool):
+    def dstflow2label(self, loc_db):
         e = self.args[0].expr
         ad = e.arg*2+4+self.offset
-        l = symbol_pool.getby_offset_create(ad)
+        l = loc_db.get_or_create_offset_location(ad)
         s = ExprId(l, e.size)
         self.args[0].expr = s
 """