aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2016-08-22 15:05:57 +0200
committerClifford Wolf <clifford@clifford.at>2016-08-22 15:05:57 +0200
commitf8a77abfac6da12e2e11c43b4e6aa6e613ac0d4b (patch)
tree99ad2f2cd96643495a5fe62a7bb71f28ddd868ae /kernel
parent450f6f59b494af14014f0cbe93df4ceca0eecd76 (diff)
downloadyosys-f8a77abfac6da12e2e11c43b4e6aa6e613ac0d4b.tar.gz
yosys-f8a77abfac6da12e2e11c43b4e6aa6e613ac0d4b.tar.bz2
yosys-f8a77abfac6da12e2e11c43b4e6aa6e613ac0d4b.zip
Added glob support to all front-ends
Diffstat (limited to 'kernel')
-rw-r--r--kernel/register.cc16
-rw-r--r--kernel/yosys.cc25
-rw-r--r--kernel/yosys.h1
3 files changed, 38 insertions, 4 deletions
diff --git a/kernel/register.cc b/kernel/register.cc
index 115880ed6..7a1d0b44b 100644
--- a/kernel/register.cc
+++ b/kernel/register.cc
@@ -382,7 +382,8 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
bool called_with_fp = f != NULL;
next_args.clear();
- for (; argidx < args.size(); argidx++)
+
+ if (argidx < args.size())
{
std::string arg = args[argidx];
@@ -419,6 +420,12 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
f = new std::istringstream(last_here_document);
} else {
rewrite_filename(filename);
+ vector<string> filenames = glob_filename(filename);
+ filename = filenames.front();
+ if (GetSize(filenames) > 1) {
+ next_args.insert(next_args.end(), args.begin(), args.begin()+argidx);
+ next_args.insert(next_args.end(), filenames.begin()+1, filenames.end());
+ }
std::ifstream *ff = new std::ifstream;
ff->open(filename.c_str());
if (ff->fail())
@@ -434,12 +441,13 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
cmd_error(args, i, "Found option, expected arguments.");
if (argidx+1 < args.size()) {
- next_args.insert(next_args.begin(), args.begin(), args.begin()+argidx);
- next_args.insert(next_args.begin()+argidx, args.begin()+argidx+1, args.end());
+ if (next_args.empty())
+ next_args.insert(next_args.end(), args.begin(), args.begin()+argidx);
+ next_args.insert(next_args.end(), args.begin()+argidx+1, args.end());
args.erase(args.begin()+argidx+1, args.end());
}
- break;
}
+
if (f == NULL)
cmd_error(args, argidx, "No filename given.");
diff --git a/kernel/yosys.cc b/kernel/yosys.cc
index 17f6847b5..08fee9741 100644
--- a/kernel/yosys.cc
+++ b/kernel/yosys.cc
@@ -37,11 +37,13 @@
# include <unistd.h>
# include <dirent.h>
# include <sys/stat.h>
+# include <glob.h>
#else
# include <unistd.h>
# include <dirent.h>
# include <sys/types.h>
# include <sys/stat.h>
+# include <glob.h>
#endif
#include <limits.h>
@@ -547,6 +549,29 @@ const char *create_prompt(RTLIL::Design *design, int recursion_counter)
return buffer;
}
+std::vector<std::string> glob_filename(const std::string &filename_pattern)
+{
+ std::vector<std::string> results;
+
+#ifdef _WIN32
+ results.push_back(filename_pattern);
+#else
+ glob_t globbuf;
+
+ int err = glob(filename_pattern.c_str(), 0, NULL, &globbuf);
+
+ if(err == 0) {
+ for (size_t i = 0; i < globbuf.gl_pathc; i++)
+ results.push_back(globbuf.gl_pathv[i]);
+ globfree(&globbuf);
+ } else {
+ results.push_back(filename_pattern);
+ }
+#endif
+
+ return results;
+}
+
void rewrite_filename(std::string &filename)
{
if (filename.substr(0, 1) == "\"" && filename.substr(GetSize(filename)-1) == "\"")
diff --git a/kernel/yosys.h b/kernel/yosys.h
index 0df750a13..aab6b5844 100644
--- a/kernel/yosys.h
+++ b/kernel/yosys.h
@@ -280,6 +280,7 @@ RTLIL::Design *yosys_get_design();
std::string proc_self_dirname();
std::string proc_share_dirname();
const char *create_prompt(RTLIL::Design *design, int recursion_counter);
+std::vector<std::string> glob_filename(const std::string &filename_pattern);
void rewrite_filename(std::string &filename);
void run_pass(std::string command, RTLIL::Design *design = nullptr);