 |
Cerata
A library to generate structural hardware designs
|
22 #include <unordered_map>
24 #include "cerata/object.h"
25 #include "cerata/type.h"
26 #include "cerata/domain.h"
42 class Node :
public Object,
public std::enable_shared_from_this<Node> {
67 #ifndef NODE_CAST_DECL_FACTORY
68 #define NODE_CAST_DECL_FACTORY(NODE_TYPE, NODE_ID) \
69 inline bool Is##NODE_TYPE() const { return node_id_ == (NodeID::NODE_ID); } \
70 NODE_TYPE* As##NODE_TYPE(); \
71 const NODE_TYPE* As##NODE_TYPE() const;
73 NODE_CAST_DECL_FACTORY(
Port, PORT)
74 NODE_CAST_DECL_FACTORY(
Signal, SIGNAL)
75 NODE_CAST_DECL_FACTORY(
Literal, LITERAL)
76 NODE_CAST_DECL_FACTORY(
Parameter, PARAMETER)
88 virtual std::vector<Edge *>
sinks()
const {
return {}; }
120 virtual std::string
ToString()
const;
135 typedef std::unordered_map<const Node *, Node *>
NodeMap;
149 std::vector<Edge *>
sources()
const override {
return {}; }
156 bool AddEdge(
const std::shared_ptr<Edge> &edge)
override;
176 std::vector<Edge *>
sources()
const override;
179 std::optional<Edge *>
input()
const;
182 bool AddEdge(
const std::shared_ptr<Edge> &edge)
override;
virtual std::vector< Edge * > sinks() const
Get the output edges of this Node.
bool AddEdge(const std::shared_ptr< Edge > &edge) override
Add an output edge to this node.
Node * SetType(const std::shared_ptr< Type > &type)
Set the node Type.
virtual std::vector< Edge * > sources() const
Get the input edges of this Node.
NormalNode(std::string name, Node::NodeID id, std::shared_ptr< Type > type)
NormalNode constructor.
bool AddEdge(const std::shared_ptr< Edge > &edge) override
Add an edge to this node.
@ LITERAL
No-input AND multi-output node with storage type and storage value.
std::shared_ptr< Edge > input_
The incoming Edge that sources this Node.
std::vector< Edge * > sources() const override
Return the incoming edges (in this case just the single input edge).
std::vector< std::shared_ptr< Edge > > outputs_
The outgoing Edges that sink this Node.
A node representing a binary tree of other nodes.
A graph representing a hardware structure.
std::vector< T * > ToRawPointers(const std::vector< std::shared_ptr< T >> &list)
Convert a list of shared pointers to raw pointers.
Node * Replace(Node *replacement)
Replace some node with another node, reconnecting all original edges. Returns the replaced node.
size_t num_outputs() const
Return the number of edges of this node.
Contains every Cerata class, function, etc...
std::shared_ptr< Type > type_
The Type of this Node.
bool Is(NodeID node_id) const
Return whether this node is of a specific node type id.
Node(std::string name, NodeID id, std::shared_ptr< Type > type)
Node constructor.
std::unordered_map< const Node *, Node * > NodeMap
A mapping from one object to another object, used in e.g. type generic rebinding.
@ PARAMETER
Single-input AND multi-output node with default value.
NodeID node_id() const
Return the node type ID.
std::string name() const
Return the name of the object.
NodeID
Node type IDs with different properties.
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.
A directed edge between two nodes.
A single-input, multiple-outputs node.
@ EXPRESSION
No-input AND multi-output node that forms a binary tree with operations and nodes.
void GetObjectReferences(const Object &obj, std::vector< Object * > *out)
Get any sub-objects that are used by an object, e.g. type generic nodes or array size nodes.
virtual bool AddEdge(const std::shared_ptr< Edge > &edge)=0
Add an edge to this node.
std::shared_ptr< Edge > output(size_t i) const
Return output edge i of this node.
NodeID node_id_
Node type ID.
A Cerata Object on a graph.
@ SIGNAL
Single-input AND multi-output node.
std::shared_ptr< Type > vector(const std::string &name, const std::shared_ptr< Node > &width)
Create a new vector type, and return a shared pointer to it.
std::vector< Edge * > sources() const override
Return the incoming edges (in this case just the single input edge) that sources this Node.
std::optional< NodeArray * > array_
Parent if this belongs to an array.
std::vector< Edge * > sinks() const override
The outgoing Edges that this Node sinks.
bool RemoveEdge(Edge *edge) override
Remove an edge from this node.
virtual std::string ToString() const
Return a human-readable string of this node.
void SetArray(NodeArray *array)
Set parent array.
void AppendReferences(std::vector< Object * > *out) const override
Return all objects referenced by this node. For default nodes, these are type generics only.
MultiOutputNode(std::string name, Node::NodeID id, std::shared_ptr< Type > type)
MultiOutputNode constructor.
std::optional< Edge * > input() const
Return the single incoming edge.
@ PORT
Single-input AND multi-output node with direction.
virtual Node * CopyOnto(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.
std::optional< NodeArray * > array() const
Return parent array, if any.
A port is a terminator node on a graph.
Type * type() const
Return the node Type.
bool RemoveEdge(Edge *edge) override
Remove an edge from this node.
void ImplicitlyRebindNodes(Graph *dst, const std::vector< Node * > &nodes, NodeMap *rebinding)
Make sure that the NodeMap contains all nodes to be rebound onto the destination graph.
A no-input, multiple-outputs node.