Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 501ba912c201
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b03efbc94d15
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Aug 31, 2015

  1. Copy the full SHA
    5e0ec3a View commit details
  2. Copy the full SHA
    3ca5967 View commit details

Commits on Sep 1, 2015

  1. Copy the full SHA
    b03efbc View commit details
Showing with 26 additions and 14 deletions.
  1. +15 −4 artiq/compiler/embedding.py
  2. +4 −4 artiq/compiler/transforms/artiq_ir_generator.py
  3. +7 −6 artiq/compiler/transforms/llvm_ir_generator.py
19 changes: 15 additions & 4 deletions artiq/compiler/embedding.py
Original file line number Diff line number Diff line change
@@ -5,10 +5,11 @@
annotated as ``@kernel`` when they are referenced.
"""

import os, re, linecache, inspect, textwrap
import sys, os, re, linecache, inspect, textwrap
from collections import OrderedDict, defaultdict

from pythonparser import ast, algorithm, source, diagnostic, parse_buffer
from pythonparser import lexer as source_lexer, parser as source_parser

from ..language import core as language_core
from . import types, builtins, asttyped, prelude
@@ -424,7 +425,7 @@ def _quote_embedded_function(self, function):

# Extract function source.
embedded_function = function.artiq_embedded.function
source_code = textwrap.dedent(inspect.getsource(embedded_function))
source_code = inspect.getsource(embedded_function)
filename = embedded_function.__code__.co_filename
module_name = embedded_function.__globals__['__name__']
first_line = embedded_function.__code__.co_firstlineno
@@ -436,10 +437,20 @@ def _quote_embedded_function(self, function):
cell_names = embedded_function.__code__.co_freevars
host_environment.update({var: cells[index] for index, var in enumerate(cell_names)})

# Find out how indented we are.
initial_whitespace = re.search(r"^\s*", source_code).group(0)
initial_indent = len(initial_whitespace.expandtabs())

# Parse.
source_buffer = source.Buffer(source_code, filename, first_line)
parsetree, comments = parse_buffer(source_buffer, engine=self.engine)
function_node = parsetree.body[0]
lexer = source_lexer.Lexer(source_buffer, version=sys.version_info[0:2],
diagnostic_engine=self.engine)
lexer.indent = [(initial_indent,
source.Range(source_buffer, 0, len(initial_whitespace)),
initial_whitespace)]
parser = source_parser.Parser(lexer, version=sys.version_info[0:2],
diagnostic_engine=self.engine)
function_node = parser.file_input().body[0]

# Mangle the name, since we put everything into a single module.
function_node.name = "{}.{}".format(module_name, function.__qualname__)
8 changes: 4 additions & 4 deletions artiq/compiler/transforms/artiq_ir_generator.py
Original file line number Diff line number Diff line change
@@ -1483,19 +1483,19 @@ def visit_CallT(self, node):
for index, arg_name in enumerate(fn_typ.args):
if keyword.arg == arg_name:
assert args[index] is None
args[index + offset] = arg
args[index] = arg
break
elif keyword.arg in fn_typ.optargs:
for index, optarg_name in enumerate(fn_typ.optargs):
if keyword.arg == optarg_name:
assert args[len(fn_typ.args) + index] is None
args[len(fn_typ.args) + index + offset] = \
args[len(fn_typ.args) + index] = \
self.append(ir.Alloc([arg], ir.TOption(arg.type)))
break

for index, optarg_name in enumerate(fn_typ.optargs):
if args[len(fn_typ.args) + index + offset] is None:
args[len(fn_typ.args) + index + offset] = \
if args[len(fn_typ.args) + index] is None:
args[len(fn_typ.args) + index] = \
self.append(ir.Alloc([], ir.TOption(fn_typ.optargs[optarg_name])))

if self_arg is not None:
13 changes: 7 additions & 6 deletions artiq/compiler/transforms/llvm_ir_generator.py
Original file line number Diff line number Diff line change
@@ -409,11 +409,7 @@ def process_function(self, func):
self.llfunction = self.llmodule.get_global(func.name)

if self.llfunction is None:
llargtys = []
for arg in func.arguments:
llargtys.append(self.llty_of_type(arg.type))
llfunty = ll.FunctionType(args=llargtys,
return_type=self.llty_of_type(func.type.ret, for_return=True))
llfunty = self.llty_of_type(func.type, bare=True)
self.llfunction = ll.Function(self.llmodule, llfunty, func.name)

if func.is_internal:
@@ -427,7 +423,12 @@ def process_function(self, func):
disubprogram = self.debug_info_emitter.emit_subprogram(func, self.llfunction)

# First, map arguments.
for arg, llarg in zip(func.arguments, self.llfunction.args):
if self.llfunction.type.pointee.__has_sret:
llactualargs = self.llfunction.args[1:]
else:
llactualargs = self.llfunction.args

for arg, llarg in zip(func.arguments, llactualargs):
self.llmap[arg] = llarg

# Second, create all basic blocks.