CIRCT 24.0.0git
Loading...
Searching...
No Matches
verilator.Verilator Class Reference
Inheritance diagram for verilator.Verilator:
Collaboration diagram for verilator.Verilator:

Public Member Functions

 __init__ (self, SourceFiles sources, Path run_dir, bool debug, bool save_waveform=False, 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, Optional[str]]] macro_definitions=None)
Path verilator_bin (self)
List[Simulator.CompileStep] compile_commands (self)
str waveform_extension (self)
 run_command (self, bool gui)
Public Member Functions inherited from simulator.Simulator
 __init__ (self, SourceFiles sources, Path run_dir, bool debug, bool save_waveform=False, 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, Optional[str]]] macro_definitions=None)
int compile (self)
SimProcess run_proc (self, bool gui=False)
int run (self, str inner_command, bool gui=False, bool server_only=False)

Static Public Attributes

str DefaultDriver = CosimCollateralDir / "driver.cpp"
tuple VerilatorBinNotFound
tuple VerilatorRootNotFound
tuple VerilatorPathInvalid
tuple VerilatorRootInvalid
Static Public Attributes inherited from simulator.Simulator
 CompileCommand = List[str]
 CompileFunction = Callable[[], Optional[int]]
 CompileStep = Union[CompileCommand, CompileFunction]
bool UsesStderr = True

Protected Member Functions

bool _use_cmake (self)
Path _depfile_path (self, Path obj_dir)
List[Path] _generated_targets (self, Path depfile)
int _write_cmake_from_depfile (self)
List[Path] _generated_cpp_sources (self, Path depfile)
Path _write_cmake (self, Path obj_dir, List[Path] generated_sources, Optional[Path] pch_header=None)
Protected Member Functions inherited from simulator.Simulator
int _run_compile_command (self, CompileCommand cmd)
int _run_compile_step (self, CompileStep step)
int|tuple[subprocess.Popen, List[threading.Thread]] _start_process_with_callbacks (self, List[str] cmd, Optional[Dict[str, str]] env, Optional[Path] cwd, Optional[Callable[[str], None]] stdout_cb, Optional[Callable[[str], None]] stderr_cb, bool wait)

Static Protected Member Functions

Optional[Path] _find_verilator_bin ()
Optional[Path] _find_verilator_root ()
None _raise_stack_limit ()
List[str] _toolchain_args ()
str _cmake_signature (List[str] cmake_cmd)
bool _is_slow (Path source)

Protected Attributes

bool _cmake_dirty = True
 _use_cmake
 _write_cmake_from_depfile
Protected Attributes inherited from simulator.Simulator
list _default_files = []
 _compile_stdout_cb
 _compile_stdout_log
 _compile_stderr_cb
 _compile_stderr_log
 _run_stdout_cb
 _run_stdout_log
 _run_stderr_cb
 _run_stderr_log

Static Protected Attributes

str _CMakeSignatureFilename = ".esi-cosim-cmake-config.json"
tuple _CMakeSignatureEnv

Additional Inherited Members

Static Public Member Functions inherited from simulator.Simulator
Dict[str, str] get_env ()
Public Attributes inherited from simulator.Simulator
 sources = sources
 run_dir = run_dir
 debug = debug
 save_waveform = save_waveform
 macro_definitions = macro_definitions

Detailed Description

Run and compile funcs for Verilator.

Calls ``verilator_bin`` directly (bypassing the Perl wrapper) to generate
C++ from RTL, then builds the simulation executable with CMake + Ninja.
Falls back to ``make`` when cmake/ninja are not available.

Definition at line 15 of file verilator.py.

Constructor & Destructor Documentation

◆ __init__()

verilator.Verilator.__init__ ( self,
SourceFiles sources,
Path run_dir,
bool debug,
bool save_waveform = False,
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, Optional[str]]] macro_definitions = None )

Definition at line 44 of file verilator.py.

References __init__().

Referenced by __init__().

Member Function Documentation

◆ _cmake_signature()

