OpenASIP 2.2
Loading...
Searching...
No Matches
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.

◆ ~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}
static bool changeWorkingDir(const std::string &path)
std::string file(int index) const
virtual std::string createWorkDir()
bool compileOneFile(std::string file, std::vector< std::string > &errors)

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}
static int runShellCommandAndGetOutput(const std::string &command, std::vector< std::string > &outputLines, std::size_t maxOutputLines=DEFAULT_MAX_OUTPUT_LINES, bool includeStdErr=false)

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}
static const std::string DIRECTORY_SEPARATOR
void setWorkDir(std::string dir)
bool mapWorkDir(std::string file, std::vector< std::string > &errors)

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}
void parseErrorMessages(std::vector< std::string > &inputMsg, std::vector< std::string > &errors)
virtual bool simulate(std::vector< std::string > &errors)

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

Referenced by simulate().

Here is the call graph for this function:

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