OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
HDLGenerator::Generatable Class Reference

#include <Generatable.hh>

Inheritance diagram for HDLGenerator::Generatable:
Inheritance graph
Collaboration diagram for HDLGenerator::Generatable:
Collaboration graph

Public Member Functions

 Generatable (std::string name)
 
virtual ~Generatable ()=default
 
virtual void build ()
 
virtual void reads (const std::string &var)
 
virtual void reads (const LHSValue &var)
 
virtual void writes (const std::string &var)
 
virtual RegistergetRegister (const std::string &var)
 
virtual bool hasOption (const std::string &var)
 
virtual bool isRegister (const std::string &name)
 
virtual bool isVariable (const std::string &name)
 
virtual bool isConstant (const std::string &name)
 
virtual Width width (const std::string &name)
 
int integerWidth (const std::string &name)
 
virtual WireType wireType (const std::string &name)
 
virtual Width width ()
 
virtual WireType wireType () const
 
virtual void hdl (std::ostream &stream, Language lang, int indent)
 
virtual void hdl (std::ostream &stream, Language lang)
 
virtual void implementAll (std::ostream &stream, Language lang)
 
virtual void implementAll (std::ostream &stream, Language lang, int indent)
 
template<typename Func >
void forAll (Func func)
 
template<typename Type , typename Func >
void forAll (Func func)
 
template<class Type >
bool parentIs ()
 
template<class Type >
Type * parentType ()
 
void pushComponent (std::shared_ptr< Generatable > c)
 
template<class Component >
void addComponent (Component c)
 
const std::string & name () const noexcept
 
void setParent (Generatable *parent) noexcept
 
Generatableparent () const noexcept
 

Private Attributes

std::string name_
 
Generatableparent_
 
std::vector< std::shared_ptr< Generatable > > components_
 

Detailed Description

Base class for all generatable classes.

Definition at line 51 of file Generatable.hh.

Constructor & Destructor Documentation

◆ Generatable()

HDLGenerator::Generatable::Generatable ( std::string  name)
inline

Definition at line 53 of file Generatable.hh.

53: name_(name), parent_(nullptr) {}
const std::string & name() const noexcept

◆ ~Generatable()

virtual HDLGenerator::Generatable::~Generatable ( )
virtualdefault

Member Function Documentation

◆ addComponent()

template<class Component >
void HDLGenerator::Generatable::addComponent ( Component  c)
inline

◆ build()

virtual void HDLGenerator::Generatable::build ( )
inlinevirtual

Reimplemented in HDLGenerator::Module, HDLGenerator::HDLOperation, HDLGenerator::Assign, HDLGenerator::Switch, HDLGenerator::If, HDLGenerator::Asynchronous, and HDLGenerator::Synchronous.

Definition at line 56 of file Generatable.hh.

56 {
57 forAll([this](std::shared_ptr<Generatable> c) {
58 c->setParent(this);
59 c->build();
60 });
61 }

References forAll().

Referenced by HDLGenerator::HDLOperation::build(), HDLGenerator::Assign::build(), HDLGenerator::Switch::build(), HDLGenerator::If::build(), HDLGenerator::Asynchronous::build(), and HDLGenerator::Synchronous::build().

Here is the call graph for this function:

◆ forAll() [1/2]

template<typename Func >
void HDLGenerator::Generatable::forAll ( Func  func)
inline

Definition at line 195 of file Generatable.hh.

195 {
196 for (auto&& c : components_) {
197 func(c);
198 }
199 }

References components_.

Referenced by HDLGenerator::Behaviour::behaviour(), build(), implementAll(), and implementAll().

◆ forAll() [2/2]

template<typename Type , typename Func >
void HDLGenerator::Generatable::forAll ( Func  func)
inline

Definition at line 201 of file Generatable.hh.

201 {
202 for (auto&& c : components_) {
203 Type* ptr = dynamic_cast<Type*>(c.get());
204 if (ptr != nullptr)
205 func(ptr);
206 }
207 }

References components_.

◆ getRegister()

virtual Register & HDLGenerator::Generatable::getRegister ( const std::string &  var)
inlinevirtual

Reimplemented in HDLGenerator::Module.

