SILICON
Loading...
Searching...
No Matches
simulationSession.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 <memory>
21#include <span>
22#include <vector>
23
24#include <core/simulator.hpp>
25
26namespace SILICON::simulation {
27
28using namespace SILICON::core;
29using namespace SILICON::waveform;
30using namespace SILICON::waveform::fst;
31
40class Session {
41public:
51 explicit Session(std::shared_ptr<Circuit> sourceCircuit,
52 Simulator::CancellationCheck isCancelled = {},
53 const SILICON::core::CircuitResolver* resolver = nullptr);
54
55 ~Session() = default;
56
57 Session(const Session&) = delete;
58 Session& operator=(const Session&) = delete;
59
63 Simulator::RunResult run(uint64_t duration,
64 Simulator::CancellationCheck isCancelled = {});
65
70
75 simulateWaveform(uint64_t duration, std::span<const Sample> inputSnapshots,
76 std::span<const Simulator::WaveformInputDriver> inputDrivers,
77 Simulator::CancellationCheck isCancelled = {});
78
82 Simulator::RunResult setBus(Bus bus, const BusValue& value,
83 Simulator::CancellationCheck isCancelled = {});
84
88 Simulator::RunResult setBus(Bus bus, const BusValue& value,
89 const Component_weakPtr& source,
90 Simulator::CancellationCheck isCancelled = {});
91
95 void setTraceBuses(std::vector<CircuitWriter::NamedBus> buses);
96
101
105 void setFstWriter(std::unique_ptr<CircuitWriter> writer);
106
110 void enableFstTracing(std::string_view fileName, CircuitWriter::Options options = {});
111
115 [[nodiscard]] uint64_t getCurrentTime() const;
116
117private:
118 std::unique_ptr<Simulator> runtimeSimulator;
119};
120
121} // namespace SILICON::simulation
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.
Session & operator=(const Session &)=delete
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
Session(const Session &)=delete
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