Cerata
A library to generate structural hardware designs
|
A node representing a binary tree of other nodes. More...
#include <expression.h>
Public Types | |
enum | Op { ADD, SUB, MUL, DIV } |
Binary expression operator enum class. | |
![]() | |
enum | NodeID { NodeID::PORT, NodeID::SIGNAL, NodeID::PARAMETER, NodeID::LITERAL, NodeID::EXPRESSION } |
Node type IDs with different properties. More... | |
![]() | |
enum | ID { NODE, ARRAY } |
Object type ID to conveniently cast the object during run-time. More... | |
Public Member Functions | |
std::shared_ptr< Object > | Copy () const override |
Copy this expression. | |
Node * | CopyOnto (Graph *dst, const std::string &name, NodeMap *rebinding) const override |
Copy this expression onto a graph and rebind anything in the expression tree. | |
void | AppendReferences (std::vector< Object * > *out) const override |
Depth-first traverse the expression tree and add any nodes owned. | |
std::string | ToString () const override |
Minimize the expression and convert it to a human-readable string. | |
Node * | lhs () const |
Return the left-hand side node of the expression. | |
Node * | rhs () const |
Return the right-hand side node of the expression. | |
![]() | |
MultiOutputNode (std::string name, Node::NodeID id, std::shared_ptr< Type > type) | |
MultiOutputNode constructor. | |
std::vector< Edge * > | sources () const override |
Return the incoming edges (in this case just the single input edge) that sources this Node. | |
std::vector< Edge * > | sinks () const override |
The outgoing Edges that this Node sinks. | |
bool | RemoveEdge (Edge *edge) override |
Remove an edge from this node. | |
bool | AddEdge (const std::shared_ptr< Edge > &edge) override |
Add an output edge to this node. | |
std::shared_ptr< Edge > | output (size_t i) const |
Return output edge i of this node. | |
size_t | num_outputs () const |
Return the number of edges of this node. | |
![]() | |
Node (std::string name, NodeID id, std::shared_ptr< Type > type) | |
Node constructor. | |
Type * | type () const |
Return the node Type. | |
Node * | SetType (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 std::vector< Edge * > | edges () const |
Return all edges this Node is on. | |
void | SetArray (NodeArray *array) |
Set parent array. | |
std::optional< NodeArray * > | array () const |
Return parent array, if any. | |
Node * | Replace (Node *replacement) |
Replace some node with another node, reconnecting all original edges. Returns the replaced node. | |
void | AppendReferences (std::vector< Object * > *out) const override |
Return all objects referenced by this node. For default nodes, these are type generics only. | |
![]() | |
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. | |
![]() | |
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. | |
Static Public Member Functions | |
static std::shared_ptr< Expression > | Make (Op op, std::shared_ptr< Node > lhs, std::shared_ptr< Node > rhs) |
Short-hand to create a smart pointer to an expression. | |
Protected Member Functions | |
Expression (Op op, std::shared_ptr< Node > lhs, std::shared_ptr< Node > rhs) | |
Construct a new expression. More... | |
Static Protected Member Functions | |
static std::shared_ptr< Node > | Minimize (Node *node) |
Minimize a node, if it is an expression, otherwise just returns a copy of the input. | |
static std::shared_ptr< Node > | MergeIntLiterals (Expression *exp) |
Merge expressions of integer literals into their resulting integer literal. | |
static std::shared_ptr< Node > | EliminateZeroOne (Expression *exp) |
Eliminate nodes that have zero or one on either side for specific expressions. | |
Protected Attributes | |
Op | operation_ |
The binary operator of this expression. | |
std::shared_ptr< Node > | lhs_ |
The left hand side node. | |
std::shared_ptr< Node > | rhs_ |
The right hand side node. | |
![]() | |
NodeID | node_id_ |
Node type ID. | |
std::shared_ptr< Type > | type_ |
The Type of this Node. | |
std::optional< NodeArray * > | array_ = {} |
Parent if this belongs to an array. | |
![]() | |
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 | |
![]() | |
std::vector< std::shared_ptr< Edge > > | outputs_ |
The outgoing Edges that sink this Node. | |
![]() | |
std::unordered_map< std::string, std::string > | meta |
KV storage for metadata of tools or specific backend implementations. | |
A node representing a binary tree of other nodes.
Definition at line 34 of file expression.h.
|
protected |
Construct a new expression.
op | The operator between two operands |
lhs | The left operand |
rhs | The right operand |
Definition at line 53 of file expression.cc.