OpenASIP  2.0
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
ModelsimSimulator Class Reference

#include <ModelsimSimulator.hh>

Inheritance diagram for ModelsimSimulator:
Inheritance graph
Collaboration diagram for ModelsimSimulator:
Collaboration graph

Public Member Functions

 ModelsimSimulator (std::string tbFile, std::vector< std::string > hdlFiles, bool verbose, bool leaveDirty)
 
virtual ~ModelsimSimulator ()
 
virtual bool compile (std::vector< std::string > &errors)
 
virtual bool simulate (std::vector< std::string > &errors)
 
- Public Member Functions inherited from ImplementationSimulator
 ImplementationSimulator (std::string tbFile, std::vector< std::string > hdlFiles, bool verbose, bool leaveDirty)
 
virtual ~ImplementationSimulator ()
 

Protected Member Functions

virtual std::string createWorkDir ()
 
- Protected Member Functions inherited from ImplementationSimulator
void setWorkDir (std::string dir)
 
std::string workDir () const
 
std::string tbDirectory () const
 
std::string tbFile () const
 
int hdlFileCount () const
 
std::string file (int index) const
 
bool verbose ()
 
void parseErrorMessages (std::vector< std::string > &inputMsg, std::vector< std::string > &errors)
 

Private Member Functions

bool mapWorkDir (std::string file, std::vector< std::string > &errors)
 
bool compileOneFile (std::string file, std::vector< std::string > &errors)
 

Detailed Description

Definition at line 40 of file ModelsimSimulator.hh.

Constructor & Destructor Documentation

◆ ModelsimSimulator()

ModelsimSimulator::ModelsimSimulator ( std::string  tbFile,
std::vector< std::string >  hdlFiles,
bool  verbose,
bool  leaveDirty 
)

Definition at line 45 of file ModelsimSimulator.cc.

49  :
50  ImplementationSimulator(tbFile, hdlFiles, verbose, leaveDirty) {
51 }

◆ ~ModelsimSimulator()

ModelsimSimulator::~ModelsimSimulator ( )
virtual

Definition at line 53 of file ModelsimSimulator.cc.

53  {
54 }

Member Function Documentation

◆ compile()

bool ModelsimSimulator::compile ( std::vector< std::string > &  errors)
virtual

Implements ImplementationSimulator.

Definition at line 56 of file ModelsimSimulator.cc.

56  {
57  string workDir = createWorkDir();
58  if (workDir.empty()) {
59  errors.push_back("Couldn't create work dir. Are the modelsim "
60  "executables in PATH?");
61  return false;
62  }
63  string baseDir = tbDirectory();
64  if (!FileSystem::changeWorkingDir(baseDir)) {
65  errors.push_back("Couldn't change directory to " + baseDir);
66  return false;
67  }
68  for (int i = 0; i < hdlFileCount(); i++) {
69  if (!compileOneFile(file(i), errors)) {
70  return false;
71  } else {
72  errors.clear();
73  }
74  }
75  if (!compileOneFile(tbFile(), errors)) {
76  return false;
77  }
78  errors.clear();
79 
80  return true;
81 }

References FileSystem::changeWorkingDir(), compileOneFile(), createWorkDir(), ImplementationSimulator::file(), ImplementationSimulator::hdlFileCount(), ImplementationSimulator::tbDirectory(), ImplementationSimulator::tbFile(), and ImplementationSimulator::workDir().

Here is the call graph for this function:

◆ compileOneFile()

bool ModelsimSimulator::compileOneFile ( std::string  file,
std::vector< std::string > &  errors 
)
private

Definition at line 132 of file ModelsimSimulator.cc.

132  {
133  string command = "vcom " + file + " 2>&1";
134  if (verbose()) {
135  std::cout << command << std::endl;
136  }
137  int rv = Application::runShellCommandAndGetOutput(command, errors);
138  return rv == 0;
139 }

References ImplementationSimulator::file(), Application::runShellCommandAndGetOutput(), and ImplementationSimulator::verbose().

Referenced by compile().

Here is the call graph for this function:

◆ createWorkDir()

std::string ModelsimSimulator::createWorkDir ( )
protectedvirtual

Reimplemented from ImplementationSimulator.

Definition at line 98 of file ModelsimSimulator.cc.

98  {
99  string work = tbDirectory() + FileSystem::DIRECTORY_SEPARATOR + "work";
100  string createLib = "vlib " + work + " 2>&1";
101  if (verbose()) {
102  std::cout << createLib << std::endl;
103  }
104  vector<string> messages;
105  int rv = Application::runShellCommandAndGetOutput(createLib, messages);
106  if (rv != 0) {
107  if (verbose()) {
108  for (unsigned int i = 0; i < messages.size(); i++) {
109  std::cout << messages.at(i) << std::endl;
110  }
111  }
112  string failed = "";
113  return failed;
114  }
115  string mapWorkDir = "vmap work " + work + " 2>&1";
116  messages.clear();
118  if (rv2 != 0) {
119  if (verbose()) {
120  for (unsigned int i = 0; i < messages.size(); i++) {
121  std::cout << messages.at(i) << std::endl;
122  }
123  }
124  string failed = "";
125  return failed;
126  }
127  setWorkDir(work);
128  return work;
129 }

References FileSystem::DIRECTORY_SEPARATOR, mapWorkDir(), Application::runShellCommandAndGetOutput(), ImplementationSimulator::setWorkDir(), ImplementationSimulator::tbDirectory(), and ImplementationSimulator::verbose().

Referenced by compile().

Here is the call graph for this function:

◆ mapWorkDir()

bool ModelsimSimulator::mapWorkDir ( std::string  file,
std::vector< std::string > &  errors 
)
private

Referenced by createWorkDir().

◆ simulate()

bool ModelsimSimulator::simulate ( std::vector< std::string > &  errors)
virtual

Implements ImplementationSimulator.

Definition at line 83 of file ModelsimSimulator.cc.

83  {
84  // get correct simulation time from somewhere?
85  // There's practically no difference between 30 ns and 300 ns simulation
86  // time
87  string simulate = "vsim -c -do \"run 300ns;quit\" work.testbench 2>&1";
88  if (verbose()) {
89  std::cout << simulate << std::endl;
90  }
91  vector<string> messages;
93  parseErrorMessages(messages, errors);
94  return rv == 0 && errors.size() == 0;
95 }

References ImplementationSimulator::parseErrorMessages(), Application::runShellCommandAndGetOutput(), and ImplementationSimulator::verbose().

Here is the call graph for this function:

The documentation for this class was generated from the following files:
ImplementationSimulator::verbose
bool verbose()
Definition: ImplementationSimulator.cc:99
ImplementationSimulator::tbDirectory
std::string tbDirectory() const
Definition: ImplementationSimulator.cc:83
ImplementationSimulator::parseErrorMessages
void parseErrorMessages(std::vector< std::string > &inputMsg, std::vector< std::string > &errors)
Definition: ImplementationSimulator.cc:104
ImplementationSimulator::file
std::string file(int index) const
Definition: ImplementationSimulator.cc:95
Application::runShellCommandAndGetOutput
static int runShellCommandAndGetOutput(const std::string &command, std::vector< std::string > &outputLines, std::size_t maxOutputLines=DEFAULT_MAX_OUTPUT_LINES, bool includeStdErr=false)
Definition: Application.cc:338
ImplementationSimulator::tbFile
std::string tbFile() const
Definition: ImplementationSimulator.cc:87
ModelsimSimulator::createWorkDir
virtual std::string createWorkDir()
Definition: ModelsimSimulator.cc:98
ImplementationSimulator::hdlFileCount
int hdlFileCount() const
Definition: ImplementationSimulator.cc:91
ImplementationSimulator::workDir
std::string workDir() const
Definition: ImplementationSimulator.cc:79
ModelsimSimulator::compileOneFile
bool compileOneFile(std::string file, std::vector< std::string > &errors)
Definition: ModelsimSimulator.cc:132
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
FileSystem::changeWorkingDir
static bool changeWorkingDir(const std::string &path)
Definition: FileSystem.cc:185
ImplementationSimulator::setWorkDir
void setWorkDir(std::string dir)
Definition: ImplementationSimulator.cc:75
ModelsimSimulator::simulate
virtual bool simulate(std::vector< std::string > &errors)
Definition: ModelsimSimulator.cc:83
ImplementationSimulator::ImplementationSimulator
ImplementationSimulator()
ModelsimSimulator::mapWorkDir
bool mapWorkDir(std::string file, std::vector< std::string > &errors)