OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Types | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
TestbenchGenerator Class Referenceabstract

#include <TestbenchGenerator.hh>

Inheritance diagram for TestbenchGenerator:
Inheritance graph
Collaboration diagram for TestbenchGenerator:
Collaboration graph

Public Member Functions

 TestbenchGenerator ()
 
virtual ~TestbenchGenerator ()
 
virtual void generateTestbench (std::ofstream &file)=0
 

Protected Types

typedef std::map< std::string, std::vector< uint32_t > > PortDataArray
 

Protected Member Functions

virtual void writeStimulusArray (std::ostringstream &stream, std::vector< uint32_t > &dataArray, std::string portName, int portWidth)
 
void writeTbConstants (int totalCycles, int outputIgnoreCycles)
 
void writeTestbench (std::ofstream &file, HDB::HWBlockImplementation *impl)
 
std::ostringstream & declarationStream ()
 
std::ostringstream & bindingStream ()
 
std::ostringstream & signalStream ()
 
std::ostringstream & instantiationStream ()
 
std::ostringstream & inputArrayStream ()
 
std::ostringstream & opcodeArrayStream ()
 
std::ostringstream & loadArrayStream ()
 
std::ostringstream & outputArrayStream ()
 
std::ostringstream & tbCodeStream ()
 

Private Member Functions

std::string findVhdlTemplate () const
 
void loadVhdlTemplate (const std::string &fileName, std::string &vhdlTemplate) const
 

Private Attributes

std::ostringstream componentDeclaration_
 
std::ostringstream componentBinding_
 
std::ostringstream signalDeclaration_
 
std::ostringstream componentInstantiation_
 
std::ostringstream inputArrays_
 
std::ostringstream opcodeArrays_
 
std::ostringstream loadSignalArrays_
 
std::ostringstream outputArrays_
 
std::ostringstream testbenchCode_
 

Static Private Attributes

static const std::string TB_TEMPLATE_
 

Detailed Description

Definition at line 47 of file TestbenchGenerator.hh.

Member Typedef Documentation

◆ PortDataArray

typedef std::map<std::string, std::vector<uint32_t> > TestbenchGenerator::PortDataArray
protected

Definition at line 56 of file TestbenchGenerator.hh.

Constructor & Destructor Documentation

◆ TestbenchGenerator()

TestbenchGenerator::TestbenchGenerator ( )

Definition at line 57 of file TestbenchGenerator.cc.

57 :
61}
std::ostringstream testbenchCode_
std::ostringstream opcodeArrays_
std::ostringstream signalDeclaration_
std::ostringstream outputArrays_
std::ostringstream loadSignalArrays_
std::ostringstream componentInstantiation_
std::ostringstream componentBinding_
std::ostringstream inputArrays_
std::ostringstream componentDeclaration_

◆ ~TestbenchGenerator()

TestbenchGenerator::~TestbenchGenerator ( )
virtual

Definition at line 63 of file TestbenchGenerator.cc.

63 {
64}

Member Function Documentation

◆ bindingStream()

std::ostringstream & TestbenchGenerator::bindingStream ( )
protected

◆ declarationStream()

std::ostringstream & TestbenchGenerator::declarationStream ( )
protected

◆ findVhdlTemplate()

std::string TestbenchGenerator::findVhdlTemplate ( ) const
private

Definition at line 142 of file TestbenchGenerator.cc.

142 {
143
144 vector<string> paths = Environment::implementationTesterTemplatePaths();
145 for (unsigned int i = 0; i < paths.size(); i++) {
146 string file = paths.at(i) + FileSystem::DIRECTORY_SEPARATOR
147 + TB_TEMPLATE_;
148 if (FileSystem::fileExists(file)) {
149 return file;
150 }
151 }
152
153 InvalidData exception(__FILE__, __LINE__, "",
154 "The VHDL template file " + TB_TEMPLATE_ +
155 "not found");
156 throw exception;
157
158 string notFound = "";
159 return notFound;
160}
static std::vector< std::string > implementationTesterTemplatePaths()
static const std::string DIRECTORY_SEPARATOR
static bool fileExists(const std::string fileName)
static const std::string TB_TEMPLATE_

References FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), Environment::implementationTesterTemplatePaths(), and TB_TEMPLATE_.

Referenced by writeTestbench().

Here is the call graph for this function:

◆ generateTestbench()

virtual void TestbenchGenerator::generateTestbench ( std::ofstream &  file)
pure virtual

◆ inputArrayStream()

std::ostringstream & TestbenchGenerator::inputArrayStream ( )
protected

◆ instantiationStream()

std::ostringstream & TestbenchGenerator::instantiationStream ( )
protected

◆ loadArrayStream()

std::ostringstream & TestbenchGenerator::loadArrayStream ( )
protected

◆ loadVhdlTemplate()

void TestbenchGenerator::loadVhdlTemplate ( const std::string &  fileName,
std::string &  vhdlTemplate 
) const
private

Definition at line 163 of file TestbenchGenerator.cc.

164 {
165
166 ifstream input(fileName.c_str());
167 if (!input.is_open()) {
168 InvalidData exception(__FILE__, __LINE__, "",
169 "The VHDL template file " + fileName +
170 "unreadable.");
171 throw exception;
172 }
173
174 string line = "";
175 while (getline(input, line)) {
176 vhdlTemplate += line;
177 vhdlTemplate += "\n";
178 }
179 input.close();
180}

Referenced by writeTestbench().

◆ opcodeArrayStream()

std::ostringstream & TestbenchGenerator::opcodeArrayStream ( )
protected

◆ outputArrayStream()

std::ostringstream & TestbenchGenerator::outputArrayStream ( )
protected

◆ signalStream()

std::ostringstream & TestbenchGenerator::signalStream ( )
protected

◆ tbCodeStream()

std::ostringstream & TestbenchGenerator::tbCodeStream ( )
protected

Definition at line 223 of file TestbenchGenerator.cc.

223 {
224 return testbenchCode_;
225}

References testbenchCode_.

Referenced by FUTestbenchGenerator::createTbCode(), and RFTestbenchGenerator::createTbCode().

◆ writeStimulusArray()

void TestbenchGenerator::writeStimulusArray ( std::ostringstream &  stream,
std::vector< uint32_t > &  dataArray,
std::string  portName,
int  portWidth 
)
protectedvirtual

Definition at line 68 of file TestbenchGenerator.cc.

70 {
71
72 stream
73 << INDENT INDENT << "type " << portName
74 << "_data_array is array (natural range <>) of" << std::endl
76 << "std_logic_vector(" << portWidth - 1 << " downto 0);"
77 << std::endl << std::endl << INDENT INDENT
78 << "constant " << portName << "_data : "
79 << portName << "_data_array :=" << std::endl;
80
81 for (std::size_t i = 0; i < dataArray.size(); ++i) {
82 uint32_t input = dataArray.at(i);
83 std::string inputAsBinaryLiteral =
84 Conversion::toBinary(input, portWidth);
85 stream << INDENT INDENT;
86
87 if (i == 0) {
88 stream << "(";
89 } else {
90 stream << " ";
91 }
92 stream << "\"" << inputAsBinaryLiteral << "\"";
93 if (i == dataArray.size() - 1) {
94 stream << ");";
95 } else {
96 stream << ",";
97 }
98 stream << "\t -- @" << i << " = " << input << std::endl;
99 }
100 stream << std::endl;
101}
#define INDENT
static std::string toBinary(unsigned int source, unsigned int stringWidth=0)

References INDENT, and Conversion::toBinary().

Referenced by FUTestbenchGenerator::createStimulusArrays(), and RFTestbenchGenerator::writeDataArrays().

Here is the call graph for this function:

◆ writeTbConstants()

void TestbenchGenerator::writeTbConstants ( int  totalCycles,
int  outputIgnoreCycles 
)
protected

Definition at line 104 of file TestbenchGenerator.cc.

105 {
106
108 << INDENT INDENT << "constant IGNORE_OUTPUT_COUNT : integer := "
109 << outputIgnoreCycles << ";" << std::endl;
111 << INDENT INDENT << "constant TOTAL_CYCLE_COUNT : integer := "
112 << totalCycles << ";" << std::endl;
113}