str verilator.Verilator._cmake_signature ( List[str] cmake_cmd)
staticprotected
Serialize inputs that can affect CMake configuration.

Definition at line 176 of file verilator.py.

◆ _depfile_path()

Path verilator.Verilator._depfile_path ( self,
Path obj_dir )
protected

Definition at line 307 of file verilator.py.

Referenced by _write_cmake_from_depfile().

◆ _find_verilator_bin()

Optional[Path] verilator.Verilator._find_verilator_bin ( )
staticprotected
Locate the ``verilator_bin`` executable.

When ``VERILATOR_PATH`` is set it must point to a valid executable;
otherwise a ``RuntimeError`` is raised. Without it, ``verilator_bin`` is
looked up on ``PATH``. Returns ``None`` when nothing is found.

Definition at line 80 of file verilator.py.

Referenced by compile_commands().

◆ _find_verilator_root()

Optional[Path] verilator.Verilator._find_verilator_root ( )
staticprotected
Locate the Verilator root containing ``include/verilated.h``.

When ``VERILATOR_ROOT`` is set it must contain ``include/verilated.h``;
otherwise a ``RuntimeError`` is raised. Without it, the packaged root
(``$PREFIX/share/verilator``) is derived from the ``verilator_bin``
location. Returns ``None`` when nothing is found.

Definition at line 105 of file verilator.py.

Referenced by _write_cmake(), and compile_commands().

◆ _generated_cpp_sources()

List[Path] verilator.Verilator._generated_cpp_sources ( self,
Path depfile )
protected

Definition at line 331 of file verilator.py.

References _generated_targets().

◆ _generated_targets()

List[Path] verilator.Verilator._generated_targets ( self,
Path depfile )
protected

Definition at line 310 of file verilator.py.

References resolve().

Referenced by _generated_cpp_sources(), and _write_cmake_from_depfile().

◆ _is_slow()

bool verilator.Verilator._is_slow ( Path source)
staticprotected
Verilator suffixes cold-path TUs, including Syms/ConstPool, with
``__Slow``.

Definition at line 342 of file verilator.py.

Referenced by _write_cmake().

◆ _raise_stack_limit()

None verilator.Verilator._raise_stack_limit ( )
staticprotected
Lift the stack soft limit to the hard limit for the verilator process.

Verilator recurses over the design AST and segfaults on large designs with
the usual 8MB stack. Its ``verilator`` wrapper script normally runs
``ulimit -s unlimited`` first; we invoke ``verilator_bin`` directly and so
have to do it ourselves. Subprocesses inherit the raised limit.

Definition at line 137 of file verilator.py.

Referenced by compile_commands().

◆ _toolchain_args()

List[str] verilator.Verilator._toolchain_args ( )
staticprotected
Prefer clang and lld when they are available.

Verilated code compiles about twice as fast with clang as with gcc, and
the model is a throwaway simulation binary, so the toolchain only affects
build time. Setting ``CXX`` or ``LDFLAGS`` opts back out.

Definition at line 157 of file verilator.py.

◆ _use_cmake()

bool verilator.Verilator._use_cmake ( self)
protected
True when both cmake and ninja are available on PATH.

Definition at line 131 of file verilator.py.

◆ _write_cmake()

Path verilator.Verilator._write_cmake ( self,
Path obj_dir,
List[Path] generated_sources,
Optional[Path] pch_header = None )
protected
Write a CMakeLists.txt for building the verilated simulation.

Returns the path to the CMake build directory.

Definition at line 347 of file verilator.py.

References _cmake_dirty, _find_verilator_root(), _is_slow(), circt::arc::runtime::impl::TraceEncoder.debug, esi::CliParser.debug, pytest.CosimPytestConfig.debug, questa.Questa.debug, simulator.Simulator.debug, and simulator.Simulator.sources.

Referenced by _write_cmake_from_depfile().

◆ _write_cmake_from_depfile()

int verilator.Verilator._write_cmake_from_depfile ( self)
protected

