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

#include <HDLGenerator.hh>

Inheritance diagram for HDLGenerator::Synchronous:
Inheritance graph
Collaboration diagram for HDLGenerator::Synchronous:
Collaboration graph

Public Member Functions

 Synchronous (std::string name)
 
template<typename SS >
Synchronousoperator<< (SS op)
 
template<typename Var >
void addVariable (Var op)
 
virtual void build () override
 
virtual void writes (const std::string &var) override
 
virtual void vhdlReset (std::ostream &stream, Language lang, int level)
 
virtual 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 reads (const std::string &var)
 
virtual void reads (const LHSValue &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::shared_ptr< Variable > > variables_
 
std::unordered_set< std::string > registers_
 

Detailed Description

Sync process/always.

Definition at line 982 of file HDLGenerator.hh.

Constructor & Destructor Documentation

◆ Synchronous()

HDLGenerator::Synchronous::Synchronous ( std::string  name)
inline

Definition at line 984 of file HDLGenerator.hh.

984 : Generatable(name) {}

Member Function Documentation

◆ addVariable()

template<typename Var >
void HDLGenerator::Synchronous::addVariable ( Var  op)
inline

Definition at line 994 of file HDLGenerator.hh.

994  {
995  std::shared_ptr<Variable> ptr = std::make_shared<Var>(op);
996  variables_.push_back(op);
997  }

References variables_.

◆ build()

void HDLGenerator::Synchronous::build ( )
overridevirtual

Reimplemented from HDLGenerator::Generatable.

Definition at line 33 of file HDLGenerator.cc.

33  {
35  for (auto&& v : variables_) {
36  parentType<Module>()->registerVariable(v);
37  }
38  for (auto&& r : registers_) {
39  if (!isRegister(r)) {
40  throw std::runtime_error(
41  r + " written in synchronous but isn't a register.");
42  }
43  }
44 }

References HDLGenerator::Generatable::build(), HDLGenerator::Generatable::isRegister(), registers_, and variables_.

Here is the call graph for this function:

◆ hdl()

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

Reimplemented from HDLGenerator::Generatable.

Definition at line 1029 of file HDLGenerator.hh.

1029  {
1030  if (lang == Language::VHDL) {
1031  stream << "\n"
1032  << StringTools::indent(level) << name() << " : process";
1033  if (hasOption("asynchronous reset")) {
1034  stream << "(clk, rstx)\n";
1035  } else {
1036  stream << "(clk)\n";
1037  }
1038 
1039  for (auto&& v : variables_) {
1040  v->declare(stream, lang, level + 1);
1041  }
1042 
1043  stream << StringTools::indent(level) << "begin\n";
1044  if (hasOption("asynchronous reset")) {
1045  vhdlReset(stream, lang, level + 1);
1046  stream << StringTools::indent(level + 1)
1047  << "elsif clk = '1' and clk'event then\n";
1048  implementAll(stream, lang, level + 2);
1049  } else {
1050  stream << StringTools::indent(level + 1)
1051  << "if clk = '1' and clk'event then\n";
1052  vhdlReset(stream, lang, level + 2);
1053  stream << StringTools::indent(level + 2) << "else\n";
1054  implementAll(stream, lang, level + 3);
1055  stream << StringTools::indent(level + 2) << "end if;\n";
1056  }
1057  stream << StringTools::indent(level + 1) << "end if;\n";
1058  stream << StringTools::indent(level)
1059  << "end process " << name() << ";\n";
1060  } else if (lang == Language::Verilog) {
1061  stream << "\n";
1062  stream << StringTools::indent(level) << "// " << name() << "\n";
1063  if (hasOption("asynchronous reset")) {
1064  stream << StringTools::indent(level)
1065  << "always @(posedge clk or negedge rstx) begin\n";
1066  } else {
1067  stream << StringTools::indent(level)
1068  << "always @(posedge clk) begin\n";
1069  }
1070  stream << StringTools::indent(level + 1)
1071  << "if (~rstx) begin\n";
1072  for (auto&& r : registers_) {
1073  Register& reg = getRegister(r);
1074  if (reg.resetOption() == ResetOption::Mandatory ||
1075  hasOption("reset everything")) {
1076  reg.reset(stream, lang, level + 2);
1077  }
1078  }
1079  stream << StringTools::indent(level + 1) << "end else begin\n";
1080  implementAll(stream, lang, level + 2);
1081  stream << StringTools::indent(level + 1) << "end\n";
1082  stream << StringTools::indent(level) << "end\n";
1083  } else {
1084  throw std::runtime_error(__PRETTY_FUNCTION__);
1085  }
1086  }

References HDLGenerator::Generatable::getRegister(), HDLGenerator::Generatable::hasOption(), HDLGenerator::Generatable::implementAll(), StringTools::indent(), HDLGenerator::Mandatory, HDLGenerator::Generatable::name(), registers_, HDLGenerator::Register::reset(), HDLGenerator::Register::resetOption(), variables_, HDLGenerator::Verilog, HDLGenerator::VHDL, and vhdlReset().

Here is the call graph for this function:

◆ operator<<()

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

Definition at line 987 of file HDLGenerator.hh.

987  {
988  std::shared_ptr<SequentialStatement> ptr = std::make_shared<SS>(op);
989  pushComponent(ptr);
990  return *this;
991  }

References HDLGenerator::Generatable::pushComponent().

Here is the call graph for this function:

◆ vhdlReset()

virtual void HDLGenerator::Synchronous::vhdlReset ( std::ostream &  stream,
Language  lang,
int  level 
)
inlinevirtual

Definition at line 1013 of file HDLGenerator.hh.

1013  {
1014  if (hasOption("active low reset"))
1015  stream << StringTools::indent(level) << "if rstx = '0' then\n";
1016  if (hasOption("active high reset"))
1017  stream << StringTools::indent(level) << "if rst = '1' then\n";
1018  for (auto&& r : registers_) {
1019  Register& reg = getRegister(r);
1020  if (reg.resetOption() == ResetOption::Mandatory ||
1021  hasOption("reset everything")) {
1022  reg.reset(stream, lang, level + 1);
1023  }
1024  }
1025  // Leaves if clause open for else/elsif
1026  }

References HDLGenerator::Generatable::getRegister(), HDLGenerator::Generatable::hasOption(), StringTools::indent(), HDLGenerator::Mandatory, registers_, HDLGenerator::Register::reset(), and HDLGenerator::Register::resetOption().

Referenced by hdl().

Here is the call graph for this function:

◆ writes()

virtual void HDLGenerator::Synchronous::writes ( const std::string &  var)
inlineoverridevirtual

Reimplemented from HDLGenerator::Generatable.

Definition at line 1001 of file HDLGenerator.hh.

1001  {
1002  //Generatable::writes(var);
1003  if (isVariable(var)) {
1004  return;
1005  }
1006  if (!isRegister(var)) {
1007  std::cerr << "Trying to write nonregister " << var << "\n";
1008  throw std::runtime_error(__PRETTY_FUNCTION__);
1009  }
1010  registers_.emplace(var);
1011  }

References HDLGenerator::Generatable::isRegister(), HDLGenerator::Generatable::isVariable(), and registers_.

Here is the call graph for this function:

Member Data Documentation

◆ registers_

std::unordered_set<std::string> HDLGenerator::Synchronous::registers_
private

Definition at line 1090 of file HDLGenerator.hh.

Referenced by build(), hdl(), vhdlReset(), and writes().

◆ variables_

std::vector< std::shared_ptr<Variable> > HDLGenerator::Synchronous::variables_
private

Definition at line 1089 of file HDLGenerator.hh.

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


The documentation for this class was generated from the following files:
HDLGenerator::Generatable::pushComponent
void pushComponent(std::shared_ptr< Generatable > c)
Definition: Generatable.hh:230
HDLGenerator::ResetOption::Mandatory
@ Mandatory
HDLGenerator::Synchronous::vhdlReset
virtual void vhdlReset(std::ostream &stream, Language lang, int level)
Definition: HDLGenerator.hh:1013
HDLGenerator::Synchronous::variables_
std::vector< std::shared_ptr< Variable > > variables_
Definition: HDLGenerator.hh:1089
StringTools::indent
static std::string indent(int level)
Definition: StringTools.cc:319
HDLGenerator::Generatable::getRegister
virtual Register & getRegister(const std::string &var)
Definition: Generatable.hh:89
HDLGenerator::Synchronous::registers_
std::unordered_set< std::string > registers_
Definition: HDLGenerator.hh:1090
HDLGenerator::Generatable::hasOption
virtual bool hasOption(const std::string &var)
Definition: Generatable.hh:98
HDLGenerator::Generatable::Generatable
Generatable(std::string name)
Definition: Generatable.hh:53
HDLGenerator::Generatable::isRegister
virtual bool isRegister(const std::string &name)
Definition: Generatable.hh:107
HDLGenerator::Language::Verilog
@ Verilog
HDLGenerator::Generatable::build
virtual void build()
Definition: Generatable.hh:56
HDLGenerator::Generatable::implementAll
virtual void implementAll(std::ostream &stream, Language lang)
Definition: Generatable.hh:183
HDLGenerator::Generatable::isVariable
virtual bool isVariable(const std::string &name)
Definition: Generatable.hh:116
HDLGenerator::Generatable::name
const std::string & name() const noexcept
Definition: Generatable.hh:239
HDLGenerator::Language::VHDL
@ VHDL