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: 8d0222c297ec
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: 7562d397500a
Choose a head ref
  • 4 commits
  • 12 files changed
  • 1 contributor

Commits on Aug 6, 2015

  1. artiq_personality: simplify.

    whitequark committed Aug 6, 2015

    Verified

    This commit was signed with the committer’s verified signature.
    makenowjust Hiroya Fujinami
    Copy the full SHA
    722dfef View commit details
  2. Copy the full SHA
    98cd428 View commit details
  3. compiler.transforms.ARTIQIRGenerator: fix typo.

    whitequark committed Aug 6, 2015
    Copy the full SHA
    ca52b2f View commit details
  4. Copy the full SHA
    7562d39 View commit details
2 changes: 1 addition & 1 deletion artiq/compiler/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .module import Module
from .module import Module, Source
65 changes: 41 additions & 24 deletions artiq/compiler/module.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,62 @@
"""
The :class:`Module` class encapsulates a single Python
The :class:`Module` class encapsulates a single Python module,
which corresponds to a single ARTIQ translation unit (one LLVM
bitcode file and one object file, unless LTO is used).
A :class:`Module` can be created from a typed AST.
The :class:`Source` class parses a single source file or
string and infers types for it using a trivial :module:`prelude`.
"""

import os
from pythonparser import source, diagnostic, parse_buffer
from . import prelude, types, transforms, validators

class Module:
class Source:
def __init__(self, source_buffer, engine=None):
if engine is None:
engine = diagnostic.Engine(all_errors_are_fatal=True)
self.engine = diagnostic.Engine(all_errors_are_fatal=True)
else:
self.engine = engine

self.name, _ = os.path.splitext(os.path.basename(source_buffer.name))

asttyped_rewriter = transforms.ASTTypedRewriter(engine=engine)
asttyped_rewriter = transforms.ASTTypedRewriter(engine=engine,
globals=prelude.globals())
inferencer = transforms.Inferencer(engine=engine)
int_monomorphizer = transforms.IntMonomorphizer(engine=engine)
monomorphism_validator = validators.MonomorphismValidator(engine=engine)
escape_validator = validators.EscapeValidator(engine=engine)
artiq_ir_generator = transforms.ARTIQIRGenerator(engine=engine, module_name=self.name)
dead_code_eliminator = transforms.DeadCodeEliminator(engine=engine)
local_access_validator = validators.LocalAccessValidator(engine=engine)

self.parsetree, self.comments = parse_buffer(source_buffer, engine=engine)
self.typedtree = asttyped_rewriter.visit(self.parsetree)
self.globals = asttyped_rewriter.globals
inferencer.visit(self.typedtree)
int_monomorphizer.visit(self.typedtree)
inferencer.visit(self.typedtree)
monomorphism_validator.visit(self.typedtree)
escape_validator.visit(self.typedtree)
self.artiq_ir = artiq_ir_generator.visit(self.typedtree)

@classmethod
def from_string(cls, source_string, name="input.py", first_line=1, engine=None):
return cls(source.Buffer(source_string + "\n", name, first_line), engine=engine)

@classmethod
def from_filename(cls, filename, engine=None):
with open(filename) as f:
return cls(source.Buffer(f.read(), filename, 1), engine=engine)

class Module:
def __init__(self, src):
int_monomorphizer = transforms.IntMonomorphizer(engine=src.engine)
inferencer = transforms.Inferencer(engine=src.engine)
monomorphism_validator = validators.MonomorphismValidator(engine=src.engine)
escape_validator = validators.EscapeValidator(engine=src.engine)
artiq_ir_generator = transforms.ARTIQIRGenerator(engine=src.engine,
module_name=src.name)
dead_code_eliminator = transforms.DeadCodeEliminator(engine=src.engine)
local_access_validator = validators.LocalAccessValidator(engine=src.engine)