Definition at line 89 of file Generatable.hh.

89 {
90 if (parent() == nullptr) {
91 std::string err =
92 std::string("Couldn't find parent for ") + name();
93 throw std::runtime_error(err.c_str());
94 }
95 return parent()->getRegister(var);
96 }
virtual Register & getRegister(const std::string &var)
Generatable * parent() const noexcept

References getRegister(), name(), and parent().

Referenced by getRegister(), HDLGenerator::Synchronous::hdl(), and HDLGenerator::Synchronous::vhdlReset().

Here is the call graph for this function:

◆ hasOption()

virtual bool HDLGenerator::Generatable::hasOption ( const std::string &  var)
inlinevirtual

Reimplemented in HDLGenerator::Module.

Definition at line 98 of file Generatable.hh.

98 {
99 if (parent() == nullptr) {
100 std::string err =
101 std::string("Couldn't find parent for ") + name();
102 throw std::runtime_error(err.c_str());
103 }
104 return parent()->hasOption(var);
105 }
virtual bool hasOption(const std::string &var)

References hasOption(), name(), and parent().

Referenced by hasOption(), HDLGenerator::Synchronous::hdl(), and HDLGenerator::Synchronous::vhdlReset().

Here is the call graph for this function:

◆ hdl() [1/2]

virtual void HDLGenerator::Generatable::hdl ( std::ostream &  stream,
Language  lang 
)
inlinevirtual

Definition at line 178 of file Generatable.hh.

178 {
179 (void)lang;
180 stream << name();
181 }

References name().

Here is the call graph for this function:

◆ hdl() [2/2]

virtual void HDLGenerator::Generatable::hdl ( std::ostream &  stream,
Language  lang,
int  indent 
)
inlinevirtual

Reimplemented in HDLGenerator::SequentialStatement, HDLGenerator::RawCodeLine, HDLGenerator::NewLine, HDLGenerator::HDLOperation, HDLGenerator::DefaultAssign, HDLGenerator::Assign, HDLGenerator::DefaultCase, HDLGenerator::Case, HDLGenerator::Switch, HDLGenerator::If, HDLGenerator::CodeBlock, HDLGenerator::Asynchronous, and HDLGenerator::Synchronous.

Definition at line 170 of file Generatable.hh.

170 {
171 (void)stream;
172 (void)lang;
173 (void)indent;
174 std::string err = std::string("Attempted to generate ") + name_;
175 throw std::runtime_error(err);
176 }

References name_.

◆ implementAll() [1/2]

virtual void HDLGenerator::Generatable::implementAll ( std::ostream &  stream,
Language  lang 
)
inlinevirtual

Definition at line 183 of file Generatable.hh.

183 {
184 forAll([&](
185 std::shared_ptr<Generatable> c) { c->hdl(stream, lang); });
186 }

References forAll().

Referenced by HDLGenerator::DefaultCase::hdl(), HDLGenerator::Case::hdl(), HDLGenerator::Switch::hdl(), HDLGenerator::CodeBlock::hdl(), HDLGenerator::Asynchronous::hdl(), and HDLGenerator::Synchronous::hdl().

Here is the call graph for this function:

◆ implementAll() [2/2]

virtual void HDLGenerator::Generatable::implementAll ( std::ostream &  stream,
Language  lang,
int  indent 
)
inlinevirtual

Definition at line 189 of file Generatable.hh.

189 {
190 forAll([&](std::shared_ptr<Generatable> c) {
191 c->hdl(stream, lang, indent);
192 });
193 }

References forAll().

Here is the call graph for this function:

◆ integerWidth()

int HDLGenerator::Generatable::integerWidth ( const std::string &  name)
inline

Definition at line 143 of file Generatable.hh.

143 {
144 int intWidth = width(name).intWidth;
145 if (intWidth == -1) {
146 std::string err = name_
147 + std::string(" does not have an integer width value.");
148 throw std::runtime_error(err.c_str());
149 }
150 return intWidth;
151 }

References HDLGenerator::Width::intWidth, name(), name_, and width().

Here is the call graph for this function:

◆ isConstant()

