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

#include <HDLGenerator.hh>

Inheritance diagram for HDLGenerator::Variable:
Inheritance graph
Collaboration diagram for HDLGenerator::Variable:
Collaboration graph

Public Member Functions

 Variable (std::string name, int width=1)
 
 Variable (std::string name, std::string width)
 
Width width () final
 
void declare (std::ostream &stream, Language lang, int level)
 
std::string vhdlRange ()
 
std::string verilogRange ()
 
virtual std::string vhdlTypeDeclaration ()
 
std::string verilogTypeDeclaration ()
 
bool isVector ()
 
WireType wireType ()
 
- 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 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 strWidth_
 
int width_
 
WireType wireType_
 

Detailed Description

Definition at line 413 of file HDLGenerator.hh.

Constructor & Destructor Documentation

◆ Variable() [1/2]

HDLGenerator::Variable::Variable ( std::string  name,
int  width = 1 
)
inline

Definition at line 415 of file HDLGenerator.hh.

416  : Generatable(name), strWidth_(std::to_string(width)),

References HDLGenerator::Auto.

◆ Variable() [2/2]

HDLGenerator::Variable::Variable ( std::string  name,
std::string  width 
)
inline

Definition at line 418 of file HDLGenerator.hh.

References HDLGenerator::Vector.

Member Function Documentation

◆ declare()

void HDLGenerator::Variable::declare ( std::ostream &  stream,
Language  lang,
int  level 
)
inline

Definition at line 424 of file HDLGenerator.hh.

424  {
425  if (lang == Language::VHDL) {
426  stream << StringTools::indent(level) << "variable " << name()
427  << " : " << vhdlTypeDeclaration() << ";\n";
428  } else if (lang == Language::Verilog) {
429  stream << StringTools::indent(level)
431  << " " << name() << ";\n";
432  } else {
433  throw std::runtime_error(__PRETTY_FUNCTION__);
434  }
435  }

References StringTools::indent(), HDLGenerator::Generatable::name(), HDLGenerator::Verilog, verilogTypeDeclaration(), HDLGenerator::VHDL, and vhdlTypeDeclaration().

Here is the call graph for this function:

◆ isVector()

bool HDLGenerator::Variable::isVector ( )
inline

◆ verilogRange()

std::string HDLGenerator::Variable::verilogRange ( )
inline

Definition at line 445 of file HDLGenerator.hh.

445  {
446  std::string width = strWidth_;
447  if (width.empty()) {
448  width = std::to_string(width_);
449  }
450  return "[" + width + "-1:0] ";
451  }

References strWidth_, width(), and width_.

Referenced by verilogTypeDeclaration(), and HDLGenerator::SignedVariable::verilogTypeDeclaration().

Here is the call graph for this function:

◆ verilogTypeDeclaration()

std::string HDLGenerator::Variable::verilogTypeDeclaration ( )
inline

Definition at line 457 of file HDLGenerator.hh.

457  {
458  std::string decl = "reg";
459  if (isVector()) {
460  decl += " " + verilogRange();
461  }
462  return decl;
463  }

References isVector(), and verilogRange().

Referenced by declare().

Here is the call graph for this function:

◆ vhdlRange()

std::string HDLGenerator::Variable::vhdlRange ( )
inline

Definition at line 437 of file HDLGenerator.hh.

437  {
438  std::string width = strWidth_;
439  if (width.empty()) {
440  width = std::to_string(width_);
441  }
442  return "(" + width + "-1 downto 0)";
443  }

References strWidth_, width(), and width_.

Referenced by HDLGenerator::LogicVariable::vhdlTypeDeclaration(), HDLGenerator::UnsignedVariable::vhdlTypeDeclaration(), and HDLGenerator::SignedVariable::vhdlTypeDeclaration().

Here is the call graph for this function:

◆ vhdlTypeDeclaration()

virtual std::string HDLGenerator::Variable::vhdlTypeDeclaration ( )
inlinevirtual

Reimplemented in HDLGenerator::SignedVariable, HDLGenerator::UnsignedVariable, and HDLGenerator::LogicVariable.

Definition at line 453 of file HDLGenerator.hh.

453  {
454  throw std::runtime_error(__PRETTY_FUNCTION__);
455  }

Referenced by declare().

◆ width()

Width HDLGenerator::Variable::width ( )
inlinefinalvirtual

Reimplemented from HDLGenerator::Generatable.

Definition at line 422 of file HDLGenerator.hh.

422 { return {strWidth_, width_}; }

References strWidth_, and width_.

Referenced by verilogRange(), and vhdlRange().

◆ wireType()

WireType HDLGenerator::Variable::wireType ( )
inline

Definition at line 469 of file HDLGenerator.hh.

469  {
470  return wireType_;
471  }

References wireType_.

Member Data Documentation

◆ strWidth_

std::string HDLGenerator::Variable::strWidth_
private

Definition at line 474 of file HDLGenerator.hh.

Referenced by verilogRange(), vhdlRange(), and width().

◆ width_

int HDLGenerator::Variable::width_
private

Definition at line 475 of file HDLGenerator.hh.

Referenced by isVector(), verilogRange(), vhdlRange(), and width().

◆ wireType_

WireType HDLGenerator::Variable::wireType_
private

Definition at line 476 of file HDLGenerator.hh.

Referenced by isVector(), and wireType().


The documentation for this class was generated from the following file:
HDLGenerator::Variable::verilogRange
std::string verilogRange()
Definition: HDLGenerator.hh:445
StringTools::indent
static std::string indent(int level)
Definition: StringTools.cc:319
HDLGenerator::Variable::vhdlTypeDeclaration
virtual std::string vhdlTypeDeclaration()
Definition: HDLGenerator.hh:453
HDLGenerator::Variable::isVector
bool isVector()
Definition: HDLGenerator.hh:465
HDLGenerator::Generatable::Generatable
Generatable(std::string name)
Definition: Generatable.hh:53
HDLGenerator::Language::Verilog
@ Verilog
HDLGenerator::Variable::width_
int width_
Definition: HDLGenerator.hh:475
HDLGenerator::Variable::verilogTypeDeclaration
std::string verilogTypeDeclaration()
Definition: HDLGenerator.hh:457
HDLGenerator::Variable::width
Width width() final
Definition: HDLGenerator.hh:422
HDLGenerator::Variable::strWidth_
std::string strWidth_
Definition: HDLGenerator.hh:474
HDLGenerator::Variable::wireType_
WireType wireType_
Definition: HDLGenerator.hh:476
HDLGenerator::WireType::Auto
@ Auto
HDLGenerator::Generatable::name
const std::string & name() const noexcept
Definition: Generatable.hh:239
HDLGenerator::WireType::Vector
@ Vector
HDLGenerator::Language::VHDL
@ VHDL