|
SILICON
|
Base class for all digital circuit components. More...
#include <component.hpp>
Public Types | |
| using | IOObserver = std::function<void(Component*)> |
| Callback type for I/O change notifications. | |
Public Member Functions | |
| Component ()=default | |
| Component (std::vector< Bus > inputs, std::vector< Bus > outputs) | |
| Constructs a component with input and output buses. | |
| virtual | ~Component ()=default |
| virtual void | simulate (SILICON::simulation::Simulator &sim) |
| Executes the component's logic. | |
| virtual void | simulate (SILICON::simulation::Simulator &sim, const SILICON::simulation::Context &context) |
| Executes the component's logic with simulator scheduling context. | |
| virtual bool | usesStagedSequentialOutputs () const |
| Whether zero-delay output writes should be staged during reactive passes. | |
| void | replaceBus (std::vector< Bus > &busCollection, unsigned int index, Bus newBus) |
| Replaces a bus in the input or output collection. | |
| void | setProperty (std::string_view key, const PropertyValue &value) |
| Sets a property value. | |
| std::optional< PropertyValue > | getProperty (std::string_view key) const |
| Gets a property value. | |
| const PropertyMap & | getProperties () const |
| Gets all properties. | |
| std::optional< std::reference_wrapper< const StringPropertyOptions > > | getStringPropertyOptions (std::string_view key) const |
| Gets allowed values for a constrained string property. | |
| template<typename T> | |
| void | setPropertyValue (std::string_view key, T &&value) |
| Sets a property value with type deduction. | |
| template<typename T> | |
| std::optional< T > | getPropertyValue (std::string_view key) const |
| Gets a property value with type deduction. | |
| void | setPropertyCallback (std::string_view key, PropertyCallback callback) |
| Sets a callback for property validation/transformation. | |
| void | setInput (unsigned int index, const Bus &bus, bool checkSize=false) |
| Sets an input bus at a specific index. | |
| void | setInputs (const std::vector< Bus > &newInputs) |
| Replaces all input buses. | |
| void | setOutput (unsigned int index, const Bus &bus) |
| Sets an output bus at a specific index. | |
| void | setOutputs (const std::vector< Bus > &newOutputs) |
| Replaces all output buses. | |
| bool | isConnectedTo (const Bus &b) const |
| Checks if this component is connected to a bus. | |
| virtual void | clearWires () |
| Clears all wire connections. | |
| std::vector< Bus > | getInputs () const |
| Gets all input buses. | |
| const std::vector< Bus > & | inputBuses () const |
| Gets all input buses without copying. | |
| std::optional< State > | unconnectedInputDefault (unsigned int input) const |
| Gets the state used when an input has no connected wire. | |
| std::vector< Bus > | getOutputs () const |
| Gets all output buses. | |
| const std::vector< Bus > & | outputBuses () const |
| Gets all output buses without copying. | |
| auto | allBuses () const |
| Borrows all buses, inputs first, without copying or deduplicating. | |
| virtual std::string_view | typeName () const =0 |
| Gets the component type name. | |
| virtual ComponentMetadata | metadata () const |
| Gets catalog metadata for this component type. | |
| virtual void | serializeYosys (SILICON::yosys::SerializationContext &context) const |
| Lower this component into native Yosys netlist cells. | |
| uint64_t | addIOListener (IOObserver cb) |
| Adds a listener for I/O changes. | |
| void | removeIOListener (uint64_t id) |
| Removes a previously added I/O listener. | |
Protected Member Functions | |
| template<typename T> | |
| void | defineProperty (std::string key, T &&defaultValue, PropertyCallback callback=nullptr) |
| Defines a property with a default value and optional callback. | |
| 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 | notifyIOListeners () |
| Notifies all registered I/O listeners of a change. | |
| void | validatePropertyValue (std::string_view key, const PropertyValue ¤tValue, const PropertyValue &newValue) const |
| Validates a property value against the declared type and metadata. | |
| void | handleInputSizeChange (const unsigned int index, const unsigned int newSize) |
| Handles input size changes. By default input size shouldn't change automatically. | |
| void | defineUnconnectedInputDefault (unsigned int input, State value) |
| Defines the state read from an input when its wire is unconnected. | |
| State | inputState (unsigned int input, unsigned short bit=0) const |
| Wire_ptr | inputWire (unsigned int input, unsigned short bit=0) const |
| template<typename Enum> requires std::is_enum_v<Enum> | |
| Wire_ptr | inputWire (Enum input, unsigned short bit=0) const |
| template<typename Enum> requires std::is_enum_v<Enum> | |
| State | inputState (Enum input, unsigned short bit=0) const |
| Reads an input bit, returning ERROR when the bus or bit is missing. | |
| Wire_ptr | outputWire (unsigned int output, unsigned short bit=0) const |
| template<typename Enum> requires std::is_enum_v<Enum> | |
| Wire_ptr | outputWire (Enum output, unsigned short bit=0) const |
| Returns an output wire, or null when the bus or bit is missing. | |
| std::size_t | outputBusSize (unsigned int output) const |
| template<typename Enum> requires std::is_enum_v<Enum> | |
| std::size_t | outputBusSize (Enum output) const |
| Returns the size of an output bus, or zero when it is missing. | |
Static Protected Member Functions | |
| template<typename Enum> requires std::is_enum_v<Enum> | |
| static constexpr unsigned int | busIndex (Enum value) |
| Converts a component-local bus enum to its storage index. | |
Protected Attributes | |
| std::vector< Bus > | inputs |
| Input buses connected to this component. | |
| std::vector< Bus > | outputs |
| Output buses produced by this component. | |
| std::unordered_map< unsigned int, State > | unconnectedInputDefaults |
| Per-input state used when a bus bit has no connected wire. | |
| PropertyMap | properties |
| Map of configurable properties for this component. | |
| PropertyCallbackMap | propertyCallbacks |
| Map of callbacks for property validation/transformation. | |
| StringPropertyOptionsMap | stringPropertyOptions |
| Allowed values for constrained string properties. | |
| uint64_t | nextIoListenerId = 0 |
| Counter for generating unique I/O listener IDs. | |
| std::unordered_map< uint64_t, IOObserver > | ioListeners |
| Map of I/O change listeners indexed by ID. | |
Base class for all digital circuit components.
The Component class represents a fundamental building block in a digital circuit. It manages input and output buses for data connectivity, maintains configurable properties, and implements an observer pattern for I/O changes.
Components operate in a reactive simulation environment where their simulate() method is called to process inputs and produce outputs.
Definition at line 199 of file component.hpp.
| using IOObserver = std::function<void(Component*)> |
Callback type for I/O change notifications.
IOObservers are invoked when the component's input or output buses change, allowing dependent components or circuits to update accordingly.
| component | Pointer to the component whose I/O changed |
Definition at line 209 of file component.hpp.
|
default |
Constructs a component with input and output buses.
| inputs | Vector of input buses |
| outputs | Vector of output buses |
Definition at line 49 of file component.cpp.
|
virtualdefault |
| uint64_t addIOListener | ( | IOObserver | cb | ) |
Adds a listener for I/O changes.
| cb | The callback function |
Definition at line 60 of file component.cpp.
|
inlinenodiscard |
Borrows all buses, inputs first, without copying or deduplicating.
Definition at line 609 of file component.hpp.
|
inlinestaticconstexprprotected |
Converts a component-local bus enum to its storage index.
| Enum | Component input/output enum type |
| value | Enum value to convert |
Definition at line 308 of file component.hpp.
|
virtual |
Clears all wire connections.
Removes references to all wires in input and output buses, disconnecting this component from the circuit.
Derived components may override this when some pins have component-specific unconnected semantics.
Definition at line 243 of file component.cpp.
|
inlineprotected |
Defines a property with a default value and optional callback.
Used by derived components to declare their configurable properties during construction.
| T | The property value type |
| key | The property name |
| defaultValue | The default property value |
| callback | Optional callback for value validation/transformation |
Definition at line 248 of file component.hpp.
|
protected |
Defines a string property constrained to a fixed set of values.
| key | The property name |
| defaultValue | The default string value |
| allowedValues | Non-empty list of accepted values |
| callback | Optional callback for validation/transformation |
Definition at line 79 of file component.cpp.
|
inlineprotected |
Defines the state read from an input when its wire is unconnected.
| input | Input bus index |
| value | State used for every unconnected bit on that input bus |
Definition at line 318 of file component.hpp.
|
inlinenodiscard |
|
inlinenodiscard |
|
inlinenodiscard |
Gets all properties.
Definition at line 478 of file component.hpp.
|
nodiscard |
Gets a property value.
| key | The property name |
Definition at line 165 of file component.cpp.
|
inline |
Gets a property value with type deduction.
| T | The expected property type |
| key | The property name |
Definition at line 504 of file component.hpp.
|
nodiscard |
Gets allowed values for a constrained string property.
Definition at line 174 of file component.cpp.
|
protected |
Handles input size changes. By default input size shouldn't change automatically.
| index | The index of the input being changed |
| newSize | The new size of the input |
Definition at line 122 of file component.cpp.
|
inlinenodiscard |
Gets all input buses without copying.
Definition at line 577 of file component.hpp.
|
inlinenodiscardprotected |
Reads an input bit, returning ERROR when the bus or bit is missing.
| Enum | Component input enum type |
| input | Input bus enum value |
| bit | Bit index inside the bus |
Definition at line 355 of file component.hpp.
|
inlinenodiscardprotected |
Definition at line 323 of file component.hpp.
|
inlinenodiscardprotected |
Definition at line 341 of file component.hpp.
|
inlinenodiscardprotected |
Definition at line 331 of file component.hpp.
| bool isConnectedTo | ( | const Bus & | b | ) | const |
Checks if this component is connected to a bus.
| b | The bus to check |
Definition at line 238 of file component.cpp.
|
nodiscardvirtual |
Gets catalog metadata for this component type.
Reimplemented in AndGate, ConstantComponent, DFlipFlop, DLatch, DummyBusInputComponent, DummyBusOutputComponent, DummyInputComponent, DummyOutputComponent, EFlipFlop, JKFlipFlop, NandGate, NorGate, NotGate, OrGate, Register, ROM, SubcircuitComponent, XorGate, AdderNBits, Comparator, Complementer, Decoder, Demultiplexer, Divider, Extender, FullAdder, HalfAdder, Multiplexer, Multiplier, Shifter, WireMerger, and WireSplitter.
Definition at line 54 of file component.cpp.
|
protected |
Notifies all registered I/O listeners of a change.
Called when the component's input or output configuration changes, typically after setInput/setOutput is called.
Definition at line 72 of file component.cpp.
|
inlinenodiscard |
Gets all output buses without copying.
Definition at line 603 of file component.hpp.
|
inlinenodiscardprotected |
Returns the size of an output bus, or zero when it is missing.
| Enum | Component output enum type |
| output | Output bus enum value |
Definition at line 395 of file component.hpp.
|
inlinenodiscardprotected |
Definition at line 382 of file component.hpp.
|
inlinenodiscardprotected |
Returns an output wire, or null when the bus or bit is missing.
| Enum | Component output enum type |
| output | Output bus enum value |
| bit | Bit index inside the bus |
Definition at line 377 of file component.hpp.
|
inlinenodiscardprotected |
Definition at line 360 of file component.hpp.
| void removeIOListener | ( | uint64_t | id | ) |
Removes a previously added I/O listener.
| id | The ID returned by addIOListener |
Definition at line 67 of file component.cpp.
Replaces a bus in the input or output collection.
| busCollection | The collection to modify (inputs or outputs) |
| index | The index of the bus to replace |
| newBus | The new bus to set |
Definition at line 131 of file component.cpp.
|
virtual |
Lower this component into native Yosys netlist cells.
Third-party components that do not override this method fail export with a descriptive error instead of silently producing an incomplete netlist.
Reimplemented in AndGate, BoundaryIoComponent, ConstantComponent, DFlipFlop, DLatch, EFlipFlop, JKFlipFlop, NandGate, NorGate, NotGate, OrGate, Register, ROM, SubcircuitComponent, XorGate, AdderNBits, Comparator, Complementer, Decoder, Demultiplexer, Divider, Extender, FullAdder, HalfAdder, Multiplexer, Multiplier, Shifter, WireMerger, and WireSplitter.
Definition at line 105 of file components.cpp.
| void setInput | ( | unsigned int | index, |
| const Bus & | bus, | ||
| bool | checkSize = false ) |
Sets an input bus at a specific index.
| index | The input index |
| bus | The bus to connect |
| checkSize | Whether to call handleInputSizeChange |
Definition at line 197 of file component.cpp.
| void setInputs | ( | const std::vector< Bus > & | newInputs | ) |
Replaces all input buses.
| newInputs | The new input buses |
Definition at line 216 of file component.cpp.
| void setOutput | ( | unsigned int | index, |
| const Bus & | bus ) |
Sets an output bus at a specific index.
| index | The output index |
| bus | The bus to connect |
Definition at line 208 of file component.cpp.
| void setOutputs | ( | const std::vector< Bus > & | newOutputs | ) |
Replaces all output buses.
| newOutputs | The new output buses |
Definition at line 227 of file component.cpp.
| void setProperty | ( | std::string_view | key, |
| const PropertyValue & | value ) |
Sets a property value.
| key | The property name |
| value | The property value |
Definition at line 143 of file component.cpp.
| void setPropertyCallback | ( | std::string_view | key, |
| PropertyCallback | callback ) |
Sets a callback for property validation/transformation.
| key | The property name |
| callback | The callback function |
Definition at line 183 of file component.cpp.
|
inline |
Sets a property value with type deduction.
| T | The property value type |
| key | The property name |
| value | The property value |
Definition at line 493 of file component.hpp.
|
inlinevirtual |
Executes the component's logic.
Called by the Simulator during circuit evaluation. Each component implements this to read input bus states and produce output bus states.
| sim | The simulator executing this component |
Reimplemented in AndGate, ConstantComponent, DummyBusInputComponent, DummyBusOutputComponent, DummyInputComponent, DummyOutputComponent, NandGate, NorGate, NotGate, OrGate, ROM, SubcircuitComponent, XorGate, AdderNBits, Comparator, Complementer, Decoder, Demultiplexer, Divider, Extender, FullAdder, HalfAdder, Multiplexer, Multiplier, Shifter, WireMerger, and WireSplitter.
Definition at line 421 of file component.hpp.
|
inlinevirtual |
Executes the component's logic with simulator scheduling context.
The default implementation preserves backwards compatibility by delegating to simulate(Simulator&). Components can override this overload only when they need to inspect the evaluation context.
| sim | The simulator executing this component |
| context | Evaluation metadata for this simulation pass |
Reimplemented in DLatch, FlipFlop, and Register.
Definition at line 436 of file component.hpp.
|
pure virtual |
Gets the component type name.
Implemented in AndGate, ConstantComponent, DFlipFlop, DLatch, DummyBusInputComponent, DummyBusOutputComponent, DummyInputComponent, DummyOutputComponent, EFlipFlop, JKFlipFlop, NandGate, NorGate, NotGate, OrGate, Register, ROM, SubcircuitComponent, XorGate, AdderNBits, Comparator, Complementer, Decoder, Demultiplexer, Divider, Extender, FullAdder, HalfAdder, Multiplexer, Multiplier, Shifter, WireMerger, and WireSplitter.
|
inlinenodiscard |
Gets the state used when an input has no connected wire.
| input | Input bus index |
Definition at line 584 of file component.hpp.
|
inlinenodiscardvirtual |
Whether zero-delay output writes should be staged during reactive passes.
Edge-triggered sequential components return true so all triggered outputs are committed from the same pre-edge snapshot. Combinational components keep the default immediate zero-delay behavior.
Reimplemented in DLatch, FlipFlop, and Register.
Definition at line 450 of file component.hpp.
|
protected |
Validates a property value against the declared type and metadata.
Definition at line 103 of file component.cpp.
|
protected |
Input buses connected to this component.
Definition at line 213 of file component.hpp.
|
protected |
Map of I/O change listeners indexed by ID.
Definition at line 234 of file component.hpp.
|
protected |
Counter for generating unique I/O listener IDs.
Definition at line 231 of file component.hpp.
|
protected |
Output buses produced by this component.
Definition at line 216 of file component.hpp.
|
protected |
Map of configurable properties for this component.
Definition at line 222 of file component.hpp.
|
protected |
Map of callbacks for property validation/transformation.
Definition at line 225 of file component.hpp.
|
protected |
Allowed values for constrained string properties.
Definition at line 228 of file component.hpp.
|
protected |
Per-input state used when a bus bit has no connected wire.
Definition at line 219 of file component.hpp.