Definition at line 318 of file verilator.py.

References _depfile_path(), _generated_targets(), and _write_cmake().

◆ compile_commands()

List[Simulator.CompileStep] verilator.Verilator.compile_commands ( self)
Return the compile steps for the full compile flow.

When cmake and ninja are available the returned list contains four
sequential steps:
  1. ``verilator_bin`` – generates C++ from RTL.
  2. Python callback – generates the CMakeLists.txt from the depfile.
  3. Python callback – configures the C++ build when inputs changed.
  4. ``ninja`` – builds the simulation executable.

Otherwise falls back to two commands:
  1. ``verilator_bin --exe`` – generates C++ and a Makefile.
  2. ``make`` – builds via the generated Makefile.

Reimplemented from simulator.Simulator.

Definition at line 186 of file verilator.py.

References _find_verilator_bin(), _find_verilator_root(), and _raise_stack_limit().

◆ run_command()

verilator.Verilator.run_command ( self,
bool gui )
Return the command to run the simulation.

Reimplemented from simulator.Simulator.

Definition at line 515 of file verilator.py.

References _use_cmake, and simulator.Simulator.sources.

Referenced by Python.setup.CustomBuild.run(), and setup.CustomBuild.run().

◆ verilator_bin()

Path verilator.Verilator.verilator_bin ( self)

Definition at line 73 of file verilator.py.

◆ waveform_extension()

str verilator.Verilator.waveform_extension ( self)
Verilator's C++ driver uses ``VerilatedFstC`` — FST format.

Reimplemented from simulator.Simulator.

Definition at line 511 of file verilator.py.

Member Data Documentation

◆ _cmake_dirty

bool verilator.Verilator._cmake_dirty = True
protected

Definition at line 70 of file verilator.py.

Referenced by _write_cmake().

◆ _CMakeSignatureEnv

tuple verilator.Verilator._CMakeSignatureEnv
staticprotected
Initial value:
= (
"CMAKE_PREFIX_PATH",
"CMAKE_TOOLCHAIN_FILE",
"CXX",
"CXXFLAGS",
"LDFLAGS",
"PATH",
)

Definition at line 24 of file verilator.py.

◆ _CMakeSignatureFilename

str verilator.Verilator._CMakeSignatureFilename = ".esi-cosim-cmake-config.json"
staticprotected

Definition at line 23 of file verilator.py.

◆ _use_cmake

verilator.Verilator._use_cmake
protected

Definition at line 242 of file verilator.py.

Referenced by run_command().

◆ _write_cmake_from_depfile

verilator.Verilator._write_cmake_from_depfile
protected

Definition at line 284 of file verilator.py.

◆ DefaultDriver

str verilator.Verilator.DefaultDriver = CosimCollateralDir / "driver.cpp"
static

Definition at line 22 of file verilator.py.

◆ VerilatorBinNotFound

tuple verilator.Verilator.VerilatorBinNotFound
static
Initial value:
= (
"Cannot find verilator_bin. Set VERILATOR_PATH to an absolute path "
"or ensure verilator_bin is in PATH.")

Definition at line 32 of file verilator.py.

◆ VerilatorPathInvalid

tuple verilator.Verilator.VerilatorPathInvalid
static
Initial value:
= (
"VERILATOR_PATH does not point to a valid verilator_bin executable.")

Definition at line 38 of file verilator.py.

◆ VerilatorRootInvalid

tuple verilator.Verilator.VerilatorRootInvalid
static
Initial value:
= (
"VERILATOR_ROOT does not point to a Verilator root containing "
"include/verilated.h.")

Definition at line 40 of file verilator.py.

◆ VerilatorRootNotFound

tuple verilator.Verilator.VerilatorRootNotFound
static
Initial value:
= (
"Cannot find VERILATOR_ROOT. Set the VERILATOR_ROOT environment "
"variable or ensure verilator_bin is in PATH.")

Definition at line 35 of file verilator.py.


The documentation for this class was generated from the following file: