36#include <boost/random.hpp> 
   37#include <boost/nondet_random.hpp> 
   58using std::ostringstream;
 
   65    rfEntry_(rf), rfImpl_(NULL), rfArch_(NULL), machRf_(NULL), msm_(NULL),
 
   66    inputPorts_(), inputLoadPorts_(), inputOpcodePorts_(), outputPorts_(),
 
   67    outputLoadPorts_(), outputOpcodePorts_() {
 
 
  157             assert(
false && 
"RF port implementation does not have direction");
 
 
  171        << 
INDENT << 
"for tested_rf_0 : rf_under_test use entity work.";
 
  175        << 
INDENT << 
"component rf_under_test" << std::endl;
 
  177        << 
INDENT << 
"tested_rf_0\t:\trf_under_test " << std::endl;
 
  181    if (!sizeGeneric.empty() || !widthGeneric.empty()) {
 
  186        if (!sizeGeneric.empty()) {
 
  193            if (!widthGeneric.empty()) {
 
  199        if (!widthGeneric.empty()) {
 
  208            << 
");" << std::endl;
 
  224             << 
"in std_logic_vector(" << portWidth
 
  225             << 
"-1 downto 0);" << std::endl;    
 
  229             << 
"in std_logic;" << std::endl;
 
  233             << 
"in std_logic_vector(" << opcodeWidth
 
  234             << 
"-1 downto 0);" << std::endl;
 
  238            << 
"std_logic_vector(" << portWidth << 
"-1 downto 0);"  
  242             << 
"\t: std_logic_vector(1-1 downto 0);" << std::endl;
 
  245             << 
"std_logic_vector(" << opcodeWidth << 
"-1 downto 0);" 
  262             << 
"out std_logic_vector(" << portWidth
 
  263             << 
"-1 downto 0);" << std::endl;    
 
  267             << 
"in std_logic;" << std::endl;
 
  271             << 
"in std_logic_vector(" << opcodeWidth
 
  272             << 
"-1 downto 0);" << std::endl;
 
  276            << 
"std_logic_vector(" << portWidth << 
"-1 downto 0);"  
  280             << 
"\t: std_logic_vector(1-1 downto 0);" << std::endl;
 
  283             << 
"std_logic_vector(" << opcodeWidth << 
"-1 downto 0);" 
  314        << 
INDENT << 
"end component;"  
 
  353    boost::uniform_int<> distribution(INT_MIN, INT_MAX);
 
  355    rng.seed(time(NULL));
 
  356    boost::variate_generator<boost::mt19937&, boost::uniform_int<> >
 
  357        randomNumber(rng, distribution);
 
  364        fillCycles = 
static_cast<int>(ceil(size/ports));
 
  375    int outputWaitCycles = 0;
 
  377    int pipelineFlushCycles = 0;
 
  378    if (fillCycles > readCycles) {
 
  381        outputWaitCycles = fillCycles + pipelineFlushCycles - readCycles;
 
  383        pipelineFlushCycles = 
rfArch_->
latency() + (readCycles - fillCycles);
 
  394    int rdLoadPortIndex = 0;
 
  395    int rdLoadRegIndex = 0;
 
  398    for (
int i = 0; i < fillCycles; i++) {
 
  400        if (i < outputWaitCycles) {
 
  403                outputData[portName].push_back(0);
 
  408                outputData[portName].push_back(
 
  423                outputOpcode[opcodePort].push_back(0);
 
  424                outputLoad[loadPort].push_back(0);
 
  430                outputOpcode[opcodePort].push_back(rdLoadRegIndex);
 
  431                outputLoad[loadPort].push_back(1);
 
  443            int nopPortIndex = wrPortIndex;
 
  446            if (j < rfArch_->maxWrites() && wrRegIndex < 
rfArch_->
size()) {
 
  447                uint32_t stimulus = (uint32_t)randomNumber();
 
  450                stimulus = (stimulus << (32 - portWidth) >> (32 - portWidth));
 
  455                inputData[portName].push_back(stimulus);
 
  458                uint32_t opcode = 
static_cast<uint32_t
>(wrRegIndex);
 
  459                inputOpcode[opcodePort].push_back(opcode);
 
  463                inputLoad[loadPort].push_back(load);
 
  471                uint32_t stimulus = 0;
 
  476                inputData[portName].push_back(stimulus);
 
  479                inputOpcode[opcodePort].push_back(opcode);
 
  481                inputLoad[loadPort].push_back(load);
 
  491    for (
int i = 0; i < pipelineFlushCycles; i++) {
 
  494            uint32_t stimulus = 0;
 
  499            inputData[portName].push_back(stimulus);
 
  502            inputOpcode[opcodePort].push_back(opcode);
 
  504            inputLoad[loadPort].push_back(load);
 
  510            outputOpcode[opcodePort].push_back(rdLoadRegIndex);
 
  511            outputLoad[loadPort].push_back(1);
 
  521            outputData[portName].push_back(
 
  532                         outputOpcode, outputLoad);
 
  534    int totalCycleCount = fillCycles + pipelineFlushCycles;
 
 
  551            << 
INDENT INDENT << portName << 
" <= " << portName << 
"_data(" 
  552            << 
"current_cycle);" << std::endl
 
  554            <<
"_data(current_cycle);" << std::endl
 
  556            << 
"_data(current_cycle);" << std::endl;
 
  565            <<
"_data(current_cycle);" << std::endl
 
  567            << 
"_data(current_cycle);" << std::endl;
 
  572        << 
"if current_cycle >= IGNORE_OUTPUT_COUNT then" << std::endl;
 
  577            << 
"assert " << portName << 
" = " << portName << 
"_data" 
  578            << 
"(current_cycle)" << std::endl
 
  580            << 
"report lf & \"TCE Assert: Verification failed at cycle \" " 
  581            << 
"& integer'image(current_cycle)" << std::endl
 
  583            << 
"& to_hstring(" << portName << 
")"  
  586            << 
"\" expected: \" & to_hstring(" << portName
 
  587            << 
"_data(current_cycle))  severity error;"  
  588            << std::endl << std::endl;
 
 
  649     std::ostringstream& stream,
 
  653    for (PortDataArray::iterator i = array.begin(); i != array.end(); i++) {
 
  654        string portName = i->first;
 
  655        vector<uint32_t> data = i->second;
 
 
#define assert(condition)
 
std::string glockPort() const
 
std::string moduleName() const
 
std::string rstPort() const
 
std::string clkPort() const
 
std::string loadPort() const
 
int readPortCount() const
 
bool hasParameterizedWidth() const
 
int writePortCount() const
 
bool zeroRegister() const
 
bool hasParameterizedSize() const
 
RFArchitecture & architecture() const
 
RFImplementation & implementation() const
 
RFPortImplementation & port(int index) const
 
std::string sizeParameter() const
 
std::string widthParameter() const
 
Direction direction() const
 
std::string opcodePort() const
 
MachineState * build(const TTAMachine::Machine &machine, MemorySystem &memSys)
 
RegisterFileState & registerFileState(const std::string &name)
 
static NullRegisterFileState & instance()
 
RFTestbenchGenerator(HDB::RFEntry *rf)
 
int opcodePortWidth() const
 
MemorySystem * memSystem_
 
void writeDataArrays(std::ostringstream &stream, PortDataArray &array, int portWidth)
 
HDB::RFArchitecture * rfArch_
 
static const std::string RF_NAME_
 
virtual ~RFTestbenchGenerator()
 
virtual void generateTestbench(std::ofstream &file)
 
TTAMachine::RegisterFile * machRf_
 
std::vector< std::string > outputPorts_
 
std::vector< std::string > inputPorts_
 
HDB::RFImplementation * rfImpl_
 
std::vector< std::string > outputOpcodePorts_
 
TTAMachine::Machine * machine_
 
std::vector< std::string > inputLoadPorts_
 
void createStimulusArrays(PortDataArray &inputData, PortDataArray &inputOpcode, PortDataArray &inputLoad, PortDataArray &outputData, PortDataArray &outputOpcode, PortDataArray &outputLoad)
 
std::vector< std::string > inputOpcodePorts_
 
void createMachineState()
 
std::vector< std::string > outputLoadPorts_
 
void createTbInstantiation()
 
virtual RegisterState & registerState(int index)
 
virtual void setValue(const SimValue &value)
 
virtual const SimValue & value() const
 
unsigned int unsignedValue() const
 
virtual void addRegisterFile(RegisterFile &unit)
 
@ NORMAL
Used for general register allocation.
 
std::ostringstream & opcodeArrayStream()
 
std::map< std::string, std::vector< uint32_t > > PortDataArray
 
std::ostringstream & inputArrayStream()
 
void writeTbConstants(int totalCycles, int outputIgnoreCycles)
 
std::ostringstream & tbCodeStream()
 
std::ostringstream & outputArrayStream()
 
std::ostringstream & instantiationStream()
 
std::ostringstream & loadArrayStream()
 
std::ostringstream & bindingStream()
 
std::ostringstream & declarationStream()
 
std::ostringstream & signalStream()
 
void writeTestbench(std::ofstream &file, HDB::HWBlockImplementation *impl)
 
virtual void writeStimulusArray(std::ostringstream &stream, std::vector< uint32_t > &dataArray, std::string portName, int portWidth)