Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
widlarizer committed Sep 25, 2024
1 parent 59fd3b6 commit 1ca8959
Showing 1 changed file with 35 additions and 36 deletions.
71 changes: 35 additions & 36 deletions kernel/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,29 +262,29 @@ int main(int argc, char **argv)
("v,verbose", "print log headers up to level <level> to the console", cxxopts::value<int>())
("t,timestamp", "annotate all log messages with a time stamp")
("d,detailed-timing", "print more detailed timing stats at exit")
("l,logfile", "write log messages to the specified file", cxxopts::value<std::string>())
("L,line-buffered-logfile", "like -l but open log file in line buffered mode", cxxopts::value<std::string>())
("l,logfile", "write log messages to the specified file", cxxopts::value<std::vector<std::string>>())
("L,line-buffered-logfile", "like -l but open log file in line buffered mode", cxxopts::value<std::vector<std::string>>())
("o,outfile", "write the design to the specified file on exit", cxxopts::value<std::string>())
("b,backend", "use this backend for the output file specified on the command line", cxxopts::value<std::string>())
("f,frontend", "use the specified frontend for the input files on the command line", cxxopts::value<std::string>())
("H", "print the command list")
("h,help", "print the help message for the specified command", cxxopts::value<std::string>()->default_value(""))
("h,help", "print the help message for the specified command", cxxopts::value<std::string>())
("s,scriptfile", "execute the commands in the script file", cxxopts::value<std::string>())
("c,tcl-scriptfile", "execute the commands in the tcl script file", cxxopts::value<std::string>())
("C,tcl-interactive", "enters TCL interactive shell mode")
("p,command", "execute the commands", cxxopts::value<std::string>())
("m,module-file", "load the specified module (aka plugin)", cxxopts::value<std::string>())
("p,command", "execute the commands", cxxopts::value<std::vector<std::string>>())
("m,module-file", "load the specified module (aka plugin)", cxxopts::value<std::vector<std::string>>())
("X,trace", "enable tracing of core data structure changes. for debugging")
("M,randomize-pointers", "will slightly randomize allocated pointer addresses. for debugging")
("A,abort", "will call abort() at the end of the script. for debugging")
("r,top-module", "elaborate command line arguments using the specified top module", cxxopts::value<std::string>())
("D,define", "set the specified Verilog define", cxxopts::value<std::vector<std::string>>())
("P,dump-design", "dump the design when printing the specified log header to a file", cxxopts::value<std::vector<std::string>>())
("W,warning-as-warning", "print a warning for all log messages matching the regex", cxxopts::value<std::string>())
("w,warning-as-message", "if a warning message matches the regex, it is printed as regular message instead", cxxopts::value<std::string>())
("e,warning-as-error", "if a warning message matches the regex, it is printed as error message instead", cxxopts::value<std::string>())
("W,warning-as-warning", "print a warning for all log messages matching the regex", cxxopts::value<std::vector<std::string>>())
("w,warning-as-message", "if a warning message matches the regex, it is printed as regular message instead", cxxopts::value<std::vector<std::string>>())
("e,warning-as-error", "if a warning message matches the regex, it is printed as error message instead", cxxopts::value<std::vector<std::string>>())
("E,deps-file", "write a Makefile dependencies file with in- and output file names", cxxopts::value<std::string>())
("x,experimental", "do not print warnings for the specified experimental feature", cxxopts::value<std::string>())
("x,experimental", "do not print warnings for the specified experimental feature", cxxopts::value<std::vector<std::string>>())
("g,debug", "globally enable debug log messages")
("V,version", "print version information and exit")
("S,synth", "shortcut for calling the \"synth\" command")
Expand All @@ -294,6 +294,11 @@ int main(int argc, char **argv)
options.parse_positional({"infile"});
options.positional_help("[<infile> [..]]");

// We can't have -h optionally require an argument. cxxopts is instructed to handle the no argument case
if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-help") || !strcmp(argv[1], "--help"))) {
std::cout << options.help() << std::endl;
exit(0);
}
try {
// Check for "--" in arguments
auto it = std::find(argv, argv + argc, std::string("--"));
Expand Down Expand Up @@ -333,46 +338,44 @@ int main(int argc, char **argv)
}
if (result.count("h")) {
std::string res = result["h"].as<std::string>();
std::cout << "res is " << res << "\n";
if (res.length()) {
passes_commands.push_back("help " + res);
run_shell = false;
} else {
std::cout << options.help() << std::endl;
exit(0);
}
passes_commands.push_back("help " + res);
run_shell = false;
}
if (result.count("b")) {
backend_command = result["b"].as<std::string>();
run_shell = false;
}
if (result.count("p")) {
auto cmds = result["p"].as<std::string>();
passes_commands.push_back(cmds);
auto cmds = result["p"].as<std::vector<std::string>>();
passes_commands.insert(passes_commands.end(), cmds.begin(), cmds.end());
run_shell = false;
}
if (result.count("o")) {
output_filename = result["o"].as<std::string>();
run_shell = false;
}
if (result.count("l")) {
auto filename = result["l"].as<std::string>();
FILE* f = fopen(filename.c_str(), "wt");
if (f == NULL) {
std::cerr << "Can't open log file `" << filename << "' for writing!" << std::endl;
exit(1);
auto filenames = result["l"].as<std::vector<std::string>>();
for (auto filename : filenames) {
FILE* f = fopen(filename.c_str(), "wt");
if (f == NULL) {
std::cerr << "Can't open log file `" << filename << "' for writing!" << std::endl;
exit(1);
}
log_files.push_back(f);
}
log_files.push_back(f);
}
if (result.count("L")) { // TODO golf
auto filename = result["l"].as<std::string>();
FILE* f = fopen(filename.c_str(), "wt");
if (f == NULL) {
std::cerr << "Can't open log file `" << filename << "' for writing!" << std::endl;
exit(1);
auto filenames = result["L"].as<std::vector<std::string>>();
for (auto filename : filenames) {
FILE* f = fopen(filename.c_str(), "wt");
if (f == NULL) {
std::cerr << "Can't open log file `" << filename << "' for writing!" << std::endl;
exit(1);
}
log_files.push_back(f);
setvbuf(f, NULL, _IOLBF, 0);
}
log_files.push_back(f);
setvbuf(f, NULL, _IOLBF, 0);
}
if (result.count("q")) {
mode_q = true;
Expand Down Expand Up @@ -447,10 +450,6 @@ int main(int argc, char **argv)
if (result.count("B")) perffile = result["B"].as<std::string>();
if (result.count("infile")) {
frontend_files = result["infile"].as<std::vector<std::string>>();
std::cout << "infiles:" << std::endl;
for (auto f : frontend_files)
std::cout << f << std::endl;
std::cout << ":infiles" << std::endl;
}


Expand Down

0 comments on commit 1ca8959

Please sign in to comment.