self.name = src.name
self.globals = src.globals
int_monomorphizer.visit(src.typedtree)
inferencer.visit(src.typedtree)
monomorphism_validator.visit(src.typedtree)
escape_validator.visit(src.typedtree)
self.artiq_ir = artiq_ir_generator.visit(src.typedtree)
dead_code_eliminator.process(self.artiq_ir)
# local_access_validator.process(self.artiq_ir)

@@ -43,15 +69,6 @@ def entry_point(self):
"""Return the name of the function that is the entry point of this module."""
return self.name + ".__modinit__"

@classmethod
def from_string(cls, source_string, name="input.py", first_line=1, engine=None):
return cls(source.Buffer(source_string + "\n", name, first_line), engine=engine)

@classmethod
def from_filename(cls, filename, engine=None):
with open(filename) as f:
return cls(source.Buffer(f.read(), filename, 1), engine=engine)

def __repr__(self):
printer = types.TypePrinter()
globals = ["%s: %s" % (var, printer.name(self.globals[var])) for var in self.globals]
2 changes: 1 addition & 1 deletion artiq/compiler/testbench/inferencer.py
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ def process_diagnostic(diag):
buf = source.Buffer("".join(fileinput.input()).expandtabs(),
os.path.basename(fileinput.filename()))
parsed, comments = parse_buffer(buf, engine=engine)
typed = ASTTypedRewriter(engine=engine).visit(parsed)
typed = ASTTypedRewriter(engine=engine, globals=prelude.globals()).visit(parsed)
Inferencer(engine=engine).visit(typed)
if monomorphize:
IntMonomorphizer(engine=engine).visit(typed)
4 changes: 2 additions & 2 deletions artiq/compiler/testbench/irgen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys, fileinput
from pythonparser import diagnostic
from .. import Module
from .. import Module, Source

def main():
def process_diagnostic(diag):
@@ -11,7 +11,7 @@ def process_diagnostic(diag):
engine = diagnostic.Engine()
engine.process = process_diagnostic

mod = Module.from_string("".join(fileinput.input()).expandtabs(), engine=engine)
mod = Module(Source.from_string("".join(fileinput.input()).expandtabs(), engine=engine))
for fn in mod.artiq_ir:
print(fn)

4 changes: 2 additions & 2 deletions artiq/compiler/testbench/jit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os, sys, fileinput, ctypes
from pythonparser import diagnostic
from llvmlite_artiq import binding as llvm
from .. import Module
from .. import Module, Source
from ..targets import NativeTarget

def main():
@@ -19,7 +19,7 @@ def process_diagnostic(diag):

source = "".join(fileinput.input())
source = source.replace("#ARTIQ#", "")
mod = Module.from_string(source.expandtabs(), engine=engine)
mod = Module(Source.from_string(source.expandtabs(), engine=engine))

target = NativeTarget()
llmod = mod.build_llvm_ir(target)
4 changes: 2 additions & 2 deletions artiq/compiler/testbench/llvmgen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys, fileinput
from pythonparser import diagnostic
from llvmlite_artiq import ir as ll
from .. import Module
from .. import Module, Source
from ..targets import NativeTarget

def main():
@@ -13,7 +13,7 @@ def process_diagnostic(diag):
engine = diagnostic.Engine()
engine.process = process_diagnostic

mod = Module.from_string("".join(fileinput.input()).expandtabs(), engine=engine)
mod = Module(Source.from_string("".join(fileinput.input()).expandtabs(), engine=engine))

target = NativeTarget()
llmod = mod.build_llvm_ir(target=target)
4 changes: 2 additions & 2 deletions artiq/compiler/testbench/perf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys, os, time, cProfile as profile, pstats
from pythonparser import diagnostic
from .. import Module
from .. import Module, Source
from ..targets import OR1KTarget

def main():
@@ -17,7 +17,7 @@ def process_diagnostic(diag):
engine.process = process_diagnostic

