|
@@ -6,25 +6,36 @@ import modelverse_jit.runtime as jit_runtime
|
|
|
|
|
|
class AnalysisState(object):
|
|
|
"""State that is common to the bytecode->CFG transformation of a function."""
|
|
|
- def __init__(self):
|
|
|
+ def __init__(self, param_dict):
|
|
|
self.counter = cfg_ir.SharedCounter()
|
|
|
self.analyzed_instructions = set()
|
|
|
self.loop_instructions = {}
|
|
|
self.entry_point = cfg_ir.BasicBlock(self.counter)
|
|
|
self.current_block = self.entry_point
|
|
|
self.root_node = None
|
|
|
- self.__write_prolog()
|
|
|
+ self.__write_prolog(param_dict)
|
|
|
|
|
|
- def __write_prolog(self):
|
|
|
+ def __write_prolog(self, param_dict):
|
|
|
# Write a prolog in CFG IR.
|
|
|
# We want to create the following definition:
|
|
|
#
|
|
|
# !entry_point():
|
|
|
# $jit_locals = alloc-root-node
|
|
|
+ # $_ = declare-local var(...)
|
|
|
+ # $param_1 = resolve-local var(...)
|
|
|
+ # $arg_1 = function-parameter ...
|
|
|
+ # $_ = store $param_1, $arg_1
|
|
|
+ # ...
|
|
|
#
|
|
|
# We also want to store '$jit_locals' in an attribute, so we can
|
|
|
# use it to shield locals from the GC.
|
|
|
self.root_node = self.current_block.append_definition(cfg_ir.AllocateRootNode())
|
|
|
+ for node_id, name in param_dict.items():
|
|
|
+ variable = bytecode_ir.VariableNode(node_id, name)
|
|
|
+ self.current_block.append_definition(cfg_ir.DeclareLocal(variable, self.root_node))
|
|
|
+ param_i = self.current_block.append_definition(cfg_ir.ResolveLocal(variable))
|
|
|
+ arg_i = self.current_block.append_definition(cfg_ir.FunctionParameter(name))
|
|
|
+ self.current_block.append_definition(cfg_ir.StoreAtPointer(param_i, arg_i))
|
|
|
|
|
|
def analyze(self, instruction):
|
|
|
"""Analyzes the given instruction as a basic block."""
|