2014-11-24 02:06:10 +00:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
//*************************************************************************
|
|
|
|
// DESCRIPTION: verilator_coverage: main()
|
|
|
|
//
|
2019-11-08 03:33:59 +00:00
|
|
|
// Code available from: https://verilator.org
|
2014-11-24 02:06:10 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2020-01-06 23:05:53 +00:00
|
|
|
// Copyright 2003-2020 by Wilson Snyder. This program is free software; you can
|
2014-11-24 02:06:10 +00:00
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
// Version 2.0.
|
|
|
|
//
|
|
|
|
// Verilator is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
//*************************************************************************
|
2019-10-05 00:17:11 +00:00
|
|
|
|
2014-11-24 02:06:10 +00:00
|
|
|
// Cheat for speed and compile .cpp files into one object
|
2018-06-28 22:55:36 +00:00
|
|
|
#include "config_build.h"
|
|
|
|
#ifndef HAVE_CONFIG_BUILD
|
2018-07-02 13:11:20 +00:00
|
|
|
# error "Something failed during ./configure as config_build.h is incomplete. Perhaps you used autoreconf, don't."
|
2018-06-28 22:55:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "verilatedos.h"
|
|
|
|
|
2014-11-24 02:06:10 +00:00
|
|
|
#define _V3ERROR_NO_GLOBAL_ 1
|
|
|
|
#include "V3Error.cpp"
|
2015-02-27 01:40:45 +00:00
|
|
|
#include "V3String.cpp"
|
|
|
|
#include "V3Os.cpp"
|
2014-11-24 02:06:10 +00:00
|
|
|
#include "VlcTop.cpp"
|
|
|
|
|
|
|
|
#include "VlcOptions.h"
|
|
|
|
#include "VlcTop.h"
|
|
|
|
|
2018-10-14 17:43:24 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <fstream>
|
|
|
|
|
2014-11-24 02:06:10 +00:00
|
|
|
//######################################################################
|
|
|
|
// VlcOptions
|
|
|
|
|
|
|
|
void VlcOptions::addReadFile(const string& filename) {
|
|
|
|
if (m_readFiles.find(filename) == m_readFiles.end()) {
|
2019-05-08 03:00:52 +00:00
|
|
|
m_readFiles.insert(filename);
|
2014-11-24 02:06:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string VlcOptions::version() {
|
|
|
|
string ver = DTVERSION;
|
|
|
|
ver += " rev "+cvtToStr(DTVERSION_rev);
|
|
|
|
return ver;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VlcOptions::onoff(const char* sw, const char* arg, bool& flag) {
|
|
|
|
// if sw==arg, then return true (found it), and flag=true
|
|
|
|
// if sw=="-no-arg", then return true (found it), and flag=false
|
|
|
|
// if sw=="-noarg", then return true (found it), and flag=false
|
|
|
|
// else return false
|
2017-04-29 00:09:27 +00:00
|
|
|
if (arg[0]!='-') v3fatalSrc("OnOff switches must have leading dash.");
|
2019-05-19 20:13:13 +00:00
|
|
|
if (0==strcmp(sw, arg)) { flag = true; return true; }
|
|
|
|
else if (0==strncmp(sw, "-no", 3) && (0==strcmp(sw+3, arg+1))) { flag = false; return true; }
|
|
|
|
else if (0==strncmp(sw, "-no-", 4) && (0==strcmp(sw+4, arg+1))) { flag = false; return true; }
|
2014-11-24 02:06:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VlcOptions::parseOptsList(int argc, char** argv) {
|
|
|
|
// Parse parameters
|
|
|
|
// Note argc and argv DO NOT INCLUDE the filename in [0]!!!
|
|
|
|
// May be called recursively when there are -f files.
|
|
|
|
#define shift { ++i; }
|
|
|
|
for (int i=0; i<argc; ) {
|
2019-05-08 03:00:52 +00:00
|
|
|
UINFO(9, " Option: "<<argv[i]<<endl);
|
|
|
|
if (argv[i][0]=='-') {
|
2019-11-10 01:35:12 +00:00
|
|
|
const char* sw = argv[i];
|
2019-05-08 03:00:52 +00:00
|
|
|
bool flag = true;
|
|
|
|
// Allow gnu -- switches
|
|
|
|
if (sw[0]=='-' && sw[1]=='-') ++sw;
|
|
|
|
if (0) {}
|
|
|
|
// Single switches
|
2019-05-19 20:13:13 +00:00
|
|
|
else if (onoff (sw, "-annotate-all", flag/*ref*/) ) { m_annotateAll = flag; }
|
|
|
|
else if (onoff (sw, "-rank", flag/*ref*/) ) { m_rank = flag; }
|
|
|
|
else if (onoff (sw, "-unlink", flag/*ref*/) ) { m_unlink = flag; }
|
2019-05-08 03:00:52 +00:00
|
|
|
// Parameterized switches
|
2019-05-19 20:13:13 +00:00
|
|
|
else if (!strcmp(sw, "-annotate-min") && (i+1)<argc ) {
|
2018-03-08 00:52:29 +00:00
|
|
|
shift;
|
|
|
|
m_annotateMin = atoi(argv[i]);
|
|
|
|
}
|
2019-05-19 20:13:13 +00:00
|
|
|
else if (!strcmp(sw, "-annotate") && (i+1)<argc ) {
|
2019-05-08 03:00:52 +00:00
|
|
|
shift;
|
|
|
|
m_annotateOut = argv[i];
|
|
|
|
}
|
2019-05-19 20:13:13 +00:00
|
|
|
else if (!strcmp(sw, "-debug") ) {
|
2019-05-08 03:00:52 +00:00
|
|
|
V3Error::debugDefault(3);
|
|
|
|
}
|
2019-05-19 20:13:13 +00:00
|
|
|
else if (!strcmp(sw, "-debugi") && (i+1)<argc ) {
|
2019-05-08 03:00:52 +00:00
|
|
|
shift;
|
|
|
|
V3Error::debugDefault(atoi(argv[i]));
|
|
|
|
}
|
2019-05-19 20:13:13 +00:00
|
|
|
else if (!strcmp(sw, "-V") ) {
|
2019-05-08 03:00:52 +00:00
|
|
|
showVersion(true);
|
|
|
|
exit(0);
|
|
|
|
}
|
2019-05-19 20:13:13 +00:00
|
|
|
else if (!strcmp(sw, "-version") ) {
|
2019-05-08 03:00:52 +00:00
|
|
|
showVersion(false);
|
|
|
|
exit(0);
|
|
|
|
}
|
2019-05-19 20:13:13 +00:00
|
|
|
else if (!strcmp(sw, "-write") && (i+1)<argc ) {
|
2019-05-08 03:00:52 +00:00
|
|
|
shift;
|
|
|
|
m_writeFile = argv[i];
|
|
|
|
}
|
|
|
|
else {
|
2018-08-25 13:52:45 +00:00
|
|
|
v3fatal("Invalid option: "<<argv[i]);
|
2019-05-08 03:00:52 +00:00
|
|
|
}
|
|
|
|
shift;
|
|
|
|
} // - options
|
|
|
|
else if (1) {
|
|
|
|
addReadFile(argv[i]);
|
|
|
|
shift;
|
|
|
|
}
|
|
|
|
else {
|
2018-08-25 13:52:45 +00:00
|
|
|
v3fatal("Invalid argument: "<<argv[i]);
|
2019-05-08 03:00:52 +00:00
|
|
|
shift;
|
|
|
|
}
|
2014-11-24 02:06:10 +00:00
|
|
|
}
|
|
|
|
#undef shift
|
|
|
|
}
|
|
|
|
|
|
|
|
void VlcOptions::showVersion(bool verbose) {
|
|
|
|
cout <<version();
|
|
|
|
cout <<endl;
|
|
|
|
if (!verbose) return;
|
|
|
|
|
|
|
|
cout <<endl;
|
2020-01-06 23:05:53 +00:00
|
|
|
cout << "Copyright 2003-2020 by Wilson Snyder. Verilator is free software; you can\n";
|
2014-11-24 02:06:10 +00:00
|
|
|
cout << "redistribute it and/or modify the Verilator internals under the terms of\n";
|
|
|
|
cout << "either the GNU Lesser General Public License Version 3 or the Perl Artistic\n";
|
|
|
|
cout << "License Version 2.0.\n";
|
|
|
|
|
|
|
|
cout <<endl;
|
2019-11-08 03:41:34 +00:00
|
|
|
cout << "See https://verilator.org for documentation\n";
|
2014-11-24 02:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
|
|
|
int main(int argc, char** argv, char** env) {
|
|
|
|
// General initialization
|
2018-02-02 02:24:41 +00:00
|
|
|
std::ios::sync_with_stdio();
|
2014-11-24 02:06:10 +00:00
|
|
|
|
|
|
|
VlcTop top;
|
|
|
|
|
|
|
|
// Command option parsing
|
|
|
|
top.opt.parseOptsList(argc-1, argv+1);
|
|
|
|
|
|
|
|
if (top.opt.readFiles().empty()) {
|
2019-05-08 03:00:52 +00:00
|
|
|
top.opt.addReadFile("vlt_coverage.dat");
|
2014-11-24 02:06:10 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 02:26:30 +00:00
|
|
|
{
|
2019-05-08 03:00:52 +00:00
|
|
|
const VlStringSet& readFiles = top.opt.readFiles();
|
|
|
|
for (VlStringSet::iterator it = readFiles.begin(); it != readFiles.end(); ++it) {
|
|
|
|
string filename = *it;
|
|
|
|
top.readCoverage(filename);
|
|
|
|
}
|
2014-11-24 02:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (debug() >= 9) {
|
2019-05-08 03:00:52 +00:00
|
|
|
top.tests().dump(true);
|
|
|
|
top.points().dump();
|
2014-11-24 02:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
V3Error::abortIfWarnings();
|
2018-10-14 22:39:33 +00:00
|
|
|
if (!top.opt.annotateOut().empty()) {
|
2014-11-24 02:06:10 +00:00
|
|
|
top.annotate(top.opt.annotateOut());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (top.opt.rank()) {
|
2019-05-08 03:00:52 +00:00
|
|
|
top.rank();
|
|
|
|
top.tests().dump(false);
|
2014-11-24 02:06:10 +00:00
|
|
|
}
|
|
|
|
|
2018-10-14 22:39:33 +00:00
|
|
|
if (!top.opt.writeFile().empty()) {
|
2019-05-08 03:00:52 +00:00
|
|
|
top.writeCoverage(top.opt.writeFile());
|
|
|
|
V3Error::abortIfWarnings();
|
2014-11-24 02:06:10 +00:00
|
|
|
if (top.opt.unlink()) {
|
2019-05-08 03:00:52 +00:00
|
|
|
const VlStringSet& readFiles = top.opt.readFiles();
|
|
|
|
for (VlStringSet::iterator it = readFiles.begin(); it != readFiles.end(); ++it) {
|
|
|
|
string filename = *it;
|
|
|
|
unlink(filename.c_str());
|
|
|
|
}
|
2014-11-24 02:06:10 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-11 23:18:58 +00:00
|
|
|
|
2014-11-24 02:06:10 +00:00
|
|
|
// Final writing shouldn't throw warnings, but...
|
|
|
|
V3Error::abortIfWarnings();
|
|
|
|
|
|
|
|
UINFO(1,"Done, Exiting...\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Local Variables:
|
|
|
|
// compile-command: "v4make bin/verilator_coverage --debugi 9 test_regress/t/t_vlcov_data_*.dat"
|
|
|
|
// End:
|