# Make sure everything's valid
modules = [Module.from_filename(filename, engine=engine)
modules = [Module(Source.from_filename(filename, engine=engine))
for filename in sys.argv[1:]]

def benchmark(f, name):
4 changes: 2 additions & 2 deletions artiq/compiler/testbench/shlib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys, os
from pythonparser import diagnostic
from .. import Module
from .. import Module, Source
from ..targets import OR1KTarget

def main():
@@ -18,7 +18,7 @@ def process_diagnostic(diag):

modules = []
for filename in sys.argv[1:]:
modules.append(Module.from_filename(filename, engine=engine))
modules.append(Module(Source.from_filename(filename, engine=engine)))

llobj = OR1KTarget().compile_and_link(modules)

4 changes: 2 additions & 2 deletions artiq/compiler/testbench/signature.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys, fileinput
from pythonparser import diagnostic
from .. import Module
from .. import Module, Source

def main():
if len(sys.argv) > 1 and sys.argv[1] == "+diag":
@@ -21,7 +21,7 @@ def process_diagnostic(diag):
engine.process = process_diagnostic

try:
mod = Module.from_string("".join(fileinput.input()).expandtabs(), engine=engine)
mod = Module(Source.from_string("".join(fileinput.input()).expandtabs(), engine=engine))
print(repr(mod))
except:
if not diag: raise
2 changes: 1 addition & 1 deletion artiq/compiler/transforms/artiq_ir_generator.py
Original file line number Diff line number Diff line change
@@ -238,7 +238,7 @@ def visit_function(self, node, is_lambda, is_internal):
return self.append(ir.Closure(func, self.current_env))

def visit_FunctionDefT(self, node):
func = self.visit_function(node, is_lambda=False, is_internal=len(name) > 2)
func = self.visit_function(node, is_lambda=False, is_internal=len(self.name) > 2)
self._set_local(node.name, func)

def visit_Return(self, node):
6 changes: 3 additions & 3 deletions artiq/compiler/transforms/asttyped_rewriter.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
"""

from pythonparser import algorithm, diagnostic
from .. import asttyped, types, builtins, prelude
from .. import asttyped, types, builtins

# This visitor will be called for every node with a scope,
# i.e.: class, function, comprehension, lambda
@@ -185,10 +185,10 @@ class ASTTypedRewriter(algorithm.Transformer):
via :class:`LocalExtractor`.
"""

def __init__(self, engine):
def __init__(self, engine, globals):
self.engine = engine
self.globals = None
self.env_stack = [prelude.globals()]
self.env_stack = [globals]

def _find_name(self, name, loc):
for typing_env in reversed(self.env_stack):
10 changes: 3 additions & 7 deletions soc/runtime/artiq_personality.c
Original file line number Diff line number Diff line change
@@ -8,14 +8,8 @@
/* Logging */

#ifndef NDEBUG
#if defined(__or1k__)
#include "log.h"
#define EH_LOG0(fmt) log("%s: " fmt, __func__)
#define EH_LOG(fmt, ...) log("%s: " fmt, __func__, __VA_ARGS__)
#else
#define EH_LOG0(fmt) fprintf(stderr, "%s: " fmt "\n", __func__)
#define EH_LOG(fmt, ...) fprintf(stderr, "%s: " fmt "\n", __func__, __VA_ARGS__)
#endif
#else
#define EH_LOG0(fmt)
#define EH_LOG(fmt, ...)
@@ -248,7 +242,9 @@ static struct artiq_raised_exception inflight;
void __artiq_raise(struct artiq_exception *artiq_exn) {
EH_LOG("===> raise (name=%s, msg=%s, params=[%lld,%lld,%lld])",
artiq_exn->name, artiq_exn->message,
artiq_exn->param[0], artiq_exn->param[1], artiq_exn->param[2]);
(long long int)artiq_exn->param[0],
(long long int)artiq_exn->param[1],
(long long int)artiq_exn->param[2]);

memmove(&inflight.artiq, artiq_exn, sizeof(struct artiq_exception));
inflight.unwind.exception_class = ARTIQ_EXCEPTION_CLASS;