CIRCT 22.0.0git
Loading...
Searching...
No Matches
verilator.py
Go to the documentation of this file.
1# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2# See https://llvm.org/LICENSE.txt for license information.
3# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5import os
6from pathlib import Path
7from typing import List, Optional, Callable, Dict
8
9from .simulator import CosimCollateralDir, Simulator, SourceFiles
10
11
13 """Run and compile funcs for Verilator."""
14
15 DefaultDriver = CosimCollateralDir / "driver.cpp"
16
18 self,
19 sources: SourceFiles,
20 run_dir: Path,
21 debug: bool,
22 run_stdout_callback: Optional[Callable[[str], None]] = None,
23 run_stderr_callback: Optional[Callable[[str], None]] = None,
24 compile_stdout_callback: Optional[Callable[[str], None]] = None,
25 compile_stderr_callback: Optional[Callable[[str], None]] = None,
26 make_default_logs: bool = True,
27 macro_definitions: Optional[Dict[str, str]] = None,
28 ):
29 super().__init__(
30 sources=sources,
31 run_dir=run_dir,
32 debug=debug,
33 run_stdout_callback=run_stdout_callback,
34 run_stderr_callback=run_stderr_callback,
35 compile_stdout_callback=compile_stdout_callback,
36 compile_stderr_callback=compile_stderr_callback,
37 make_default_logs=make_default_logs,
38 macro_definitions=macro_definitions,
39 )
40 self.verilator = "verilator"
41 if "VERILATOR_PATH" in os.environ:
42 self.verilator = os.environ["VERILATOR_PATH"]
43
44 def compile_commands(self) -> List[List[str]]:
45 cmd: List[str] = [
46 self.verilator,
47 "--cc",
48 ]
49
50 if self.macro_definitions:
51 cmd += [
52 f"+define+{k}={v}" if v is not None else f"+define+{k}"
53 for k, v in self.macro_definitions.items()
54 ]
55
56 cmd += [
57 "--top-module",
58 self.sources.top,
59 "-DSIMULATION",
60 "-Wno-TIMESCALEMOD",
61 "-Wno-fatal",
62 "-sv",
63 "--exe",
64 "--build",
65 "-j",
66 "0",
67 "--output-split",
68 "--autoflush",
69 "--assert",
70 str(Verilator.DefaultDriver),
71 ]
72 cflags = [
73 "-DTOP_MODULE=" + self.sources.top,
74 ]
75 if self.debug:
76 cmd += [
77 "--trace-fst", "--trace-params", "--trace-structs",
78 "--trace-underscore"
79 ]
80 cflags.append("-DTRACE")
81 if len(cflags) > 0:
82 cmd += ["-CFLAGS", " ".join(cflags)]
83 if len(self.sources.dpi_so) > 0:
84 cmd += ["-LDFLAGS", " ".join(["-l" + so for so in self.sources.dpi_so])]
85 cmd += [str(p) for p in self.sources.rtl_sources]
86 return [cmd]
87
88 def run_command(self, gui: bool):
89 if gui:
90 raise RuntimeError("Verilator does not support GUI mode.")
91 exe = Path.cwd() / "obj_dir" / ("V" + self.sources.top)
92 return [str(exe)]
__init__(self, SourceFiles sources, Path run_dir, bool debug, Optional[Callable[[str], None]] run_stdout_callback=None, Optional[Callable[[str], None]] run_stderr_callback=None, Optional[Callable[[str], None]] compile_stdout_callback=None, Optional[Callable[[str], None]] compile_stderr_callback=None, bool make_default_logs=True, Optional[Dict[str, str]] macro_definitions=None)
Definition verilator.py:28
run_command(self, bool gui)
Definition verilator.py:88
List[List[str]] compile_commands(self)
Definition verilator.py:44