OpenASIP  2.0
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 ( )

◆ ~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 }

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

Definition at line 203 of file TestbenchGenerator.cc.

203  {
204  return inputArrays_;
205 }

References inputArrays_.

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

◆ 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

Definition at line 208 of file TestbenchGenerator.cc.

208  {
209  return opcodeArrays_;
210 }

References opcodeArrays_.

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

◆ outputArrayStream()

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

Definition at line 218 of file TestbenchGenerator.cc.

218  {
219  return outputArrays_;
220 }

References outputArrays_.

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

◆ 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 RFTestbenchGenerator::createTbCode(), and FUTestbenchGenerator::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 }

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 RFTestbenchGenerator::createStimulus(), and FUTestbenchGenerator::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)
125  % componentDeclaration_.str()
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 }

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

Referenced by RFTestbenchGenerator::generateTestbench(), and FUTestbenchGenerator::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:
HDB::HWBlockImplementation::clkPort
std::string clkPort() const
Definition: HWBlockImplementation.cc:175
TestbenchGenerator::componentDeclaration_
std::ostringstream componentDeclaration_
Definition: TestbenchGenerator.hh:85
TestbenchGenerator::inputArrays_
std::ostringstream inputArrays_
Definition: TestbenchGenerator.hh:89
Environment::implementationTesterTemplatePaths
static std::vector< std::string > implementationTesterTemplatePaths()
Definition: Environment.cc:1129
HDB::HWBlockImplementation::rstPort
std::string rstPort() const
Definition: HWBlockImplementation.cc:197
INDENT
#define INDENT
Definition: TestbenchGenerator.cc:52
TestbenchGenerator::TB_TEMPLATE_
static const std::string TB_TEMPLATE_
Definition: TestbenchGenerator.hh:95
TestbenchGenerator::componentBinding_
std::ostringstream componentBinding_
Definition: TestbenchGenerator.hh:86
Conversion::toBinary
static std::string toBinary(unsigned int source, unsigned int stringWidth=0)
Definition: Conversion.cc:155
TestbenchGenerator::loadSignalArrays_
std::ostringstream loadSignalArrays_
Definition: TestbenchGenerator.hh:91
InvalidData
Definition: Exception.hh:149
TestbenchGenerator::componentInstantiation_
std::ostringstream componentInstantiation_
Definition: TestbenchGenerator.hh:88
TestbenchGenerator::opcodeArrays_
std::ostringstream opcodeArrays_
Definition: TestbenchGenerator.hh:90
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
TestbenchGenerator::findVhdlTemplate
std::string findVhdlTemplate() const
Definition: TestbenchGenerator.cc:142
FileSystem::fileExists
static bool fileExists(const std::string fileName)
TestbenchGenerator::loadVhdlTemplate
void loadVhdlTemplate(const std::string &fileName, std::string &vhdlTemplate) const
Definition: TestbenchGenerator.cc:163
HDB::HWBlockImplementation::glockPort
std::string glockPort() const
Definition: HWBlockImplementation.cc:219
TestbenchGenerator::signalDeclaration_
std::ostringstream signalDeclaration_
Definition: TestbenchGenerator.hh:87
TestbenchGenerator::outputArrays_
std::ostringstream outputArrays_
Definition: TestbenchGenerator.hh:92
TestbenchGenerator::testbenchCode_
std::ostringstream testbenchCode_
Definition: TestbenchGenerator.hh:93