mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 13:29:12 +00:00 
			
		
		
		
	raise_error.cc: Option for direct to stderr
Add more to help text to describe usage. Add test for no value (should `exit(1)`).
This commit is contained in:
		
							parent
							
								
									134da811f7
								
							
						
					
					
						commit
						8d5dbae06e
					
				
					 2 changed files with 57 additions and 10 deletions
				
			
		| 
						 | 
				
			
			@ -9,18 +9,35 @@ struct RaiseErrorPass : public Pass {
 | 
			
		|||
	{
 | 
			
		||||
		//   |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
 | 
			
		||||
		log("\n");
 | 
			
		||||
		log("    raise_error [selection]\n");
 | 
			
		||||
		log("    raise_error [options] [selection]\n");
 | 
			
		||||
		log("\n");
 | 
			
		||||
		log("Test error handling by raising arbitrary errors. This pass iterates over the\n");
 | 
			
		||||
		log("design (or selection of it) checking for objects with the 'raise_error'\n");
 | 
			
		||||
		log("attribute set.\n");
 | 
			
		||||
		log("attribute set. Assigning 'raise_error' to a string more than one character long\n");
 | 
			
		||||
		log("will log that string as an error message before exiting. Assigning 'raise_error'\n");
 | 
			
		||||
		log("to an integer (less than 256) will exit with that value as the exit code.\n");
 | 
			
		||||
		log("\n");
 | 
			
		||||
		log("    -stderr\n");
 | 
			
		||||
		log("        Log error messages directly to stderr instead of using 'log_error'.\n");
 | 
			
		||||
		log("\n");
 | 
			
		||||
	}
 | 
			
		||||
	void execute(vector<string> args, RTLIL::Design *design) override
 | 
			
		||||
	{
 | 
			
		||||
		log_header(design, "Executing RAISE_ERROR pass.\n");
 | 
			
		||||
 | 
			
		||||
		extra_args(args, 1, design, true);
 | 
			
		||||
		bool use_stderr = false;
 | 
			
		||||
 | 
			
		||||
		int argidx;
 | 
			
		||||
		for (argidx = 1; argidx < GetSize(args); argidx++)
 | 
			
		||||
		{
 | 
			
		||||
			if (args[argidx] == "-stderr") {
 | 
			
		||||
				use_stderr = true;
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		extra_args(args, argidx, design, true);
 | 
			
		||||
 | 
			
		||||
		RTLIL::NamedObject *err_obj = nullptr;
 | 
			
		||||
		
 | 
			
		||||
| 
						 | 
				
			
			@ -43,15 +60,20 @@ struct RaiseErrorPass : public Pass {
 | 
			
		|||
			auto err_no = err_obj->attributes[ID::raise_error].as_int();
 | 
			
		||||
			if (err_no < 256) {
 | 
			
		||||
				log_flush();
 | 
			
		||||
			#if defined(_MSC_VER)
 | 
			
		||||
				_exit(err_no);
 | 
			
		||||
			#else
 | 
			
		||||
				_Exit(err_no);
 | 
			
		||||
			#endif
 | 
			
		||||
			} else {
 | 
			
		||||
				auto err_msg = err_obj->get_string_attribute(ID::raise_error);
 | 
			
		||||
				log_error("%s\n", err_msg.c_str());
 | 
			
		||||
				if (use_stderr) {
 | 
			
		||||
					std::cerr << err_msg << std::endl;
 | 
			
		||||
					err_no = 1;
 | 
			
		||||
				} else {
 | 
			
		||||
					log_error("%s\n", err_msg.c_str());
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		#if defined(_MSC_VER)
 | 
			
		||||
			_exit(err_no);
 | 
			
		||||
		#else
 | 
			
		||||
			_Exit(err_no);
 | 
			
		||||
		#endif
 | 
			
		||||
		} else {
 | 
			
		||||
			log("'raise_error' attribute not found\n");
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,8 @@ endmodule
 | 
			
		|||
module other();
 | 
			
		||||
endmodule
 | 
			
		||||
 | 
			
		||||
module zzy();
 | 
			
		||||
(* raise_error *)
 | 
			
		||||
module def();
 | 
			
		||||
endmodule
 | 
			
		||||
EOF
 | 
			
		||||
select -assert-mod-count 3 =*
 | 
			
		||||
| 
						 | 
				
			
			@ -25,3 +26,27 @@ rename top abc
 | 
			
		|||
bugpoint -yosys ../../yosys -command raise_error -grep "help me"
 | 
			
		||||
select -assert-mod-count 1 =*
 | 
			
		||||
select -assert-mod-count 1 other
 | 
			
		||||
 | 
			
		||||
# raise_error with no value exits with 1
 | 
			
		||||
design -load read
 | 
			
		||||
rename def zzy
 | 
			
		||||
bugpoint -yosys ../../yosys -command raise_error -expect-return 1
 | 
			
		||||
select -assert-mod-count 1 =*
 | 
			
		||||
select -assert-mod-count 1 zzy
 | 
			
		||||
 | 
			
		||||
# raise_error -stderr exits with 1
 | 
			
		||||
design -load read
 | 
			
		||||
rename top abc
 | 
			
		||||
delete def
 | 
			
		||||
bugpoint -yosys ../../yosys -command "raise_error -stderr" -expect-return 1
 | 
			
		||||
select -assert-mod-count 1 =*
 | 
			
		||||
select -assert-mod-count 1 other
 | 
			
		||||
 | 
			
		||||
#TODO
 | 
			
		||||
# raise_error -stderr prints to stderr
 | 
			
		||||
design -load read
 | 
			
		||||
rename top abc
 | 
			
		||||
delete def
 | 
			
		||||
# bugpoint -yosys ../../yosys -command "raise_error -stderr" -grep "help me"
 | 
			
		||||
# select -assert-mod-count 1 =*
 | 
			
		||||
# select -assert-mod-count 1 other
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue