Cerata
A library to generate structural hardware designs
parameter.h
1 // Copyright 2018-2019 Delft University of Technology
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <vector>
18 #include <string>
19 #include <memory>
20 
21 #include "cerata/node.h"
22 
23 namespace cerata {
29 class Parameter : public NormalNode {
30  public:
32  Parameter(std::string name, const std::shared_ptr<Type> &type, std::shared_ptr<Literal> default_value);
34  std::shared_ptr<Object> Copy() const override;
36  Node *value() const;
38  Parameter *SetValue(const std::shared_ptr<Node> &value);
40  void TraceValue(std::vector<Node *> *trace);
42  Literal *default_value() { return default_value_.get(); }
43 
44  // TODO(johanpel): Work-around for parameters nodes that are size nodes of arrays.
45  // To prevent this, it requires a restructuring of node arrays.
47  std::optional<NodeArray *> node_array_parent;
48 
50  std::shared_ptr<Literal> default_value_;
51 };
52 
63 std::shared_ptr<Parameter> parameter(const std::string &name,
64  const std::shared_ptr<Type> &type,
65  std::shared_ptr<Literal> default_value = nullptr);
66 
68 std::shared_ptr<Parameter> parameter(const std::string &name, int default_value);
69 
71 std::shared_ptr<Parameter> parameter(const std::string &name);
72 
74 std::shared_ptr<Parameter> parameter(const std::string &name, bool default_value);
75 
77 std::shared_ptr<Parameter> parameter(const std::string &name, std::string default_value);
78 
79 } // namespace cerata
cerata::Parameter::TraceValue
void TraceValue(std::vector< Node * > *trace)
Append this node and nodes that source this node's value, until an expression or literal is encounter...
Definition: parameter.cc:91
cerata::Literal
A Literal Node.
Definition: literal.h:36
cerata::Parameter::value
Node * value() const
Return the value node.
Definition: parameter.cc:68
cerata::Parameter::node_array_parent
std::optional< NodeArray * > node_array_parent
If this parametrizes a node array, this stores a pointer to the NodeArray.
Definition: parameter.h:47
cerata
Contains every Cerata class, function, etc...
Definition: api.h:41
cerata::Parameter::default_value_
std::shared_ptr< Literal > default_value_
Parameter value.
Definition: parameter.h:50
cerata::Node
A node.
Definition: node.h:42
cerata::Parameter::SetValue
Parameter * SetValue(const std::shared_ptr< Node > &value)
Set the value of the parameter node. Can only be expression, parameter, or literal.
Definition: parameter.cc:76
cerata::Named::name
std::string name() const
Return the name of the object.
Definition: utils.h:45
cerata::Parameter::Parameter
Parameter(std::string name, const std::shared_ptr< Type > &type, std::shared_ptr< Literal > default_value)
Construct a new Parameter, optionally defining a default value Literal.
Definition: parameter.cc:27
cerata::NormalNode
A single-input, multiple-outputs node.
Definition: node.h:167
cerata::Parameter::Copy
std::shared_ptr< Object > Copy() const override
Create a copy of this Parameter.
Definition: parameter.cc:85
cerata::Parameter
A Parameter node.
Definition: parameter.h:29
cerata::Parameter::default_value
Literal * default_value()
Return the default value node.
Definition: parameter.h:42
cerata::parameter
std::shared_ptr< Parameter > parameter(const std::string &name, const std::shared_ptr< Type > &type, std::shared_ptr< Literal > default_value)
Create a new parameter.
Definition: parameter.cc:45
cerata::Node::type
Type * type() const
Return the node Type.
Definition: node.h:57