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

Constructor & Destructor Documentation

◆ If()

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

Definition at line 790 of file HDLGenerator.hh.

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

References ifBlocks_.

Member Function Documentation

◆ build()

void HDLGenerator::If::build ( )
inlineoverridevirtual

Reimplemented from HDLGenerator::Generatable.

Definition at line 855 of file HDLGenerator.hh.

855 {
857 for (auto&& block : ifBlocks_) {
858 reads(block.first);
859 block.second->setParent(this);
860 block.second->build();
861 }
862 if (elseBlock_ != nullptr) {
863 elseBlock_->setParent(this);
864 elseBlock_->build();
865 }
866 }
virtual void reads(const std::string &var)

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

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

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

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

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

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

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

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


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