changeset 72:6c2efdeffa7b

Strip instruction string for opcode with no any argument.
author Thinker K.F. Li <thinker@codemud.net>
date Sat, 02 Jul 2011 00:03:17 +0800
parents 17b9d02a5f3c
children 6d56483b56cd
files paraspace/dalvik_opcodes.py paraspace/tests/dalvik_opcodes_test.py
diffstat 2 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dalvik_opcodes.py	Fri Jul 01 17:58:43 2011 +0800
+++ b/paraspace/dalvik_opcodes.py	Sat Jul 02 00:03:17 2011 +0800
@@ -1195,8 +1195,13 @@
     fmt_parse_cfg = fmt_parse_cfgs[fmt_name]
     arg_part = ''.join([encode_arg(arg, sz)
                         for arg, sz in map(None, args, fmt_parse_cfg)])
+
+    inst = chr(opcode) + arg_part
+
+    while len(inst) % 2:
+        encode_arg(0, 1)
+        pass
     
-    inst = chr(opcode) + arg_part
     return inst
 
 
@@ -1209,7 +1214,11 @@
     fmt_name = fmt_names[fmt]
     fmt_str = fmt_fmtstr[fmt_name]
 
-    line = opname + ' ' + fmt_str.format(*args)
+    if fmt_str:
+        line = opname + ' ' + fmt_str.format(*args)
+    else:
+        line = opname
+        pass
     return line
 
 
--- a/paraspace/tests/dalvik_opcodes_test.py	Fri Jul 01 17:58:43 2011 +0800
+++ b/paraspace/tests/dalvik_opcodes_test.py	Sat Jul 02 00:03:17 2011 +0800
@@ -54,4 +54,8 @@
     line = format_inst(opv)
     assert line == 'OP_INVOKE_SUPER {v1, v0, v0, v0, v0},' \
         ' thing@a601 (1: count, A: vG)'
+
+    opv = (0, ())
+    line = format_inst(opv)
+    assert line == 'OP_NOP'
     pass