References INDENT, and outputArrays_.

Referenced by FUTestbenchGenerator::createStimulus(), and RFTestbenchGenerator::createStimulus().

◆ writeTestbench()

void TestbenchGenerator::writeTestbench ( std::ofstream &  file,
HDB::HWBlockImplementation impl 
)
protected

Definition at line 116 of file TestbenchGenerator.cc.

117 {
118
119 string templateFile = findVhdlTemplate();
120 string vhdlTemplate = "";
121 loadVhdlTemplate(templateFile, vhdlTemplate);
122
123 string testBench =
124 (boost::format(vhdlTemplate)
126 % componentBinding_.str()
127 % signalDeclaration_.str()
129 % inputArrays_.str()
130 % opcodeArrays_.str()
131 % loadSignalArrays_.str()
132 % outputArrays_.str()
133 % impl->clkPort()
134 % impl->rstPort()
135 % impl->glockPort()
136 % testbenchCode_.str()).str();
137
138 file << testBench;
139}
void loadVhdlTemplate(const std::string &fileName, std::string &vhdlTemplate) const
std::string findVhdlTemplate() const

References HDB::HWBlockImplementation::clkPort(), componentBinding_, componentDeclaration_, componentInstantiation_, findVhdlTemplate(), HDB::HWBlockImplementation::glockPort(), inputArrays_, loadSignalArrays_, loadVhdlTemplate(), opcodeArrays_, outputArrays_, HDB::HWBlockImplementation::rstPort(), signalDeclaration_, and testbenchCode_.

Referenced by FUTestbenchGenerator::generateTestbench(), and RFTestbenchGenerator::generateTestbench().

Here is the call graph for this function:

Member Data Documentation

◆ componentBinding_

std::ostringstream TestbenchGenerator::componentBinding_
private

Definition at line 86 of file TestbenchGenerator.hh.

Referenced by bindingStream(), and writeTestbench().

◆ componentDeclaration_

std::ostringstream TestbenchGenerator::componentDeclaration_
private

Definition at line 85 of file TestbenchGenerator.hh.

Referenced by declarationStream(), and writeTestbench().

◆ componentInstantiation_

std::ostringstream TestbenchGenerator::componentInstantiation_
private

Definition at line 88 of file TestbenchGenerator.hh.

Referenced by instantiationStream(), and writeTestbench().

◆ inputArrays_

std::ostringstream TestbenchGenerator::inputArrays_
private

Definition at line 89 of file TestbenchGenerator.hh.

Referenced by inputArrayStream(), and writeTestbench().

◆ loadSignalArrays_

std::ostringstream TestbenchGenerator::loadSignalArrays_
private

Definition at line 91 of file TestbenchGenerator.hh.

Referenced by loadArrayStream(), and writeTestbench().

◆ opcodeArrays_

std::ostringstream TestbenchGenerator::opcodeArrays_
private

Definition at line 90 of file TestbenchGenerator.hh.

Referenced by opcodeArrayStream(), and writeTestbench().

◆ outputArrays_

std::ostringstream TestbenchGenerator::outputArrays_
private

Definition at line 92 of file TestbenchGenerator.hh.

Referenced by outputArrayStream(), writeTbConstants(), and writeTestbench().

◆ signalDeclaration_

std::ostringstream TestbenchGenerator::signalDeclaration_
private

Definition at line 87 of file TestbenchGenerator.hh.

Referenced by signalStream(), and writeTestbench().

◆ TB_TEMPLATE_

const std::string TestbenchGenerator::TB_TEMPLATE_
staticprivate
Initial value:
=
"testbench.vhdl.template"

Definition at line 95 of file TestbenchGenerator.hh.

Referenced by findVhdlTemplate().

◆ testbenchCode_

std::ostringstream TestbenchGenerator::testbenchCode_
private

Definition at line 93 of file TestbenchGenerator.hh.

Referenced by tbCodeStream(), and writeTestbench().


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