Cerata
A library to generate structural hardware designs
signal.cc
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 #include <string>
16 #include <memory>
17 #include <utility>
18 
19 #include "cerata/signal.h"
20 
21 namespace cerata {
22 
23 Signal::Signal(std::string name, std::shared_ptr<Type> type, std::shared_ptr<ClockDomain> domain)
24  : NormalNode(std::move(name), Node::NodeID::SIGNAL, std::move(type)), Synchronous(std::move(domain)) {}
25 
26 std::shared_ptr<Object> Signal::Copy() const {
27  auto result = signal(this->name(), this->type_, this->domain_);
28  result->meta = this->meta;
29  return result;
30 }
31 
32 std::string Signal::ToString() const {
33  return name() + ":" + type()->name();
34 }
35 
36 std::shared_ptr<Signal> signal(const std::string &name,
37  const std::shared_ptr<Type> &type,
38  const std::shared_ptr<ClockDomain> &domain) {
39  auto ret = std::make_shared<Signal>(name, type, domain);
40  return ret;
41 }
42 
43 std::shared_ptr<Signal> signal(const std::shared_ptr<Type> &type, const std::shared_ptr<ClockDomain> &domain) {
44  auto ret = std::make_shared<Signal>(type->name() + "_signal", type, domain);
45  return ret;
46 }
47 
48 } // namespace cerata
cerata::Signal::ToString
std::string ToString() const override
Return a human-readable string of this node.
Definition: signal.cc:32
cerata::Object::meta
std::unordered_map< std::string, std::string > meta
KV storage for metadata of tools or specific backend implementations.
Definition: object.h:67
cerata::Signal::Signal
Signal(std::string name, std::shared_ptr< Type > type, std::shared_ptr< ClockDomain > domain=default_domain())
Signal constructor.
Definition: signal.cc:23
cerata::Signal::Copy
std::shared_ptr< Object > Copy() const override
Create a copy of this Signal.
Definition: signal.cc:26
cerata
Contains every Cerata class, function, etc...
Definition: api.h:41
cerata::Node::type_
std::shared_ptr< Type > type_
The Type of this Node.
Definition: node.h:126
cerata::Node
A node.
Definition: node.h:42
cerata::Synchronous
Class to mark nodes with information for synchronous designs, e.g. clock domain.
Definition: domain.h:46
cerata::Named::name
std::string name() const
Return the name of the object.
Definition: utils.h:45
cerata::Node::NodeID
NodeID
Node type IDs with different properties.
Definition: node.h:45
cerata::Synchronous::domain_
std::shared_ptr< ClockDomain > domain_
The clock domain.
Definition: domain.h:56
cerata::NormalNode
A single-input, multiple-outputs node.
Definition: node.h:167
cerata::signal
std::shared_ptr< Signal > signal(const std::string &name, const std::shared_ptr< Type > &type, const std::shared_ptr< ClockDomain > &domain)
Create a new Signal and return a smart pointer to it.
Definition: signal.cc:36
cerata::Node::type
Type * type() const
Return the node Type.
Definition: node.h:57