Trace
class Trace
@defgroup trace Trace System @brief Waveform file loading and signal access
The Trace System provides unified access to hardware waveforms in multiple formats: - VCD (Verilog Change Dump) - standard format - FST (Fast Signal Trace) - compressed format - CSV (Comma-Separated Values) - custom format
Architecture:
@mermaid
graph TD
A["TraceContainer"] --> B["Trace
Base Class"]
B --> B1["VCDTrace"]
B --> B2["FSTTrace"]
B --> B3["CSVTrace"]
A -->|routes to| B1
A -->|routes to| B2
A -->|routes to| B3
B1 --> S1["VCD Parser"]
B2 --> S2["FST Parser"]
B3 --> S3["CSV Parser"]
@endmermaid
Signal Access Pattern:
Once a trace is loaded, signals are accessed as WAL variables:
Special Signals:
- SIGNALS - list of all signal names
- INDEX - current time index
- MAX-INDEX - maximum time index in trace
- TIMESTAMP (or TS) - current simulation time
- TRACE-NAME - name of loaded trace
- SCOPES - hierarchical scope names
- See
- "Wal::load" for loading traces
- See
- for signal query operators
@{ Abstract base class for waveform traces
Provides unified interface for different waveform file formats. Subclasses (VCDTrace, FSTTrace, CSVTrace) implement format-specific parsing.
Key Concepts: - Time Index: Index into the trace timeline (0 to max_index) - Time Offset: Relative offset from current index (for lookahead/lookbehind) - Signal Value: Value of a signal at current time+offset - Virtual Signals: Derived signals computed by operators
Scope Hierarchy:
Traces support hierarchical signal naming (e.g., top.module.signal)
using the SCOPE_SEPARATOR ('.') character.
Variables
| Name | Description |
|---|---|
| SIGNALS | All available signals in this trace |
| SIGNALS_NO_ALIAS | All signals excluding aliases |
| VIRTUAL_SIGNALS | Virtual/derived signals created by operators |
| LOCAL_SIGNALS | Signals defined in current scope only |
| INDEX | Current time index (integer) |
| MAX_INDEX | Maximum valid time index |
| TIMESTAMP | Simulation timestamp at current index |
| TRACE_NAME | Name of the trace file |
| TRACE_FILE | Path to trace file |
| SCOPES | All hierarchical scope names |
| LOCAL_SCOPES | Scopes in current hierarchy level |
| SCOPE_SEPARATOR | @brief Character that separates hierarchy levels in a signal name. |
| query_scope | see set_query_scope() |
| sampling_points | see set_sampling_points() |
Functions
| Name | Description |
|---|---|
| signal_value | @name Signal Access @{ Get signal value at given time Retrieves the value of a signal at (current_index + offset). |
| signal_width | Get signal width in bits name : Signal name Return : Width in bits (1+ for vectors, 1 for scalars) @throws TraceError if signal not found |
| contains_signal | Check if signal exists in this trace name : Signal name Return : true if signal is present |
| get_all_signals | Get all signal names Return : Vector of available signal names |
| get_scopes | Get all scope names Return : Vector of hierarchical scope names |
| set_query_scope | @brief Scope that LOCAL-SCOPES and LOCAL-SIGNALS are resolved against. |
| set_index | @} @name Time Navigation @{ Set current time index All subsequent signal_value() calls use this index. |
| step | Step forward or backward in time Moves current_index by steps amount. |
| get_tid | @} @name Accessors @{ Get trace ID assigned at load time |
| get_filename | Get source file path |
| get_index | Get current time index |
| get_max_index | Get maximum time index |
| set_max_index | @brief Shorten the trace, for trim-trace. |
| set_sampling_points | @brief Restrict the trace to the listed indices, for sample-at. |
| dump_vcd | @brief Write this trace out as VCD, for dump-trace. |
| get_timestamp | Get actual simulation timestamp at current index (default: returns index) |
| get_signal_names | Get all signal names |
| get_virtual_signals | @} @name Virtual Signals @{ Access virtual/derived signals |
| set_virtual_signal | Create a virtual signal |
| get_special_signal | @} @name Special Signals @{ Get special signal values Handles meta-signals like INDEX, MAX-INDEX, SIGNALS, etc. |
| Trace | @} Constructor for subclasses tid : Trace ID for identification filename : Source file path container : Parent TraceContainer |
| is_valid_index | Check if time index is valid idx : Index to check Return : true if 0 <= idx <= max_index |
Variable Details
INDEX
static constexpr const char* INDEX
Current time index (integer)
LOCAL_SCOPES
static constexpr const char* LOCAL_SCOPES
Scopes in current hierarchy level
LOCAL_SIGNALS
static constexpr const char* LOCAL_SIGNALS
Signals defined in current scope only
MAX_INDEX
static constexpr const char* MAX_INDEX
Maximum valid time index
SCOPES
static constexpr const char* SCOPES
All hierarchical scope names
SCOPE_SEPARATOR
static constexpr char SCOPE_SEPARATOR
@brief Character that separates hierarchy levels in a signal name.
., as upstream WAL (ics-jku/wal) and as WAL++'s own --fast-* paths have
always spelled it: tb.dut.counter.
It used to be ^, which disagreed with BOTH of those at once. That left the
interpreter and the fast paths of the same binary naming the same signal two
different ways, and it took ^ away from the meaning upstream gives it, which
is to prefix a TRACE ID: a^tb.dut.clk selects the signal from the trace
loaded under id a.
A name written the old way still resolves, so existing scripts keep working: see resolve_signal_name() in signal_resolve.h.
SIGNALS
static constexpr const char* SIGNALS
All available signals in this trace
SIGNALS_NO_ALIAS
static constexpr const char* SIGNALS_NO_ALIAS
All signals excluding aliases
TIMESTAMP
static constexpr const char* TIMESTAMP
Simulation timestamp at current index
TRACE_FILE
static constexpr const char* TRACE_FILE
Path to trace file
TRACE_NAME
static constexpr const char* TRACE_NAME
Name of the trace file
VIRTUAL_SIGNALS
static constexpr const char* VIRTUAL_SIGNALS
Virtual/derived signals created by operators
query_scope
std::string query_scope
see set_query_scope()
sampling_points
std::vector<int> sampling_points
see set_sampling_points()
Function Details
Trace
Trace(const std::string& tid, const std::string& filename, std::shared_ptr<TraceContainer> container)
@} Constructor for subclasses
-
tid - Trace ID for identification
-
filename - Source file path
-
container - Parent TraceContainer
contains_signal
virtual bool contains_signal(const std::string& name) const = 0
Check if signal exists in this trace
-
name - Signal name
- Return
- true if signal is present
dump_vcd
std::string dump_vcd(const std::string& path = "")
@brief Write this trace out as VCD, for dump-trace.
With no path, the text goes to stdout and the returned string is empty; otherwise it is the path written. Virtual signals are not included: their values are expressions evaluated against a trace, not stored samples.
get_all_signals
virtual std::vector<std::string> get_all_signals() const = 0
Get all signal names
- Return
- Vector of available signal names
get_filename
const std::string& get_filename() const
Get source file path
get_index
int get_index() const
Get current time index
get_max_index
int get_max_index() const
Get maximum time index
get_scopes
virtual std::vector<std::string> get_scopes() const
Get all scope names
- Return
- Vector of hierarchical scope names
get_signal_names
const std::vector<std::string>& get_signal_names() const
Get all signal names
get_special_signal
virtual Value get_special_signal(const std::string& name)
@} @name Special Signals @{ Get special signal values
Handles meta-signals like INDEX, MAX-INDEX, SIGNALS, etc. Override in subclasses to provide format-specific info.
-
name - Special signal name (e.g., "SIGNALS")
- Return
- Special signal value or nil if not found
- See
- SIGNALS, INDEX, MAX-INDEX, etc.
get_tid
const std::string& get_tid() const
@} @name Accessors @{ Get trace ID assigned at load time
get_timestamp
virtual int64_t get_timestamp() const
Get actual simulation timestamp at current index (default: returns index)
get_virtual_signals
const std::unordered_map<std::string, Value>& get_virtual_signals() const
@} @name Virtual Signals @{ Access virtual/derived signals
is_valid_index
bool is_valid_index(int idx) const
Check if time index is valid
-
idx - Index to check
- Return
- true if 0 <= idx <= max_index
set_index
virtual void set_index(int idx)
@} @name Time Navigation @{ Set current time index
All subsequent signal_value() calls use this index.
-
idx - New time index (0 to max_index) @throws TraceError if index out of range
set_max_index
void set_max_index(int idx)
@brief Shorten the trace, for trim-trace.
Only ever downwards: a trace cannot grow data it never read.
set_query_scope
void set_query_scope(const std::string& scope)
@brief Scope that LOCAL-SCOPES and LOCAL-SIGNALS are resolved against.
Upstream keeps this in the global variable CS and passes it down on every special-signal read. The evaluator sets it before reading those two names.
set_sampling_points
void set_sampling_points(const std::vector<int>& points)
@brief Restrict the trace to the listed indices, for sample-at.
Sampling points are a view, not a rewrite: the data stays, and the points say which indices an analysis should visit. An empty list clears the restriction.
set_virtual_signal
void set_virtual_signal(const std::string& name, const Value& value)
Create a virtual signal
signal_value
virtual Value signal_value(const std::string& name, int offset = 0, const std::string& scope = "") = 0
@name Signal Access @{ Get signal value at given time
Retrieves the value of a signal at (current_index + offset).
Offset semantics: - offset=0: Current time - offset>0: Future value (lookahead) - offset<0: Past value (lookbehind)
Scope handling: - Empty scope: Search in all scopes, prefer matching base name - Specific scope: Only search in that scope
-
name - Signal name (possibly with '~' scope prefix)
-
offset - Time offset from current index (default: 0)
-
scope - Optional scope prefix for hierarchical signals
- Return
- The signal value at specified time @throws TraceError if signal not found or index out of bounds
signal_width
virtual int signal_width(const std::string& name) = 0
Get signal width in bits
-
name - Signal name
- Return
- Width in bits (1+ for vectors, 1 for scalars) @throws TraceError if signal not found
step
virtual bool step(int steps = 1)
Step forward or backward in time
Moves current_index by steps amount. Clamped to valid range [0, max_index].
-
steps - Number of steps (positive=forward, negative=backward)
- Return
- True if successful, false if clamped to boundary