OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
HDLGenerator::Case Class Reference

#include <HDLGenerator.hh>

Inheritance diagram for HDLGenerator::Case:
Inheritance graph
Collaboration diagram for HDLGenerator::Case:
Collaboration graph

Public Member Functions

 Case ()
 
 Case (std::string stringCase)
 
template<typename SS >
Caseoperator<< (SS op)
 
Caseoperator<< (BinaryLiteral &&rhs)
 
Caseoperator<< (BinaryLiteral &rhs)
 
Caseoperator<< (int rhs)
 
Caseoperator<< (std::string &rhs)
 
Caseoperator<< (std::string &&rhs)
 
void hdl (std::ostream &stream, Language lang, int level) override
 
- 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 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::string stringCase_
 
std::vector< int > intCases_
 
std::vector< BinaryLiteralbinaryCases_
 

Detailed Description

Case in a switch-case.

Definition at line 646 of file HDLGenerator.hh.

Constructor & Destructor Documentation

◆ Case() [1/2]

HDLGenerator::Case::Case ( )
inline

Definition at line 648 of file HDLGenerator.hh.

648: Generatable("case") {}
Generatable(std::string name)

◆ Case() [2/2]

HDLGenerator::Case::Case ( std::string  stringCase)
inline

Definition at line 649 of file HDLGenerator.hh.

649 : Generatable("case"),
650 stringCase_(stringCase) {}
std::string stringCase_

Member Function Documentation

◆ hdl()

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

Reimplemented from HDLGenerator::Generatable.

Definition at line 684 of file HDLGenerator.hh.

684 {
685 if (lang == Language::VHDL) {
686 stream << StringTools::indent(level) << "when ";
687 if (!stringCase_.empty()) {
688 stream << stringCase_;
689 } else if (!intCases_.empty()) {
690 std::string separator = "";
691 for (auto&& c : intCases_) {
692 stream << separator << std::to_string(c);
693 separator = " | ";
694 }
695 } else if (!binaryCases_.empty()) {
696 std::string separator = "";
697 for (auto&& c : binaryCases_) {
698 stream << separator;
699 c.hdl(stream, lang);
700 separator = " | ";
701 }
702 } else {
703 throw std::runtime_error("Case has no case");
704 }
705 stream << " =>\n";
706 implementAll(stream, lang, level + 1);
707 } else if (lang == Language::Verilog) {
708 stream << StringTools::indent(level);
709 if (!stringCase_.empty()) {
710 stream << stringCase_;
711 } else if (!intCases_.empty()) {
712 std::string separator = "";
713 for (auto&& c : intCases_) {
714 stream << separator << std::to_string(c);
715 separator = ", ";
716 }
717 } else if (!binaryCases_.empty()) {
718 std::string separator = "";
719 for (auto&& c : binaryCases_) {
720 stream << separator;
721 c.hdl(stream, lang);
722 separator = ", ";
723 }
724 } else {
725 throw std::runtime_error("Case has no case");
726 }
727 stream << ": begin\n";
728 implementAll(stream, lang, level + 1);
729 stream << StringTools::indent(level) << "end\n";
730 } else {
731 throw std::runtime_error(__PRETTY_FUNCTION__);
732 }
733 }
std::vector< int > intCases_
std::vector< BinaryLiteral > binaryCases_
virtual void implementAll(std::ostream &stream, Language lang)
static std::string indent(int level)

References binaryCases_, HDLGenerator::Generatable::implementAll(), StringTools::indent(), intCases_, stringCase_, HDLGenerator::Verilog, and HDLGenerator::VHDL.

Here is the call graph for this function:

◆ operator<<() [1/6]

Case & HDLGenerator::Case::operator<< ( BinaryLiteral &&  rhs)
inline

Definition at line 659 of file HDLGenerator.hh.

659 {
660 binaryCases_.emplace_back(rhs);
661 return *this;
662 }

References binaryCases_.

◆ operator<<() [2/6]

Case & HDLGenerator::Case::operator<< ( BinaryLiteral rhs)
inline

Definition at line 664 of file HDLGenerator.hh.

664 {
665 binaryCases_.emplace_back(rhs);
666 return *this;
667 }

References binaryCases_.

◆ operator<<() [3/6]

Case & HDLGenerator::Case::operator<< ( int  rhs)
inline

Definition at line 669 of file HDLGenerator.hh.

669 {
670 intCases_.emplace_back(rhs);
671 return *this;
672 }

References intCases_.

◆ operator<<() [4/6]

template<typename SS >
Case & HDLGenerator::Case::operator<< ( SS  op)
inline

Definition at line 653 of file HDLGenerator.hh.

653 {
654 std::shared_ptr<SequentialStatement> ptr = std::make_shared<SS>(op);
655 pushComponent(ptr);
656 return *this;
657 }
void pushComponent(std::shared_ptr< Generatable > c)

References HDLGenerator::Generatable::pushComponent().

Here is the call graph for this function:

◆ operator<<() [5/6]

Case & HDLGenerator::Case::operator<< ( std::string &&  rhs)
inline

Definition at line 679 of file HDLGenerator.hh.

679 {
680 stringCase_ = rhs;
681 return *this;
682 }

References stringCase_.

◆ operator<<() [6/6]

Case & HDLGenerator::Case::operator<< ( std::string &  rhs)
inline

Definition at line 674 of file HDLGenerator.hh.

674 {
675 stringCase_ = rhs;
676 return *this;
677 }

References stringCase_.

Member Data Documentation

◆ binaryCases_

std::vector<BinaryLiteral> HDLGenerator::Case::binaryCases_
private

Definition at line 738 of file HDLGenerator.hh.

Referenced by hdl(), operator<<(), and operator<<().

◆ intCases_

std::vector<int> HDLGenerator::Case::intCases_
private

Definition at line 737 of file HDLGenerator.hh.

Referenced by hdl(), and operator<<().

◆ stringCase_

std::string HDLGenerator::Case::stringCase_
private

Definition at line 736 of file HDLGenerator.hh.

Referenced by hdl(), operator<<(), and operator<<().


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