2017-01-30 09:24:43 +08:00
|
|
|
#!/usr/bin/env python3
|
2015-04-07 15:41:32 +08:00
|
|
|
|
2015-12-21 21:15:18 +08:00
|
|
|
import os, sys, logging, argparse
|
2015-04-07 15:41:32 +08:00
|
|
|
|
2015-10-12 19:32:16 +08:00
|
|
|
from artiq.master.databases import DeviceDB, DatasetDB
|
|
|
|
from artiq.master.worker_db import DeviceManager, DatasetManager
|
2016-05-29 01:57:04 +08:00
|
|
|
from artiq.language.environment import ProcessArgumentManager
|
2015-09-01 12:52:39 +08:00
|
|
|
from artiq.coredevice.core import CompileError
|
2015-04-07 15:41:32 +08:00
|
|
|
from artiq.tools import *
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def get_argparser():
|
|
|
|
parser = argparse.ArgumentParser(description="ARTIQ static compiler")
|
|
|
|
|
|
|
|
verbosity_args(parser)
|
2015-10-12 19:32:16 +08:00
|
|
|
parser.add_argument("--device-db", default="device_db.pyon",
|
|
|
|
help="device database file (default: '%(default)s')")
|
|
|
|
parser.add_argument("--dataset-db", default="dataset_db.pyon",
|
|
|
|
help="dataset file (default: '%(default)s')")
|
2015-04-07 15:41:32 +08:00
|
|
|
|
|
|
|
parser.add_argument("-e", "--experiment", default=None,
|
|
|
|
help="experiment to compile")
|
|
|
|
|
|
|
|
parser.add_argument("-o", "--output", default=None,
|
|
|
|
help="output file")
|
2016-04-22 16:33:44 +08:00
|
|
|
parser.add_argument("file", metavar="FILE",
|
2015-04-07 15:41:32 +08:00
|
|
|
help="file containing the experiment to compile")
|
2016-04-22 16:33:44 +08:00
|
|
|
parser.add_argument("arguments", metavar="ARGUMENTS",
|
|
|
|
nargs="*", help="run arguments")
|
2015-04-07 15:41:32 +08:00
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = get_argparser().parse_args()
|
|
|
|
init_logger(args)
|
|
|
|
|
2015-10-12 19:32:16 +08:00
|
|
|
device_mgr = DeviceManager(DeviceDB(args.device_db))
|
|
|
|
dataset_mgr = DatasetManager(DatasetDB(args.dataset_db))
|
2015-04-07 15:41:32 +08:00
|
|
|
|
|
|
|
try:
|
2015-11-21 17:37:14 +08:00
|
|
|
module = file_import(args.file, prefix="artiq_run_")
|
2015-04-07 15:41:32 +08:00
|
|
|
exp = get_experiment(module, args.experiment)
|
|
|
|
arguments = parse_arguments(args.arguments)
|
2016-05-29 01:57:04 +08:00
|
|
|
argument_mgr = ProcessArgumentManager(arguments)
|
|
|
|
exp_inst = exp((device_mgr, dataset_mgr, argument_mgr))
|
2015-04-07 15:41:32 +08:00
|
|
|
|
2015-08-28 14:43:46 +08:00
|
|
|
if not hasattr(exp.run, "artiq_embedded"):
|
2015-04-07 15:41:32 +08:00
|
|
|
raise ValueError("Experiment entry point must be a kernel")
|
2015-08-28 14:43:46 +08:00
|
|
|
core_name = exp.run.artiq_embedded.core_name
|
2015-04-07 15:41:32 +08:00
|
|
|
core = getattr(exp_inst, core_name)
|
|
|
|
|
2016-05-29 01:57:04 +08:00
|
|
|
object_map, kernel_library, _, _ = \
|
2015-08-28 14:43:46 +08:00
|
|
|
core.compile(exp.run, [exp_inst], {},
|
2017-04-11 11:16:34 +08:00
|
|
|
attribute_writeback=False, print_as_rpc=False)
|
2015-09-01 12:52:39 +08:00
|
|
|
except CompileError as error:
|
|
|
|
return
|
2015-04-07 15:41:32 +08:00
|
|
|
finally:
|
2015-10-12 19:32:16 +08:00
|
|
|
device_mgr.close_devices()
|
2015-04-07 15:41:32 +08:00
|
|
|
|
2015-08-28 14:43:46 +08:00
|
|
|
if object_map.has_rpc():
|
2015-04-07 15:41:32 +08:00
|
|
|
raise ValueError("Experiment must not use RPC")
|
|
|
|
|
|
|
|
output = args.output
|
|
|
|
if output is None:
|
2015-08-28 14:43:46 +08:00
|
|
|
basename, ext = os.path.splitext(args.file)
|
|
|
|
output = "{}.elf".format(basename)
|
|
|
|
|
2015-04-07 15:41:32 +08:00
|
|
|
with open(output, "wb") as f:
|
2015-08-28 14:43:46 +08:00
|
|
|
f.write(kernel_library)
|
2015-04-07 15:41:32 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|