CIRCT 24.0.0git
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
verilator.Verilator Class Reference
Inheritance diagram for verilator.Verilator:
Inheritance graph
[legend]
Collaboration diagram for verilator.Verilator:
Collaboration graph
[legend]

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, str]] macro_definitions=None)
 
Path verilator_bin (self)
 
List[Simulator.CompileStepcompile_commands (self)
 
str waveform_extension (self)
 
 run_command (self, bool gui)
 
- Public Member Functions inherited from simulator.Simulator
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

 _cmake_dirty
 
 _write_cmake_from_depfile
 
- Protected Attributes inherited from simulator.Simulator
 _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
 
 run_dir
 
 debug
 
 save_waveform
 
 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, str]]   macro_definitions = None 
)
Simulator base class.

Optional sinks can be provided for capturing output. If not provided,
the simulator will write to log files in `run_dir`.

Args:
  sources: SourceFiles describing RTL/DPI inputs.
  run_dir: Directory where build/run artifacts are placed.
  debug: Enable cosim debug mode.
  save_waveform: When True and debug=True, dump simulator waveforms to a
    waveform file. The exact format depends on the backend (e.g. FST for
    Verilator, VCD for Questa). Requires debug to be enabled.
  run_stdout_callback: Line-based callback for runtime stdout.
  run_stderr_callback: Line-based callback for runtime stderr.
  compile_stdout_callback: Line-based callback for compile stdout.
  compile_stderr_callback: Line-based callback for compile stderr.
  make_default_logs: If True and corresponding callback is not supplied,
    create log file and emit via internally-created callback.
  macro_definitions: Optional dictionary of macro definitions to be defined
    during compilation.

Reimplemented from simulator.Simulator.

Definition at line 44 of file verilator.py.

References verilator.Verilator.__init__().

Referenced by verilator.Verilator.__init__(), synth.LongestPathCollection.drop_non_critical_paths(), and synth.LongestPathCollection.merge().

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.

Referenced by verilator.Verilator.compile_commands().

◆ _depfile_path()

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

Definition at line 307 of file verilator.py.

Referenced by verilator.Verilator._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 verilator.Verilator.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 verilator.Verilator._write_cmake(), and verilator.Verilator.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 verilator.Verilator._generated_targets().

◆ _generated_targets()

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

◆ _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 verilator.Verilator._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 verilator.Verilator.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.

Referenced by verilator.Verilator.compile_commands().

◆ _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.

Referenced by verilator.Verilator.compile_commands(), and verilator.Verilator.run_command().

◆ _write_cmake()

Path verilator.Verilator._write_cmake (   self,
Path  obj_dir,
List[Path]  generated_sources,
Optional[Path]   pch_header = None 
)
protected

◆ _write_cmake_from_depfile()

int verilator.Verilator._write_cmake_from_depfile (   self)
protected

◆ 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 verilator.Verilator._cmake_signature(), verilator.Verilator._CMakeSignatureFilename, verilator.Verilator._find_verilator_bin(), verilator.Verilator._find_verilator_root(), verilator.Verilator._raise_stack_limit(), simulator.Simulator._run_compile_command(), verilator.Verilator._toolchain_args(), verilator.Verilator._use_cmake(), circt::arc::runtime::impl::TraceEncoder.debug, esi::CliParser.debug, esi::Logger.debug(), esi::Logger.debug(), pytest.CosimPytestConfig.debug, simulator.Simulator.debug, simulator.Simulator.macro_definitions, and simulator.Simulator.sources.

Referenced by simulator.Simulator.compile().

◆ run_command()

verilator.Verilator.run_command (   self,
bool  gui 
)

◆ 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

verilator.Verilator._cmake_dirty
protected

Definition at line 70 of file verilator.py.

Referenced by verilator.Verilator._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.

Referenced by verilator.Verilator.compile_commands().

◆ _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: