CIRCT 22.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
20from typing import Dict, List
21
22from esiaccel.cosim.questa import Questa
23from esiaccel.cosim.verilator import Verilator
24from esiaccel.cosim.simulator import SourceFiles
25
26
27def __main__(args):
28 argparser = argparse.ArgumentParser(
29 description="Wrap a 'inner_cmd' in an ESI cosimulation environment.",
30 formatter_class=argparse.RawDescriptionHelpFormatter,
31 epilog=textwrap.dedent("""
32 Notes:
33 - For Verilator, libEsiCosimDpiServer.so must be in the dynamic
34 library runtime search path (LD_LIBRARY_PATH) and link time path
35 (LIBRARY_PATH). If it is installed to a standard location (e.g.
36 /usr/lib), this should be handled automatically.
37 - This script needs to sit in the same directory as the ESI support
38 SystemVerilog (e.g. Cosim_DpiPkg.sv, Cosim_MMIO.sv, etc.). It can,
39 however, be soft linked to a different location.
40 - The simulator executable(s) must be in your PATH.
41 """))
42
43 argparser.add_argument(
44 "--sim",
45 type=str,
46 default="verilator",
47 help="Name of the RTL simulator to use or path to an executable.")
48 argparser.add_argument("--rundir",
49 default="run",
50 help="Directory in which simulation should be run.")
51 argparser.add_argument(
52 "--top",
53 default="ESI_Cosim_Top",
54 help="Name of the 'top' module to use in the simulation.")
55 argparser.add_argument("--no-compile",
56 action="store_true",
57 help="Do not run the compile.")
58 argparser.add_argument("--debug",
59 action="store_true",
60 help="Enable debug output.")
61 argparser.add_argument("--gui",
62 action="store_true",
63 help="Run the simulator in GUI mode (if supported).")
64 argparser.add_argument("--source",
65 help="Directories containing the source files.",
66 default="hw")
67
68 argparser.add_argument("inner_cmd",
69 nargs=argparse.REMAINDER,
70 help="Command to run in the simulation environment.")
71
72 argparser.add_argument(
73 "--server-only",
74 action="store_true",
75 help="Only run the cosim server, and do not run any inner command.")
76
77 if len(args) <= 1:
78 argparser.print_help()
79 return
80 args = argparser.parse_args(args[1:])
81
82 sources = SourceFiles(args.top)
83 sources.add_dir(Path(args.source))
84
85 if args.sim == "verilator":
86 sim = Verilator(sources, Path(args.rundir), args.debug)
87 elif args.sim == "questa":
88 sim = Questa(sources, Path(args.rundir), args.debug)
89 else:
90 print("Unknown simulator: " + args.sim)
91 print("Supported simulators: ")
92 print(" - verilator")
93 print(" - questa")
94 return 1
95
96 if not args.no_compile:
97 rc = sim.compile()
98 if rc != 0:
99 return rc
100 return sim.run(args.inner_cmd[1:], gui=args.gui, server_only=args.server_only)
101
102
103if __name__ == '__main__':
104 sys.exit(__main__(sys.argv))
static void print(TypedAttr val, llvm::raw_ostream &os)
__main__(args)
Definition esi-cosim.py:27