mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-03 21:09:12 +00:00 
			
		
		
		
	Merge pull request #4837 from YosysHQ/json_scopinfo_opt
write_json: add option to include $scopeinfo cells
This commit is contained in:
		
						commit
						7e3990b681
					
				
					 2 changed files with 60 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -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<SigBit, string> sigids;
 | 
			
		||||
	pool<Aig> 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)
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			@ -192,9 +193,7 @@ struct JsonWriter
 | 
			
		|||
		for (auto c : module->cells()) {
 | 
			
		||||
			if (use_selection && !module->selected(c))
 | 
			
		||||
				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 +355,9 @@ struct JsonBackend : public Backend {
 | 
			
		|||
		log("    -selected\n");
 | 
			
		||||
		log("        output only select module\n");
 | 
			
		||||
		log("\n");
 | 
			
		||||
		log("    -noscopeinfo\n");
 | 
			
		||||
		log("        don't 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 +603,7 @@ struct JsonBackend : public Backend {
 | 
			
		|||
		bool aig_mode = false;
 | 
			
		||||
		bool compat_int_mode = false;
 | 
			
		||||
		bool use_selection = false;
 | 
			
		||||
		bool scopeinfo_mode = true;
 | 
			
		||||
 | 
			
		||||
		size_t argidx;
 | 
			
		||||
		for (argidx = 1; argidx < args.size(); argidx++)
 | 
			
		||||
| 
						 | 
				
			
			@ -617,13 +620,17 @@ struct JsonBackend : public Backend {
 | 
			
		|||
				use_selection = true;
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
			if (args[argidx] == "-noscopeinfo") {
 | 
			
		||||
				scopeinfo_mode = false;
 | 
			
		||||
				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 +655,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("    -noscopeinfo\n");
 | 
			
		||||
		log("        don't 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 +666,7 @@ struct JsonPass : public Pass {
 | 
			
		|||
		std::string filename;
 | 
			
		||||
		bool aig_mode = false;
 | 
			
		||||
		bool compat_int_mode = false;
 | 
			
		||||
		bool scopeinfo_mode = true;
 | 
			
		||||
 | 
			
		||||
		size_t argidx;
 | 
			
		||||
		for (argidx = 1; argidx < args.size(); argidx++)
 | 
			
		||||
| 
						 | 
				
			
			@ -672,6 +683,10 @@ struct JsonPass : public Pass {
 | 
			
		|||
				compat_int_mode = true;
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
			if (args[argidx] == "-noscopeinfo") {
 | 
			
		||||
				scopeinfo_mode = false;
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
		extra_args(args, argidx, design);
 | 
			
		||||
| 
						 | 
				
			
			@ -693,7 +708,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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										38
									
								
								tests/various/json_scopeinfo.ys
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								tests/various/json_scopeinfo.ys
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,38 @@
 | 
			
		|||
read_verilog <<EOT
 | 
			
		||||
module top(input in, output out);
 | 
			
		||||
	wire [1:0] w1, w2;
 | 
			
		||||
	f1_test u1 (.in(in), .out(w1[0]));
 | 
			
		||||
	f2_test u2 (.in(w1), .out(w2));
 | 
			
		||||
	f3_test u3 (.in(w2[0]), .out(out));
 | 
			
		||||
endmodule
 | 
			
		||||
 | 
			
		||||
module f1_test(input in, output out);
 | 
			
		||||
	assign out = in;
 | 
			
		||||
endmodule
 | 
			
		||||
 | 
			
		||||
module f2_test(input [1:0] in, output [1:0] out);
 | 
			
		||||
	assign out[0] = in[0];
 | 
			
		||||
	assign out[1] = in[1];
 | 
			
		||||
endmodule
 | 
			
		||||
 | 
			
		||||
module f3_test(input in, output [1:0] out);
 | 
			
		||||
	assign out[0] = in;
 | 
			
		||||
	assign out[1] = in;
 | 
			
		||||
endmodule
 | 
			
		||||
EOT
 | 
			
		||||
 | 
			
		||||
hierarchy -top top
 | 
			
		||||
flatten -scopename
 | 
			
		||||
prep
 | 
			
		||||
 | 
			
		||||
write_json json_scopeinfo.out
 | 
			
		||||
!grep -qF '$scopeinfo' json_scopeinfo.out
 | 
			
		||||
 | 
			
		||||
write_json -noscopeinfo json_scopeinfo.out
 | 
			
		||||
!grep -qvF '$scopeinfo' json_scopeinfo.out
 | 
			
		||||
 | 
			
		||||
json -o json_scopeinfo.out
 | 
			
		||||
!grep -qF '$scopeinfo' json_scopeinfo.out
 | 
			
		||||
 | 
			
		||||
json -noscopeinfo -o json_scopeinfo.out
 | 
			
		||||
!grep -qvF '$scopeinfo' json_scopeinfo.out
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue