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

Constructor & Destructor Documentation

◆ Assign() [1/3]

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

Definition at line 542 of file HDLGenerator.hh.

◆ Assign() [2/3]

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

Definition at line 545 of file HDLGenerator.hh.

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

◆ Assign() [3/3]

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

Definition at line 548 of file HDLGenerator.hh.

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

Member Function Documentation

◆ build()

void HDLGenerator::Assign::build ( )
inlineoverridevirtual

Reimplemented from HDLGenerator::Generatable.

Definition at line 552 of file HDLGenerator.hh.

552 {
554 writes(name());
555 reads(value_);
556 }
virtual void reads(const std::string &var)
const std::string & name() const noexcept
virtual void writes(const std::string &var)

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

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

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

Referenced by hdl().

◆ lowerBound_

int HDLGenerator::Assign::lowerBound_
private

Definition at line 608 of file HDLGenerator.hh.

Referenced by hdl().

◆ upperBound_

int HDLGenerator::Assign::upperBound_
private

Definition at line 607 of file HDLGenerator.hh.

Referenced by hdl().

◆ value_

LHSValue HDLGenerator::Assign::value_
private

Definition at line 609 of file HDLGenerator.hh.

Referenced by build(), and hdl().


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