Skip to content
This repository was archived by the owner on Jan 18, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions artiq/coredevice/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,13 @@ def close(self):
"""
self.comm.close()

def compile(self, method, args, kwargs, embedding_map, file_output=None, target=None):
def compile(self, method, args, kwargs, embedding_map, output_filename=None, debug_filename=None, target=None):
if target is not None:
# NAC3TODO: subkernels
raise NotImplementedError

if (output_filename is None) != (debug_filename is None):
raise ValueError("both output and debug filenames should be specified or unspecified")

if not self.analyzed:
self.compiler.analyze(
Expand All @@ -261,27 +264,27 @@ def compile(self, method, args, kwargs, embedding_map, file_output=None, target=
name = ""

# NAC3TODO: handle self.report_invariants
if file_output is None:
if output_filename is None and debug_filename is None:
return self.compiler.compile_method_to_mem(obj, name, args, embedding_map)
else:
self.compiler.compile_method_to_file(obj, name, args, file_output, embedding_map)
self.compiler.compile_method_to_file(obj, name, args, output_filename, debug_filename, embedding_map)

def run(self, function, args, kwargs):
embedding_map = EmbeddingMap()
kernel_library = self.compile(function, args, kwargs, embedding_map)
kernel_library, debug_object = self.compile(function, args, kwargs, embedding_map)

self._run_compiled(kernel_library, embedding_map)
self._run_compiled(kernel_library, debug_object, embedding_map)

# set by NAC3
if embedding_map.expects_return:
return embedding_map.return_value

def _run_compiled(self, kernel_library, embedding_map):
def _run_compiled(self, kernel_library, debug_object, embedding_map):
if self.first_run:
self.comm.check_system_info()
self.first_run = False

symbolizer = lambda addresses: symbolize(kernel_library, addresses)
symbolizer = lambda addresses: symbolize(debug_object, addresses)

self.comm.load(kernel_library)
self.comm.run()
Expand Down Expand Up @@ -459,7 +462,7 @@ def __exit__(self, exc_typ, exc_value, exc_trace):
os.unlink(filename)


def symbolize(library, addresses):
def symbolize(debug_library, addresses):
if addresses == []:
return []

Expand All @@ -470,8 +473,8 @@ def symbolize(library, addresses):
last_inlined = None
offset_addresses = [hex(addr - 1) for addr in addresses]
with RunTool(["llvm-addr2line", "--addresses", "--functions", "--inlines",
"--demangle", "--exe={library}"] + offset_addresses,
library=library) \
"--demangle", "--exe={debug_library}"] + offset_addresses,
debug_library=debug_library) \
as results:
lines = iter(results["__stdout__"].read().rstrip().split("\n"))
backtrace = []
Expand Down
11 changes: 6 additions & 5 deletions artiq/frontend/artiq_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def get_argparser():

parser.add_argument("-o", "--output", default=None,
help="output file")
parser.add_argument("-d", "--debug", default=None,
help="debug file")
parser.add_argument("file", metavar="FILE",
help="file containing the experiment to compile")
parser.add_argument("arguments", metavar="ARGUMENTS",
Expand All @@ -51,10 +53,9 @@ def main():
dataset_mgr = DatasetManager(dataset_db)
embedding_map = EmbeddingMap()

output = args.output
if output is None:
basename, ext = os.path.splitext(args.file)
output = "{}.elf".format(basename)
basename, ext = os.path.splitext(args.file)
output = "{}.elf".format(basename) if args.output is None else args.output
debug = "{}_debug.elf".format(basename) if args.debug is None else args.debug

module = file_import(args.file, prefix="artiq_run_")
exp = get_experiment(module, args.class_name)
Expand All @@ -65,7 +66,7 @@ def main():

if not getattr(exp.run, "__artiq_kernel__", False):
raise ValueError("Experiment entry point must be a kernel")
exp_inst.core.compile(exp_inst.run, [], {}, embedding_map, file_output=output)
exp_inst.core.compile(exp_inst.run, [], {}, embedding_map, output_filename=output, debug_filename=debug)
finally:
dataset_db.close_db()
finally:
Expand Down