SILICON
Loading...
Searching...
No Matches
Register Class Reference

#include <register.hpp>

Inheritance diagram for Register:
Collaboration diagram for Register:

Public Types

enum class  Inputs : unsigned int {
  Data = 0 , Clock = 1 , Enable = 2 , Clear = 3 ,
  Load = 4
}
enum class  Outputs : unsigned int { Out = 0 }
Public Types inherited from Component
using IOObserver = std::function<void(Component*)>
 Callback type for I/O change notifications.

Public Member Functions

 Register ()
 Register (Bus data, Wire_ptr clock, Wire_ptr enable, Wire_ptr clear, Bus output)
std::string_view typeName () const override
 Gets the component type name.
ComponentMetadata metadata () const override
 Gets catalog metadata for this component type.
bool usesStagedSequentialOutputs () const override
 Whether zero-delay output writes should be staged during reactive passes.
int setSize (int size)
std::string setInputType (std::string inputType)
std::string setOutputType (std::string outputType)
void simulate (SILICON::simulation::Simulator &sim, const SILICON::simulation::Context &context) override
 Executes the component's logic with simulator scheduling context.
void serializeYosys (SILICON::yosys::SerializationContext &context) const override
 Lower this component into native Yosys netlist cells.
Public Member Functions inherited from Component
 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.
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.
uint64_t addIOListener (IOObserver cb)
 Adds a listener for I/O changes.
void removeIOListener (uint64_t id)
 Removes a previously added I/O listener.

Static Public Attributes

static constexpr std::string_view Type = "Register"
static constexpr std::string_view PARALLEL_TYPE = "Parallel"
static constexpr std::string_view SERIAL_TYPE = "Serial"

Private Member Functions

void initializeProperties ()
void reshapeBuses ()
void reshapeBuses (int size, const std::string &inputType, const std::string &outputType)
void driveOutput (SILICON::simulation::Simulator &sim)
void clearState ()
int configuredSize () const
std::string configuredInputType () const
std::string configuredOutputType () const
bool parallelInput () const
bool parallelOutput () const

Private Attributes

std::vector< State > state

Additional Inherited Members

Protected Member Functions inherited from Component
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 &currentValue, 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 inherited from Component
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 inherited from Component
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.

Detailed Description

Definition at line 29 of file register.hpp.

Member Enumeration Documentation

◆ Inputs

enum class Inputs : unsigned int
strong
Enumerator
Data 
Clock 
Enable 
Clear 
Load 

Definition at line 35 of file register.hpp.

◆ Outputs

enum class Outputs : unsigned int
strong
Enumerator
Out 

Definition at line 43 of file register.hpp.

Constructor & Destructor Documentation

◆ Register() [1/2]

Register ( )

Definition at line 55 of file register.cpp.

◆ Register() [2/2]

Register ( Bus data,
Wire_ptr clock,
Wire_ptr enable,
Wire_ptr clear,
Bus output )

Definition at line 60 of file register.cpp.

Member Function Documentation

◆ clearState()

void clearState ( )
private

Definition at line 186 of file register.cpp.

◆ configuredInputType()

std::string configuredInputType ( ) const
nodiscardprivate

Definition at line 84 of file register.cpp.

◆ configuredOutputType()

std::string configuredOutputType ( ) const
nodiscardprivate

Definition at line 89 of file register.cpp.

◆ configuredSize()

int configuredSize ( ) const
nodiscardprivate

Definition at line 79 of file register.cpp.

◆ driveOutput()

void driveOutput ( SILICON::simulation::Simulator & sim)
private

Definition at line 191 of file register.cpp.

◆ initializeProperties()

void initializeProperties ( )
private

Definition at line 104 of file register.cpp.

◆ metadata()

ComponentMetadata metadata ( ) const
inlineoverridevirtual

Gets catalog metadata for this component type.

Returns
Display name, description, and category for UI catalogs.

Reimplemented from Component.

Definition at line 51 of file register.hpp.

◆ parallelInput()

bool parallelInput ( ) const
nodiscardprivate

Definition at line 94 of file register.cpp.

◆ parallelOutput()

bool parallelOutput ( ) const
nodiscardprivate

Definition at line 99 of file register.cpp.

◆ reshapeBuses() [1/2]

void reshapeBuses ( )
private

Definition at line 159 of file register.cpp.

◆ reshapeBuses() [2/2]

void reshapeBuses ( int size,
const std::string & inputType,
const std::string & outputType )
private

Definition at line 164 of file register.cpp.

◆ serializeYosys()

void serializeYosys ( SILICON::yosys::SerializationContext & context) const
overridevirtual

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 from Component.

Definition at line 730 of file components.cpp.

◆ setInputType()

std::string setInputType ( std::string inputType)

Definition at line 147 of file register.cpp.

◆ setOutputType()

std::string setOutputType ( std::string outputType)

Definition at line 153 of file register.cpp.

◆ setSize()

int setSize ( int size)

Definition at line 138 of file register.cpp.

◆ simulate()

void simulate ( SILICON::simulation::Simulator & sim,
const SILICON::simulation::Context & context )
overridevirtual

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.

Parameters
simThe simulator executing this component
contextEvaluation metadata for this simulation pass

Reimplemented from Component.

Definition at line 210 of file register.cpp.

◆ typeName()

std::string_view typeName ( ) const
inlineoverridevirtual

Gets the component type name.

Returns
String view of the type identifier

Implements Component.

Definition at line 50 of file register.hpp.

◆ usesStagedSequentialOutputs()

bool usesStagedSequentialOutputs ( ) const
inlinenodiscardoverridevirtual

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 from Component.

Definition at line 57 of file register.hpp.

Member Data Documentation

◆ PARALLEL_TYPE

std::string_view PARALLEL_TYPE = "Parallel"
staticconstexpr

Definition at line 32 of file register.hpp.

◆ SERIAL_TYPE

std::string_view SERIAL_TYPE = "Serial"
staticconstexpr

Definition at line 33 of file register.hpp.

◆ state

std::vector<State> state
private

Definition at line 81 of file register.hpp.

◆ Type

std::string_view Type = "Register"
staticconstexpr

Definition at line 31 of file register.hpp.


The documentation for this class was generated from the following files: