Cerata
A library to generate structural hardware designs
port.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 
20 #include "cerata/node.h"
21 
22 namespace cerata {
23 
27 class Term {
28  public:
30  enum Dir { IN, OUT };
31 
33  static Dir Reverse(Dir dir);
34 
36  [[nodiscard]] inline Dir dir() const { return dir_; }
37 
39  explicit Term(Dir dir) : dir_(dir) {}
40 
42  inline bool IsInput() { return dir_ == IN; }
44  inline bool IsOutput() { return dir_ == OUT; }
45 
47  static std::string str(Dir dir);
48 
49  protected:
52 };
53 
57 class Port : public NormalNode, public Synchronous, public Term {
58  public:
60  Port(std::string name, std::shared_ptr<Type> type, Term::Dir dir, std::shared_ptr<ClockDomain> domain);
62  std::shared_ptr<Object> Copy() const override;
64  Port &Reverse();
65 
66  std::string ToString() const override;
67 };
68 
70 std::shared_ptr<Port> port(const std::string &name,
71  const std::shared_ptr<Type> &type,
72  Term::Dir dir,
73  const std::shared_ptr<ClockDomain> &domain = default_domain());
75 std::shared_ptr<Port> port(const std::shared_ptr<Type> &type,
76  Term::Dir dir,
77  const std::shared_ptr<ClockDomain> &domain = default_domain());
78 
79 } // namespace cerata
cerata::Port::Copy
std::shared_ptr< Object > Copy() const override
Deep-copy the port.
Definition: port.cc:35
cerata::Port::Reverse
Port & Reverse()
Invert the direction of this port. Removes any edges.
Definition: port.cc:44
cerata::Term
A terminator structure to enable terminator sanity checks.
Definition: port.h:27
cerata::Term::str
static std::string str(Dir dir)
Convert a Dir to a human-readable string.
Definition: port.cc:56
cerata::Term::dir
Dir dir() const
Return the direction of this terminator.
Definition: port.h:36
cerata
Contains every Cerata class, function, etc...
Definition: api.h:41
cerata::Term::Dir
Dir
Terminator direction.
Definition: port.h:30
cerata::Term::Term
Term(Dir dir)
Construct a new Term.
Definition: port.h:39
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::NormalNode
A single-input, multiple-outputs node.
Definition: node.h:167
cerata::Port::ToString
std::string ToString() const override
Return a human-readable string of this node.
Definition: port.cc:52
cerata::Term::Reverse
static Dir Reverse(Dir dir)
Return the inverse of a direction.
Definition: port.cc:64
cerata::Port::Port
Port(std::string name, std::shared_ptr< Type > type, Term::Dir dir, std::shared_ptr< ClockDomain > domain)
Construct a new port.
Definition: port.cc:41
cerata::Term::IsOutput
bool IsOutput()
Return true if this Term is an output, false otherwise.
Definition: port.h:44
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::Term::dir_
Dir dir_
The direction of this terminator.
Definition: port.h:51
cerata::Port
A port is a terminator node on a graph.
Definition: port.h:57
cerata::Term::IsInput
bool IsInput()
Return true if this Term is an input, false otherwise.
Definition: port.h:42
cerata::port
std::shared_ptr< Port > port(const std::string &name, const std::shared_ptr< Type > &type, Term::Dir dir, const std::shared_ptr< ClockDomain > &domain)
Make a new port with some name, type and direction.
Definition: port.cc:22
cerata::Node::type
Type * type() const
Return the node Type.
Definition: node.h:57