SILICON
Toggle main menu visibility
Loading...
Searching...
No Matches
fstTraceWriter.hpp
Go to the documentation of this file.
1
/*
2
Copyright (c) 2026. Giulio Cocconi
3
4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#pragma once
19
20
#include <cstddef>
21
#include <cstdint>
22
#include <optional>
23
#include <span>
24
#include <string>
25
#include <string_view>
26
#include <unordered_map>
27
#include <vector>
28
29
#include <
core/fstWrapper.hpp
>
30
#include <
utils/transparent_string.hpp
>
31
32
namespace
SILICON::waveform::fst
{
33
34
using namespace
SILICON::core;
35
44
class
TraceWriter
final {
45
public
:
49
struct
TraceSignal
{
53
std::string
name
;
54
58
std::size_t
width
= 1;
59
};
60
64
struct
Options
{
68
std::string
topScopeName
;
69
73
int
timescale
= -9;
74
78
std::string
version
= std::string(
"Generated by SILICON "
) + SILICON_VERSION;
79
};
80
81
TraceWriter
(std::string_view fileName,
const
std::vector<TraceSignal>& traceSignals);
82
94
TraceWriter
(std::string_view fileName,
const
std::vector<TraceSignal>& traceSignals,
95
Options
options);
96
97
TraceWriter
(
const
TraceWriter
&) =
delete
;
98
TraceWriter
&
operator=
(
const
TraceWriter
&) =
delete
;
99
100
TraceWriter
(
TraceWriter
&&) noexcept = default;
101
TraceWriter
& operator=(
TraceWriter
&&) noexcept = default;
102
113
void
emitSnapshot
(uint64_t time, std::span<const std::
string
> values);
114
118
void
flush
();
119
123
[[nodiscard]] std::optional<fstHandle>
handleForSignal
(std::string_view name) const;
124
128
[[nodiscard]] std::
size_t
signalCount
()
const
{
return
registeredSignals
.size(); }
129
130
private
:
131
struct
RegisteredSignal
{
132
std::string
name
;
133
std::size_t
valueIndex
;
134
std::size_t
width
;
135
fstHandle
handle
;
136
};
137
138
[[nodiscard]]
static
std::string
normalizeValue
(std::string_view value,
139
std::size_t width);
140
141
std::vector<RegisteredSignal>
registeredSignals
;
142
std::unordered_map<std::string, fstHandle,
TransparentStringHash
,
143
TransparentStringEqual
>
144
handlesBySignalName
;
145
DataWriter
writer
;
146
};
147
148
}
// namespace SILICON::waveform::fst
SILICON::waveform::fst::DataWriter
Stateful writer for waveform value emission.
Definition
fstWrapper.hpp:406
SILICON::waveform::fst::TraceWriter::signalCount
std::size_t signalCount() const
Number of non-zero-width signals registered in the FST hierarchy.
Definition
fstTraceWriter.hpp:128
SILICON::waveform::fst::TraceWriter::emitSnapshot
void emitSnapshot(uint64_t time, std::span< const std::string > values)
Emits one timestamped snapshot of already-sampled signal values.
Definition
fstTraceWriter.cpp:79
SILICON::waveform::fst::TraceWriter::TraceWriter
TraceWriter(std::string_view fileName, const std::vector< TraceSignal > &traceSignals)
Definition
fstTraceWriter.cpp:43
SILICON::waveform::fst::TraceWriter::handleForSignal
std::optional< fstHandle > handleForSignal(std::string_view name) const
Returns the libfst handle associated with a registered signal name.
Definition
fstTraceWriter.cpp:97
SILICON::waveform::fst::TraceWriter::TraceWriter
TraceWriter(TraceWriter &&) noexcept=default
SILICON::waveform::fst::TraceWriter::registeredSignals
std::vector< RegisteredSignal > registeredSignals
Definition
fstTraceWriter.hpp:141
SILICON::waveform::fst::TraceWriter::handlesBySignalName
std::unordered_map< std::string, fstHandle, TransparentStringHash, TransparentStringEqual > handlesBySignalName
Definition
fstTraceWriter.hpp:144
SILICON::waveform::fst::TraceWriter::writer
DataWriter writer
Definition
fstTraceWriter.hpp:145
SILICON::waveform::fst::TraceWriter::operator=
TraceWriter & operator=(const TraceWriter &)=delete
SILICON::waveform::fst::TraceWriter::TraceWriter
TraceWriter(const TraceWriter &)=delete
SILICON::waveform::fst::TraceWriter::flush
void flush()
Flushes pending FST data so external tools can read recent snapshots.
Definition
fstTraceWriter.cpp:92
SILICON::waveform::fst::TraceWriter::normalizeValue
static std::string normalizeValue(std::string_view value, std::size_t width)
Definition
fstTraceWriter.cpp:106
fstWrapper.hpp
SILICON::waveform::fst
Definition
fstTraceWriter.cpp:27
SILICON::core::TransparentStringEqual
Transparent equality functor for string-like keys.
Definition
transparent_string.hpp:66
SILICON::core::TransparentStringHash
Transparent hash functor for string-like keys.
Definition
transparent_string.hpp:40
SILICON::waveform::fst::TraceWriter::Options
FST file metadata and hierarchy options.
Definition
fstTraceWriter.hpp:64
SILICON::waveform::fst::TraceWriter::Options::topScopeName
std::string topScopeName
Definition
fstTraceWriter.hpp:68
SILICON::waveform::fst::TraceWriter::Options::version
std::string version
Definition
fstTraceWriter.hpp:78
SILICON::waveform::fst::TraceWriter::Options::timescale
int timescale
Definition
fstTraceWriter.hpp:73
SILICON::waveform::fst::TraceWriter::RegisteredSignal
Definition
fstTraceWriter.hpp:131
SILICON::waveform::fst::TraceWriter::RegisteredSignal::valueIndex
std::size_t valueIndex
Definition
fstTraceWriter.hpp:133
SILICON::waveform::fst::TraceWriter::RegisteredSignal::handle
fstHandle handle
Definition
fstTraceWriter.hpp:135
SILICON::waveform::fst::TraceWriter::RegisteredSignal::width
std::size_t width
Definition
fstTraceWriter.hpp:134
SILICON::waveform::fst::TraceWriter::RegisteredSignal::name
std::string name
Definition
fstTraceWriter.hpp:132
SILICON::waveform::fst::TraceWriter::TraceSignal
Static description of a signal to register in the FST hierarchy.
Definition
fstTraceWriter.hpp:49
SILICON::waveform::fst::TraceWriter::TraceSignal::width
std::size_t width
Definition
fstTraceWriter.hpp:58
SILICON::waveform::fst::TraceWriter::TraceSignal::name
std::string name
Definition
fstTraceWriter.hpp:53
transparent_string.hpp
src
core
fstTraceWriter.hpp
Generated by
1.17.0