mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 03:32:29 +00:00 
			
		
		
		
	Remove log_str() functions and convert their log_signal() users to return std::string
				
					
				
			This is a small but easy step towards removing the `log_id_cache`. See issue #5210.
This commit is contained in:
		
							parent
							
								
									c2291c10a6
								
							
						
					
					
						commit
						c7017f7f79
					
				
					 5 changed files with 23 additions and 34 deletions
				
			
		|  | @ -865,41 +865,41 @@ DriveSpec DriverMap::operator()(DriveSpec spec) | ||||||
| 	return result; | 	return result; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const char *log_signal(DriveChunkWire const &chunk) | std::string log_signal(DriveChunkWire const &chunk) | ||||||
| { | { | ||||||
| 	const char *id = log_id(chunk.wire->name); | 	const char *id = log_id(chunk.wire->name); | ||||||
| 	if (chunk.is_whole()) | 	if (chunk.is_whole()) | ||||||
| 		return id; | 		return id; | ||||||
| 	if (chunk.width == 1) | 	if (chunk.width == 1) | ||||||
| 		return log_str(stringf("%s [%d]", id, chunk.offset)); | 		return stringf("%s [%d]", id, chunk.offset); | ||||||
| 	return log_str(stringf("%s [%d:%d]", id, chunk.offset + chunk.width - 1, chunk.offset)); | 	return stringf("%s [%d:%d]", id, chunk.offset + chunk.width - 1, chunk.offset); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| const char *log_signal(DriveChunkPort const &chunk) | std::string log_signal(DriveChunkPort const &chunk) | ||||||
| { | { | ||||||
| 	const char *cell_id = log_id(chunk.cell->name); | 	const char *cell_id = log_id(chunk.cell->name); | ||||||
| 	const char *port_id = log_id(chunk.port); | 	const char *port_id = log_id(chunk.port); | ||||||
| 	if (chunk.is_whole()) | 	if (chunk.is_whole()) | ||||||
| 		return log_str(stringf("%s <%s>", cell_id, port_id)); | 		return stringf("%s <%s>", cell_id, port_id); | ||||||
| 	if (chunk.width == 1) | 	if (chunk.width == 1) | ||||||
| 		return log_str(stringf("%s <%s> [%d]", cell_id, port_id, chunk.offset)); | 		return stringf("%s <%s> [%d]", cell_id, port_id, chunk.offset); | ||||||
| 	return log_str(stringf("%s <%s> [%d:%d]", cell_id, port_id, chunk.offset + chunk.width - 1, chunk.offset)); | 	return stringf("%s <%s> [%d:%d]", cell_id, port_id, chunk.offset + chunk.width - 1, chunk.offset); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const char *log_signal(DriveChunkMarker const &chunk) | std::string log_signal(DriveChunkMarker const &chunk) | ||||||
| { | { | ||||||
| 	if (chunk.width == 1) | 	if (chunk.width == 1) | ||||||
| 		return log_str(stringf("<marker %d> [%d]", chunk.marker, chunk.offset)); | 		return stringf("<marker %d> [%d]", chunk.marker, chunk.offset); | ||||||
| 	return log_str(stringf("<marker %d> [%d:%d]", chunk.marker, chunk.offset + chunk.width - 1, chunk.offset)); | 	return stringf("<marker %d> [%d:%d]", chunk.marker, chunk.offset + chunk.width - 1, chunk.offset); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const char *log_signal(DriveChunk const &chunk) | std::string log_signal(DriveChunk const &chunk) | ||||||
| { | { | ||||||
| 	switch (chunk.type()) | 	switch (chunk.type()) | ||||||
| 	{ | 	{ | ||||||
| 		case DriveType::NONE: | 		case DriveType::NONE: | ||||||
| 			return log_str(stringf("<none x%d>", chunk.size())); | 			return stringf("<none x%d>", chunk.size()); | ||||||
| 		case DriveType::CONSTANT: | 		case DriveType::CONSTANT: | ||||||
| 			return log_const(chunk.constant()); | 			return log_const(chunk.constant()); | ||||||
| 		case DriveType::WIRE: | 		case DriveType::WIRE: | ||||||
|  | @ -917,14 +917,14 @@ const char *log_signal(DriveChunk const &chunk) | ||||||
| 				str += log_signal(single); | 				str += log_signal(single); | ||||||
| 			} | 			} | ||||||
| 			str += ">"; | 			str += ">"; | ||||||
| 			return log_str(str); | 			return str; | ||||||
| 		} | 		} | ||||||
| 		default: | 		default: | ||||||
| 			log_abort(); | 			log_abort(); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const char *log_signal(DriveSpec const &spec) | std::string log_signal(DriveSpec const &spec) | ||||||
| { | { | ||||||
| 	auto &chunks = spec.chunks(); | 	auto &chunks = spec.chunks(); | ||||||
| 	if (chunks.empty()) | 	if (chunks.empty()) | ||||||
|  | @ -943,7 +943,7 @@ const char *log_signal(DriveSpec const &spec) | ||||||
| 	} | 	} | ||||||
| 	str += " }"; | 	str += " }"; | ||||||
| 
 | 
 | ||||||
| 	return log_str(str); | 	return str; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| YOSYS_NAMESPACE_END | YOSYS_NAMESPACE_END | ||||||
|  |  | ||||||
|  | @ -20,6 +20,7 @@ | ||||||
| #ifndef DRIVERTOOLS_H | #ifndef DRIVERTOOLS_H | ||||||
| #define DRIVERTOOLS_H | #define DRIVERTOOLS_H | ||||||
| 
 | 
 | ||||||
|  | #include <string> | ||||||
| #include <type_traits> | #include <type_traits> | ||||||
| 
 | 
 | ||||||
| #include "kernel/rtlil.h" | #include "kernel/rtlil.h" | ||||||
|  | @ -39,11 +40,11 @@ struct DriveChunk; | ||||||
| 
 | 
 | ||||||
| struct DriveSpec; | struct DriveSpec; | ||||||
| 
 | 
 | ||||||
| const char *log_signal(DriveChunkWire const &chunk); | std::string log_signal(DriveChunkWire const &chunk); | ||||||
| const char *log_signal(DriveChunkPort const &chunk); | std::string log_signal(DriveChunkPort const &chunk); | ||||||
| const char *log_signal(DriveChunkMarker const &chunk); | std::string log_signal(DriveChunkMarker const &chunk); | ||||||
| const char *log_signal(DriveChunk const &chunk); | std::string log_signal(DriveChunk const &chunk); | ||||||
| const char *log_signal(DriveSpec const &chunk); | std::string log_signal(DriveSpec const &chunk); | ||||||
| 
 | 
 | ||||||
| enum class DriveType : unsigned char | enum class DriveType : unsigned char | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -638,7 +638,7 @@ private: | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	void undriven(const char *name) { | 	void undriven(const std::string& name) { | ||||||
| 		log_error("The design contains an undriven signal %s. This is not supported by the functional backend. " | 		log_error("The design contains an undriven signal %s. This is not supported by the functional backend. " | ||||||
| 			"Call setundef with appropriate options to avoid this error.\n", name); | 			"Call setundef with appropriate options to avoid this error.\n", name); | ||||||
| 	} | 	} | ||||||
|  | @ -646,7 +646,7 @@ private: | ||||||
| 	void check_undriven(DriveSpec const& spec, std::string const& name) { | 	void check_undriven(DriveSpec const& spec, std::string const& name) { | ||||||
| 		for(auto const &chunk : spec.chunks()) | 		for(auto const &chunk : spec.chunks()) | ||||||
| 			if(chunk.is_none()) | 			if(chunk.is_none()) | ||||||
| 				undriven(name.c_str()); | 				undriven(name); | ||||||
| 	} | 	} | ||||||
| public: | public: | ||||||
| 	void process_queue() | 	void process_queue() | ||||||
|  |  | ||||||
|  | @ -621,16 +621,6 @@ const char *log_id(const RTLIL::IdString &str) | ||||||
| 	return log_id_cache.back(); | 	return log_id_cache.back(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const char *log_str(const char *str) |  | ||||||
| { |  | ||||||
| 	log_id_cache.push_back(strdup(str)); |  | ||||||
| 	return log_id_cache.back(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| const char *log_str(std::string const &str) { |  | ||||||
| 	return log_str(str.c_str()); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void log_module(RTLIL::Module *module, std::string indent) | void log_module(RTLIL::Module *module, std::string indent) | ||||||
| { | { | ||||||
| 	std::stringstream buf; | 	std::stringstream buf; | ||||||
|  |  | ||||||
|  | @ -256,8 +256,6 @@ void log_check_expected(); | ||||||
| const char *log_signal(const RTLIL::SigSpec &sig, bool autoint = true); | const char *log_signal(const RTLIL::SigSpec &sig, bool autoint = true); | ||||||
| const char *log_const(const RTLIL::Const &value, bool autoint = true); | const char *log_const(const RTLIL::Const &value, bool autoint = true); | ||||||
| const char *log_id(const RTLIL::IdString &id); | const char *log_id(const RTLIL::IdString &id); | ||||||
| const char *log_str(const char *str); |  | ||||||
| const char *log_str(std::string const &str); |  | ||||||
| 
 | 
 | ||||||
| template<typename T> static inline const char *log_id(T *obj, const char *nullstr = nullptr) { | template<typename T> static inline const char *log_id(T *obj, const char *nullstr = nullptr) { | ||||||
| 	if (nullstr && obj == nullptr) | 	if (nullstr && obj == nullptr) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue