 |
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/node.h"
43 const std::shared_ptr<Type> &
type,
52 String_val_(std::move(str_val)) {}
58 #define LITERAL_DECL_FACTORY(NAME, TYPENAME) \
60 explicit Literal(std::string name, const std::shared_ptr<Type> &type, TYPENAME value); \
61 static std::shared_ptr<Literal> Make##NAME(TYPENAME value); \
62 static std::shared_ptr<Literal> Make##NAME(const std::shared_ptr<Type> &type, TYPENAME value); \
63 static std::shared_ptr<Literal> Make##NAME(std::string name, const std::shared_ptr<Type> &type, TYPENAME value); \
64 TYPENAME NAME##Value() const { return NAME##_val_; } \
67 TYPENAME NAME##_val_ {}
80 static std::shared_ptr<Literal>
Make(
bool value) {
return MakeBool(value); }
82 static std::shared_ptr<Literal>
Make(int64_t value) {
return MakeInt(value); }
84 static std::shared_ptr<Literal>
Make(std::string value) {
return MakeString(std::move(value)); }
87 std::shared_ptr<Object>
Copy()
const override;
90 inline std::vector<Edge *>
sources()
const override {
return {}; }
95 std::string
ToString()
const override;
108 T
RawValueOf(
const Literal &node) {
throw std::runtime_error(
"Can not obtain raw value for type."); }
116 inline int64_t
RawValueOf(
const Literal &node) {
return node.IntValue(); }
120 inline std::string
RawValueOf(
const Literal &node) {
return node.StringValue(); }
LITERAL_DECL_FACTORY(String, std::string)
Strings.
void SetParent(Graph *graph) override
Literal nodes are only owned by the literal pool, hence never have a parent graph.
std::shared_ptr< Object > Copy() const override
Create a copy of this Literal.
static std::shared_ptr< Literal > Make(bool value)
Create a boolean literal.
Literal::StorageType StorageTypeOf< uint64_t >()
Template specialization for StorageTypeOf<int>
std::vector< std::shared_ptr< Edge > > outputs_
The outgoing Edges that sink this Node.
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.
Contains every Cerata class, function, etc...
Literal(std::string name, const std::shared_ptr< Type > &type, StorageType st, std::string str_val, int64_t int_val, bool bool_val)
Literal constructor.
T RawValueOf(const Literal &node)
Obtain the raw value of a literal node.
std::vector< Edge * > sources() const override
A literal node has no inputs. This function returns an empty list.
std::string name() const
Return the name of the object.
NodeID
Node type IDs with different properties.
std::string ToString() const override
Convert the Literal value to a human-readable string.
LITERAL_DECL_FACTORY(Int, int64_t)
Ints.
StorageType storage_type() const
Return the storage type of the literal.
static std::shared_ptr< Literal > Make(int64_t value)
Create an integer literal.
std::vector< Edge * > sinks() const override
Get the output edges of this Node.
Literal::StorageType StorageTypeOf< int64_t >()
Template specialization for StorageTypeOf<int>
Literal::StorageType StorageTypeOf()
Obtain the Literal::StorageType enum value of a C++ type T.
LITERAL_DECL_FACTORY(Bool, bool)
Bools.
StorageType
The storage type of the literal value.
StorageType storage_type_
The raw storage type of the literal node.
static std::shared_ptr< Literal > Make(std::string value)
Create a string literal.
Literal::StorageType StorageTypeOf< bool >()
Template specialization for StorageTypeOf<bool>
Type * type() const
Return the node Type.
A no-input, multiple-outputs node.