OpenASIP  2.0
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 645 of file HDLGenerator.hh.

Constructor & Destructor Documentation

◆ Case() [1/2]

HDLGenerator::Case::Case ( )
inline

Definition at line 647 of file HDLGenerator.hh.

647 : Generatable("case") {}

◆ Case() [2/2]

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

Definition at line 648 of file HDLGenerator.hh.

648  : Generatable("case"),
649  stringCase_(stringCase) {}

Member Function Documentation

◆ hdl()

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

Reimplemented from HDLGenerator::Generatable.

Definition at line 683 of file HDLGenerator.hh.

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

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

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

References binaryCases_.

◆ operator<<() [2/6]

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

Definition at line 663 of file HDLGenerator.hh.

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

References binaryCases_.

◆ operator<<() [3/6]

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

Definition at line 668 of file HDLGenerator.hh.

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

References intCases_.

◆ operator<<() [4/6]

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

Definition at line 652 of file HDLGenerator.hh.

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

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

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

References stringCase_.

◆ operator<<() [6/6]

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

Definition at line 673 of file HDLGenerator.hh.

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

References stringCase_.

Member Data Documentation

◆ binaryCases_

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

Definition at line 737 of file HDLGenerator.hh.

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

◆ intCases_

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

Definition at line 736 of file HDLGenerator.hh.

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

◆ stringCase_

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

Definition at line 735 of file HDLGenerator.hh.

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


The documentation for this class was generated from the following file:
HDLGenerator::Generatable::pushComponent
void pushComponent(std::shared_ptr< Generatable > c)
Definition: Generatable.hh:230
StringTools::indent
static std::string indent(int level)
Definition: StringTools.cc:319
HDLGenerator::Case::stringCase_
std::string stringCase_
Definition: HDLGenerator.hh:735
HDLGenerator::Case::binaryCases_
std::vector< BinaryLiteral > binaryCases_
Definition: HDLGenerator.hh:737
HDLGenerator::Generatable::Generatable
Generatable(std::string name)
Definition: Generatable.hh:53
HDLGenerator::Language::Verilog
@ Verilog
HDLGenerator::Generatable::implementAll
virtual void implementAll(std::ostream &stream, Language lang)
Definition: Generatable.hh:183
HDLGenerator::Language::VHDL
@ VHDL
HDLGenerator::Case::intCases_
std::vector< int > intCases_
Definition: HDLGenerator.hh:736