CIRCT 23.0.0git
Loading...
Searching...
No Matches
esi-cosim.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3# ===- esi-cosim.py - ESI cosimulation launch utility --------*- python -*-===//
4#
5# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6# See https://llvm.org/LICENSE.txt for license information.
7# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8#
9# ===----------------------------------------------------------------------===//
10#
11# Utility script to start a simulation and launch a command to interact with it
12# via ESI cosimulation.
13#
14# ===----------------------------------------------------------------------===//
15
16import argparse
17from pathlib import Path
18import sys
19import textwrap
20
21from esiaccel.cosim.simulator import get_simulator, SourceFiles
22
23
24def __main__(args):
25 argparser = argparse.ArgumentParser(
26 description="Wrap a 'inner_cmd' in an ESI cosimulation environment.",
27 formatter_class=argparse.RawDescriptionHelpFormatter,
28 epilog=textwrap.dedent("""
29 Notes:
30 - For Verilator, libEsiCosimDpiServer.so must be in the dynamic
31 library runtime search path (LD_LIBRARY_PATH) and link time path
32 (LIBRARY_PATH). If it is installed to a standard location (e.g.
33 /usr/lib), this should be handled automatically.
34 - This script needs to sit in the same directory as the ESI support
35 SystemVerilog (e.g. Cosim_DpiPkg.sv, Cosim_MMIO.sv, etc.). It can,
36 however, be soft linked to a different location.
37 - The simulator executable(s) must be in your PATH.
38 """))
39
40 argparser.add_argument(
41 "--sim",
42 type=str,
43 default="verilator",
44 help="Name of the RTL simulator to use or path to an executable.")
45 argparser.add_argument("--rundir",
46 default="run",
47 help="Directory in which simulation should be run.")
48 argparser.add_argument(
49 "--top",
50 default="ESI_Cosim_Top",
51 help="Name of the 'top' module to use in the simulation.")
52 argparser.add_argument("--no-compile",
53 action="store_true",
54 help="Do not run the compile.")
55 argparser.add_argument("--debug",
56 action="store_true",
57 help="Enable debug output.")
58 argparser.add_argument(
59 "--save-waveform",
60 action="store_true",
61 help="Save waveform dumps (format depends on simulator). Requires --debug."
62 )
63 argparser.add_argument("--gui",
64 action="store_true",
65 help="Run the simulator in GUI mode (if supported).")
66 argparser.add_argument("--source",
67 help="Directories containing the source files.",
68 default="hw")
69
70 argparser.add_argument("inner_cmd",
71 nargs=argparse.REMAINDER,
72 help="Command to run in the simulation environment.")
73
74 argparser.add_argument(
75 "--server-only",
76 action="store_true",
77 help="Only run the cosim server, and do not run any inner command.")
78
79 if len(args) <= 1:
80 argparser.print_help()
81 return
82 args = argparser.parse_args(args[1:])
83
84 # Validate that save_waveform requires debug
85 if args.save_waveform and not args.debug:
86 print("ERROR: --save-waveform requires --debug to be enabled",
87 file=sys.stderr)
88 return 1
89
90 sources = SourceFiles(args.top)
91 sources.add_dir(Path(args.source))
92
93 sim = get_simulator(args.sim, sources, Path(args.rundir), args.debug,
94 args.save_waveform)
95 if not args.no_compile:
96 rc = sim.compile()
97 if rc != 0:
98 return rc
99 return sim.run(args.inner_cmd[1:], gui=args.gui, server_only=args.server_only)
100
101
102if __name__ == '__main__':
103 sys.exit(__main__(sys.argv))
static void print(TypedAttr val, llvm::raw_ostream &os)
__main__(args)
Definition esi-cosim.py:24