mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 11:42:30 +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; | ||||
| 
 | ||||
| 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::unique_ptr<debug_attrs>> attrs_table; | ||||
| 
 | ||||
|  | @ -1344,20 +1352,17 @@ struct debug_items { | |||
| 		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); | ||||
| 	} | ||||
| 
 | ||||
| 	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); | ||||
| 		assert(parts.size() == 1); | ||||
| 		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 { | ||||
| 		return attrs_table.at(name)->map; | ||||
| 	} | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue