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

#include <HDLGenerator.hh>

Inheritance diagram for HDLGenerator::BinaryConstant:
Inheritance graph
Collaboration diagram for HDLGenerator::BinaryConstant:
Collaboration graph

Public Member Functions

 BinaryConstant (std::string name, int width, int value)
 
int value () const noexcept
 
Width width () final
 
void declare (std::ostream &stream, Language lang, int level)
 
- 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

int width_
 
int value_
 

Detailed Description

Binary constant.

Definition at line 244 of file HDLGenerator.hh.

Constructor & Destructor Documentation

◆ BinaryConstant()

HDLGenerator::BinaryConstant::BinaryConstant ( std::string  name,
int  width,
int  value 
)
inline

Definition at line 246 of file HDLGenerator.hh.

Member Function Documentation

◆ declare()

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

Definition at line 253 of file HDLGenerator.hh.

253  {
254  std::string binVal = "";
255  int tempVal = value_;
256  for (int i = width_ - 1; i >= 0; --i) {
257  long power = static_cast<long>(std::pow(2, i));
258  if (power <= tempVal) {
259  tempVal -= power;
260  binVal += "1";
261  } else {
262  binVal += "0";
263  }
264  }
265 
266  if (lang == Language::VHDL) {
267  stream << StringTools::indent(level) << "constant " << name()
268  << " : std_logic_vector(" << width_ - 1
269  << " downto 0) := \"" << binVal << "\";\n";
270  } else if (lang == Language::Verilog) {
271  stream << StringTools::indent(level)
272  << "localparam [" << width_-1 << ":0] "
273  << name() << " = " << width_ << "'b" << binVal << ";\n";
274  } else {
275  throw std::runtime_error(__PRETTY_FUNCTION__);
276  }
277  }

References StringTools::indent(), HDLGenerator::Generatable::name(), value_, HDLGenerator::Verilog, HDLGenerator::VHDL, and width_.

Here is the call graph for this function:

◆ value()

int HDLGenerator::BinaryConstant::value ( ) const
inlinenoexcept

Definition at line 249 of file HDLGenerator.hh.

249 { return value_; }

References value_.

◆ width()

Width HDLGenerator::BinaryConstant::width ( )
inlinefinalvirtual

Reimplemented from HDLGenerator::Generatable.

Definition at line 251 of file HDLGenerator.hh.

251 { return {name(), width_}; }

References HDLGenerator::Generatable::name(), and width_.

Here is the call graph for this function:

Member Data Documentation

◆ value_

int HDLGenerator::BinaryConstant::value_
private

Definition at line 281 of file HDLGenerator.hh.

Referenced by declare(), and value().

◆ width_

int HDLGenerator::BinaryConstant::width_
private

Definition at line 280 of file HDLGenerator.hh.

Referenced by declare(), and width().


The documentation for this class was generated from the following file:
StringTools::indent
static std::string indent(int level)
Definition: StringTools.cc:319
HDLGenerator::BinaryConstant::width_
int width_
Definition: HDLGenerator.hh:280
HDLGenerator::BinaryConstant::width
Width width() final
Definition: HDLGenerator.hh:251
HDLGenerator::BinaryConstant::value
int value() const noexcept
Definition: HDLGenerator.hh:249
HDLGenerator::Generatable::Generatable
Generatable(std::string name)
Definition: Generatable.hh:53
HDLGenerator::Language::Verilog
@ Verilog
HDLGenerator::BinaryConstant::value_
int value_
Definition: HDLGenerator.hh:281
HDLGenerator::Generatable::name
const std::string & name() const noexcept
Definition: Generatable.hh:239
HDLGenerator::Language::VHDL
@ VHDL