|
@@ -12,6 +12,19 @@ class AnalysisState(object):
|
|
|
self.loop_instructions = {}
|
|
|
self.entry_point = cfg_ir.BasicBlock(self.counter)
|
|
|
self.current_block = self.entry_point
|
|
|
+ self.root_node = None
|
|
|
+ self.__write_prolog()
|
|
|
+
|
|
|
+ def __write_prolog(self):
|
|
|
+ # Write a prolog in CFG IR.
|
|
|
+ # We want to create the following definition:
|
|
|
+ #
|
|
|
+ # !entry_point():
|
|
|
+ # $jit_locals = alloc-root-node
|
|
|
+ #
|
|
|
+ # 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())
|
|
|
|
|
|
def analyze(self, instruction):
|
|
|
"""Analyzes the given instruction as a basic block."""
|
|
@@ -132,6 +145,8 @@ class AnalysisState(object):
|
|
|
return_value = self.current_block.append_definition(cfg_ir.Literal(None))
|
|
|
else:
|
|
|
return_value = self.analyze(instruction.value)
|
|
|
+ # Don't forget to deallocate the root node.
|
|
|
+ self.current_block.append_definition(cfg_ir.DeallocateRootNode(self.root_node))
|
|
|
self.current_block.flow = cfg_ir.ReturnFlow(return_value)
|
|
|
self.current_block = cfg_ir.BasicBlock(self.counter)
|
|
|
return self.current_block.append_definition(cfg_ir.Literal(None))
|
|
@@ -155,7 +170,8 @@ class AnalysisState(object):
|
|
|
|
|
|
def analyze_declare(self, instruction):
|
|
|
"""Analyzes a 'declare' instruction."""
|
|
|
- return self.current_block.append_definition(cfg_ir.DeclareLocal(instruction.variable))
|
|
|
+ return self.current_block.append_definition(
|
|
|
+ cfg_ir.DeclareLocal(instruction.variable, self.root_node))
|
|
|
|
|
|
def analyze_global(self, instruction):
|
|
|
"""Analyzes a 'global' instruction."""
|