3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-23 17:15:33 +00:00

Add support for "yosys -E"

Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
Clifford Wolf 2018-01-07 16:36:13 +01:00
parent 446ccf1f05
commit a96c775a73
13 changed files with 53 additions and 4 deletions

View file

@ -160,6 +160,7 @@ int main(int argc, char **argv)
std::vector<std::string> plugin_filenames;
std::string output_filename = "";
std::string scriptfile = "";
std::string depsfile = "";
bool scriptfile_tcl = false;
bool got_output_filename = false;
bool print_banner = true;
@ -256,6 +257,9 @@ int main(int argc, char **argv)
printf(" if a warning message matches the regex, it is printes as regular\n");
printf(" message instead.\n");
printf("\n");
printf(" -E <depsfile>\n");
printf(" write a Makefile dependencies file with in- and output file names\n");
printf("\n");
printf(" -V\n");
printf(" print version information and exit\n");
printf("\n");
@ -276,7 +280,7 @@ int main(int argc, char **argv)
}
int opt;
while ((opt = getopt(argc, argv, "MXAQTVSm:f:Hh:b:o:p:l:L:qv:tds:c:W:w:D:")) != -1)
while ((opt = getopt(argc, argv, "MXAQTVSm:f:Hh:b:o:p:l:L:qv:tds:c:W:w:D:E:")) != -1)
{
switch (opt)
{
@ -392,6 +396,9 @@ int main(int argc, char **argv)
}
}
break;
case 'E':
depsfile = optarg;
break;
default:
fprintf(stderr, "Run '%s -h' for help.\n", argv[0]);
exit(1);
@ -442,6 +449,24 @@ int main(int argc, char **argv)
if (!backend_command.empty())
run_backend(output_filename, backend_command);
if (!depsfile.empty())
{
FILE *f = fopen(depsfile.c_str(), "wt");
if (f == nullptr)
log_error("Can't open dependencies file for writing: %s\n", strerror(errno));
bool first = true;
for (auto fn : yosys_output_files) {
fprintf(f, "%s%s", first ? "" : " ", fn.c_str());
first = false;
}
fprintf(f, ":");
for (auto fn : yosys_input_files) {
if (yosys_output_files.count(fn) == 0)
fprintf(f, " %s", fn.c_str());
}
fprintf(f, "\n");
}
if (print_stats)
{
std::string hash = log_hasher->final().substr(0, 10);

View file

@ -428,6 +428,7 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
}
std::ifstream *ff = new std::ifstream;
ff->open(filename.c_str());
yosys_input_files.insert(filename);
if (ff->fail())
delete ff;
else
@ -543,6 +544,7 @@ void Backend::extra_args(std::ostream *&f, std::string &filename, std::vector<st
filename = arg;
std::ofstream *ff = new std::ofstream;
ff->open(filename.c_str(), std::ofstream::trunc);
yosys_output_files.insert(filename);
if (ff->fail()) {
delete ff;
log_cmd_error("Can't open output file `%s' for writing: %s\n", filename.c_str(), strerror(errno));

View file

@ -64,6 +64,8 @@ CellTypes yosys_celltypes;
Tcl_Interp *yosys_tcl_interp = NULL;
#endif
std::set<std::string> yosys_input_files, yosys_output_files;
bool memhasher_active = false;
uint32_t memhasher_rng = 123456;
std::vector<void*> memhasher_store;
@ -831,8 +833,10 @@ void run_frontend(std::string filename, std::string command, std::string *backen
FILE *f = stdin;
if (filename != "-")
if (filename != "-") {
f = fopen(filename.c_str(), "r");
yosys_input_files.insert(filename);
}
if (f == NULL)
log_error("Can't open script file `%s' for reading: %s\n", filename.c_str(), strerror(errno));

View file

@ -305,6 +305,9 @@ void run_frontend(std::string filename, std::string command, RTLIL::Design *desi
void run_backend(std::string filename, std::string command, RTLIL::Design *design = nullptr);
void shell(RTLIL::Design *design);
// journal of all input and output files read (for "yosys -E")
extern std::set<std::string> yosys_input_files, yosys_output_files;
// from kernel/version_*.o (cc source generated from Makefile)
extern const char *yosys_version_str;