Browse Source

Define some simple CFG JIT intrinsics

jonathanvdc 8 years ago
parent
commit
bd107ed8b4
2 changed files with 21 additions and 1 deletions
  1. 15 0
      kernel/modelverse_jit/intrinsics.py
  2. 6 1
      kernel/modelverse_jit/jit.py

+ 15 - 0
kernel/modelverse_jit/intrinsics.py

@@ -1,6 +1,7 @@
 import time
 import modelverse_jit.jit as jit
 import modelverse_jit.tree_ir as tree_ir
+import modelverse_jit.cfg_ir as cfg_ir
 import modelverse_jit.runtime as jit_runtime
 
 BINARY_INTRINSICS = {
@@ -279,6 +280,18 @@ MISC_INTRINSICS = {
     'log' : __log
 }
 
+MISC_CFG_INTRINSICS = {
+    # State creation
+    'create_node' :
+        lambda original_def:
+        original_def.redefine(
+            cfg_ir.CreateNode(original_def.insert_before(cfg_ir.Literal(None)))),
+    'create_value' :
+        lambda original_def, a:
+        original_def.redefine(
+            cfg_ir.CreateNode(original_def.insert_before(cfg_ir.Read(a))))
+}
+
 def register_time_intrinsic(target_jit):
     """Registers the time() intrinsic with the given JIT."""
     import_name = target_jit.import_value(time.time, 'time')
@@ -299,5 +312,7 @@ def register_intrinsics(target_jit):
         target_jit.register_cast_intrinsic(key, value)
     for (key, value) in MISC_INTRINSICS.items():
         target_jit.register_intrinsic(key, value)
+    for (key, value) in MISC_CFG_INTRINSICS.items():
+        target_jit.register_cfg_intrinsic(key, value)
 
     register_time_intrinsic(target_jit)

+ 6 - 1
kernel/modelverse_jit/jit.py

@@ -341,7 +341,12 @@ class ModelverseJit(object):
            the function with the given entry point by an application of the specified function."""
         self.jit_intrinsics[name] = intrinsic_function
         if cfg_intrinsic_function is not None:
-            self.cfg_jit_intrinsics[name] = cfg_intrinsic_function
+            self.register_cfg_intrinsic(name, cfg_intrinsic_function)
+
+    def register_cfg_intrinsic(self, name, cfg_intrinsic_function):
+        """Registers the given intrisic with the JIT. This will make the JIT replace calls to
+           the function with the given entry point by an application of the specified function."""
+        self.cfg_jit_intrinsics[name] = cfg_intrinsic_function
 
     def register_binary_intrinsic(self, name, operator):
         """Registers an intrinsic with the JIT that represents the given binary operation."""