|
@@ -31,6 +31,19 @@ def apply_intrinsic(intrinsic_function, named_args):
|
|
|
tree_ir.create_block(*store_instructions),
|
|
|
intrinsic_function(**arg_value_dict))
|
|
|
|
|
|
+class LocalNameMap(object):
|
|
|
+ """A map that converts local variable nodes to identifiers."""
|
|
|
+ def __init__(self, local_mapping=None):
|
|
|
+ if local_mapping is None:
|
|
|
+ local_mapping = {}
|
|
|
+ self.local_mapping = local_mapping
|
|
|
+
|
|
|
+ def get_local_name(self, local_variable_id):
|
|
|
+ """Gets the name for the local variable node with the given id."""
|
|
|
+ if local_variable_id not in self.local_mapping:
|
|
|
+ self.local_mapping[local_variable_id] = 'local%d' % local_variable_id
|
|
|
+ return self.local_mapping[local_variable_id]
|
|
|
+
|
|
|
class AnalysisState(object):
|
|
|
"""The state of a bytecode analysis call graph."""
|
|
|
def __init__(self, jit, body_id, task_root, local_mapping, max_instructions=None):
|
|
@@ -41,16 +54,10 @@ class AnalysisState(object):
|
|
|
self.max_instructions = max_instructions
|
|
|
self.task_root = task_root
|
|
|
self.jit = jit
|
|
|
- self.local_mapping = local_mapping
|
|
|
+ self.local_name_map = LocalNameMap(local_mapping)
|
|
|
self.function_name = jit.jitted_entry_points[body_id]
|
|
|
self.enclosing_loop_instruction = None
|
|
|
|
|
|
- def get_local_name(self, local_id):
|
|
|
- """Gets the name for a local with the given id."""
|
|
|
- if local_id not in self.local_mapping:
|
|
|
- self.local_mapping[local_id] = 'local%d' % local_id
|
|
|
- return self.local_mapping[local_id]
|
|
|
-
|
|
|
def register_local_var(self, local_id):
|
|
|
"""Registers the given variable node id as a local."""
|
|
|
if local_id in self.function_vars:
|
|
@@ -348,7 +355,7 @@ class AnalysisState(object):
|
|
|
#
|
|
|
# tmp = global_var
|
|
|
|
|
|
- name = self.get_local_name(instruction.variable.node_id)
|
|
|
+ name = self.local_name_map.get_local_name(instruction.variable.node_id)
|
|
|
|
|
|
if instruction.variable.name is None:
|
|
|
raise primitive_functions.PrimitiveFinished(
|
|
@@ -391,7 +398,7 @@ class AnalysisState(object):
|
|
|
"""Tries to analyze the given 'declare' function."""
|
|
|
self.register_local_var(instruction.variable.node_id)
|
|
|
|
|
|
- name = self.get_local_name(instruction.variable.node_id)
|
|
|
+ name = self.local_name_map.get_local_name(instruction.variable.node_id)
|
|
|
|
|
|
# The following logic declares a local:
|
|
|
#
|