mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 03:32:29 +00:00 
			
		
		
		
	cxxrtl: rationalize debug_items accessors.
				
					
				
			Before this commit, `at()` and `operator[]` did the same thing, making
one of them redundant. There was also a somewhat awkward `parts_at()`,
which is more generic than `at()`.
After this commit, `parts_at()` becomes `at()`, and `at()` becomes
`operator[]`. Any quick-and-dirty accesses should use `items["name"]`,
which expects a single-part item. Generic code should instead use
`items.at("name")`, which will return multiple parts. Both will check
for the existence of the name.
This is unlikely to break downstream code since it's likely been using
the shorter `operator[]`. (In any case this API is not stable.)
			
			
This commit is contained in:
		
							parent
							
								
									c3c44225de
								
							
						
					
					
						commit
						42920c9bc0
					
				
					 2 changed files with 12 additions and 7 deletions
				
			
		|  | @ -1320,6 +1320,14 @@ namespace cxxrtl { | ||||||
| using debug_attrs = ::_cxxrtl_attr_set; | using debug_attrs = ::_cxxrtl_attr_set; | ||||||
| 
 | 
 | ||||||
| struct debug_items { | struct debug_items { | ||||||
|  | 	// Debug items may be composed of multiple parts, but the attributes are shared between all of them.
 | ||||||
|  | 	// There are additional invariants, not all of which are not checked by this code:
 | ||||||
|  | 	// - Memories and non-memories cannot be mixed together.
 | ||||||
|  | 	// - Bit indices (considering `lsb_at` and `width`) must not overlap.
 | ||||||
|  | 	// - Row indices (considering `depth` and `zero_at`) must be the same.
 | ||||||
|  | 	// - The `INPUT` and `OUTPUT` flags must be the same for all parts.
 | ||||||
|  | 	// Other than that, the parts can be quite different, e.g. it is OK to mix a value, a wire, an alias,
 | ||||||
|  | 	// and an outline, in the debug information for a single name in four parts.
 | ||||||
| 	std::map<std::string, std::vector<debug_item>> table; | 	std::map<std::string, std::vector<debug_item>> table; | ||||||
| 	std::map<std::string, std::unique_ptr<debug_attrs>> attrs_table; | 	std::map<std::string, std::unique_ptr<debug_attrs>> attrs_table; | ||||||
| 
 | 
 | ||||||
|  | @ -1344,20 +1352,17 @@ struct debug_items { | ||||||
| 		return table.at(name).size(); | 		return table.at(name).size(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	const std::vector<debug_item> &parts_at(const std::string &name) const { | 	const std::vector<debug_item> &at(const std::string &name) const { | ||||||
| 		return table.at(name); | 		return table.at(name); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	const debug_item &at(const std::string &name) const { | 	// Like `at()`, but operates only on single-part debug items.
 | ||||||
|  | 	const debug_item &operator [](const std::string &name) const { | ||||||
| 		const std::vector<debug_item> &parts = table.at(name); | 		const std::vector<debug_item> &parts = table.at(name); | ||||||
| 		assert(parts.size() == 1); | 		assert(parts.size() == 1); | ||||||
| 		return parts.at(0); | 		return parts.at(0); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	const debug_item &operator [](const std::string &name) const { |  | ||||||
| 		return at(name); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	const metadata_map &attrs(const std::string &name) const { | 	const metadata_map &attrs(const std::string &name) const { | ||||||
| 		return attrs_table.at(name)->map; | 		return attrs_table.at(name)->map; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -641,7 +641,7 @@ public: | ||||||
| 			assert(items.count(name) != 0); | 			assert(items.count(name) != 0); | ||||||
| 			assert(part_index < items.count(name)); | 			assert(part_index < items.count(name)); | ||||||
| 
 | 
 | ||||||
| 			const debug_item &part = items.parts_at(name).at(part_index); | 			const debug_item &part = items.at(name).at(part_index); | ||||||
| 			assert(chunks == (part.width + sizeof(chunk_t) * 8 - 1) / (sizeof(chunk_t) * 8)); | 			assert(chunks == (part.width + sizeof(chunk_t) * 8 - 1) / (sizeof(chunk_t) * 8)); | ||||||
| 			assert(depth == part.depth); | 			assert(depth == part.depth); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue