diff --git a/backends/json/json.cc b/backends/json/json.cc index 287c01ead..197223c63 100644 --- a/backends/json/json.cc +++ b/backends/json/json.cc @@ -34,6 +34,7 @@ struct JsonWriter bool use_selection; bool aig_mode; bool compat_int_mode; + bool scopeinfo_mode; Design *design; Module *module; @@ -43,9 +44,9 @@ struct JsonWriter dict sigids; pool aig_models; - JsonWriter(std::ostream &f, bool use_selection, bool aig_mode, bool compat_int_mode) : + JsonWriter(std::ostream &f, bool use_selection, bool aig_mode, bool compat_int_mode, bool scopeinfo_mode) : f(f), use_selection(use_selection), aig_mode(aig_mode), - compat_int_mode(compat_int_mode) { } + compat_int_mode(compat_int_mode), scopeinfo_mode(scopeinfo_mode) { } string get_string(string str) { @@ -194,7 +195,7 @@ struct JsonWriter continue; // Eventually we will want to emit $scopeinfo, but currently this // will break JSON netlist consumers like nextpnr - if (c->type == ID($scopeinfo)) + if (!scopeinfo_mode && c->type == ID($scopeinfo)) continue; f << stringf("%s\n", first ? "" : ","); f << stringf(" %s: {\n", get_name(c->name).c_str()); @@ -356,6 +357,9 @@ struct JsonBackend : public Backend { log(" -selected\n"); log(" output only select module\n"); log("\n"); + log(" -scopeinfo\n"); + log(" include $scopeinfo cells in the output\n"); + log("\n"); log("\n"); log("The general syntax of the JSON output created by this command is as follows:\n"); log("\n"); @@ -601,6 +605,7 @@ struct JsonBackend : public Backend { bool aig_mode = false; bool compat_int_mode = false; bool use_selection = false; + bool scopeinfo_mode = false; size_t argidx; for (argidx = 1; argidx < args.size(); argidx++) @@ -617,13 +622,17 @@ struct JsonBackend : public Backend { use_selection = true; continue; } + if (args[argidx] == "-scopeinfo") { + scopeinfo_mode = true; + continue; + } break; } extra_args(f, filename, args, argidx); log_header(design, "Executing JSON backend.\n"); - JsonWriter json_writer(*f, use_selection, aig_mode, compat_int_mode); + JsonWriter json_writer(*f, use_selection, aig_mode, compat_int_mode, scopeinfo_mode); json_writer.write_design(design); } } JsonBackend; @@ -648,6 +657,9 @@ struct JsonPass : public Pass { log(" emit 32-bit or smaller fully-defined parameter values directly\n"); log(" as JSON numbers (for compatibility with old parsers)\n"); log("\n"); + log(" -scopeinfo\n"); + log(" include $scopeinfo cells in the output\n"); + log("\n"); log("See 'help write_json' for a description of the JSON format used.\n"); log("\n"); } @@ -656,6 +668,7 @@ struct JsonPass : public Pass { std::string filename; bool aig_mode = false; bool compat_int_mode = false; + bool scopeinfo_mode = false; size_t argidx; for (argidx = 1; argidx < args.size(); argidx++) @@ -672,6 +685,10 @@ struct JsonPass : public Pass { compat_int_mode = true; continue; } + if (args[argidx] == "-scopeinfo") { + scopeinfo_mode = true; + continue; + } break; } extra_args(args, argidx, design); @@ -693,7 +710,7 @@ struct JsonPass : public Pass { f = &buf; } - JsonWriter json_writer(*f, true, aig_mode, compat_int_mode); + JsonWriter json_writer(*f, true, aig_mode, compat_int_mode, scopeinfo_mode); json_writer.write_design(design); if (!empty) { diff --git a/tests/various/json_scopeinfo.ys b/tests/various/json_scopeinfo.ys new file mode 100644 index 000000000..50219f16e --- /dev/null +++ b/tests/various/json_scopeinfo.ys @@ -0,0 +1,38 @@ +read_verilog <