about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAjax <commial@gmail.com>2016-09-02 16:23:22 +0200
committerAjax <commial@gmail.com>2016-09-02 17:45:54 +0200
commitb263ac231d0ed0f78511ad666ea6d0ff4fb1dd53 (patch)
treeae242dc705dbdb96bd92578dd8f5a2c0ca607c6c
parent54aa823f145fb2c920f5ab1d97773dfca126f0e4 (diff)
downloadmiasm-b263ac231d0ed0f78511ad666ea6d0ff4fb1dd53.tar.gz
miasm-b263ac231d0ed0f78511ad666ea6d0ff4fb1dd53.zip
Move Jitcore specifics code into respective classes
-rw-r--r--miasm2/jitter/jitcore_gcc.py22
-rw-r--r--miasm2/jitter/jitcore_tcc.py60
2 files changed, 39 insertions, 43 deletions
diff --git a/miasm2/jitter/jitcore_gcc.py b/miasm2/jitter/jitcore_gcc.py
index 7f72d8e7..e2f308e6 100644
--- a/miasm2/jitter/jitcore_gcc.py
+++ b/miasm2/jitter/jitcore_gcc.py
@@ -28,16 +28,6 @@ def gen_core(arch, attrib):
     return txt
 
 
-def gen_C_source(ir_arch, func_code):
-    c_source = ""
-    c_source += "\n".join(func_code)
-
-    c_source = gen_core(ir_arch.arch, ir_arch.attrib) + c_source
-    c_source = "#include <Python.h>\n" + c_source
-
-    return c_source
-
-
 class myresolver(object):
 
     def __init__(self, offset):
@@ -131,7 +121,7 @@ class JitCore_Gcc(jitcore.JitCore):
         out = [f_declaration + '{'] + out + ['}\n']
         c_code = out
 
-        return gen_C_source(self.ir_arch, c_code)
+        return self.gen_C_source(self.ir_arch, c_code)
 
     def add_bloc(self, block):
         """Add a bloc to JiT and JiT it.
@@ -166,3 +156,13 @@ class JitCore_Gcc(jitcore.JitCore):
             os.remove(fname_in)
 
         self.load_code(block.label, fname_out)
+
+    @staticmethod
+    def gen_C_source(ir_arch, func_code):
+        c_source = ""
+        c_source += "\n".join(func_code)
+
+        c_source = gen_core(ir_arch.arch, ir_arch.attrib) + c_source
+        c_source = "#include <Python.h>\n" + c_source
+
+        return c_source
diff --git a/miasm2/jitter/jitcore_tcc.py b/miasm2/jitter/jitcore_tcc.py
index 1bb25a3a..c6f30224 100644
--- a/miasm2/jitter/jitcore_tcc.py
+++ b/miasm2/jitter/jitcore_tcc.py
@@ -8,12 +8,7 @@ from hashlib import md5
 import tempfile
 
 from miasm2.jitter import jitcore, Jittcc
-
-
-def jit_tcc_compil(func_name, func_code):
-    global Jittcc
-    c = Jittcc.tcc_compil(func_name, func_code)
-    return c
+from miasm2.core.utils import keydefaultdict
 
 
 def gen_core(arch, attrib):
@@ -32,28 +27,6 @@ def gen_core(arch, attrib):
     return txt
 
 
-def gen_C_source(ir_arch, func_code):
-    c_source = ""
-    c_source += "\n".join(func_code)
-
-    c_source = gen_core(ir_arch.arch, ir_arch.attrib) + c_source
-
-    c_source = """
- #ifdef __x86_64__
- #ifndef __LP64__
- /*
-  for ubuntu ?!? XXX TODO
-  /!\ force 64 bit system using 64 bits libc
-  change this to __ILP32__ to do so.
- */
- #define __LP64__
- #endif
- #endif
- """ + "#include <Python.h>\n" + c_source
-
-    return c_source
-
-
 class myresolver:
 
     def __init__(self, offset):
@@ -62,8 +35,6 @@ class myresolver:
     def ret(self):
         return "return PyLong_FromUnsignedLongLong(0x%X);" % self.offset
 
-from miasm2.core.utils import keydefaultdict
-
 
 class resolver:
 
@@ -143,6 +114,9 @@ class JitCore_Tcc(jitcore.JitCore):
         """
         return "block_%s" % label.name
 
+    def jit_tcc_compil(self, func_name, func_code):
+        return Jittcc.tcc_compil(func_name, func_code)
+
     def compil_code(self, block, func_code):
         """
         Compil the C code of @func_code from @block
@@ -151,7 +125,7 @@ class JitCore_Tcc(jitcore.JitCore):
         """
         label = block.label
         self.jitcount += 1
-        tcc_state, mcode = jit_tcc_compil(self.label2fname(label), func_code)
+        tcc_state, mcode = self.jit_tcc_compil(self.label2fname(label), func_code)
         self.lbl2jitbloc[label.offset] = mcode
         self.tcc_states[label.offset] = tcc_state
 
@@ -167,7 +141,7 @@ class JitCore_Tcc(jitcore.JitCore):
         out = [f_declaration + '{'] + out + ['}\n']
         c_code = out
 
-        return gen_C_source(self.ir_arch, c_code)
+        return self.gen_C_source(self.ir_arch, c_code)
 
     def add_bloc(self, block):
         """Add a bloc to JiT and JiT it.
@@ -191,3 +165,25 @@ class JitCore_Tcc(jitcore.JitCore):
             os.rename(fname_tmp, fname_out)
 
         self.compil_code(block, func_code)
+
+    @staticmethod
+    def gen_C_source(ir_arch, func_code):
+        c_source = ""
+        c_source += "\n".join(func_code)
+
+        c_source = gen_core(ir_arch.arch, ir_arch.attrib) + c_source
+
+        c_source = """
+     #ifdef __x86_64__
+     #ifndef __LP64__
+     /*
+      for ubuntu ?!? XXX TODO
+      /!\ force 64 bit system using 64 bits libc
+      change this to __ILP32__ to do so.
+     */
+     #define __LP64__
+     #endif
+     #endif
+     """ + "#include <Python.h>\n" + c_source
+
+        return c_source