|
@@ -649,6 +649,15 @@ class LoweringState(object):
|
|
|
self.root_edge_names = {}
|
|
|
self.inlinable_definitions = inlinable_definitions
|
|
|
self.scheduler = None
|
|
|
+ self.macro_lowerings = {
|
|
|
+ cfg_ir.PRINT_MACRO_NAME: tree_ir.PrintInstruction,
|
|
|
+ cfg_ir.OUTPUT_MACRO_NAME: bytecode_to_tree.create_output,
|
|
|
+ cfg_ir.INPUT_MACRO_NAME: lambda: bytecode_to_tree.create_input(self.jit.use_input_function),
|
|
|
+ cfg_ir.READ_DICT_KEYS_MACRO_NAME: tree_ir.ReadDictionaryKeysInstruction,
|
|
|
+ cfg_ir.REVERSE_LIST_MACRO_NAME:
|
|
|
+ lambda seq:
|
|
|
+ tree_ir.ListSliceInstruction(seq, None, None, tree_ir.LiteralInstruction(-1))
|
|
|
+ }
|
|
|
|
|
|
def __get_root_edge_name(self, root_node):
|
|
|
"""Gets the name of the given root edge's variable."""
|
|
@@ -807,14 +816,6 @@ class LoweringState(object):
|
|
|
lhs, rhs = self.use_definition(value.lhs), self.use_definition(value.rhs)
|
|
|
return tree_ir.BinaryInstruction(lhs, value.operator, rhs)
|
|
|
|
|
|
- def lower_input(self, _):
|
|
|
- """Lowers an 'input' value."""
|
|
|
- return bytecode_to_tree.create_input(self.jit.use_input_function)
|
|
|
-
|
|
|
- def lower_output(self, value):
|
|
|
- """Lowers an 'output' value."""
|
|
|
- return bytecode_to_tree.create_output(self.use_definition(value.value))
|
|
|
-
|
|
|
def lower_direct_call(self, value):
|
|
|
"""Lowers a direct function call."""
|
|
|
calling_convention = value.calling_convention
|
|
@@ -862,8 +863,8 @@ class LoweringState(object):
|
|
|
def lower_macro_call(self, value):
|
|
|
"""Expands a macro call."""
|
|
|
arg_list = [self.use_definition(arg) for _, arg in value.argument_list]
|
|
|
- if value.target_name in LoweringState.macro_lowerings:
|
|
|
- return LoweringState.macro_lowerings[value.target_name](*arg_list)
|
|
|
+ if value.target_name in self.macro_lowerings:
|
|
|
+ return self.macro_lowerings[value.target_name](*arg_list)
|
|
|
else:
|
|
|
raise jit_runtime.JitCompilationFailedException(
|
|
|
"Unknown macro: '%s' in instruction '%s'" %
|
|
@@ -947,8 +948,6 @@ class LoweringState(object):
|
|
|
cfg_ir.Read : lower_read,
|
|
|
cfg_ir.CreateNode : lower_create_node,
|
|
|
cfg_ir.Binary : lower_binary,
|
|
|
- cfg_ir.Input : lower_input,
|
|
|
- cfg_ir.Output : lower_output,
|
|
|
cfg_ir.DirectFunctionCall : lower_direct_call,
|
|
|
cfg_ir.IndirectFunctionCall : lower_indirect_call,
|
|
|
cfg_ir.JumpFlow : lower_jump,
|
|
@@ -967,14 +966,6 @@ class LoweringState(object):
|
|
|
cfg_ir.MACRO_POSITIONAL_CALLING_CONVENTION : lower_macro_call
|
|
|
}
|
|
|
|
|
|
- macro_lowerings = {
|
|
|
- cfg_ir.PRINT_MACRO_NAME: tree_ir.PrintInstruction,
|
|
|
- cfg_ir.READ_DICT_KEYS_MACRO_NAME: tree_ir.ReadDictionaryKeysInstruction,
|
|
|
- cfg_ir.REVERSE_LIST_MACRO_NAME:
|
|
|
- lambda seq:
|
|
|
- tree_ir.ListSliceInstruction(seq, None, None, tree_ir.LiteralInstruction(-1))
|
|
|
- }
|
|
|
-
|
|
|
def lower_flow_graph(entry_point, jit):
|
|
|
"""Lowers the control-flow graph defined by the given entry point to tree IR."""
|
|
|
cfg_lowerer = LoweringState(jit, find_inlinable_definitions(entry_point))
|