SILICON
Loading...
Searching...
No Matches
siliconFst.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 <cstdint>
21#include <optional>
22#include <string>
23#include <string_view>
24#include <utility>
25#include <vector>
26
27#include <core/circuit.hpp>
29
30namespace SILICON::waveform::fst {
31
32using namespace SILICON::core;
33
42class CircuitWriter final {
43public:
47 using NamedBus = std::pair<std::string, Bus>;
48
53
54 CircuitWriter(std::string_view fileName, const Circuit& circuit);
55 CircuitWriter(std::string_view fileName, const Circuit& circuit, Options options);
56 CircuitWriter(std::string_view fileName, const std::vector<NamedBus>& buses);
57 CircuitWriter(std::string_view fileName, const std::vector<NamedBus>& buses,
58 Options options);
59
60 CircuitWriter(const CircuitWriter&) = delete;
62
63 CircuitWriter(CircuitWriter&&) noexcept = default;
64 CircuitWriter& operator=(CircuitWriter&&) noexcept = default;
65
69 void emitSnapshot(uint64_t time);
70
74 void flush();
75
79 [[nodiscard]] std::optional<fstHandle> handleForBus(std::string_view name) const;
80
84 [[nodiscard]] std::size_t busCount() const { return buses.size(); }
85
89 [[nodiscard]] static char stateToFstValue(State state);
90
91private:
92 std::vector<NamedBus> buses;
94};
95
96} // namespace SILICON::waveform::fst
Represents a digital circuit as a directed graph of components.
Definition circuit.hpp:125
std::optional< fstHandle > handleForBus(std::string_view name) const
Returns the FST handle associated with a registered bus name, if present.
CircuitWriter(const CircuitWriter &)=delete
std::size_t busCount() const
Number of circuit buses registered in the FST hierarchy.
static char stateToFstValue(State state)
Maps SILICON states to VCD/FST scalar symbols.
TraceWriter::Options Options
FST file metadata and hierarchy options shared with TraceWriter.
std::pair< std::string, Bus > NamedBus
Bus registered under a stable trace signal name.
void emitSnapshot(uint64_t time)
Emits all registered bus states at the given simulation timestamp.
CircuitWriter(std::string_view fileName, const Circuit &circuit)
CircuitWriter & operator=(const CircuitWriter &)=delete
void flush()
Flushes pending FST data so external tools can read recent snapshots.
CircuitWriter(CircuitWriter &&) noexcept=default
Writes named vector signals from already-sampled FST value strings.
FST file metadata and hierarchy options.