Cerata
A library to generate structural hardware designs
stream.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/type.h"
22 
23 namespace cerata {
24 
26 class Stream : public Record {
27  public:
29  static std::shared_ptr<Type> valid();
31  static std::shared_ptr<Type> ready();
32 
34  Stream(const std::string &name,
35  const std::string &element_name,
36  const std::shared_ptr<Type> &element_type,
37  const std::vector<std::shared_ptr<Field>> &control);
38 
40  Field *data() { return this->fields_.back().get(); }
41 
43  Stream &SetElementType(std::shared_ptr<Type> type);
44 };
45 
58 std::shared_ptr<Stream> stream(const std::string &name,
59  const std::string &element_name,
60  const std::shared_ptr<Type> &element_type,
61  const std::vector<std::shared_ptr<Field>> &control =
62  {field(Stream::valid()),
63  field(Stream::ready())->Reverse()});
64 
71 std::shared_ptr<Stream> stream(const std::string &element_name, const std::shared_ptr<Type> &element_type);
72 
78 std::shared_ptr<Stream> stream(const std::shared_ptr<Type> &element_type);
79 
80 } // namespace cerata
cerata::Record::fields_
std::vector< std::shared_ptr< Field > > fields_
The fields of this Record.
Definition: type.h:339
cerata::field
std::shared_ptr< Field > field(const std::string &name, const std::shared_ptr< Type > &type, bool reverse, bool sep)
Create a new RecordField, and return a shared pointer to it.
Definition: type.cc:273
cerata::Stream::ready
static std::shared_ptr< Type > ready()
Return a 'ready' bit type.
Definition: stream.cc:52
cerata::Stream::SetElementType
Stream & SetElementType(std::shared_ptr< Type > type)
Set the element type of this stream.
Definition: stream.cc:23
cerata::Field
A Record field.
Definition: type.h:256
cerata::Record
A Record type containing zero or more fields.
Definition: type.h:301
cerata
Contains every Cerata class, function, etc...
Definition: api.h:41
cerata::Named::name
std::string name() const
Return the name of the object.
Definition: utils.h:45
cerata::Stream::data
Field * data()
Return the stream data field.
Definition: stream.h:40
cerata::Stream::valid
static std::shared_ptr< Type > valid()
Return a 'valid' bit type.
Definition: stream.cc:47
cerata::Stream
A Stream type.
Definition: stream.h:26
cerata::stream
std::shared_ptr< Stream > stream(const std::string &name, const std::string &element_name, const std::shared_ptr< Type > &element_type, const std::vector< std::shared_ptr< Field >> &control)
Construct a new Stream type and return a shared pointer to it.
Definition: stream.cc:57
cerata::Stream::Stream
Stream(const std::string &name, const std::string &element_name, const std::shared_ptr< Type > &element_type, const std::vector< std::shared_ptr< Field >> &control)
Stream constructor.
Definition: stream.cc:36