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

#include <GhdlSimulator.hh>

Inheritance diagram for GhdlSimulator:
Inheritance graph
Collaboration diagram for GhdlSimulator:
Collaboration graph

Public Member Functions

 GhdlSimulator (std::string tbFile, std::vector< std::string > hdlFiles, bool verbose, bool leaveDirty)
 
virtual ~GhdlSimulator ()
 
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 ()
 

Private Member Functions

bool importFile (std::string file, std::vector< std::string > &errors)
 
bool compileDesign (std::vector< std::string > &errors)
 

Additional Inherited Members

- Protected Member Functions inherited from ImplementationSimulator
virtual std::string createWorkDir ()
 
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)
 

Detailed Description

Definition at line 40 of file GhdlSimulator.hh.

Constructor & Destructor Documentation

◆ GhdlSimulator()

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

Definition at line 44 of file GhdlSimulator.cc.

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

◆ ~GhdlSimulator()

GhdlSimulator::~GhdlSimulator ( )
virtual

Definition at line 52 of file GhdlSimulator.cc.

52  {
53 }

Member Function Documentation

◆ compile()

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

Implements ImplementationSimulator.

Definition at line 55 of file GhdlSimulator.cc.

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

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

Here is the call graph for this function:

◆ compileDesign()

bool GhdlSimulator::compileDesign ( std::vector< std::string > &  errors)
private

Definition at line 120 of file GhdlSimulator.cc.

120  {
121  string command = "ghdl -m --ieee=synopsys --workdir="
122  + workDir() + " testbench 2>&1";
123  if (verbose()) {
124  // TODO: get output stream
125  std::cout << command << std::endl;
126  }
127  int rv = Application::runShellCommandAndGetOutput(command, errors);
128  return rv == 0;
129 }

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

Referenced by compile().

Here is the call graph for this function:

◆ importFile()

bool GhdlSimulator::importFile ( std::string  file,
std::vector< std::string > &  errors 
)
private

Definition at line 108 of file GhdlSimulator.cc.

109  {
110  string command = "ghdl -i --ieee=synopsys --workdir="
111  + workDir() + " " + file + " 2>&1";
112  if (verbose()) {
113  // TODO: get output stream
114  std::cout << command << std::endl;
115  }
116  int rv = Application::runShellCommandAndGetOutput(command, errors);
117  return rv == 0;
118 }

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

Referenced by compile().

Here is the call graph for this function:

◆ simulate()

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

Implements ImplementationSimulator.

Definition at line 80 of file GhdlSimulator.cc.

80  {
81  errors.clear();
82  string baseDir = tbDirectory();
83  if (!FileSystem::changeWorkingDir(baseDir)) {
84  errors.push_back("Couldn't change directory to " + baseDir);
85  return false;
86  }
87 
88  string command;
89  if (FileSystem::fileExists("testbench")) {
90  command = "./testbench 2>&1";
91  } else {
92  // In the latest GHDL no executable is produces, thus the simulation
93  // command is different.
94  command = string("ghdl -r --ieee=synopsys --workdir=") + workDir()
95  + " testbench 2>&1";
96  }
97  if (verbose()) {
98  std::cout << command << std::endl;
99  }
100  vector<string> messages;
101  int rv = Application::runShellCommandAndGetOutput(command, messages);
102  // call parse
103  parseErrorMessages(messages, errors);
104  return rv == 0 && errors.size() == 0;
105 }

References FileSystem::changeWorkingDir(), FileSystem::fileExists(), ImplementationSimulator::parseErrorMessages(), Application::runShellCommandAndGetOutput(), ImplementationSimulator::tbDirectory(), ImplementationSimulator::verbose(), and ImplementationSimulator::workDir().

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
ImplementationSimulator::createWorkDir
virtual std::string createWorkDir()
Definition: ImplementationSimulator.cc:66
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
ImplementationSimulator::hdlFileCount
int hdlFileCount() const
Definition: ImplementationSimulator.cc:91
GhdlSimulator::importFile
bool importFile(std::string file, std::vector< std::string > &errors)
Definition: GhdlSimulator.cc:108
ImplementationSimulator::workDir
std::string workDir() const
Definition: ImplementationSimulator.cc:79
GhdlSimulator::compileDesign
bool compileDesign(std::vector< std::string > &errors)
Definition: GhdlSimulator.cc:120
FileSystem::changeWorkingDir
static bool changeWorkingDir(const std::string &path)
Definition: FileSystem.cc:185
FileSystem::fileExists
static bool fileExists(const std::string fileName)
ImplementationSimulator::ImplementationSimulator
ImplementationSimulator()