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

Module-instantiation dependency graph for a Yosys JSON design. More...

#include <netlist.hpp>

Classes

struct  VertexProperty
 Per-vertex payload holding the declared module name. More...

Public Types

using ModuleNameList = std::vector<std::string>
 List of module names.
using Graph
 Boost graph type: set out-edges, vector vertices, directed.
using Vertex = boost::graph_traits<Graph>::vertex_descriptor
 Boost vertex descriptor (an integer index under vecS).
using NameToVertex
 O(1) index mapping a module name to its graph vertex.

Public Member Functions

void addModule (std::string_view moduleName)
 Ensures a module vertex exists, creating it if necessary.
void addDependency (std::string_view from, std::string_view to)
 Records that from instantiates to.
ModuleNameList dependenciesOf (std::string_view moduleName) const
 Returns the sorted, unique modules moduleName instantiates.
ModuleNameList dependencyOrder (const ModuleNameList &roots) const
 Returns the unique dependency closure of roots in dependency-first order.
ModuleNameList modules () const
 Returns every declared module name.
bool containsModule (std::string_view moduleName) const
 Checks whether a module vertex is present in the graph.
const Graph & boost () const
 Read-only access to the underlying Boost graph.

Private Member Functions

std::optional< Vertex > findVertex (std::string_view moduleName) const
Vertex ensureVertex (std::string_view moduleName)
 Ensures a module vertex exists in this graph (O(1)).
void rebuildNameIndex ()
 Rebuilds nameToVertex from the current graph.

Private Attributes

Graph graph
 The dependency graph itself.
NameToVertex nameToVertex
 Name-to-vertex index kept in sync with graph.

Detailed Description

Module-instantiation dependency graph for a Yosys JSON design.

Vertices are declared module names. Edges point from an instantiating module to the declared modules it instantiates; primitive and external cell types are not included. The graph is derived from a Yosys write_json document and is never serialized.

The graph uses boost::vecS for its vertex container, which means vertex descriptors are integer indices. As a consequence, removing a vertex reindexes every subsequent vertex, so the nameToVertex index must be rebuilt after a removal. Name lookup remains average O(1) thanks to the std::unordered_map index.

Definition at line 58 of file netlist.hpp.

Member Typedef Documentation

◆ Graph

using Graph
Initial value:
boost::adjacency_list<boost::setS, boost::vecS, boost::directedS, VertexProperty>

Boost graph type: set out-edges, vector vertices, directed.

Definition at line 69 of file netlist.hpp.

◆ ModuleNameList

using ModuleNameList = std::vector<std::string>

List of module names.

Definition at line 61 of file netlist.hpp.

◆ NameToVertex

using NameToVertex
Initial value:
std::unordered_map<std::string, Vertex, core::TransparentStringHash,
boost::graph_traits< Graph >::vertex_descriptor Vertex
Boost vertex descriptor (an integer index under vecS).
Definition netlist.hpp:72
Transparent equality functor for string-like keys.
Transparent hash functor for string-like keys.

O(1) index mapping a module name to its graph vertex.

Definition at line 75 of file netlist.hpp.

◆ Vertex

using Vertex = boost::graph_traits<Graph>::vertex_descriptor

Boost vertex descriptor (an integer index under vecS).

Definition at line 72 of file netlist.hpp.

Member Function Documentation

◆ addDependency()

void addDependency ( std::string_view from,
std::string_view to )

Records that from instantiates to.

Both modules are ensured as vertices first. Duplicate edges are ignored, so dependencies remain unique.

Parameters
fromInstantiating module name.
toInstantiated declared module name.

Definition at line 1653 of file deserialization.cpp.

◆ addModule()

void addModule ( std::string_view moduleName)

Ensures a module vertex exists, creating it if necessary.

Parameters
moduleNameDeclared module name to register.

Definition at line 1648 of file deserialization.cpp.

◆ boost()

const Graph & boost ( ) const
inlinenodiscard

Read-only access to the underlying Boost graph.

Definition at line 133 of file netlist.hpp.

◆ containsModule()

bool containsModule ( std::string_view moduleName) const
nodiscard

Checks whether a module vertex is present in the graph.

Parameters
moduleNameDeclared module name to look up.
Returns
true if the module is registered.

Definition at line 1733 of file deserialization.cpp.

◆ dependenciesOf()

ModuleDependencyGraph::ModuleNameList dependenciesOf ( std::string_view moduleName) const
nodiscard

Returns the sorted, unique modules moduleName instantiates.

Parameters
moduleNameDeclared module name to query.
Returns
The dependency names, sorted lexicographically; empty if the module is unknown or has no dependencies.

Definition at line 1710 of file deserialization.cpp.

◆ dependencyOrder()

ModuleDependencyGraph::ModuleNameList dependencyOrder ( const ModuleNameList & roots) const
nodiscard

Returns the unique dependency closure of roots in dependency-first order.

Explicit roots are included in the result. Shared dependencies occur once, and otherwise-independent names are ordered deterministically.

Exceptions
std::invalid_argumentIf a requested root is unknown.
std::runtime_errorIf the selected hierarchy is recursive.

Definition at line 1662 of file deserialization.cpp.

◆ ensureVertex()

ModuleDependencyGraph::Vertex ensureVertex ( std::string_view moduleName)
private

Ensures a module vertex exists in this graph (O(1)).

Parameters
moduleNameDeclared module name.
Returns
The descriptor of the existing or newly created vertex.

Definition at line 1748 of file deserialization.cpp.

◆ findVertex()

std::optional< ModuleDependencyGraph::Vertex > findVertex ( std::string_view moduleName) const
nodiscardprivate

Definition at line 1739 of file deserialization.cpp.

◆ modules()

ModuleDependencyGraph::ModuleNameList modules ( ) const
nodiscard

Returns every declared module name.

Returns
The module names, sorted lexicographically; empty if the graph is empty.

Definition at line 1723 of file deserialization.cpp.

◆ rebuildNameIndex()

void rebuildNameIndex ( )
private

Rebuilds nameToVertex from the current graph.

Required after remove_vertex because vecS reindexes descriptors.

Definition at line 1757 of file deserialization.cpp.

Member Data Documentation

◆ graph

Graph graph
private

The dependency graph itself.

Definition at line 137 of file netlist.hpp.

◆ nameToVertex

NameToVertex nameToVertex
private

Name-to-vertex index kept in sync with graph.

Definition at line 139 of file netlist.hpp.


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