5 #include "pybind11/operators.h"
6 #include "pybind11/pybind11.h"
7 #include "pybind11/stl.h"
8 #include "pybind11/stl_bind.h"
10 namespace py = pybind11;
14 #ifdef PYBIND11_MODULE
15 PYBIND11_MODULE(netlist_simulator, m)
17 m.doc() =
"hal NetlistSimulatorPlugin python bindings";
21 py::module m(
"hal_simulator",
"hal NetlistSimulatorPlugin python bindings");
24 py::class_<NetlistSimulatorPlugin, RawPtrWrapper<NetlistSimulatorPlugin>,
BasePluginInterface>(m,
"NetlistSimulatorPlugin")
26 The name of the plugin.
32 Get the name of the plugin.
34 :returns: The name of the plugin.
39 The version of the plugin.
45 Get the version of the plugin.
47 :returns: The version of the plugin.
51 py::class_<NetlistSimulator>(m, "NetlistSimulator")
98 Set the signal for a specific wire to control input signals between simulation cycles.
100 :param hal_py.Net net: The net to set a signal value for.
101 :param hal_py.BooleanFunction.Value value: The value to set.
105 Configure the sequential gates matching the (optional) user-defined filter condition with initialization data specified within the netlist.
106 Schedules the respective gates for initialization, the actual configuration is applied during initialization of the simulator.
107 This function can only be called before the simulation has started.
109 :param lambda filter: The optional filter to be applied before initialization.
112 .def("initialize_sequential_gates",
115 py::arg(
"filter") =
nullptr,
117 Configure the sequential gates matching the (optional) user-defined filter condition with the specified value.
118 Schedules the respective gates for initialization, the actual configuration is applied during initialization of the simulator.
119 This function can only be called before the simulation has started.
121 :param hal_py.BooleanFunction.Value value: The value to initialize the selected gates with.
122 :param lambda filter: The optional filter to be applied before initialization.
126 Load the specified initial value into the current state of all sequential elements.
128 :param hal_py.BooleanFunction.Value value: The initial value to load.
132 Load the initial value specified within the netlist file into the current state of all sequential elements.
133 This is especially relevant for FPGA netlists, since these may provide initial values to load on startup.
137 Initialize the simulation.
138 No additional gates or clocks can be added after this point.
142 Simulate for a specific period, advancing the internal state.
143 Automatically initializes the simulation if 'initialize' has not yet been called.
144 Use \p set_input to control specific signals.
146 :param int picoseconds: The duration to simulate.
150 Reset the simulator state, i.e., treat all signals as unknown.
151 Does not remove gates/nets from the simulation set.
155 Set the simulator state, i.e., net signals, to a given state.
156 Does not influence gates/nets added to the simulation set.
158 :param netlist_simulator.Simulation state: The state to apply.
162 Get the current simulation state.
164 :returns: The current simulation state.
165 :rtype: libnetlist_simulator.Simulation
169 Set the iteration timeout, i.e., the maximum number of events processed for a single point in time.
170 Useful to abort in case of infinite loops.
171 A value of 0 disables the timeout.
173 :param int iterations: The iteration timeout.
177 Get the current iteration timeout value.
179 :returns: The iteration timeout.
183 .def("generate_vcd", &
NetlistSimulator::generate_vcd, py::arg(
"path"), py::arg(
"start_time"), py::arg(
"end_time"), py::arg(
"nets") = std::set<u32>(), R
"(
184 Generates the a VCD file for parts the simulated netlist.
186 :param pathlib.Path path: The path to the VCD file.
187 :param int start_time: Start of the timeframe to write to the file (in picoseconds).
188 :param int end_time: End of the timeframe to write to the file (in picoseconds).
189 :param set[hal_py.Net] nets: Nets to include in the VCD file.
190 :returns: ``True`` if the file gerneration was successful, ``False`` otherwise.
194 py::class_<Simulation>(m, "Simulation")
198 Get the signal value of a specific net at a specific point in time specified in picoseconds.
200 :param hal_py.Net net: The net to inspect.
201 :param int time: The time in picoseconds.
202 :returns: The net's signal value.
203 :rtype: hal_py.BooleanFunction.Value
207 Adds a custom event to the simulation.
209 :param netlist_simulator.Event event: The event to add.
213 Get all events of the simulation.
215 :returns: A map from net to associated events for that net sorted by time.
218 #ifndef PYBIND11_MODULE
Value
represents the type of the node
u64 get_simulation_timeout() const
void load_initial_values_from_netlist()
void set_iteration_timeout(u64 iterations)
void simulate(u64 picoseconds)
void initialize_sequential_gates(const std::function< bool(const Gate *)> &filter=nullptr)
void set_simulation_state(const Simulation &state)
void load_initial_values(BooleanFunction::Value value)
const Simulation & get_simulation_state() const
bool generate_vcd(const std::filesystem::path &path, u32 start_time, u32 end_time, std::set< const Net * > nets={}) const
void set_input(const Net *net, BooleanFunction::Value value)
std::string get_name() const override
std::string get_version() const override
BooleanFunction::Value get_net_value(const Net *net, u64 time) const
std::unordered_map< const Net *, std::vector< WaveEvent > > get_events() const
void add_event(const WaveEvent &event)
const Module * module(const Gate *g, const NodeBoxes &boxes)