mirror of
https://github.com/Minres/RISCV-VP.git
synced 2025-12-17 17:01:35 +00:00
initial version
This commit is contained in:
113
src/CLIParser.cpp
Normal file
113
src/CLIParser.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2019 -2021 MINRES Technolgies GmbH
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "CLIParser.h"
|
||||
#include <scc/report.h>
|
||||
#include <iostream>
|
||||
#include <iss/log_categories.h>
|
||||
#include <scc/report.h>
|
||||
#include <stdexcept>
|
||||
#include <unordered_set>
|
||||
#ifdef ERROR
|
||||
#undef ERROR
|
||||
#endif
|
||||
namespace po = boost::program_options;
|
||||
using namespace sc_core;
|
||||
|
||||
namespace {
|
||||
std::unordered_set<std::string> backend_opts = {"interp", "tcc", "llvm", "asmjit"};
|
||||
}
|
||||
CLIParser::CLIParser(int argc, char *argv[])
|
||||
: desc("Options")
|
||||
, valid(false) {
|
||||
build();
|
||||
try {
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm_); // can throw
|
||||
// --help option
|
||||
if (vm_.count("help")) {
|
||||
std::cout << "DBT-RISE-TGC based virtual platform of TGC cores" << std::endl << desc << std::endl;
|
||||
}
|
||||
po::notify(vm_); // throws on error, so do after help in case there are any problems
|
||||
valid = true;
|
||||
if(backend_opts.find(vm_["backend"].as<std::string>())== std::end(backend_opts))
|
||||
throw po::error("Illegal value for switch backend");
|
||||
} catch (po::error &e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
|
||||
std::cerr << desc << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
auto log_level = vm_["verbose"].as<scc::log>();
|
||||
auto log_level_num = static_cast<unsigned>(log_level);
|
||||
LOGGER(DEFAULT)::reporting_level() = logging::as_log_level(log_level_num > 6 ? 6 : log_level_num);;
|
||||
LOGGER(DEFAULT)::print_time() = false;
|
||||
LOG_OUTPUT(DEFAULT)::ostream() = &std::cout;
|
||||
LOGGER(connection)::reporting_level() = logging::as_log_level(log_level_num > 4 ? log_level_num-1 : log_level_num);;
|
||||
LOGGER(connection)::print_time() = false;
|
||||
LOG_OUTPUT(connection)::ostream() = &std::cout;
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// configure logging
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
scc::init_logging(scc::LogConfig()
|
||||
.logFileName(vm_["log-file"].as<std::string>())
|
||||
.logLevel(vm_["verbose"].as<scc::log>())
|
||||
.logFilterRegex(vm_["log-filter"].as<std::string>())
|
||||
.logAsync(!vm_["log-sync"].as<bool>()));
|
||||
scc::stream_redirection cout_redir(std::cout, scc::log::DEBUG);
|
||||
scc::stream_redirection cerr_redir(std::cerr, scc::log::ERROR);
|
||||
sc_core::sc_report_handler::set_actions("/IEEE_Std_1666/deprecated", sc_core::SC_DO_NOTHING);
|
||||
sc_core::sc_report_handler::set_actions(sc_core::SC_ID_MORE_THAN_ONE_SIGNAL_DRIVER_, sc_core::SC_DO_NOTHING);
|
||||
sc_core::sc_report_handler::set_actions(sc_core::SC_ERROR, sc_core::SC_LOG | sc_core::SC_CACHE_REPORT | sc_core::SC_DISPLAY | sc_core::SC_STOP);
|
||||
}
|
||||
|
||||
void CLIParser::build() {
|
||||
// clang-format off
|
||||
desc.add_options()
|
||||
("help,h",
|
||||
"Print help message")
|
||||
("verbose,v", po::value<scc::log>()->default_value(scc::log::INFO),
|
||||
"debug output level (NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE, TRACEALL)")
|
||||
("log-file,l", po::value<std::string>()->default_value(""),
|
||||
"log file name")
|
||||
("log-filter", po::value<std::string>()->default_value(""),
|
||||
"log filter regular expression name")
|
||||
("log-sync", po::bool_switch(),
|
||||
"Disable asynchronous logging")
|
||||
("disass,d", po::value<std::string>()->implicit_value(""),
|
||||
"Enables disassembly")
|
||||
("elf,f", po::value<std::string>(),
|
||||
"ELF file to load")
|
||||
("gdb-port,g", po::value<unsigned short>()->default_value(0),
|
||||
"enable gdb server and specify port to use")
|
||||
("backend", po::value<std::string>()->default_value("interp"),
|
||||
"the ISS backend to use, options are: interp, tcc")
|
||||
("isa", po::value<std::string>()->default_value("tgc5c"),
|
||||
"core or isa name to use for simulation, use '?' to get list")
|
||||
("dump-ir",
|
||||
"dump the intermediate representation")
|
||||
("dump-structure", po::value<std::string>(),
|
||||
"dump model structure to ELK file")
|
||||
("quantum", po::value<unsigned>(),
|
||||
"SystemC quantum time in ns")
|
||||
("reset,r", po::value<std::string>(),
|
||||
"reset address")
|
||||
("trace-level,t", po::value<unsigned>()->default_value(0),
|
||||
"enable tracing, or combination of 1=signals and 2=TX")
|
||||
("trace-default-on",
|
||||
"enables tracing for all unspecified modules")
|
||||
("trace-file", po::value<std::string>()->default_value("system"),
|
||||
"set th ename of the trace file")
|
||||
("max_time,m", po::value<std::string>(),
|
||||
"maximum time to run")
|
||||
("config-file,c", po::value<std::string>()->default_value(""),
|
||||
"read configuration from file")
|
||||
("plugin,p", po::value<std::vector<std::string>>(),
|
||||
"plugin(s) to activate")
|
||||
("dump-config,dc", po::value<std::string>()->default_value(""),
|
||||
"dump configuration to file file");
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
CLIParser::~CLIParser() = default;
|
||||
Reference in New Issue
Block a user