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

Constructor & Destructor Documentation

◆ Synchronous()

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

Definition at line 985 of file HDLGenerator.hh.

985: Generatable(name) {}
const std::string & name() const noexcept
Generatable(std::string name)

Member Function Documentation

◆ addVariable()

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

Definition at line 995 of file HDLGenerator.hh.

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

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}
virtual bool isRegister(const std::string &name)
std::unordered_set< std::string > registers_

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

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

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

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

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

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

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

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

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

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


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