forked from M-Labs/artiq
1
0
Fork 0

compiler: refuse to embed a function from another core device.

Fixes #332.
This commit is contained in:
whitequark 2016-03-18 02:01:14 +00:00
parent 82ab21dbd5
commit 78fa5becea
3 changed files with 18 additions and 4 deletions

View File

@ -448,7 +448,9 @@ class TypedtreeHasher(algorithm.Visitor):
return hash(tuple(freeze(getattr(node, field_name)) for field_name in fields)) return hash(tuple(freeze(getattr(node, field_name)) for field_name in fields))
class Stitcher: class Stitcher:
def __init__(self, engine=None): def __init__(self, core, dmgr, engine=None):
self.core = core
self.dmgr = dmgr
if engine is None: if engine is None:
self.engine = diagnostic.Engine(all_errors_are_fatal=True) self.engine = diagnostic.Engine(all_errors_are_fatal=True)
else: else:
@ -473,7 +475,7 @@ class Stitcher:
# We synthesize source code for the initial call so that # We synthesize source code for the initial call so that
# diagnostics would have something meaningful to display to the user. # diagnostics would have something meaningful to display to the user.
synthesizer = self._synthesizer() synthesizer = self._synthesizer(self._function_loc(function.artiq_embedded.function))
call_node = synthesizer.call(function_node, args, kwargs, callback) call_node = synthesizer.call(function_node, args, kwargs, callback)
synthesizer.finalize() synthesizer.finalize()
self.typedtree.append(call_node) self.typedtree.append(call_node)
@ -752,6 +754,17 @@ class Stitcher:
notes=[note]) notes=[note])
self.engine.process(diag) self.engine.process(diag)
if self.dmgr.get(function.artiq_embedded.core_name) != self.core:
note = diagnostic.Diagnostic("note",
"called from this function", {},
loc)
diag = diagnostic.Diagnostic("fatal",
"this function runs on a different core device '{name}'",
{"name": function.artiq_embedded.core_name},
self._function_loc(function.artiq_embedded.function),
notes=[note])
self.engine.process(diag)
# Insert the typed AST for the new function and restart inference. # Insert the typed AST for the new function and restart inference.
# It doesn't really matter where we insert as long as it is before # It doesn't really matter where we insert as long as it is before
# the final call. # the final call.

View File

@ -31,7 +31,7 @@ def main():
def embed(): def embed():
experiment = testcase_vars["Benchmark"](dmgr) experiment = testcase_vars["Benchmark"](dmgr)
stitcher = Stitcher() stitcher = Stitcher(core=experiment.core, dmgr=dmgr)
stitcher.stitch_call(experiment.run, (experiment,), {}) stitcher.stitch_call(experiment.run, (experiment,), {})
stitcher.finalize() stitcher.finalize()
return stitcher return stitcher

View File

@ -67,6 +67,7 @@ class Core:
self.comm = dmgr.get(comm_device) self.comm = dmgr.get(comm_device)
self.first_run = True self.first_run = True
self.dmgr = dmgr
self.core = self self.core = self
self.comm.core = self self.comm.core = self
@ -74,7 +75,7 @@ class Core:
try: try:
engine = _DiagnosticEngine(all_errors_are_fatal=True) engine = _DiagnosticEngine(all_errors_are_fatal=True)
stitcher = Stitcher(engine=engine) stitcher = Stitcher(engine=engine, core=self, dmgr=self.dmgr)
stitcher.stitch_call(function, args, kwargs, set_result) stitcher.stitch_call(function, args, kwargs, set_result)
stitcher.finalize() stitcher.finalize()