CIRCT 24.0.0git
Loading...
Searching...
No Matches
simulator.Simulator Class Reference
Inheritance diagram for simulator.Simulator:
Collaboration diagram for simulator.Simulator:

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)
List[CompileStep] compile_commands (self)
int compile (self)
List[str] run_command (self, bool gui)
str waveform_extension (self)
SimProcess run_proc (self, bool gui=False)
int run (self, str inner_command, bool gui=False, bool server_only=False)

Static Public Member Functions

Dict[str, str] get_env ()

Public Attributes

 sources = sources
 run_dir = run_dir
 debug = debug
 save_waveform = save_waveform
 macro_definitions = macro_definitions

Static Public Attributes

 CompileCommand = List[str]
 CompileFunction = Callable[[], Optional[int]]
 CompileStep = Union[CompileCommand, CompileFunction]
bool UsesStderr = True

Protected Member Functions

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)

Protected Attributes

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

Detailed Description

Definition at line 197 of file simulator.py.

Constructor & Destructor Documentation

◆ __init__()

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 )
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.

Definition at line 208 of file simulator.py.

Member Function Documentation

◆ _run_compile_command()

int simulator.Simulator._run_compile_command ( self,
CompileCommand cmd )
protected

◆ _run_compile_step()

int simulator.Simulator._run_compile_step ( self,
CompileStep step )
protected

Definition at line 342 of file simulator.py.

References _run_compile_command().

Referenced by compile().

◆ _start_process_with_callbacks()

int | tuple[subprocess.Popen, List[threading.Thread]] simulator.Simulator._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 )
protected
Start a subprocess and stream its stdout/stderr to callbacks.

If wait is True, blocks until process completes and returns its exit code.
If wait is False, returns the Popen object (threads keep streaming).

Definition at line 438 of file simulator.py.

References print().

Referenced by _run_compile_command(), and run_proc().

◆ compile()

int simulator.Simulator.compile ( self)

◆ compile_commands()

List[CompileStep] simulator.Simulator.compile_commands ( self)
Return the compile steps for the simulator.

Each step may be either a shell command (`List[str]`) or a Python callback
(`Callable[[], Optional[int]]`). Python callbacks should return `0` or
`None` on success and a non-zero integer on failure.

Reimplemented in questa.Questa, and verilator.Verilator.

Definition at line 308 of file simulator.py.

Referenced by compile().

◆ get_env()

Dict[str, str] simulator.Simulator.get_env ( )
static
Get the environment variables to locate shared objects.

Definition at line 284 of file simulator.py.

◆ run()

int simulator.Simulator.run ( self,
str inner_command,
bool gui = False,
bool server_only = False )
Start the simulation then run the command specified. Kill the simulation
when the command exits.

Reimplemented in questa.Questa.

Definition at line 494 of file simulator.py.

References print(), and run_proc().

◆ run_command()

List[str] simulator.Simulator.run_command ( self,
bool gui )
Return the command to run the simulation.

Reimplemented in questa.Questa, and verilator.Verilator.

Definition at line 361 of file simulator.py.

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

◆ run_proc()

SimProcess simulator.Simulator.run_proc ( self,
bool gui = False )
Run the simulation process. Returns the Popen object and the port which
  the simulation is listening on.

If user-provided stdout/stderr sinks were supplied in the constructor,
they are used. Otherwise, log files are created in `run_dir`.

Definition at line 375 of file simulator.py.

References _run_stderr_cb, _run_stdout_cb, _start_process_with_callbacks(), circt::arc::runtime::impl::TraceEncoder.debug, esi::CliParser.debug, pytest.CosimPytestConfig.debug, questa.Questa.debug, debug, resolve(), questa.Questa.run_command(), run_command(), run_dir, pytest.CosimPytestConfig.save_waveform, and save_waveform.

Referenced by run().

◆ waveform_extension()

str simulator.Simulator.waveform_extension ( self)
File extension for waveform dumps.

Subclasses should override if their format differs.  The Verilator C++
driver writes FST (via ``VerilatedFstC``); the generic SV driver uses
``$dumpfile/$dumpvars`` which produces VCD.

Reimplemented in verilator.Verilator.

Definition at line 366 of file simulator.py.

Member Data Documentation

◆ _compile_stderr_cb

simulator.Simulator._compile_stderr_cb
protected

Definition at line 276 of file simulator.py.

Referenced by _run_compile_command().

◆ _compile_stderr_log

simulator.Simulator._compile_stderr_log
protected
Initial value:
= _ensure_default(
compile_stderr_callback, 'compile_stderr.log')

Definition at line 276 of file simulator.py.

Referenced by _run_compile_command().

◆ _compile_stdout_cb

simulator.Simulator._compile_stdout_cb
protected

Definition at line 274 of file simulator.py.

Referenced by _run_compile_command().

◆ _compile_stdout_log

simulator.Simulator._compile_stdout_log
protected
Initial value:
= _ensure_default(
compile_stdout_callback, 'compile_stdout.log')

Definition at line 274 of file simulator.py.

Referenced by _run_compile_command().

◆ _default_files

list simulator.Simulator._default_files = []
protected

Definition at line 247 of file simulator.py.

◆ _run_stderr_cb

simulator.Simulator._run_stderr_cb
protected

Definition at line 280 of file simulator.py.

Referenced by run_proc().

◆ _run_stderr_log

simulator.Simulator._run_stderr_log
protected
Initial value:
= _ensure_default(
run_stderr_callback, 'sim_stderr.log')

Definition at line 280 of file simulator.py.

◆ _run_stdout_cb

simulator.Simulator._run_stdout_cb
protected

Definition at line 278 of file simulator.py.

Referenced by run_proc().

◆ _run_stdout_log

simulator.Simulator._run_stdout_log
protected
Initial value:
= _ensure_default(
run_stdout_callback, 'sim_stdout.log')

Definition at line 278 of file simulator.py.

◆ CompileCommand

simulator.Simulator.CompileCommand = List[str]
static

Definition at line 199 of file simulator.py.

◆ CompileFunction

simulator.Simulator.CompileFunction = Callable[[], Optional[int]]
static

Definition at line 200 of file simulator.py.

◆ CompileStep

simulator.Simulator.CompileStep = Union[CompileCommand, CompileFunction]
static

Definition at line 201 of file simulator.py.

◆ debug

simulator.Simulator.debug = debug

Definition at line 242 of file simulator.py.

Referenced by verilator.Verilator._write_cmake(), and run_proc().

◆ macro_definitions

simulator.Simulator.macro_definitions = macro_definitions

Definition at line 244 of file simulator.py.

◆ run_dir

simulator.Simulator.run_dir = run_dir

Definition at line 241 of file simulator.py.

Referenced by compile(), questa.Questa.run(), and run_proc().

◆ save_waveform

simulator.Simulator.save_waveform = save_waveform

Definition at line 243 of file simulator.py.

Referenced by run_proc().

◆ sources

simulator.Simulator.sources = sources

◆ UsesStderr

bool simulator.Simulator.UsesStderr = True
static

Definition at line 206 of file simulator.py.


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