compiler.ir.Function: add loc field.

This commit is contained in:
whitequark 2015-08-10 13:14:52 +03:00
parent 22570afbda
commit 8f510a4407
3 changed files with 13 additions and 5 deletions

View File

@ -184,9 +184,10 @@ class Stitcher:
inferencer.visit(self.typedtree) inferencer.visit(self.typedtree)
# After we have found all functions, synthesize a module to hold them. # After we have found all functions, synthesize a module to hold them.
source_buffer = source.Buffer("", "<synthesized>")
self.typedtree = asttyped.ModuleT( self.typedtree = asttyped.ModuleT(
typing_env=self.globals, globals_in_scope=set(), typing_env=self.globals, globals_in_scope=set(),
body=self.typedtree, loc=None) body=self.typedtree, loc=source.Range(source_buffer, 0, 0))
def _quote_embedded_function(self, function): def _quote_embedded_function(self, function):
if not hasattr(function, "artiq_embedded"): if not hasattr(function, "artiq_embedded"):

View File

@ -138,6 +138,9 @@ class User(NamedValue):
class Instruction(User): class Instruction(User):
""" """
An SSA instruction. An SSA instruction.
:ivar loc: (:class:`pythonparser.source.Range` or None)
source location
""" """
def __init__(self, operands, typ, name=""): def __init__(self, operands, typ, name=""):
@ -388,13 +391,15 @@ class Function:
""" """
A function containing SSA IR. A function containing SSA IR.
:ivar loc: (:class:`pythonparser.source.Range` or None)
source location of function definition
:ivar is_internal: :ivar is_internal:
(bool) if True, the function should not be accessible from outside (bool) if True, the function should not be accessible from outside
the module it is contained in the module it is contained in
""" """
def __init__(self, typ, name, arguments): def __init__(self, typ, name, arguments, loc=None):
self.type, self.name = typ, name self.type, self.name, self.loc = typ, name, loc
self.names, self.arguments, self.basic_blocks = set(), [], [] self.names, self.arguments, self.basic_blocks = set(), [], []
self.next_name = 1 self.next_name = 1
self.set_arguments(arguments) self.set_arguments(arguments)

View File

@ -129,7 +129,8 @@ class ARTIQIRGenerator(algorithm.Visitor):
try: try:
typ = types.TFunction(OrderedDict(), OrderedDict(), builtins.TNone()) typ = types.TFunction(OrderedDict(), OrderedDict(), builtins.TNone())
func = ir.Function(typ, ".".join(self.name + ['__modinit__']), []) func = ir.Function(typ, ".".join(self.name + ['__modinit__']), [],
loc=node.loc.begin())
self.functions.append(func) self.functions.append(func)
old_func, self.current_function = self.current_function, func old_func, self.current_function = self.current_function, func
@ -184,7 +185,8 @@ class ARTIQIRGenerator(algorithm.Visitor):
for arg_name in typ.optargs: for arg_name in typ.optargs:
optargs.append(ir.Argument(ir.TOption(typ.optargs[arg_name]), "arg." + arg_name)) optargs.append(ir.Argument(ir.TOption(typ.optargs[arg_name]), "arg." + arg_name))
func = ir.Function(typ, ".".join(self.name), [env_arg] + args + optargs) func = ir.Function(typ, ".".join(self.name), [env_arg] + args + optargs,
loc=node.keyword_loc)
func.is_internal = is_internal func.is_internal = is_internal
self.functions.append(func) self.functions.append(func)
old_func, self.current_function = self.current_function, func old_func, self.current_function = self.current_function, func