Cerata
A library to generate structural hardware designs
domain.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 <memory>
18 #include <string>
19 #include <utility>
20 
21 #include "cerata/utils.h"
22 
23 namespace cerata {
24 
25 class Node;
26 
32 struct ClockDomain : public Named {
34  explicit ClockDomain(std::string name);
36  static std::shared_ptr<ClockDomain> Make(const std::string &name) { return std::make_shared<ClockDomain>(name); }
37  // TODO(johanpel): add other properties
38 };
39 
41 std::shared_ptr<ClockDomain> default_domain();
42 
46 class Synchronous {
47  public:
49  explicit Synchronous(std::shared_ptr<ClockDomain> domain) : domain_(std::move(domain)) {}
51  [[nodiscard]] std::shared_ptr<ClockDomain> domain() const { return domain_; }
53  void SetDomain(std::shared_ptr<ClockDomain> domain) { domain_ = std::move(domain); }
54  protected:
56  std::shared_ptr<ClockDomain> domain_;
57 };
58 
60 std::optional<std::shared_ptr<ClockDomain>> GetDomain(const Node& node);
61 
62 } // namespace cerata
cerata::GetDomain
std::optional< std::shared_ptr< ClockDomain > > GetDomain(const Node &node)
Return the clock domain of a node, if it is a synchronous node.
Definition: domain.cc:33
cerata::Synchronous::SetDomain
void SetDomain(std::shared_ptr< ClockDomain > domain)
Set the clock domain to which something should be synchronized.
Definition: domain.h:53
cerata
Contains every Cerata class, function, etc...
Definition: api.h:41
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::Synchronous::Synchronous
Synchronous(std::shared_ptr< ClockDomain > domain)
Synchronous constructor.
Definition: domain.h:49
cerata::Named::name
std::string name() const
Return the name of the object.
Definition: utils.h:45
cerata::Synchronous::domain_
std::shared_ptr< ClockDomain > domain_
The clock domain.
Definition: domain.h:56
cerata::ClockDomain
A clock domain.
Definition: domain.h:32
cerata::Named
Convenience structure for anything that is named. Names are case-sensitive.
Definition: utils.h:40
cerata::ClockDomain::Make
static std::shared_ptr< ClockDomain > Make(const std::string &name)
Create a new clock domain and return a shared pointer to it.
Definition: domain.h:36
cerata::default_domain
std::shared_ptr< ClockDomain > default_domain()
Return a static default clock domain.
Definition: domain.cc:28
cerata::Synchronous::domain
std::shared_ptr< ClockDomain > domain() const
Return the clock domain to which something is synchronized.
Definition: domain.h:51
cerata::ClockDomain::ClockDomain
ClockDomain(std::string name)
Clock domain constructor.
Definition: domain.cc:26