3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-12 20:18:20 +00:00

backend: jny: updated the JnyWriter to emite a new "invocation" entry as well as a "$schema" entry to point to the location the schema will be at

This commit is contained in:
Aki Van Ness 2022-08-02 06:58:41 -04:00
parent 7d4f87d69f
commit 4f0ee383c9
No known key found for this signature in database
GPG key ID: C629E8EC06327BEE

View file

@ -27,6 +27,8 @@
#include <algorithm> #include <algorithm>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <sstream>
#include <iterator>
USING_YOSYS_NAMESPACE USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN PRIVATE_NAMESPACE_BEGIN
@ -116,17 +118,17 @@ struct JnyWriter
_include_connections(connections), _include_attributes(attributes), _include_properties(properties) _include_connections(connections), _include_attributes(attributes), _include_properties(properties)
{ } { }
void write_metadata(Design *design, uint16_t indent_level = 0) void write_metadata(Design *design, uint16_t indent_level = 0, std::string invk = "")
{ {
log_assert(design != nullptr); log_assert(design != nullptr);
design->sort(); design->sort();
f << "{\n"; f << "{\n";
f << " \"$schema\": \"https://raw.githubusercontent.com/YosysHQ/yosys/master/misc/jny.schema.json\",\n";
f << stringf(" \"generator\": \"%s\",\n", escape_string(yosys_version_str).c_str()); f << stringf(" \"generator\": \"%s\",\n", escape_string(yosys_version_str).c_str());
// XXX(aki): Replace this with a proper version info eventually:tm: f << " \"version\": \"0.0.1\",\n";
f << " \"version\": \"0.0.0\",\n"; f << " \"invocation\": \"" << escape_string(invk) << "\",\n";
f << " \"features\": ["; f << " \"features\": [";
size_t fnum{0}; size_t fnum{0};
@ -409,11 +411,12 @@ struct JnyWriter
struct JnyBackend : public Backend { struct JnyBackend : public Backend {
JnyBackend() : Backend("jny", "generate design metadata") { } JnyBackend() : Backend("jny", "generate design metadata") { }
void help() override { void help() override {
// XXX(aki): TODO: explicitly document the JSON schema
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
log("\n"); log("\n");
log(" jny [options] [selection]\n"); log(" jny [options] [selection]\n");
log("\n"); log("\n");
log("Write JSON netlist metadata for the current design\n");
log("\n");
log(" -no-connections\n"); log(" -no-connections\n");
log(" Don't include connection information in the netlist output.\n"); log(" Don't include connection information in the netlist output.\n");
log("\n"); log("\n");
@ -423,8 +426,8 @@ struct JnyBackend : public Backend {
log(" -no-properties\n"); log(" -no-properties\n");
log(" Don't include property information in the netlist output.\n"); log(" Don't include property information in the netlist output.\n");
log("\n"); log("\n");
log("Write a JSON metadata for the current design\n"); log("The JSON schema for JNY output files is located in the \"jny.schema.json\" file\n");
log("\n"); log("which is located at \"https://raw.githubusercontent.com/YosysHQ/yosys/master/misc/jny.schema.json\"\n");
log("\n"); log("\n");
} }
@ -453,12 +456,22 @@ struct JnyBackend : public Backend {
break; break;
} }
// Compose invocation line
std::ostringstream invk;
if (!args.empty()) {
std::copy(args.begin(), args.end(),
std::ostream_iterator<std::string>(invk, " ")
);
}
invk << filename;
extra_args(f, filename, args, argidx); extra_args(f, filename, args, argidx);
log_header(design, "Executing jny backend.\n"); log_header(design, "Executing jny backend.\n");
JnyWriter jny_writer(*f, false, connections, attributes, properties); JnyWriter jny_writer(*f, false, connections, attributes, properties);
jny_writer.write_metadata(design); jny_writer.write_metadata(design, 0, invk.str());
} }
} JnyBackend; } JnyBackend;
@ -472,7 +485,7 @@ struct JnyPass : public Pass {
log("\n"); log("\n");
log(" jny [options] [selection]\n"); log(" jny [options] [selection]\n");
log("\n"); log("\n");
log("Write a JSON netlist metadata for the current design\n"); log("Write JSON netlist metadata for the current design\n");
log("\n"); log("\n");
log(" -o <filename>\n"); log(" -o <filename>\n");
log(" write to the specified file.\n"); log(" write to the specified file.\n");
@ -520,6 +533,15 @@ struct JnyPass : public Pass {
break; break;
} }
// Compose invocation line
std::ostringstream invk;
if (!args.empty()) {
std::copy(args.begin(), args.end(),
std::ostream_iterator<std::string>(invk, " ")
);
}
extra_args(args, argidx, design); extra_args(args, argidx, design);
std::ostream *f; std::ostream *f;
@ -534,13 +556,14 @@ struct JnyPass : public Pass {
log_error("Can't open file `%s' for writing: %s\n", filename.c_str(), strerror(errno)); log_error("Can't open file `%s' for writing: %s\n", filename.c_str(), strerror(errno));
} }
f = ff; f = ff;
invk << filename;
} else { } else {
f = &buf; f = &buf;
} }
JnyWriter jny_writer(*f, false, connections, attributes, properties); JnyWriter jny_writer(*f, false, connections, attributes, properties);
jny_writer.write_metadata(design); jny_writer.write_metadata(design, 0, invk.str());
if (!filename.empty()) { if (!filename.empty()) {
delete f; delete f;