Cerata
A library to generate structural hardware designs
vhdl_types.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 "cerata/vhdl/vhdl_types.h"
16 
17 #include <memory>
18 #include <vector>
19 
20 #include "cerata/vhdl/vhdl.h"
21 #include "cerata/type.h"
22 
23 namespace cerata::vhdl {
24 
25 std::shared_ptr<Type> valid() {
26  static std::shared_ptr<Type> result = std::make_shared<Bit>("valid");
27  result->meta[meta::EXPAND_TYPE] = "valid";
28  return result;
29 }
30 
31 std::shared_ptr<Type> ready() {
32  static std::shared_ptr<Type> result = std::make_shared<Bit>("ready");
33  result->meta[meta::EXPAND_TYPE] = "ready";
34  return result;
35 }
36 
37 std::string ToString(Port::Dir dir) {
38  if (dir == Port::Dir::IN) {
39  return "in";
40  } else {
41  return "out";
42  }
43 }
44 
46  if (dir == Port::Dir::IN) {
47  return Port::Dir::OUT;
48  } else {
49  return Port::Dir::IN;
50  }
51 }
52 
53 std::vector<FlatType> FilterForVHDL(const std::vector<FlatType> &list) {
54  std::vector<FlatType> result;
55  for (const auto &ft : list) {
56  // Only keep types that are not abstract, or boolean.
57  if (ft.type_->IsPhysical() || ft.type_->Is(Type::BOOLEAN)) {
58  if (!ft.type_->Is(Type::ID::RECORD)) {
59  result.push_back(ft);
60  }
61  }
62  }
63  return result;
64 }
65 
66 std::string Range::ToString() {
67  if (type == SINGLE) {
68  return "(" + bottom + ")";
69  } else if (type == MULTI) {
70  return "(" + top + " downto " + bottom + ")";
71  } else {
72  return "";
73  }
74 }
75 } // namespace cerata::vhdl
cerata::vhdl::Range::top
std::string top
Top of the range.
Definition: vhdl_types.h:65
cerata::Type::BOOLEAN
@ BOOLEAN
No | No | No.
Definition: type.h:75
cerata::vhdl::ready
std::shared_ptr< Type > ready()
A stream ready-valid handshake "ready" signal.
Definition: vhdl_types.cc:31
cerata::vhdl::valid
std::shared_ptr< Type > valid()
A stream ready-valid handshake "valid" signal.
Definition: vhdl_types.cc:25
cerata::Term::Dir
Dir
Terminator direction.
Definition: port.h:30
cerata::vhdl::Range::type
enum cerata::vhdl::Range::@0 type
Range types.
cerata::vhdl::FilterForVHDL
std::vector< FlatType > FilterForVHDL(const std::vector< FlatType > &list)
Filter abstract types from a list of flattened types.
Definition: vhdl_types.cc:53
cerata::vhdl::Range::SINGLE
@ SINGLE
For range of size 1.
Definition: vhdl_types.h:58
cerata::vhdl::Range::bottom
std::string bottom
Bottom of the range.
Definition: vhdl_types.h:63
cerata::vhdl::Range::MULTI
@ MULTI
For a range of size > 1.
Definition: vhdl_types.h:59
cerata::vhdl::ToString
std::string ToString(const std::vector< Block > &blocks)
Return a vector of blocks as a single string.
Definition: block.cc:186
cerata::vhdl::Reverse
Port::Dir Reverse(Port::Dir dir)
Reverse a terminator direction.
Definition: vhdl_types.cc:45
cerata::vhdl::Range::ToString
std::string ToString()
Return a human-readable version of the range.
Definition: vhdl_types.cc:66
cerata::vhdl
Contains everything related to the VHDL back-end.
Definition: architecture.cc:31