virtual bool HDLGenerator::Generatable::isConstant ( const std::string &  name)
inlinevirtual

Reimplemented in HDLGenerator::Module.

Definition at line 125 of file Generatable.hh.

125 {
126 if (parent() == nullptr) {
127 std::string err =
128 std::string("Couldn't find parent for ") + name_;
129 throw std::runtime_error(err.c_str());
130 }
131 return parent()->isConstant(name);
132 }
virtual bool isConstant(const std::string &name)

References isConstant(), name(), name_, and parent().

Referenced by HDLGenerator::Asynchronous::hdl(), and isConstant().

Here is the call graph for this function:

◆ isRegister()

virtual bool HDLGenerator::Generatable::isRegister ( const std::string &  name)
inlinevirtual

Reimplemented in HDLGenerator::Module.

Definition at line 107 of file Generatable.hh.

107 {
108 if (parent() == nullptr) {
109 std::string err =
110 std::string("Couldn't find parent for ") + name_;
111 throw std::runtime_error(err.c_str());
112 }
113 return parent()->isRegister(name);
114 }
virtual bool isRegister(const std::string &name)

References isRegister(), name(), name_, and parent().

Referenced by HDLGenerator::Synchronous::build(), HDLGenerator::Assign::hdl(), isRegister(), and HDLGenerator::Synchronous::writes().

Here is the call graph for this function:

◆ isVariable()

virtual bool HDLGenerator::Generatable::isVariable ( const std::string &  name)
inlinevirtual

Reimplemented in HDLGenerator::Module.

Definition at line 116 of file Generatable.hh.

116 {
117 if (parent() == nullptr) {
118 std::string err =
119 std::string("Couldn't find parent for ") + name_;
120 throw std::runtime_error(err.c_str());
121 }
122 return parent()->isVariable(name);
123 }
virtual bool isVariable(const std::string &name)

References isVariable(), name(), name_, and parent().

Referenced by HDLGenerator::DefaultAssign::hdl(), HDLGenerator::Assign::hdl(), isVariable(), and HDLGenerator::Synchronous::writes().

Here is the call graph for this function:

◆ name()

const std::string & HDLGenerator::Generatable::name ( ) const
inlinenoexcept

◆ parent()

Generatable * HDLGenerator::Generatable::parent ( ) const
inlinenoexcept

◆ parentIs()

template<class Type >
bool HDLGenerator::Generatable::parentIs ( )
inline

Definition at line 209 of file Generatable.hh.

209 {
210 if (parent() == nullptr) {
211 return false;
212 } else if (dynamic_cast<Type*>(parent()) != nullptr) {
213 return true;
214 } else {
215 return parent()->parentIs<Type>();
216 }
217 }

References parent(), and parentIs().

Referenced by parentIs().

Here is the call graph for this function:

◆ parentType()

template<class Type >
Type * HDLGenerator::Generatable::parentType ( )
inline

Definition at line 219 of file Generatable.hh.

219 {
220 if (parent() == nullptr) {
221 throw std::runtime_error("Couldn't find parent'");
222 } else if (dynamic_cast<Type*>(parent()) != nullptr) {
223 return dynamic_cast<Type*>(parent());
224 } else {
225 return parent()->parentType<Type>();
226 }
227 }

References parent(), and parentType().

Referenced by parentType().

Here is the call graph for this function:

◆ pushComponent()

void HDLGenerator::Generatable::pushComponent ( std::shared_ptr< Generatable c)
inline

◆ reads() [1/2]

virtual void HDLGenerator::Generatable::reads ( const LHSValue var)
inlinevirtual

Definition at line 72 of file Generatable.hh.

72 {
73 std::unordered_set<std::string> readList;
74 var.writeSignals(readList);
75 for (auto&& r : readList) {
76 reads(r);
77 }
78 }
virtual void reads(const std::string &var)

References reads(), and HDLGenerator::LHSValue::writeSignals().

Here is the call graph for this function:

◆ reads() [2/2]

virtual void HDLGenerator::Generatable::reads ( const std::string &  var)
inlinevirtual

Reimplemented in HDLGenerator::Module, and HDLGenerator::Asynchronous.

Definition at line 63 of file Generatable.hh.

