OpenASIP 2.2
Loading...
Searching...
No Matches
ModelsimSimulator.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2010 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file ModelsimSimulator.cc
26 *
27 * Implementation of ModelsimSimulator
28 *
29 * @author Otto Esko 2010 (otto.esko-no.spam-tut.fi)
30 * @note rating: red
31 */
32
33#include <string>
34#include <vector>
35#include <iostream>
36#include "FileSystem.hh"
38#include "ModelsimSimulator.hh"
39#include "Application.hh"
40
41using std::string;
42using std::vector;
43
44
46 std::string tbFile,
47 std::vector<std::string> hdlFiles,
48 bool verbose,
49 bool leaveDirty):
50 ImplementationSimulator(tbFile, hdlFiles, verbose, leaveDirty) {
51}
52
55
56bool ModelsimSimulator::compile(vector<string>& errors) {
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}
82
83bool ModelsimSimulator::simulate(vector<string>& errors) {
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}
96
97
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}
130
131bool
132ModelsimSimulator::compileOneFile(string file, vector<string>& errors) {
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)
static bool changeWorkingDir(const std::string &path)
static const std::string DIRECTORY_SEPARATOR
void setWorkDir(std::string dir)
std::string file(int index) const
void parseErrorMessages(std::vector< std::string > &inputMsg, std::vector< std::string > &errors)
virtual bool compile(std::vector< std::string > &errors)
virtual std::string createWorkDir()
bool compileOneFile(std::string file, std::vector< std::string > &errors)
ModelsimSimulator(std::string tbFile, std::vector< std::string > hdlFiles, bool verbose, bool leaveDirty)
bool mapWorkDir(std::string file, std::vector< std::string > &errors)
virtual bool simulate(std::vector< std::string > &errors)