OpenASIP  2.0
Public Member Functions | Private Attributes | List of all members
HDLGenerator::DefaultAssign Class Reference

#include <HDLGenerator.hh>

Inheritance diagram for HDLGenerator::DefaultAssign:
Inheritance graph
Collaboration diagram for HDLGenerator::DefaultAssign:
Collaboration graph

Public Member Functions

 DefaultAssign (std::string name, std::string value)
 
 DefaultAssign (std::string name)
 
void hdl (std::ostream &stream, Language lang, int level) override
 
- Public Member Functions inherited from HDLGenerator::SequentialStatement
 SequentialStatement (std::string name)
 
- Public Member Functions inherited from HDLGenerator::Generatable
 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)
 
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 value_
 
bool dontCare_
 

Detailed Description

Assign default value.

Definition at line 366 of file HDLGenerator.hh.

Constructor & Destructor Documentation

◆ DefaultAssign() [1/2]

HDLGenerator::DefaultAssign::DefaultAssign ( std::string  name,
std::string  value 
)
inline

Definition at line 368 of file HDLGenerator.hh.

369  : SequentialStatement(name), value_(value), dontCare_(false) {}

◆ DefaultAssign() [2/2]

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

Definition at line 370 of file HDLGenerator.hh.

371  : SequentialStatement(name), value_(""), dontCare_(true) {}

Member Function Documentation

◆ hdl()

void HDLGenerator::DefaultAssign::hdl ( std::ostream &  stream,
Language  lang,
int  level 
)
inlineoverridevirtual

Reimplemented from HDLGenerator::SequentialStatement.

Definition at line 373 of file HDLGenerator.hh.

373  {
374  Width w = width(name());
375  WireType t = wireType(name());
376 
377 
378  if (lang == Language::VHDL) {
379  std::string def = "-";
380  if (!dontCare_)
381  def = value_.substr(0, 1);
382 
383  std::string assign = " <= ";
384  if (isVariable(name())) {
385  assign = " := ";
386  }
387  stream << StringTools::indent(level) << name() << assign;
388 
389  if (w.strWidth.empty() && w.intWidth == 1) {
390  char delim = t == WireType::Auto ? '\'' : '"';
391  stream << delim << def << delim << ";\n";
392  } else {
393  stream << "(others => '" << def << "');\n";
394  }
395  } else if (lang == Language::Verilog) {
396  std::string def = "x";
397  if (!dontCare_)
398  def = value_.substr(0, 1);
399 
400  stream << StringTools::indent(level)
401  << name() << " = 'b" << def << ";\n";
402  } else {
403  throw std::runtime_error(__PRETTY_FUNCTION__);
404  }
405  }

References HDLGenerator::Auto, dontCare_, StringTools::indent(), HDLGenerator::Width::intWidth, HDLGenerator::Generatable::isVariable(), HDLGenerator::Generatable::name(), HDLGenerator::Width::strWidth, value_, HDLGenerator::Verilog, HDLGenerator::VHDL, HDLGenerator::Generatable::width(), and HDLGenerator::Generatable::wireType().

Here is the call graph for this function:

Member Data Documentation

◆ dontCare_

bool HDLGenerator::DefaultAssign::dontCare_
private

Definition at line 409 of file HDLGenerator.hh.

Referenced by hdl().

◆ value_

std::string HDLGenerator::DefaultAssign::value_
private

Definition at line 408 of file HDLGenerator.hh.

Referenced by hdl().


The documentation for this class was generated from the following file:
StringTools::indent
static std::string indent(int level)
Definition: StringTools.cc:319
HDLGenerator::DefaultAssign::dontCare_
bool dontCare_
Definition: HDLGenerator.hh:409
HDLGenerator::DefaultAssign::value_
std::string value_
Definition: HDLGenerator.hh:408
HDLGenerator::WireType
WireType
Definition: HWGenTools.hh:34
HDLGenerator::Language::Verilog
@ Verilog
HDLGenerator::SequentialStatement::SequentialStatement
SequentialStatement(std::string name)
Definition: HDLGenerator.hh:123
HDLGenerator::Generatable::width
virtual Width width()
Definition: Generatable.hh:162
HDLGenerator::Generatable::isVariable
virtual bool isVariable(const std::string &name)
Definition: Generatable.hh:116
HDLGenerator::WireType::Auto
@ Auto
HDLGenerator::Generatable::name
const std::string & name() const noexcept
Definition: Generatable.hh:239
HDLGenerator::Generatable::wireType
virtual WireType wireType() const
Definition: Generatable.hh:166
HDLGenerator::Language::VHDL
@ VHDL