cli: Cleanups for tcl argument handling

* Keep the previous behavior when no tcl script is used
* Do not treat "-" as a flag but as a positional argument
* Keep including <unistd.h> as it's also used for other functions (at
  least for the emscripten build)
* Move the custom getopt implementation into the Yosys namespace to
  avoid potential collisions
This commit is contained in:
Jannis Harder 2023-11-06 16:40:13 +01:00
parent ea91f189a3
commit d415b4d98a
1 changed files with 13 additions and 4 deletions

View File

@ -49,6 +49,12 @@
# include <sys/user.h> # include <sys/user.h>
#endif #endif
#if !defined(_WIN32) || defined(__MINGW32__)
# include <unistd.h>
#endif
USING_YOSYS_NAMESPACE
char *optarg; char *optarg;
int optind = 1, optcur = 1, optopt = 0; int optind = 1, optcur = 1, optopt = 0;
int getopt(int argc, char **argv, const char *optstring) int getopt(int argc, char **argv, const char *optstring)
@ -56,7 +62,7 @@ int getopt(int argc, char **argv, const char *optstring)
if (optind >= argc) if (optind >= argc)
return -1; return -1;
if (argv[optind][0] != '-') { if (argv[optind][0] != '-' || argv[optind][1] == 0) {
optopt = 1; optopt = 1;
optarg = argv[optind++]; optarg = argv[optind++];
return optopt; return optopt;
@ -91,9 +97,6 @@ int getopt(int argc, char **argv, const char *optstring)
return optopt; return optopt;
} }
USING_YOSYS_NAMESPACE
#ifdef EMSCRIPTEN #ifdef EMSCRIPTEN
# include <sys/stat.h> # include <sys/stat.h>
# include <sys/types.h> # include <sys/types.h>
@ -573,6 +576,12 @@ int main(int argc, char **argv)
run_pass(vdef_cmd); run_pass(vdef_cmd);
} }
if (scriptfile.empty() || !scriptfile_tcl) {
// Without a TCL script, arguments following '--' are also treated as frontend files
for (int i = optind; i < argc; ++i)
frontend_files.push_back(argv[i]);
}
for (auto it = frontend_files.begin(); it != frontend_files.end(); ++it) { for (auto it = frontend_files.begin(); it != frontend_files.end(); ++it) {
if (run_frontend((*it).c_str(), frontend_command)) if (run_frontend((*it).c_str(), frontend_command))
run_shell = false; run_shell = false;