44 this->inputs = std::move(
inputs);
45 this->outputs = std::move(
outputs);
65 const bool selectedClockEdge = clockEdge ==
edgeType;
69 if (timingInputChanged)
83 if (selectedClockEdge) {
127 this->
setupTime =
static_cast<uint64_t
>(std::get<int>(validated));
132 this->
holdTime =
static_cast<uint64_t
>(std::get<int>(validated));
136 this->
edgeType = std::get<std::string>(value) ==
"PET"
159 for (
unsigned int inputIndex = 0; inputIndex <
inputs.size(); ++inputIndex) {
163 for (
const auto& wire :
inputs[inputIndex]) {
173 const bool timingInputChanged)
const
178 if (timingInputChanged)
186 const bool timingInputChanged)
const
193 const State currentClock)
const
206 {{std::move(d)}, {std::move(clock)}, {std::move(clear)}, {std::move(preset)}},
207 {{std::move(q)}, {std::move(notQ)}}, busIndex(Inputs::Clock),
208 busIndex(Inputs::Clear), busIndex(Inputs::Preset))
228 {std::move(preset)}},
229 {{std::move(q)}, {std::move(notQ)}}, busIndex(Inputs::Clock),
230 busIndex(Inputs::Clear), busIndex(Inputs::Preset))
255 :
Component({{std::move(d)}, {std::move(enable)}}, {{std::move(q)}, {std::move(notQ)}})
257 initializeProperties();
309 {std::move(preset)}},
310 {{std::move(q)}, {std::move(notQ)}}, busIndex(Inputs::Clock),
311 busIndex(Inputs::Clear), busIndex(Inputs::Preset))
static constexpr unsigned int busIndex(Enum value)
Converts a component-local bus enum to its storage index.
Wire_ptr outputWire(unsigned int output, unsigned short bit=0) const
State inputState(unsigned int input, unsigned short bit=0) const
std::vector< Bus > outputs
Output buses produced by this component.
void defineUnconnectedInputDefault(unsigned int input, State value)
Defines the state read from an input when its wire is unconnected.
std::vector< Bus > inputs
Input buses connected to this component.
void defineStringListProperty(std::string key, std::string defaultValue, StringPropertyOptions allowedValues, PropertyCallback callback=nullptr)
Defines a string property constrained to a fixed set of values.
void setPropertyCallback(std::string_view key, PropertyCallback callback)
Sets a callback for property validation/transformation.
Wire_ptr inputWire(unsigned int input, unsigned short bit=0) const
void defineProperty(std::string key, T &&defaultValue, PropertyCallback callback=nullptr)
Defines a property with a default value and optional callback.
std::size_t outputBusSize(unsigned int output) const
@ D
Data input captured on the selected clock edge.
bool isTimingSensitiveInput(unsigned int inputIndex) const override
Returns true for synchronous pins governed by setup/hold timing.
DFlipFlop()
Constructs an unconnected D flip-flop.
State captureState() const override
Computes the state captured on the selected clock edge.
@ Enable
Active-high transparency enable.
@ D
Data input followed while the latch is transparent.
uint64_t propagationDelay
void driveOutput(SILICON::simulation::Simulator &sim, State newState)
DLatch()
Constructs an unconnected D latch.
void simulate(SILICON::simulation::Simulator &sim, const SILICON::simulation::Context &context) override
Executes the component's logic with simulator scheduling context.
void initializeProperties()
@ Enable
Capture enable input.
@ D
Data input captured when Enable is HIGH.
EFlipFlop()
Constructs an unconnected enabled D flip-flop.
bool isTimingSensitiveInput(unsigned int inputIndex) const override
Returns true for synchronous pins governed by setup/hold timing.
State captureState() const override
Computes the state captured on the selected clock edge.
FlipFlop(unsigned int clockIndex, unsigned int clearIndex, unsigned int presetIndex)
Constructs a flip-flop base with the input indices used for control pins.
bool violatesSetupTime(uint64_t currentTime, bool timingInputChanged) const
bool mayHaveSelectedEdge(State previousClock, State currentClock) const
Checks if an ambiguous clock transition occurred that might be the triggering edge.
uint64_t propagationDelay
std::optional< uint64_t > lastSelectedClockEdgeTime
bool hasTimingSensitiveInputChange(const SILICON::simulation::Context &context) const
void driveOutput(SILICON::simulation::Simulator &sim, State newState)
bool violatesHoldTime(uint64_t currentTime, bool timingInputChanged) const
void simulate(SILICON::simulation::Simulator &sim, const SILICON::simulation::Context &context) override
Evaluates async controls and selected clock edges.
virtual State captureState() const =0
Computes the state captured on the selected clock edge.
void initializeProperties()
State latchedState() const
Returns the currently stored state.
std::optional< uint64_t > lastTimingInputChangeTime
virtual bool isTimingSensitiveInput(unsigned int inputIndex) const =0
Returns true for synchronous pins governed by setup/hold timing.
SILICON::simulation::Simulator::EdgeType edgeType
void clearState()
Clear FF internal state (state, last transitions time, ...).
bool isTimingSensitiveInput(unsigned int inputIndex) const override
Returns true for synchronous pins governed by setup/hold timing.
JKFlipFlop()
Constructs an unconnected JK flip-flop.
State captureState() const override
Computes the state captured on the selected clock edge.
Executes event-driven simulation of a Circuit.
static EdgeType edgeType(const Context &context, const Wire_ptr &wire)
Classifies one wire's transition in a simulation context.
uint64_t getCurrentTime() const
Gets the current simulation time.
void updateWire(const Wire_ptr &target, State newState, uint64_t delay, const Component_weakPtr &source)
Updates a wire with a new state and optional delay.
std::shared_ptr< Wire > Wire_ptr
std::variant< int, bool, std::string, BusValue > PropertyValue
Variant type for component properties.
PropertyValue requireNonNegative(const std::string_view name, const PropertyValue &value)
Validates that an integer property value is non-negative.
State normalizeBinaryOrUnknown(const State state)
Normalizes non-binary states for stored binary elements.
bool mayBe(const State actual, const State expected)
Tests whether an actual state could represent an expected binary state.
bool isKnownBinary(const State state)
Tests whether a state is a concrete binary logic value.
Context describing why a component is being evaluated.
bool changed(const core::Wire_ptr &wire) const
Returns true when a wire has a captured previous state different from now.
bool initialEvaluation
True for initial or otherwise full-plan evaluation.
std::optional< core::State > previousState(const core::Wire_ptr &wire) const
Returns the state a wire had before this reactive evaluation, if captured.