mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-30 19:22:31 +00:00 
			
		
		
		
	log_help: Include source_location
Use `std::experimental::source_location` because clang support is `??` Add `ENABLE_SOURCE_LOCATION` make variable and corresponding `YOSYS_ENABLE_SOURCE_LOCATION` define. Dummy out the struct if disabled and check for null instead of using `#ifdef` blocks everywhere.
This commit is contained in:
		
							parent
							
								
									10fea26fa9
								
							
						
					
					
						commit
						ae3514adfd
					
				
					 3 changed files with 54 additions and 12 deletions
				
			
		
							
								
								
									
										3
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								Makefile
									
										
									
									
									
								
							|  | @ -532,6 +532,9 @@ LIBS_VERIFIC += -Wl,--whole-archive $(patsubst %,$(VERIFIC_DIR)/%/*-linux.a,$(VE | ||||||
| endif | endif | ||||||
| endif | endif | ||||||
| 
 | 
 | ||||||
|  | ifeq ($(ENABLE_SOURCE_LOCATION),1) | ||||||
|  | CXXFLAGS += -DYOSYS_ENABLE_SOURCE_LOCATION | ||||||
|  | endif | ||||||
| 
 | 
 | ||||||
| ifeq ($(ENABLE_COVER),1) | ifeq ($(ENABLE_COVER),1) | ||||||
| CXXFLAGS += -DYOSYS_ENABLE_COVER | CXXFLAGS += -DYOSYS_ENABLE_COVER | ||||||
|  |  | ||||||
|  | @ -78,13 +78,15 @@ bool PrettyHelp::has_content() | ||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void PrettyHelp::usage(const string &usage) | void PrettyHelp::usage(const string &usage, | ||||||
|  | 	const source_location location) | ||||||
| { | { | ||||||
| 	log_pass_str(usage, current_indent+1, true); | 	log_pass_str(usage, current_indent+1, true); | ||||||
| 	log("\n"); | 	log("\n"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void PrettyHelp::option(const string &text, const string &description) | void PrettyHelp::option(const string &text, const string &description, | ||||||
|  | 	const source_location location) | ||||||
| { | { | ||||||
| 	open_option(text); | 	open_option(text); | ||||||
| 	if (description.length()) { | 	if (description.length()) { | ||||||
|  | @ -94,23 +96,27 @@ void PrettyHelp::option(const string &text, const string &description) | ||||||
| 	close(1); | 	close(1); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void PrettyHelp::codeblock(const string &code, const string &) | void PrettyHelp::codeblock(const string &code, const string &, | ||||||
|  | 	const source_location location) | ||||||
| { | { | ||||||
| 	log("%s\n", code.c_str()); | 	log("%s\n", code.c_str()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void PrettyHelp::paragraph(const string &text) | void PrettyHelp::paragraph(const string &text, | ||||||
|  | 	const source_location location) | ||||||
| { | { | ||||||
| 	log_pass_str(text, current_indent); | 	log_pass_str(text, current_indent); | ||||||
| 	log("\n"); | 	log("\n"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void PrettyHelp::open_optiongroup(const string &) | void PrettyHelp::open_optiongroup(const string &, | ||||||
|  | 	const source_location location) | ||||||
| { | { | ||||||
| 	current_indent += 1; | 	current_indent += 1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void PrettyHelp::open_option(const string &text) | void PrettyHelp::open_option(const string &text, | ||||||
|  | 	const source_location location) | ||||||
| { | { | ||||||
| 	log_pass_str(text, current_indent); | 	log_pass_str(text, current_indent); | ||||||
| 	current_indent += 1; | 	current_indent += 1; | ||||||
|  |  | ||||||
|  | @ -23,6 +23,19 @@ | ||||||
| #include "kernel/yosys_common.h" | #include "kernel/yosys_common.h" | ||||||
| #include "kernel/json.h" | #include "kernel/json.h" | ||||||
| 
 | 
 | ||||||
|  | #ifdef YOSYS_ENABLE_SOURCE_LOCATION | ||||||
|  | #include <experimental/source_location> | ||||||
|  | using std::experimental::source_location; | ||||||
|  | #else | ||||||
|  | struct source_location { // dummy placeholder
 | ||||||
|  | 	int line() const { return 0; } | ||||||
|  | 	int column() const { return 0; } | ||||||
|  | 	const char* file_name() const { return nullptr; } | ||||||
|  | 	const char* function_name() const { return nullptr; } | ||||||
|  | 	static const source_location current(...) { return source_location(); } | ||||||
|  | }; | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| YOSYS_NAMESPACE_BEGIN | YOSYS_NAMESPACE_BEGIN | ||||||
| 
 | 
 | ||||||
| class PrettyHelp | class PrettyHelp | ||||||
|  | @ -37,13 +50,33 @@ public: | ||||||
| 
 | 
 | ||||||
| 	bool has_content(); | 	bool has_content(); | ||||||
| 
 | 
 | ||||||
| 	void usage(const string &usage); | 	void usage( | ||||||
| 	void option(const string &text, const string &description = ""); | 		const string &usage, | ||||||
| 	void codeblock(const string &code, const string &language = "none"); | 		const source_location location = source_location::current() | ||||||
| 	void paragraph(const string &text); | 	); | ||||||
|  | 	void option( | ||||||
|  | 		const string &text, | ||||||
|  | 		const string &description = "", | ||||||
|  | 		const source_location location = source_location::current() | ||||||
|  | 	); | ||||||
|  | 	void codeblock( | ||||||
|  | 		const string &code, | ||||||
|  | 		const string &language = "none", | ||||||
|  | 		const source_location location = source_location::current() | ||||||
|  | 	); | ||||||
|  | 	void paragraph( | ||||||
|  | 		const string &text, | ||||||
|  | 		const source_location location = source_location::current() | ||||||
|  | 	); | ||||||
| 
 | 
 | ||||||
| 	void open_optiongroup(const string &group = ""); | 	void open_optiongroup( | ||||||
| 	void open_option(const string &text); | 		const string &group = "", | ||||||
|  | 		const source_location location = source_location::current() | ||||||
|  | 	); | ||||||
|  | 	void open_option( | ||||||
|  | 		const string &text, | ||||||
|  | 		const source_location location = source_location::current() | ||||||
|  | 	); | ||||||
| 	void close(int levels = 1); | 	void close(int levels = 1); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue