 |
Cerata
A library to generate structural hardware designs
|
15 #include "cerata/literal.h"
16 #include "cerata/pool.h"
22 return Bool_val_ ?
"true" :
"false";
26 return std::to_string(Int_val_);
30 #ifndef LITERAL_IMPL_FACTORY
31 #define LITERAL_IMPL_FACTORY(NAME, BASETYPE, IDNAME, TYPENAME) \
32 Literal::Literal(std::string name, const std::shared_ptr<Type> &type, TYPENAME value) \
33 : MultiOutputNode(std::move(name), Node::NodeID::LITERAL, type), \
34 storage_type_(StorageType::IDNAME), \
35 NAME##_val_(std::move(value)) {} \
37 std::shared_ptr<Literal> Literal::Make##NAME(TYPENAME value) { \
38 std::stringstream str; \
39 str << #NAME << "_" << value; \
40 auto ret = std::make_shared<Literal>(str.str(), BASETYPE(), value); \
45 LITERAL_IMPL_FACTORY(
String,
string, STRING, std::string)
46 LITERAL_IMPL_FACTORY(Bool,
boolean, BOOL,
bool)
47 LITERAL_IMPL_FACTORY(Int,
integer, INT, int64_t)
50 switch (storage_type_) {
51 default:
return strl(String_val_);
52 case StorageType::BOOL:
return booll(Bool_val_);
53 case StorageType::INT:
return intl(Int_val_);
std::shared_ptr< Literal > booll(bool value)
Return a literal node representing a Boolean.
void SetParent(Graph *graph) override
Literal nodes are only owned by the literal pool, hence never have a parent graph.
A graph representing a hardware structure.
Contains every Cerata class, function, etc...
std::shared_ptr< Literal > strl(std::string str)
Obtain a shared pointer to a string literal from the default node pool.
std::string ToString() const override
Convert the Literal value to a human-readable string.
std::shared_ptr< Literal > intl(int64_t i)
Obtain a shared pointer to an integer literal from the default node pool.
A Cerata Object on a graph.
std::shared_ptr< Type > integer()
Return a static integer type.
StorageType storage_type_
The raw storage type of the literal node.
std::optional< Graph * > parent_
An optional parent Graph to which this Object belongs. Initially no value.