33 argparser = argparse.ArgumentParser(
34 description=
"Wrap a 'inner_cmd' in an ESI cosimulation environment.",
35 formatter_class=argparse.RawDescriptionHelpFormatter,
36 epilog=textwrap.dedent(
"""
38 - For Verilator, libEsiCosimDpiServer.so must be in the dynamic
39 library runtime search path (LD_LIBRARY_PATH) and link time path
40 (LIBRARY_PATH). If it is installed to a standard location (e.g.
41 /usr/lib), this should be handled automatically.
42 - This script needs to sit in the same directory as the ESI support
43 SystemVerilog (e.g. Cosim_DpiPkg.sv, Cosim_MMIO.sv, etc.). It can,
44 however, be soft linked to a different location.
45 - The simulator executable(s) must be in your PATH.
48 argparser.add_argument(
52 help=
"Name of the RTL simulator to use or path to an executable.")
53 argparser.add_argument(
"--rundir",
55 help=
"Directory in which simulation should be run.")
56 argparser.add_argument(
58 default=
"ESI_Cosim_Top",
59 help=
"Name of the 'top' module to use in the simulation.")
60 argparser.add_argument(
"--no-compile",
62 help=
"Do not run the compile.")
63 argparser.add_argument(
"--debug",
65 help=
"Enable debug output.")
66 argparser.add_argument(
69 help=
"Save waveform dumps (format depends on simulator). Requires --debug."
71 argparser.add_argument(
"--gui",
73 help=
"Run the simulator in GUI mode (if supported).")
74 argparser.add_argument(
"--source",
75 help=
"Directories containing the source files.",
77 argparser.add_argument(
80 dest=
"macro_definitions",
83 metavar=
"NAME[=VALUE]",
84 type=_parse_macro_definition,
85 help=
"Define an RTL macro during compilation. May be specified multiple "
87 argparser.add_argument(
89 dest=
"macro_definitions_file",
91 help=
"Read RTL macro definitions from a JSON file: an object mapping "
92 "macro name to value, where null defines the macro without one. Useful "
93 "when the macros are produced by the same build that generated the "
94 "sources. Any -D on the command line overrides what the file defines.")
96 argparser.add_argument(
"inner_cmd",
97 nargs=argparse.REMAINDER,
98 help=
"Command to run in the simulation environment.")
100 argparser.add_argument(
103 help=
"Only run the cosim server, and do not run any inner command.")
106 argparser.print_help()
108 args = argparser.parse_args(args[1:])
111 if args.save_waveform
and not args.debug:
112 print(
"ERROR: --save-waveform requires --debug to be enabled",
116 sources = SourceFiles(args.top)
117 sources.add_dir(Path(args.source))
119 macro_definitions = {}
120 if args.macro_definitions_file
is not None:
121 macro_definitions.update(
122 load_macro_definitions(Path(args.macro_definitions_file)))
123 macro_definitions.update(args.macro_definitions)
125 sim = get_simulator(args.sim,
130 macro_definitions=macro_definitions)
131 if not args.no_compile:
135 return sim.run(args.inner_cmd[1:], gui=args.gui, server_only=args.server_only)