63 {
64 if (parent() == nullptr) {
65 std::string err =
66 std::string("Couldn't find parent for ") + name();
67 throw std::runtime_error(err.c_str());
68 }
69 parent()->reads(var);
70 }

References name(), parent(), and reads().

Referenced by HDLGenerator::HDLOperation::build(), HDLGenerator::Assign::build(), HDLGenerator::Switch::build(), HDLGenerator::If::build(), reads(), reads(), and HDLGenerator::Asynchronous::reads().

Here is the call graph for this function:

◆ setParent()

void HDLGenerator::Generatable::setParent ( Generatable parent)
inlinenoexcept

Definition at line 241 of file Generatable.hh.

241{ parent_ = parent; }

References parent(), and parent_.

Here is the call graph for this function:

◆ width() [1/2]

virtual Width HDLGenerator::Generatable::width ( )
inlinevirtual

Reimplemented in HDLGenerator::Parameter, HDLGenerator::BinaryConstant, HDLGenerator::IntegerConstant, HDLGenerator::Wire, and HDLGenerator::Variable.

Definition at line 162 of file Generatable.hh.

162 {
163 throw std::runtime_error("Shouldn't be here!");
164 }

Referenced by HDLGenerator::DefaultAssign::hdl(), and integerWidth().

◆ width() [2/2]

virtual Width HDLGenerator::Generatable::width ( const std::string &  name)
inlinevirtual

Reimplemented in HDLGenerator::Module.

Definition at line 134 of file Generatable.hh.

134 {
135 if (parent() == nullptr) {
136 std::string err =
137 std::string("Couldn't find parent for ") + name_;
138 throw std::runtime_error(err.c_str());
139 }
140 return parent()->width(name);
141 }
virtual Width width(const std::string &name)

References name(), name_, parent(), and width().

Referenced by width().

Here is the call graph for this function:

◆ wireType() [1/2]

virtual WireType HDLGenerator::Generatable::wireType ( ) const
inlinevirtual

Reimplemented in HDLGenerator::Wire.

Definition at line 166 of file Generatable.hh.

166 {
167 throw std::runtime_error("Shouldn't be here!");
168 }

Referenced by HDLGenerator::DefaultAssign::hdl().

◆ wireType() [2/2]

virtual WireType HDLGenerator::Generatable::wireType ( const std::string &  name)
inlinevirtual

Reimplemented in HDLGenerator::Module.

Definition at line 153 of file Generatable.hh.

153 {
154 if (parent() == nullptr) {
155 std::string err =
156 std::string("Couldn't find parent for ") + name_;
157 throw std::runtime_error(err.c_str());
158 }
159 return parent()->wireType(name);
160 }
virtual WireType wireType(const std::string &name)

References name(), name_, parent(), and wireType().

Referenced by wireType().

Here is the call graph for this function:

◆ writes()

virtual void HDLGenerator::Generatable::writes ( const std::string &  var)
inlinevirtual

Reimplemented in HDLGenerator::Module, and HDLGenerator::Synchronous.

Definition at line 80 of file Generatable.hh.

80 {
81 if (parent() == nullptr) {
82 std::string err =
83 std::string("Couldn't find parent for ") + name();
84 throw std::runtime_error(err.c_str());
85 }
86 parent()->writes(var);
87 }
virtual void writes(const std::string &var)

References name(), parent(), and writes().

Referenced by HDLGenerator::Assign::build(), and writes().

Here is the call graph for this function:

Member Data Documentation

◆ components_

std::vector<std::shared_ptr<Generatable> > HDLGenerator::Generatable::components_
private

Definition at line 247 of file Generatable.hh.

Referenced by addComponent(), forAll(), and pushComponent().

◆ name_

std::string HDLGenerator::Generatable::name_
private

Definition at line 245 of file Generatable.hh.

Referenced by hdl(), integerWidth(), isConstant(), isRegister(), isVariable(), name(), width(), and wireType().

◆ parent_

Generatable* HDLGenerator::Generatable::parent_
private

Definition at line 246 of file Generatable.hh.

Referenced by parent(), and setParent().


The documentation for this class was generated from the following file: