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

#include <HDLGenerator.hh>

Inheritance diagram for HDLGenerator::Assign:
Inheritance graph
Collaboration diagram for HDLGenerator::Assign:
Collaboration graph

Public Member Functions

 Assign (std::string var, LHSValue value)
 
 Assign (std::string var, LHSValue value, int idx)
 
 Assign (std::string var, LHSValue value, int ub, int lb)
 
void build () override
 
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 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

int index_
 
int upperBound_
 
int lowerBound_
 
LHSValue value_
 

Detailed Description

Assignment.

Definition at line 539 of file HDLGenerator.hh.

Constructor & Destructor Documentation

◆ Assign() [1/3]

HDLGenerator::Assign::Assign ( std::string  var,
LHSValue  value 
)
inline

Definition at line 541 of file HDLGenerator.hh.

542  : SequentialStatement(var), index_(-1), upperBound_(-1),
543  lowerBound_(-1), value_(value) {}

◆ Assign() [2/3]

HDLGenerator::Assign::Assign ( std::string  var,
LHSValue  value,
int  idx 
)
inline

Definition at line 544 of file HDLGenerator.hh.

545  : SequentialStatement(var), index_(idx), upperBound_(-1),
546  lowerBound_(-1), value_(value) {}

◆ Assign() [3/3]

HDLGenerator::Assign::Assign ( std::string  var,
LHSValue  value,
int  ub,
int  lb 
)
inline

Definition at line 547 of file HDLGenerator.hh.

548  : SequentialStatement(var), index_(-1), upperBound_(ub),
549  lowerBound_(lb), value_(value) {}

Member Function Documentation

◆ build()

void HDLGenerator::Assign::build ( )
inlineoverridevirtual

Reimplemented from HDLGenerator::Generatable.

Definition at line 551 of file HDLGenerator.hh.

551  {
553  writes(name());
554  reads(value_);
555  }

References HDLGenerator::Generatable::build(), HDLGenerator::Generatable::name(), HDLGenerator::Generatable::reads(), value_, and HDLGenerator::Generatable::writes().

Here is the call graph for this function:

◆ hdl()

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

Reimplemented from HDLGenerator::SequentialStatement.

Definition at line 557 of file HDLGenerator.hh.

557  {
558  if (isRegister(name()) && !parentIs<Synchronous>()) {
559  throw std::runtime_error(
560  "assigning to register '" + name() +
561  "' is only allowed in synchronous context");
562  } else if (isVariable(name()) && (!parentIs<Synchronous>() ||
563  !parentIs<Asynchronous>())) {
564  throw std::runtime_error("Not allowed to assign to '" +
565  name() + "' in this context.");
566  }
567  if (lang == Language::VHDL) {
568  stream << StringTools::indent(level) << name();
569  if (upperBound_ >= 0) {
570  stream << "(" << upperBound_ << " downto "
571  << lowerBound_ << ")";
572  } else if (index_ >= 0) {
573  stream << "(" << index_ << ")";
574  }
575  if (isVariable(name())) {
576  stream << " := ";
577  } else {
578  stream << " <= ";
579  }
580  } else if (lang == Language::Verilog) {
581  if (!(parentIs<Synchronous>() || parentIs<Asynchronous>())) {
582  stream << StringTools::indent(level) << "always @*\n"
583  << StringTools::indent(level + 1) << name();
584  } else {
585  stream << StringTools::indent(level) << name();
586  }
587  if (upperBound_ >= 0) {
588  stream << "[" << upperBound_ << ":" << lowerBound_ << "]";
589  } else if (index_ >= 0) {
590  stream << "[" << index_ << "]";
591  }
592  if (isRegister(name())) {
593  stream << " <= ";
594  } else {
595  stream << " = ";
596  }
597  } else {
598  throw std::runtime_error(__PRETTY_FUNCTION__);
599  }
600  value_.hdl(stream, lang);
601  stream << ";\n";
602  }

References HDLGenerator::LHSValue::hdl(), StringTools::indent(), index_, HDLGenerator::Generatable::isRegister(), HDLGenerator::Generatable::isVariable(), lowerBound_, HDLGenerator::Generatable::name(), upperBound_, value_, HDLGenerator::Verilog, and HDLGenerator::VHDL.

Here is the call graph for this function:

Member Data Documentation

◆ index_

int HDLGenerator::Assign::index_
private

Definition at line 605 of file HDLGenerator.hh.

Referenced by hdl().

◆ lowerBound_

int HDLGenerator::Assign::lowerBound_
private

Definition at line 607 of file HDLGenerator.hh.

Referenced by hdl().

◆ upperBound_

int HDLGenerator::Assign::upperBound_
private

Definition at line 606 of file HDLGenerator.hh.

Referenced by hdl().

◆ value_

LHSValue HDLGenerator::Assign::value_
private

Definition at line 608 of file HDLGenerator.hh.

Referenced by build(), and hdl().


The documentation for this class was generated from the following file:
HDLGenerator::Generatable::writes
virtual void writes(const std::string &var)
Definition: Generatable.hh:80
HDLGenerator::Assign::index_
int index_
Definition: HDLGenerator.hh:605
StringTools::indent
static std::string indent(int level)
Definition: StringTools.cc:319
HDLGenerator::Assign::upperBound_
int upperBound_
Definition: HDLGenerator.hh:606
HDLGenerator::Generatable::isRegister
virtual bool isRegister(const std::string &name)
Definition: Generatable.hh:107
HDLGenerator::Language::Verilog
@ Verilog
HDLGenerator::SequentialStatement::SequentialStatement
SequentialStatement(std::string name)
Definition: HDLGenerator.hh:123
HDLGenerator::Assign::lowerBound_
int lowerBound_
Definition: HDLGenerator.hh:607
HDLGenerator::Generatable::build
virtual void build()
Definition: Generatable.hh:56
HDLGenerator::Assign::value_
LHSValue value_
Definition: HDLGenerator.hh:608
HDLGenerator::Generatable::reads
virtual void reads(const std::string &var)
Definition: Generatable.hh:63
HDLGenerator::Generatable::isVariable
virtual bool isVariable(const std::string &name)
Definition: Generatable.hh:116
HDLGenerator::LHSValue::hdl
void hdl(std::ostream &stream, Language lang, int level)
Definition: LHSValue.cc:37
HDLGenerator::Generatable::name
const std::string & name() const noexcept
Definition: Generatable.hh:239
HDLGenerator::Language::VHDL
@ VHDL