|
SILICON
|
Represents a digital circuit as a directed graph of components. More...
#include <circuit.hpp>
Classes | |
| struct | SimulationBlock |
| Represents a block of components for simulation execution. More... | |
Public Types | |
| using | LevelMap |
Public Member Functions | |
| Circuit ()=default | |
| Circuit (const Component_set &components, bool explore=false) | |
| Constructs a circuit from a set of components. | |
| Circuit (const std::vector< Component_ptr > &components, bool explore=false) | |
| Constructs a circuit preserving the supplied component and boundary port order. | |
| Circuit (const Component_ptr &component, bool explore=true) | |
| Constructs a circuit from a single component. | |
| void | addComponent (const Component_ptr &component) |
| Adds a component to the circuit recursively. | |
| void | removeComponent (const Component_ptr &component) |
| Removes a component from the circuit. | |
| std::optional< VertexDescriptor > | getVertexId (const Component *component) const |
| Gets the vertex ID for a component. | |
| const std::unordered_map< const Component *, VertexDescriptor > & | getComponentToVertex () const |
| Gets all component-to-vertex mappings. | |
| Component_ptr | getComponentByVertexId (VertexDescriptor vertexId) const |
| Gets a component by its vertex ID. | |
| void | buildTopologyMap () |
| Builds a reverse mapping from wires to components that use them. | |
| std::vector< Bus > | getInputs () const |
| Gets all input buses of the circuit. | |
| std::vector< CircuitPort > | getInputPorts () const |
| Gets named input ports using boundary names or deterministic fallbacks. | |
| std::vector< Bus > | getOutputs () const |
| Gets all output buses of the circuit. | |
| std::vector< CircuitPort > | getOutputPorts () const |
| Gets named output ports using boundary names or deterministic fallbacks. | |
| Component_set | getComponentsForBus (Bus b) const |
| Finds all components that are connected to a given bus. | |
| std::vector< CircuitConnection > | getConnections () const |
| Gets concrete output-to-input logical connections for routing. | |
| std::vector< Component_weakPtr > | getListenersForWire (uint64_t wireId) const |
| Gets all components listening to changes on a specific wire. | |
| Circuit | getBackwardsSubgraph (const Bus &targetOutput) const |
| Extracts the cone of influence (COI) for a target output bus. | |
| Circuit | getForwardSubgraph (const Bus &sourceInput) const |
| Extracts the forward cone of influence for a source input bus. | |
| const CircuitGraph & | getGraph () const |
| Gets the underlying circuit graph. | |
| std::vector< SimulationBlock > | splitCyclic () const |
| Splits the circuit into simulation blocks separating cyclic from acyclic parts. | |
| Circuit::LevelMap | getLevelMap () const |
| Get a levelized map between the components and their level number. | |
| std::string | serialize () const |
| Serializes the core circuit model to a JSON string. | |
Static Public Member Functions | |
| static Circuit | deserialize (const std::string &jsonStr, const ComponentRegistry ®, const CircuitResolver *resolver=nullptr) |
| Deserializes the core circuit model from a JSON string. | |
Private Member Functions | |
| VertexDescriptor | getOrAddVertex (const Component_ptr &component) |
| Gets or adds a vertex for a component. | |
| void | rebuildEdges (VertexDescriptor v) |
| Rebuilds directed edges in the graph based on wire connections. | |
| std::pair< std::vector< Bus >, std::vector< Bus > > | getComponentIOs () const |
| Collects all unique input and output buses from every component in the circuit. | |
| std::vector< CircuitPort > | interfacePorts (PortRole role) const |
| void | addComponentRecursive (const Component_ptr &component, std::vector< VertexDescriptor > &newlyAdded) |
| Recursively adds a component and all connected components. | |
| std::vector< VertexDescriptor > | topologicalOrder () const |
| Computes a valid execution order for all vertices in the circuit. | |
Private Attributes | |
| CircuitGraph | graph |
| The Boost graph representing the circuit topology. | |
| std::unordered_map< const Component *, VertexDescriptor > | componentToVertex |
| Maps components to their vertex descriptors in the graph. | |
| std::unordered_map< uint64_t, std::vector< Component_ptr > > | wireListeners |
| Maps wire IDs to components that listen to changes on that wire. | |
| std::vector< Component_ptr > | ownedComponents |
| Components owned by this circuit (for deserialization). | |
| std::vector< Wire_ptr > | ownedWires |
| Wires owned by this circuit (for deserialization). | |
Represents a digital circuit as a directed graph of components.
The Circuit class manages a collection of components and their connections through wires. It uses a Boost Graph-based internal representation to track component relationships and enable operations like topological sorting, subgraph extraction, and reactive simulation.
Definition at line 125 of file circuit.hpp.
| using LevelMap |
Definition at line 362 of file circuit.hpp.
|
default |
|
explicit |
Constructs a circuit from a set of components.
| components | The set of components to include |
| explore | If true, recursively explore and add connected components |
Definition at line 242 of file circuit.cpp.
|
explicit |
Constructs a circuit preserving the supplied component and boundary port order.
| components | The ordered components to include |
| explore | If true, recursively explore and add connected components |
Definition at line 247 of file circuit.cpp.
|
explicit |
Constructs a circuit from a single component.
| component | The root component to add |
| explore | If true, recursively explore and add connected components |
Definition at line 265 of file circuit.cpp.
| void addComponent | ( | const Component_ptr & | component | ) |
Adds a component to the circuit recursively.
Adds the component and all components reachable through shared buses.
| component | The component to add |
Definition at line 294 of file circuit.cpp.
|
private |
Recursively adds a component and all connected components.
| component | The component to add |
| newlyAdded | Vector to collect newly added vertex descriptors |
Definition at line 278 of file circuit.cpp.
| void buildTopologyMap | ( | ) |
Builds a reverse mapping from wires to components that use them.
This enables O(1) lookup of components connected to a specific wire, used for subgraph extraction and reactive updates.
Definition at line 205 of file circuit.cpp.
|
staticnodiscard |
Deserializes the core circuit model from a JSON string.
Expects the payload documented in core_serialization_format. The registry is used to recreate component instances by serialized type name.
| jsonStr | The JSON string to deserialize |
| reg | The component registry to create components |
| resolver | Optional non-owning resolver that must outlive the returned circuit. |
Definition at line 749 of file circuit.cpp.
Extracts the cone of influence (COI) for a target output bus.
Returns a new Circuit containing all components that can affect the target bus through dataflow dependencies (reading from sources that eventually drive the target).
| targetOutput | The output bus to get the backwards subgraph for |
Definition at line 464 of file circuit.cpp.
|
nodiscard |
Gets a component by its vertex ID.
| vertexId | The vertex ID |
Definition at line 113 of file circuit.cpp.
Collects all unique input and output buses from every component in the circuit.
Used to determine circuit interface.
Definition at line 177 of file circuit.cpp.
|
nodiscard |
Finds all components that are connected to a given bus.
A component is connected if any of its input or output buses share wires with the target bus.
| b | The bus to find components for |
Definition at line 390 of file circuit.cpp.
|
inlinenodiscard |
Gets all component-to-vertex mappings.
Definition at line 246 of file circuit.hpp.
|
nodiscard |
Gets concrete output-to-input logical connections for routing.
Each returned item represents one source output bus connected to one target input bus. Fan-out is expanded into multiple connections, while multi-wire buses are deduplicated so each source/target/bus-index tuple appears once.
Definition at line 423 of file circuit.cpp.
Extracts the forward cone of influence for a source input bus.
Returns a new Circuit containing all components that can be affected by changes to the source bus (directly or indirectly through dataflow).
| sourceInput | The input bus to get the forward subgraph for |
Definition at line 514 of file circuit.cpp.
|
inlinenodiscard |
Gets the underlying circuit graph.
Definition at line 349 of file circuit.hpp.
|
nodiscard |
Gets named input ports using boundary names or deterministic fallbacks.
Definition at line 348 of file circuit.cpp.
|
nodiscard |
Gets all input buses of the circuit.
Boundary components with PortRole::Input define the interface when present. Otherwise topology-derived inputs are returned.
Definition at line 341 of file circuit.cpp.
|
nodiscard |
Get a levelized map between the components and their level number.
Definition at line 658 of file circuit.cpp.
|
nodiscard |
Gets all components listening to changes on a specific wire.
| wireId | The ID of the wire |
Definition at line 223 of file circuit.cpp.
|
private |
Gets or adds a vertex for a component.
| component | The component to get or add |
Definition at line 122 of file circuit.cpp.
|
nodiscard |
Gets named output ports using boundary names or deterministic fallbacks.
Definition at line 385 of file circuit.cpp.
|
nodiscard |
Gets all output buses of the circuit.
Boundary components with PortRole::Output define the interface when present. Otherwise topology-derived outputs are returned.
Definition at line 378 of file circuit.cpp.
|
nodiscard |
Gets the vertex ID for a component.
| component | The component |
Definition at line 330 of file circuit.cpp.
|
nodiscardprivate |
Definition at line 353 of file circuit.cpp.
|
private |
Rebuilds directed edges in the graph based on wire connections.
A directed edge (u -> v) is added when component u's output bus shares at least one wire with component v's input bus. This creates the dataflow graph used for topological sorting and subgraph extraction.
| v | The vertex whose edges should be rebuilt |
Definition at line 139 of file circuit.cpp.
| void removeComponent | ( | const Component_ptr & | component | ) |
Removes a component from the circuit.
Removes the vertex and all incident edges from the graph, and removes the component from componentToVertex map.
| component | The component to remove |
Definition at line 307 of file circuit.cpp.
|
nodiscard |
Serializes the core circuit model to a JSON string.
This is the canonical serialization for the logical circuit only. It stores the component graph, not the editor layout.
The payload contains:
Wire connectivity is represented by shared wire IDs inside the serialized bus lists. During deserialization, components are reinserted in serialized id order so their Boost vertex descriptors match the saved graph IDs again.
This format intentionally does not store any UI state such as graphical positions, rotations, wire segment geometry, or runtime scene item IDs. Those belong to the DiagramScene serialization format documented in diagramscene_serialization_format.
Definition at line 694 of file circuit.cpp.
|
nodiscard |
Splits the circuit into simulation blocks separating cyclic from acyclic parts.
This is essential for proper simulation: acyclic parts execute once in topological order, while cyclic parts require iterative delta cycles to converge.
Definition at line 557 of file circuit.cpp.
|
nodiscardprivate |
Computes a valid execution order for all vertices in the circuit.
Definition at line 644 of file circuit.cpp.
|
private |
Maps components to their vertex descriptors in the graph.
Definition at line 131 of file circuit.hpp.
|
private |
The Boost graph representing the circuit topology.
Definition at line 128 of file circuit.hpp.
|
private |
Components owned by this circuit (for deserialization).
Definition at line 137 of file circuit.hpp.
|
private |
Wires owned by this circuit (for deserialization).
Definition at line 140 of file circuit.hpp.
|
private |
Maps wire IDs to components that listen to changes on that wire.
Definition at line 134 of file circuit.hpp.