Explorar o código

Refactor indirect call analysis

jonathanvdc %!s(int64=8) %!d(string=hai) anos
pai
achega
7a95cc02a7
Modificáronse 1 ficheiros con 18 adicións e 11 borrados
  1. 18 11
      kernel/modelverse_jit/bytecode_to_tree.py

+ 18 - 11
kernel/modelverse_jit/bytecode_to_tree.py

@@ -216,6 +216,20 @@ def create_output(output_value):
         tree_ir.DeleteEdgeInstruction(last_output_link.create_load()),
         tree_ir.NopInstruction())
 
+def create_indirect_call(target, argument_list):
+    """Creates an indirect call to the function defined by the node with the id computed
+       by the first argument."""
+    # Call the __call_function function to run the interpreter, like so:
+    #
+    # __call_function(function_id, { first_param_name : first_param_val, ... }, **kwargs)
+    #
+    dict_literal = tree_ir.DictionaryLiteralInstruction(
+        [(tree_ir.LiteralInstruction(key), val) for key, val in argument_list])
+    return tree_ir.create_jit_call(
+        tree_ir.LoadGlobalInstruction(jit_runtime.CALL_FUNCTION_NAME),
+        [('function_id', target), ('named_arguments', dict_literal)],
+        tree_ir.LoadLocalInstruction(jit_runtime.KWARGS_PARAMETER_NAME))
+
 class LocalNameMap(object):
     """A map that converts local variable nodes to identifiers."""
     def __init__(self, local_mapping=None):
@@ -578,18 +592,11 @@ class AnalysisState(object):
         # First off, let's analyze the callee and the argument list.
         func_val, = yield [("CALL_ARGS", [self.analyze, (target,)])]
         named_args, = yield [("CALL_ARGS", [self.analyze_arguments, (argument_list,)])]
-
-        # Call the __call_function function to run the interpreter, like so:
-        #
-        # __call_function(function_id, { first_param_name : first_param_val, ... }, **kwargs)
-        #
-        dict_literal = tree_ir.DictionaryLiteralInstruction(
-            [(tree_ir.LiteralInstruction(key), val) for key, val in named_args])
+        func_val = tree_ir.StoreLocalInstruction(None, func_val)
         raise primitive_functions.PrimitiveFinished(
-            tree_ir.create_jit_call(
-                tree_ir.LoadGlobalInstruction(jit_runtime.CALL_FUNCTION_NAME),
-                [('function_id', func_val), ('named_arguments', dict_literal)],
-                tree_ir.LoadLocalInstruction(jit_runtime.KWARGS_PARAMETER_NAME)))
+            tree_ir.create_block(
+                func_val,
+                create_indirect_call(func_val.create_load(), named_args)))
 
     def try_analyze_direct_call(self, target, argument_list):
         """Tries to analyze the given 'call' instruction as a direct call."""