From 8f510a440706f93091b92a5cc8039627ab2694d9 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 10 Aug 2015 13:14:52 +0300 Subject: [PATCH] compiler.ir.Function: add loc field. --- artiq/compiler/embedding.py | 3 ++- artiq/compiler/ir.py | 9 +++++++-- artiq/compiler/transforms/artiq_ir_generator.py | 6 ++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/artiq/compiler/embedding.py b/artiq/compiler/embedding.py index bf1ed49d0..3dacbdc13 100644 --- a/artiq/compiler/embedding.py +++ b/artiq/compiler/embedding.py @@ -184,9 +184,10 @@ class Stitcher: inferencer.visit(self.typedtree) # After we have found all functions, synthesize a module to hold them. + source_buffer = source.Buffer("", "") self.typedtree = asttyped.ModuleT( 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): if not hasattr(function, "artiq_embedded"): diff --git a/artiq/compiler/ir.py b/artiq/compiler/ir.py index 327e8c5f6..2561d4ea4 100644 --- a/artiq/compiler/ir.py +++ b/artiq/compiler/ir.py @@ -138,6 +138,9 @@ class User(NamedValue): class Instruction(User): """ An SSA instruction. + + :ivar loc: (:class:`pythonparser.source.Range` or None) + source location """ def __init__(self, operands, typ, name=""): @@ -388,13 +391,15 @@ class Function: """ A function containing SSA IR. + :ivar loc: (:class:`pythonparser.source.Range` or None) + source location of function definition :ivar is_internal: (bool) if True, the function should not be accessible from outside the module it is contained in """ - def __init__(self, typ, name, arguments): - self.type, self.name = typ, name + def __init__(self, typ, name, arguments, loc=None): + self.type, self.name, self.loc = typ, name, loc self.names, self.arguments, self.basic_blocks = set(), [], [] self.next_name = 1 self.set_arguments(arguments) diff --git a/artiq/compiler/transforms/artiq_ir_generator.py b/artiq/compiler/transforms/artiq_ir_generator.py index f30250d92..b0ce78c91 100644 --- a/artiq/compiler/transforms/artiq_ir_generator.py +++ b/artiq/compiler/transforms/artiq_ir_generator.py @@ -129,7 +129,8 @@ class ARTIQIRGenerator(algorithm.Visitor): try: 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) old_func, self.current_function = self.current_function, func @@ -184,7 +185,8 @@ class ARTIQIRGenerator(algorithm.Visitor): for arg_name in typ.optargs: 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 self.functions.append(func) old_func, self.current_function = self.current_function, func