Explorar el Código

Include reference-interpreter calls in the request handler stack frame

jonathanvdc hace 8 años
padre
commit
12d36cd0c0
Se han modificado 2 ficheros con 45 adiciones y 3 borrados
  1. 16 1
      kernel/modelverse_jit/runtime.py
  2. 29 2
      kernel/modelverse_jit/source_map.py

+ 16 - 1
kernel/modelverse_jit/runtime.py

@@ -1,4 +1,5 @@
 import modelverse_kernel.primitives as primitive_functions
+import modelverse_jit.source_map as source_map
 
 class JitCompilationFailedException(Exception):
     """A type of exception that is raised when the jit fails to compile a function."""
@@ -43,6 +44,9 @@ LOCALS_EDGE_NAME = "jit_locals_edge"
 GLOBAL_NOT_FOUND_MESSAGE_FORMAT = "Not found as global: %s"
 """The format of the 'not found as global' message. Takes a single argument."""
 
+REFERENCE_INTERPRETER_ORIGIN_NAME = "reference-interpreter"
+"""The origin name for functions that are interpreted by the reference interpreter."""
+
 BYTECODE_INTERPRETER_ORIGIN_NAME = "bytecode-interpreter"
 """The origin name for functions that were produced by the bytecode interpreter."""
 
@@ -90,7 +94,7 @@ def call_function(function_id, named_arguments, **kwargs):
 
     if is_mutable is not None:
         kernel.jit.mark_no_jit(body_id)
-        yield [("TAIL_CALL_ARGS", [handle_jit_failed, ()])]
+        yield [("TAIL_CALL_ARGS", [handle_jit_failed, (None,)])]
     else:
         kernel.jit.mark_entry_point(body_id)
 
@@ -162,6 +166,17 @@ def interpret_function_body(body_id, named_arguments, **kwargs):
         yield [("CE", [symbol_edge, param_var])]
 
     taskname = kwargs['taskname']
+
+    # Append a debug info record and set up a source map.
+    kernel.debug_info[taskname].append(UNKNOWN_LOCATION_REPR)
+    src_map = source_map.InterpreterSourceMap(
+        kernel, taskname, len(kernel.debug_info[taskname]) - 1)
+    function_name = kernel.jit.get_global_name(body_id)
+    if function_name is None:
+        function_name = UNKNOWN_FUNCTION_REPR
+
+    yield [("DEBUG_INFO", [function_name, src_map, REFERENCE_INTERPRETER_ORIGIN_NAME])]
+
     def exception_handler(ex):
         # print('Returning from interpreted function. Result: %s' % ex.result)
         raise primitive_functions.PrimitiveFinished(ex.result)

+ 29 - 2
kernel/modelverse_jit/source_map.py

@@ -1,8 +1,17 @@
 """Defines source maps: dictionaries that map lines in generated source to debug information."""
 
-class SourceMap(object):
+class SourceMapBase(object):
+    """Define a base class for source maps: objects that can convert line numbers
+       to debug information."""
+    def get_debug_info(self, line_number):
+        """Gets the debug information for the given line number, or None if no debug info was
+           found."""
+        raise NotImplementedError()
+
+class SourceMap(SourceMapBase):
     """A source map, which converts generated source lines to debug information."""
     def __init__(self):
+        SourceMapBase.__init__(self)
         self.lines = {}
 
     def map_line(self, line_number, debug_info):
@@ -50,9 +59,10 @@ class SourceMapBuilder(object):
     def __str__(self):
         return str(self.source_map)
 
-class ManualSourceMap(object):
+class ManualSourceMap(SourceMapBase):
     """A source map whose debug information can be set and reset. Line numbers are ignored."""
     def __init__(self):
+        SourceMapBase.__init__(self)
         self.debug_information = None
 
     def get_debug_info(self, _):
@@ -63,3 +73,20 @@ class ManualSourceMap(object):
     def __str__(self):
         return str(self.debug_information)
 
+class InterpreterSourceMap(SourceMapBase):
+    """A source map that extracts debug information from the reference interpreter's debug info
+       stack. Line numbers are ignored."""
+    def __init__(self, kernel, task_name, stack_index):
+        SourceMapBase.__init__(self)
+        self.kernel = kernel
+        self.task_name = task_name
+        self.stack_index = stack_index
+
+    def get_debug_info(self, _):
+        """Gets the debug information for the given line number, or None if no debug info was
+           found."""
+        return self.kernel.debug_info[self.task_name][self.stack_index]
+
+    def __str__(self):
+        return str(self.get_debug_info(None))
+