SILICON
Loading...
Searching...
No Matches
simulationSession.cpp
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#include "simulationSession.hpp"
19
20#include <stdexcept>
21#include <utility>
22
23#include <core/elaboration.hpp>
25
26namespace SILICON::simulation {
27
28using namespace SILICON::core;
29using namespace SILICON::waveform;
30using namespace SILICON::waveform::fst;
31
32Session::Session(std::shared_ptr<Circuit> sourceCircuit,
34 const SILICON::core::CircuitResolver* resolver)
35{
36 if (!sourceCircuit)
37 throw std::invalid_argument("Session requires a valid Circuit pointer");
38
39 CircuitElaborator elaborator(ComponentRegistry::instance(), resolver);
40 runtimeSimulator = std::make_unique<Simulator>(elaborator.elaborate(*sourceCircuit), 0,
41 nullptr, std::move(isCancelled));
42}
43
44Simulator::RunResult Session::run(const uint64_t duration,
46{
47 return runtimeSimulator->run(duration, std::move(isCancelled));
48}
49
51{
52 return runtimeSimulator->runUntilIdle(std::move(isCancelled));
53}
54
56Session::simulateWaveform(const uint64_t duration, std::span<const Sample> inputSnapshots,
57 std::span<const Simulator::WaveformInputDriver> inputDrivers,
59{
60 return runtimeSimulator->simulateWaveform(duration, inputSnapshots, inputDrivers,
61 std::move(isCancelled));
62}
63
66{
67 return runtimeSimulator->setBus(std::move(bus), value, std::move(isCancelled));
68}
69
71 const Component_weakPtr& source,
73{
74 return runtimeSimulator->setBus(std::move(bus), value, source, std::move(isCancelled));
75}
76
77void Session::setTraceBuses(std::vector<CircuitWriter::NamedBus> buses)
78{
79 runtimeSimulator->setTraceBuses(std::move(buses));
80}
81
83{
84 runtimeSimulator->setTraceSink(std::move(sink));
85}
86
87void Session::setFstWriter(std::unique_ptr<CircuitWriter> writer)
88{
89 runtimeSimulator->setFstWriter(std::move(writer));
90}
91
92void Session::enableFstTracing(std::string_view fileName, CircuitWriter::Options options)
93{
94 runtimeSimulator->enableFstTracing(fileName, std::move(options));
95}
96
98{
99 return runtimeSimulator->getCurrentTime();
100}
101
102} // namespace SILICON::simulation
static ComponentRegistry & instance()
Converts source designs into simulator-ready runtime circuits.
std::shared_ptr< Circuit > elaborate(const Circuit &sourceCircuit) const
Builds a simulator-ready runtime circuit from a source design.
Session(std::shared_ptr< Circuit > sourceCircuit, Simulator::CancellationCheck isCancelled={}, const SILICON::core::CircuitResolver *resolver=nullptr)
Creates a simulation session for a source circuit.
void setTraceSink(Simulator::TraceSink sink)
Configures the callback that receives encoded trace snapshots.
Simulator::RunResult setBus(Bus bus, const BusValue &value, Simulator::CancellationCheck isCancelled={})
Forces a bus value and propagates the change through the runtime circuit.
void setFstWriter(std::unique_ptr< CircuitWriter > writer)
Installs or clears the active FST writer on the current runtime simulator.
Simulator::RunResult simulateWaveform(uint64_t duration, std::span< const Sample > inputSnapshots, std::span< const Simulator::WaveformInputDriver > inputDrivers, Simulator::CancellationCheck isCancelled={})
Drives input buses from waveform samples and simulates the runtime circuit.
Simulator::RunResult runUntilIdle(Simulator::CancellationCheck isCancelled={})
Runs pending simulation events until the runtime circuit is idle.
uint64_t getCurrentTime() const
Returns the current runtime simulator time.
Simulator::RunResult run(uint64_t duration, Simulator::CancellationCheck isCancelled={})
Runs the active simulation for a bounded duration.
void enableFstTracing(std::string_view fileName, CircuitWriter::Options options={})
Creates and installs an FST writer for the current runtime simulator.
void setTraceBuses(std::vector< CircuitWriter::NamedBus > buses)
Configures the named buses emitted by trace snapshots.
std::unique_ptr< Simulator > runtimeSimulator
std::function< bool()> CancellationCheck
Framework-independent cooperative cancellation callback.
Definition simulator.hpp:89
std::function< void(uint64_t, const std::vector< BusValue > &)> TraceSink
Receives encoded waveform values for a simulation timestamp.
Definition simulator.hpp:77
RunResult
Outcome of a cancellable simulator operation.
Definition simulator.hpp:92
TraceWriter::Options Options
FST file metadata and hierarchy options shared with TraceWriter.
std::weak_ptr< Component > Component_weakPtr
Definition wire.hpp:52
std::vector< State > BusValue
Definition wire.hpp:120