@@ -34,6 +34,7 @@ struct JsonWriter
3434 bool use_selection;
3535 bool aig_mode;
3636 bool compat_int_mode;
37+ bool scopeinfo_mode;
3738
3839 Design *design;
3940 Module *module ;
@@ -43,9 +44,9 @@ struct JsonWriter
4344 dict<SigBit, string> sigids;
4445 pool<Aig> aig_models;
4546
46- JsonWriter (std::ostream &f, bool use_selection, bool aig_mode, bool compat_int_mode) :
47+ JsonWriter (std::ostream &f, bool use_selection, bool aig_mode, bool compat_int_mode, bool scopeinfo_mode ) :
4748 f (f), use_selection(use_selection), aig_mode(aig_mode),
48- compat_int_mode (compat_int_mode) { }
49+ compat_int_mode (compat_int_mode), scopeinfo_mode(scopeinfo_mode) { }
4950
5051 string get_string (string str)
5152 {
@@ -194,7 +195,7 @@ struct JsonWriter
194195 continue ;
195196 // Eventually we will want to emit $scopeinfo, but currently this
196197 // will break JSON netlist consumers like nextpnr
197- if (c->type == ID ($scopeinfo))
198+ if (!scopeinfo_mode && c->type == ID ($scopeinfo))
198199 continue ;
199200 f << stringf (" %s\n " , first ? " " : " ," );
200201 f << stringf (" %s: {\n " , get_name (c->name ).c_str ());
@@ -356,6 +357,9 @@ struct JsonBackend : public Backend {
356357 log (" -selected\n " );
357358 log (" output only select module\n " );
358359 log (" \n " );
360+ log (" -scopeinfo\n " );
361+ log (" include $scopeinfo cells in the output\n " );
362+ log (" \n " );
359363 log (" \n " );
360364 log (" The general syntax of the JSON output created by this command is as follows:\n " );
361365 log (" \n " );
@@ -601,6 +605,7 @@ struct JsonBackend : public Backend {
601605 bool aig_mode = false ;
602606 bool compat_int_mode = false ;
603607 bool use_selection = false ;
608+ bool scopeinfo_mode = false ;
604609
605610 size_t argidx;
606611 for (argidx = 1 ; argidx < args.size (); argidx++)
@@ -617,13 +622,17 @@ struct JsonBackend : public Backend {
617622 use_selection = true ;
618623 continue ;
619624 }
625+ if (args[argidx] == " -scopeinfo" ) {
626+ scopeinfo_mode = true ;
627+ continue ;
628+ }
620629 break ;
621630 }
622631 extra_args (f, filename, args, argidx);
623632
624633 log_header (design, " Executing JSON backend.\n " );
625634
626- JsonWriter json_writer (*f, use_selection, aig_mode, compat_int_mode);
635+ JsonWriter json_writer (*f, use_selection, aig_mode, compat_int_mode, scopeinfo_mode );
627636 json_writer.write_design (design);
628637 }
629638} JsonBackend;
@@ -648,6 +657,9 @@ struct JsonPass : public Pass {
648657 log (" emit 32-bit or smaller fully-defined parameter values directly\n " );
649658 log (" as JSON numbers (for compatibility with old parsers)\n " );
650659 log (" \n " );
660+ log (" -scopeinfo\n " );
661+ log (" include $scopeinfo cells in the output\n " );
662+ log (" \n " );
651663 log (" See 'help write_json' for a description of the JSON format used.\n " );
652664 log (" \n " );
653665 }
@@ -656,6 +668,7 @@ struct JsonPass : public Pass {
656668 std::string filename;
657669 bool aig_mode = false ;
658670 bool compat_int_mode = false ;
671+ bool scopeinfo_mode = false ;
659672
660673 size_t argidx;
661674 for (argidx = 1 ; argidx < args.size (); argidx++)
@@ -672,6 +685,10 @@ struct JsonPass : public Pass {
672685 compat_int_mode = true ;
673686 continue ;
674687 }
688+ if (args[argidx] == " -scopeinfo" ) {
689+ scopeinfo_mode = true ;
690+ continue ;
691+ }
675692 break ;
676693 }
677694 extra_args (args, argidx, design);
@@ -693,7 +710,7 @@ struct JsonPass : public Pass {
693710 f = &buf;
694711 }
695712
696- JsonWriter json_writer (*f, true , aig_mode, compat_int_mode);
713+ JsonWriter json_writer (*f, true , aig_mode, compat_int_mode, scopeinfo_mode );
697714 json_writer.write_design (design);
698715
699716 if (!empty) {
0 commit comments