OpenASIP 2.2
Loading...
Searching...
No Matches
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 245 of file HDLGenerator.hh.

Constructor & Destructor Documentation

◆ BinaryConstant()

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

Definition at line 247 of file HDLGenerator.hh.

Member Function Documentation

◆ declare()

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

Definition at line 254 of file HDLGenerator.hh.

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

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 250 of file HDLGenerator.hh.

250{ return value_; }

References value_.

◆ width()

Width HDLGenerator::BinaryConstant::width ( )
inlinefinalvirtual

Reimplemented from HDLGenerator::Generatable.

Definition at line 252 of file HDLGenerator.hh.

252{ 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 282 of file HDLGenerator.hh.

Referenced by declare(), and value().

◆ width_

int HDLGenerator::BinaryConstant::width_
private

Definition at line 281 of file HDLGenerator.hh.

Referenced by declare(), and width().


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