about summary refs log tree commit diff stats
path: root/miasm/arch/mep/arch.py
diff options
context:
space:
mode:
Diffstat (limited to 'miasm/arch/mep/arch.py')
-rw-r--r--miasm/arch/mep/arch.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/miasm/arch/mep/arch.py b/miasm/arch/mep/arch.py
index a6b994ac..67dd5288 100644
--- a/miasm/arch/mep/arch.py
+++ b/miasm/arch/mep/arch.py
@@ -10,6 +10,7 @@ from miasm.core.asm_ast import AstId, AstMem
 
 from miasm.arch.mep.regs import *
 import miasm.arch.mep.regs as mep_regs_module  # will be used to set mn_mep.regs
+from miasm.ir.ir import color_expr_html
 
 
 # Note: pyparsing is used to alter the way special operands are parsed
@@ -97,6 +98,38 @@ class instruction_mep(instruction):
                    to do with a '%s' instance." % type(expr)
         raise Disasm_Exception(message)
 
+    @staticmethod
+    def arg2html(expr, pos=None, loc_db=None):
+        """Convert mnemonics arguments into readable html strings according to the
+        MeP-c4 architecture manual and their internal types
+
+        Notes:
+            - it must be implemented ! However, a simple 'return str(expr)'
+              could do the trick.
+            - it is used to mimic objdump output
+
+        Args:
+            expr: argument as a miasm expression
+            pos: position index in the arguments list
+        """
+
+        if isinstance(expr, ExprId) or isinstance(expr, ExprInt) or isinstance(expr, ExprLoc):
+            return color_expr_html(expr, loc_db)
+
+        elif isinstance(expr, ExprMem) and (isinstance(expr.ptr, ExprId) or isinstance(expr.ptr, ExprInt)):
+            return "(%s)" % color_expr_html(expr.ptr, loc_db)
+
+        elif isinstance(expr, ExprMem) and isinstance(expr.ptr, ExprOp):
+            return "%s(%s)" % (
+                color_expr_html(expr.ptr.args[1], loc_db),
+                color_expr_html(expr.ptr.args[0], loc_db)
+            )
+
+        # Raise an exception if the expression type was not processed
+        message = "instruction_mep.arg2str(): don't know what \
+                   to do with a '%s' instance." % type(expr)
+        raise Disasm_Exception(message)
+
     def __str__(self):
         """Return the mnemonic as a string.