Cerata
A library to generate structural hardware designs
cerata::Node Class Referenceabstract

A node. More...

#include <node.h>

+ Inheritance diagram for cerata::Node:
+ Collaboration diagram for cerata::Node:

Public Types

enum  NodeID {
  NodeID::PORT, NodeID::SIGNAL, NodeID::PARAMETER, NodeID::LITERAL,
  NodeID::EXPRESSION
}
 Node type IDs with different properties. More...
 
- Public Types inherited from cerata::Object
enum  ID { NODE, ARRAY }
 Object type ID to conveniently cast the object during run-time. More...
 

Public Member Functions

 Node (std::string name, NodeID id, std::shared_ptr< Type > type)
 Node constructor.
 
Typetype () const
 Return the node Type.
 
NodeSetType (const std::shared_ptr< Type > &type)
 Set the node Type.
 
NodeID node_id () const
 Return the node type ID.
 
bool Is (NodeID node_id) const
 Return whether this node is of a specific node type id.
 
virtual bool AddEdge (const std::shared_ptr< Edge > &edge)=0
 Add an edge to this node.
 
virtual bool RemoveEdge (Edge *edge)=0
 Remove an edge of this node.
 
virtual std::vector< Edge * > edges () const
 Return all edges this Node is on.
 
virtual std::vector< Edge * > sources () const
 Get the input edges of this Node.
 
virtual std::vector< Edge * > sinks () const
 Get the output edges of this Node.
 
void SetArray (NodeArray *array)
 Set parent array.
 
std::optional< NodeArray * > array () const
 Return parent array, if any.
 
NodeReplace (Node *replacement)
 Replace some node with another node, reconnecting all original edges. Returns the replaced node.
 
virtual NodeCopyOnto (Graph *dst, const std::string &name, NodeMap *rebinding) const
 Copy node onto a graph, implicitly copying over and rebinding e.g. type generics of referenced nodes. More...
 
void AppendReferences (std::vector< Object * > *out) const override
 Return all objects referenced by this node. For default nodes, these are type generics only.
 
virtual std::string ToString () const
 Return a human-readable string of this node.
 
- Public Member Functions inherited from cerata::Object
 Object (std::string name, ID id)
 Cerata object constructor. More...
 
ID obj_id () const
 Return the object ID of this object.
 
bool IsNode () const
 Return true if this object is a node.
 
bool IsArray () const
 Return true if this object is an array.
 
virtual void SetParent (Graph *parent)
 Set the parent graph of this object.
 
virtual std::optional< Graph * > parent () const
 Return the parent graph of this object, if any. Returns empty option otherwise.
 
virtual std::shared_ptr< ObjectCopy () const =0
 Deep-copy the object.
 
- Public Member Functions inherited from cerata::Named
 Named (std::string name)
 Named constructor.
 
std::string name () const
 Return the name of the object.
 
void SetName (std::string name)
 Change the name of the object.
 
virtual ~Named ()=default
 Destructor.
 

Protected Attributes

NodeID node_id_
 Node type ID.
 
std::shared_ptr< Typetype_
 The Type of this Node.
 
std::optional< NodeArray * > array_ = {}
 Parent if this belongs to an array.
 
- Protected Attributes inherited from cerata::Object
ID obj_id_
 The object type ID.
 
std::optional< Graph * > parent_ = {}
 An optional parent Graph to which this Object belongs. Initially no value.
 

Additional Inherited Members

- Public Attributes inherited from cerata::Object
std::unordered_map< std::string, std::string > meta
 KV storage for metadata of tools or specific backend implementations.
 

Detailed Description

A node.

Definition at line 42 of file node.h.

Member Enumeration Documentation

◆ NodeID

enum cerata::Node::NodeID
strong

Node type IDs with different properties.

Enumerator
PORT 

Single-input AND multi-output node with direction.

SIGNAL 

Single-input AND multi-output node.

PARAMETER 

Single-input AND multi-output node with default value.

LITERAL 

No-input AND multi-output node with storage type and storage value.

EXPRESSION 

No-input AND multi-output node that forms a binary tree with operations and nodes.

Definition at line 45 of file node.h.

Member Function Documentation

◆ CopyOnto()

Node * cerata::Node::CopyOnto ( Graph dst,
const std::string &  name,
NodeMap rebinding 
) const
virtual

Copy node onto a graph, implicitly copying over and rebinding e.g. type generics of referenced nodes.

Referenced nodes means any nodes this node references in its implementation (including its type), but not that it connects to through edges in the graph.

Implicitly rebinding means that, first, any referenced nodes will be searched for on the graph by name. If they don't exist, copies will be made onto the graph as well.

This function appends this node to the rebinding.

Parameters
dstThe destination graph to copy the node onto.
nameThe name of the new node.
rebindingThe rebinding to use, and to append, if required.
Returns
The copy.

Reimplemented in cerata::Expression.

Definition at line 54 of file node.cc.


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