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

#include <HDLGenerator.hh>

Inheritance diagram for HDLGenerator::If:
Inheritance graph
Collaboration diagram for HDLGenerator::If:
Collaboration graph

Public Member Functions

template<typename SS >
 If (LHSValue cls, SS ifBlock)
 
template<typename SS >
void elseIfClause (LHSValue cls, SS ifBlock)
 
template<typename SS >
void elseClause (SS elseBlock)
 
virtual void hdl (std::ostream &stream, Language lang, int level) override
 
void build () 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

std::vector< std::pair< LHSValue, std::shared_ptr< SequentialStatement > > > ifBlocks_
 
std::shared_ptr< SequentialStatementelseBlock_
 

Detailed Description

if/elsif/else.

Definition at line 786 of file HDLGenerator.hh.

Constructor & Destructor Documentation

◆ If()

template<typename SS >
HDLGenerator::If::If ( LHSValue  cls,
SS  ifBlock 
)
inline

Definition at line 789 of file HDLGenerator.hh.

789  : SequentialStatement("if"),
790  elseBlock_(nullptr) {
791  std::shared_ptr<SequentialStatement> ptr
792  = std::make_shared<SS>(ifBlock);
793  ifBlocks_.emplace_back(cls, ptr);
794  }

References ifBlocks_.

Member Function Documentation

◆ build()

void HDLGenerator::If::build ( )
inlineoverridevirtual

Reimplemented from HDLGenerator::Generatable.

Definition at line 854 of file HDLGenerator.hh.

854  {
856  for (auto&& block : ifBlocks_) {
857  reads(block.first);
858  block.second->setParent(this);
859  block.second->build();
860  }
861  if (elseBlock_ != nullptr) {
862  elseBlock_->setParent(this);
863  elseBlock_->build();
864  }
865  }

References HDLGenerator::Generatable::build(), elseBlock_, ifBlocks_, and HDLGenerator::Generatable::reads().

Here is the call graph for this function:

◆ elseClause()

template<typename SS >
void HDLGenerator::If::elseClause ( SS  elseBlock)
inline

Definition at line 804 of file HDLGenerator.hh.

804  {
805  if (elseBlock_) {
806  throw std::runtime_error("Cannot to add a second else block.");
807  }
808  std::shared_ptr<SequentialStatement> ptr
809  = std::make_shared<SS>(elseBlock);
810  elseBlock_ = ptr;
811  }

References elseBlock_.

Referenced by FUGen::createOutputPipeline(), and FUGen::createShadowRegisters().

◆ elseIfClause()

template<typename SS >
void HDLGenerator::If::elseIfClause ( LHSValue  cls,
SS  ifBlock 
)
inline

Definition at line 797 of file HDLGenerator.hh.

797  {
798  std::shared_ptr<SequentialStatement> ptr
799  = std::make_shared<SS>(ifBlock);
800  ifBlocks_.emplace_back(cls, ptr);
801  }

References ifBlocks_.

Referenced by FUGen::createOutputPipeline().

◆ hdl()

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

Reimplemented from HDLGenerator::SequentialStatement.

Definition at line 813 of file HDLGenerator.hh.

814  {
815  if (lang == Language::VHDL) {
816  for (auto iter = ifBlocks_.begin(); iter != ifBlocks_.end();
817  ++iter) {
818  if (iter == ifBlocks_.begin()) {
819  stream << StringTools::indent(level) << "if ";
820  } else {
821  stream << StringTools::indent(level) << "elsif ";
822  }
823  iter->first.hdl(stream, lang);
824  stream << " then\n";
825  iter->second->hdl(stream, lang, level + 1);
826  }
827  if (elseBlock_ != nullptr) {
828  stream << StringTools::indent(level) << "else\n";
829  elseBlock_->hdl(stream, lang, level + 1);
830  }
831  stream << StringTools::indent(level) << "end if;\n";
832  } else if (lang == Language::Verilog) {
833  for (auto iter = ifBlocks_.begin(); iter != ifBlocks_.end();
834  ++iter) {
835  if (iter == ifBlocks_.begin()) {
836  stream << StringTools::indent(level) << "if ";
837  } else {
838  stream << StringTools::indent(level) << "end else if ";
839  }
840  iter->first.hdl(stream, lang);
841  stream << ") begin\n";
842  iter->second->hdl(stream, lang, level + 1);
843  }
844  if (elseBlock_ != nullptr) {
845  stream << StringTools::indent(level) << "end else begin\n";
846  elseBlock_->hdl(stream, lang, level + 1);
847  }
848  stream << StringTools::indent(level) << "end\n";
849  } else {
850  throw std::runtime_error(__PRETTY_FUNCTION__);
851  }
852  }

References elseBlock_, ifBlocks_, StringTools::indent(), HDLGenerator::Verilog, and HDLGenerator::VHDL.

Here is the call graph for this function:

Member Data Documentation

◆ elseBlock_

std::shared_ptr<SequentialStatement> HDLGenerator::If::elseBlock_
private

Definition at line 870 of file HDLGenerator.hh.

Referenced by build(), elseClause(), and hdl().

◆ ifBlocks_

std::vector<std::pair<LHSValue,std::shared_ptr<SequentialStatement> > > HDLGenerator::If::ifBlocks_
private

Definition at line 869 of file HDLGenerator.hh.

Referenced by build(), elseIfClause(), hdl(), and If().


The documentation for this class was generated from the following file:
HDLGenerator::If::elseBlock_
std::shared_ptr< SequentialStatement > elseBlock_
Definition: HDLGenerator.hh:870
StringTools::indent
static std::string indent(int level)
Definition: StringTools.cc:319
HDLGenerator::Language::Verilog
@ Verilog
HDLGenerator::SequentialStatement::SequentialStatement
SequentialStatement(std::string name)
Definition: HDLGenerator.hh:123
HDLGenerator::Generatable::build
virtual void build()
Definition: Generatable.hh:56
HDLGenerator::Generatable::reads
virtual void reads(const std::string &var)
Definition: Generatable.hh:63
HDLGenerator::If::ifBlocks_
std::vector< std::pair< LHSValue, std::shared_ptr< SequentialStatement > > > ifBlocks_
Definition: HDLGenerator.hh:869
HDLGenerator::Language::VHDL
@ VHDL