CIRCT 23.0.0git
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | 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 ()
 

Protected Attributes

 _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
 

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 14 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 34 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

◆ _depfile_path()

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

Definition at line 223 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 68 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 93 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 247 of file verilator.py.

References verilator.Verilator._generated_targets().

◆ _generated_targets()

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

◆ _use_cmake()

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

Definition at line 119 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. ``cmake`` – configures the C++ build (Ninja generator).
  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 124 of file verilator.py.

References verilator.Verilator._find_verilator_bin(), verilator.Verilator._find_verilator_root(), 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 61 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 387 of file verilator.py.

Member Data Documentation

◆ _write_cmake_from_depfile

verilator.Verilator._write_cmake_from_depfile
protected

Definition at line 200 of file verilator.py.

◆ DefaultDriver

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

Definition at line 21 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 22 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 28 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 30 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 25 of file verilator.py.


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