mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 11:42:30 +00:00 
			
		
		
		
	SigSpec refactoring: added RTLIL::SigSpec::bits() and pack/unpack api
This commit is contained in:
		
							parent
							
								
									28b3fd05fa
								
							
						
					
					
						commit
						08e1e25169
					
				
					 2 changed files with 135 additions and 18 deletions
				
			
		
							
								
								
									
										111
									
								
								kernel/rtlil.cc
									
										
									
									
									
								
							
							
						
						
									
										111
									
								
								kernel/rtlil.cc
									
										
									
									
									
								
							|  | @ -1487,8 +1487,48 @@ RTLIL::SigSpec::SigSpec(std::set<RTLIL::SigBit> bits) | ||||||
| 	check(); | 	check(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void RTLIL::SigSpec::pack() const | ||||||
|  | { | ||||||
|  | 	RTLIL::SigSpec *that = (RTLIL::SigSpec*)this; | ||||||
|  | 
 | ||||||
|  | 	if (that->bits_.empty()) | ||||||
|  | 		return; | ||||||
|  | 
 | ||||||
|  | 	log_assert(that->chunks_.empty()); | ||||||
|  | 
 | ||||||
|  | 	std::vector<RTLIL::SigBit> old_bits; | ||||||
|  | 	old_bits.swap(that->bits_); | ||||||
|  | 
 | ||||||
|  | 	that->width_ = 0; | ||||||
|  | 	for (auto &bit : old_bits) | ||||||
|  | 		that->append_bit(bit); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void RTLIL::SigSpec::unpack() const | ||||||
|  | { | ||||||
|  | 	RTLIL::SigSpec *that = (RTLIL::SigSpec*)this; | ||||||
|  | 
 | ||||||
|  | 	if (that->chunks_.empty()) | ||||||
|  | 		return; | ||||||
|  | 
 | ||||||
|  | 	log_assert(that->bits_.empty()); | ||||||
|  | 
 | ||||||
|  | 	that->bits_.reserve(that->width_); | ||||||
|  | 	for (auto &c : that->chunks_) | ||||||
|  | 		for (int i = 0; i < c.width; i++) | ||||||
|  | 			that->bits_.push_back(RTLIL::SigBit(c, i)); | ||||||
|  | 
 | ||||||
|  | 	that->chunks_.clear(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | bool RTLIL::SigSpec::packed() const | ||||||
|  | { | ||||||
|  | 	return bits_.empty(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void RTLIL::SigSpec::expand() | void RTLIL::SigSpec::expand() | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	std::vector<RTLIL::SigChunk> new_chunks; | 	std::vector<RTLIL::SigChunk> new_chunks; | ||||||
| 	for (size_t i = 0; i < chunks_.size(); i++) { | 	for (size_t i = 0; i < chunks_.size(); i++) { | ||||||
| 		for (int j = 0; j < chunks_[i].width; j++) | 		for (int j = 0; j < chunks_[i].width; j++) | ||||||
|  | @ -1500,6 +1540,7 @@ void RTLIL::SigSpec::expand() | ||||||
| 
 | 
 | ||||||
| void RTLIL::SigSpec::optimize() | void RTLIL::SigSpec::optimize() | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	std::vector<RTLIL::SigChunk> new_chunks; | 	std::vector<RTLIL::SigChunk> new_chunks; | ||||||
| 	for (auto &c : chunks_) | 	for (auto &c : chunks_) | ||||||
| 		if (new_chunks.size() == 0) { | 		if (new_chunks.size() == 0) { | ||||||
|  | @ -1519,6 +1560,7 @@ void RTLIL::SigSpec::optimize() | ||||||
| 
 | 
 | ||||||
| RTLIL::SigSpec RTLIL::SigSpec::optimized() const | RTLIL::SigSpec RTLIL::SigSpec::optimized() const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	RTLIL::SigSpec ret = *this; | 	RTLIL::SigSpec ret = *this; | ||||||
| 	ret.optimize(); | 	ret.optimize(); | ||||||
| 	return ret; | 	return ret; | ||||||
|  | @ -1543,6 +1585,7 @@ bool RTLIL::SigChunk::compare(const RTLIL::SigChunk &a, const RTLIL::SigChunk &b | ||||||
| 
 | 
 | ||||||
| void RTLIL::SigSpec::sort() | void RTLIL::SigSpec::sort() | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	expand(); | 	expand(); | ||||||
| 	std::sort(chunks_.begin(), chunks_.end(), RTLIL::SigChunk::compare); | 	std::sort(chunks_.begin(), chunks_.end(), RTLIL::SigChunk::compare); | ||||||
| 	optimize(); | 	optimize(); | ||||||
|  | @ -1550,6 +1593,7 @@ void RTLIL::SigSpec::sort() | ||||||
| 
 | 
 | ||||||
| void RTLIL::SigSpec::sort_and_unify() | void RTLIL::SigSpec::sort_and_unify() | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	expand(); | 	expand(); | ||||||
| 	std::sort(chunks_.begin(), chunks_.end(), RTLIL::SigChunk::compare); | 	std::sort(chunks_.begin(), chunks_.end(), RTLIL::SigChunk::compare); | ||||||
| 	for (size_t i = 1; i < chunks_.size(); i++) { | 	for (size_t i = 1; i < chunks_.size(); i++) { | ||||||
|  | @ -1571,6 +1615,13 @@ void RTLIL::SigSpec::replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec | ||||||
| 
 | 
 | ||||||
| void RTLIL::SigSpec::replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with, RTLIL::SigSpec *other) const | void RTLIL::SigSpec::replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with, RTLIL::SigSpec *other) const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
|  | 	pattern.pack(); | ||||||
|  | 	with.pack(); | ||||||
|  | 
 | ||||||
|  | 	if (other != NULL) | ||||||
|  | 		other->pack(); | ||||||
|  | 
 | ||||||
| 	int pos = 0, restart_pos = 0; | 	int pos = 0, restart_pos = 0; | ||||||
| 	assert(other == NULL || width_ == other->width_); | 	assert(other == NULL || width_ == other->width_); | ||||||
| 	for (size_t i = 0; i < chunks_.size(); i++) { | 	for (size_t i = 0; i < chunks_.size(); i++) { | ||||||
|  | @ -1609,6 +1660,12 @@ void RTLIL::SigSpec::remove(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other | ||||||
| 
 | 
 | ||||||
| void RTLIL::SigSpec::remove2(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other) | void RTLIL::SigSpec::remove2(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other) | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
|  | 	pattern.pack(); | ||||||
|  | 
 | ||||||
|  | 	if (other != NULL) | ||||||
|  | 		other->pack(); | ||||||
|  | 
 | ||||||
| 	int pos = 0; | 	int pos = 0; | ||||||
| 	assert(other == NULL || width_ == other->width_); | 	assert(other == NULL || width_ == other->width_); | ||||||
| 	for (size_t i = 0; i < chunks_.size(); i++) { | 	for (size_t i = 0; i < chunks_.size(); i++) { | ||||||
|  | @ -1638,6 +1695,12 @@ restart: | ||||||
| 
 | 
 | ||||||
| RTLIL::SigSpec RTLIL::SigSpec::extract(RTLIL::SigSpec pattern, RTLIL::SigSpec *other) const | RTLIL::SigSpec RTLIL::SigSpec::extract(RTLIL::SigSpec pattern, RTLIL::SigSpec *other) const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
|  | 	pattern.pack(); | ||||||
|  | 
 | ||||||
|  | 	if (other != NULL) | ||||||
|  | 		other->pack(); | ||||||
|  | 
 | ||||||
| 	assert(other == NULL || width_ == other->width_); | 	assert(other == NULL || width_ == other->width_); | ||||||
| 
 | 
 | ||||||
| 	std::set<RTLIL::SigBit> pat = pattern.to_sigbit_set(); | 	std::set<RTLIL::SigBit> pat = pattern.to_sigbit_set(); | ||||||
|  | @ -1661,6 +1724,9 @@ RTLIL::SigSpec RTLIL::SigSpec::extract(RTLIL::SigSpec pattern, RTLIL::SigSpec *o | ||||||
| 
 | 
 | ||||||
| void RTLIL::SigSpec::replace(int offset, const RTLIL::SigSpec &with) | void RTLIL::SigSpec::replace(int offset, const RTLIL::SigSpec &with) | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
|  | 	with.pack(); | ||||||
|  | 
 | ||||||
| 	int pos = 0; | 	int pos = 0; | ||||||
| 	assert(offset >= 0); | 	assert(offset >= 0); | ||||||
| 	assert(with.width_ >= 0); | 	assert(with.width_ >= 0); | ||||||
|  | @ -1683,6 +1749,7 @@ void RTLIL::SigSpec::replace(int offset, const RTLIL::SigSpec &with) | ||||||
| 
 | 
 | ||||||
| void RTLIL::SigSpec::remove_const() | void RTLIL::SigSpec::remove_const() | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	for (size_t i = 0; i < chunks_.size(); i++) { | 	for (size_t i = 0; i < chunks_.size(); i++) { | ||||||
| 		if (chunks_[i].wire != NULL) | 		if (chunks_[i].wire != NULL) | ||||||
| 			continue; | 			continue; | ||||||
|  | @ -1694,6 +1761,7 @@ void RTLIL::SigSpec::remove_const() | ||||||
| 
 | 
 | ||||||
| void RTLIL::SigSpec::remove(int offset, int length) | void RTLIL::SigSpec::remove(int offset, int length) | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	int pos = 0; | 	int pos = 0; | ||||||
| 	assert(offset >= 0); | 	assert(offset >= 0); | ||||||
| 	assert(length >= 0); | 	assert(length >= 0); | ||||||
|  | @ -1733,6 +1801,7 @@ void RTLIL::SigSpec::remove(int offset, int length) | ||||||
| 
 | 
 | ||||||
| RTLIL::SigSpec RTLIL::SigSpec::extract(int offset, int length) const | RTLIL::SigSpec RTLIL::SigSpec::extract(int offset, int length) const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	int pos = 0; | 	int pos = 0; | ||||||
| 	RTLIL::SigSpec ret; | 	RTLIL::SigSpec ret; | ||||||
| 	assert(offset >= 0); | 	assert(offset >= 0); | ||||||
|  | @ -1762,6 +1831,9 @@ RTLIL::SigSpec RTLIL::SigSpec::extract(int offset, int length) const | ||||||
| 
 | 
 | ||||||
| void RTLIL::SigSpec::append(const RTLIL::SigSpec &signal) | void RTLIL::SigSpec::append(const RTLIL::SigSpec &signal) | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
|  | 	signal.pack(); | ||||||
|  | 
 | ||||||
| 	for (size_t i = 0; i < signal.chunks_.size(); i++) { | 	for (size_t i = 0; i < signal.chunks_.size(); i++) { | ||||||
| 		chunks_.push_back(signal.chunks_[i]); | 		chunks_.push_back(signal.chunks_[i]); | ||||||
| 		width_ += signal.chunks_[i].width; | 		width_ += signal.chunks_[i].width; | ||||||
|  | @ -1771,6 +1843,7 @@ void RTLIL::SigSpec::append(const RTLIL::SigSpec &signal) | ||||||
| 
 | 
 | ||||||
| void RTLIL::SigSpec::append_bit(const RTLIL::SigBit &bit) | void RTLIL::SigSpec::append_bit(const RTLIL::SigBit &bit) | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	if (chunks_.size() == 0) | 	if (chunks_.size() == 0) | ||||||
| 		chunks_.push_back(bit); | 		chunks_.push_back(bit); | ||||||
| 	else | 	else | ||||||
|  | @ -1789,8 +1862,11 @@ void RTLIL::SigSpec::append_bit(const RTLIL::SigBit &bit) | ||||||
| 	// check();
 | 	// check();
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool RTLIL::SigSpec::combine(RTLIL::SigSpec signal, RTLIL::State freeState, bool override) | bool RTLIL::SigSpec::combine(RTLIL::SigSpec signal, RTLIL::State freeState, bool do_override) | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
|  | 	signal.pack(); | ||||||
|  | 
 | ||||||
| 	bool no_collisions = true; | 	bool no_collisions = true; | ||||||
| 
 | 
 | ||||||
| 	assert(width_ == signal.width_); | 	assert(width_ == signal.width_); | ||||||
|  | @ -1801,7 +1877,7 @@ bool RTLIL::SigSpec::combine(RTLIL::SigSpec signal, RTLIL::State freeState, bool | ||||||
| 		bool self_free = chunks_[i].wire == NULL && chunks_[i].data.bits[0] == freeState; | 		bool self_free = chunks_[i].wire == NULL && chunks_[i].data.bits[0] == freeState; | ||||||
| 		bool other_free = signal.chunks_[i].wire == NULL && signal.chunks_[i].data.bits[0] == freeState; | 		bool other_free = signal.chunks_[i].wire == NULL && signal.chunks_[i].data.bits[0] == freeState; | ||||||
| 		if (!self_free && !other_free) { | 		if (!self_free && !other_free) { | ||||||
| 			if (override) | 			if (do_override) | ||||||
| 				chunks_[i] = signal.chunks_[i]; | 				chunks_[i] = signal.chunks_[i]; | ||||||
| 			else | 			else | ||||||
| 				chunks_[i] = RTLIL::SigChunk(RTLIL::State::Sx, 1); | 				chunks_[i] = RTLIL::SigChunk(RTLIL::State::Sx, 1); | ||||||
|  | @ -1817,6 +1893,8 @@ bool RTLIL::SigSpec::combine(RTLIL::SigSpec signal, RTLIL::State freeState, bool | ||||||
| 
 | 
 | ||||||
| void RTLIL::SigSpec::extend(int width, bool is_signed) | void RTLIL::SigSpec::extend(int width, bool is_signed) | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
|  | 
 | ||||||
| 	if (width_ > width) | 	if (width_ > width) | ||||||
| 		remove(width, width_ - width); | 		remove(width, width_ - width); | ||||||
| 	 | 	 | ||||||
|  | @ -1834,6 +1912,8 @@ void RTLIL::SigSpec::extend(int width, bool is_signed) | ||||||
| 
 | 
 | ||||||
| void RTLIL::SigSpec::extend_u0(int width, bool is_signed) | void RTLIL::SigSpec::extend_u0(int width, bool is_signed) | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
|  | 
 | ||||||
| 	if (width_ > width) | 	if (width_ > width) | ||||||
| 		remove(width, width_ - width); | 		remove(width, width_ - width); | ||||||
| 	 | 	 | ||||||
|  | @ -1850,6 +1930,8 @@ void RTLIL::SigSpec::extend_u0(int width, bool is_signed) | ||||||
| 
 | 
 | ||||||
| void RTLIL::SigSpec::check() const | void RTLIL::SigSpec::check() const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
|  | 
 | ||||||
| 	int w = 0; | 	int w = 0; | ||||||
| 	for (size_t i = 0; i < chunks_.size(); i++) { | 	for (size_t i = 0; i < chunks_.size(); i++) { | ||||||
| 		const RTLIL::SigChunk chunk = chunks_[i]; | 		const RTLIL::SigChunk chunk = chunks_[i]; | ||||||
|  | @ -1869,6 +1951,9 @@ void RTLIL::SigSpec::check() const | ||||||
| 
 | 
 | ||||||
| bool RTLIL::SigSpec::operator <(const RTLIL::SigSpec &other) const | bool RTLIL::SigSpec::operator <(const RTLIL::SigSpec &other) const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
|  | 	other.pack(); | ||||||
|  | 
 | ||||||
| 	if (width_ != other.width_) | 	if (width_ != other.width_) | ||||||
| 		return width_ < other.width_; | 		return width_ < other.width_; | ||||||
| 
 | 
 | ||||||
|  | @ -1888,6 +1973,9 @@ bool RTLIL::SigSpec::operator <(const RTLIL::SigSpec &other) const | ||||||
| 
 | 
 | ||||||
| bool RTLIL::SigSpec::operator ==(const RTLIL::SigSpec &other) const | bool RTLIL::SigSpec::operator ==(const RTLIL::SigSpec &other) const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
|  | 	other.pack(); | ||||||
|  | 
 | ||||||
| 	if (width_ != other.width_) | 	if (width_ != other.width_) | ||||||
| 		return false; | 		return false; | ||||||
| 
 | 
 | ||||||
|  | @ -1914,6 +2002,7 @@ bool RTLIL::SigSpec::operator !=(const RTLIL::SigSpec &other) const | ||||||
| 
 | 
 | ||||||
| bool RTLIL::SigSpec::is_fully_const() const | bool RTLIL::SigSpec::is_fully_const() const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	for (auto it = chunks_.begin(); it != chunks_.end(); it++) | 	for (auto it = chunks_.begin(); it != chunks_.end(); it++) | ||||||
| 		if (it->width > 0 && it->wire != NULL) | 		if (it->width > 0 && it->wire != NULL) | ||||||
| 			return false; | 			return false; | ||||||
|  | @ -1922,6 +2011,7 @@ bool RTLIL::SigSpec::is_fully_const() const | ||||||
| 
 | 
 | ||||||
| bool RTLIL::SigSpec::is_fully_def() const | bool RTLIL::SigSpec::is_fully_def() const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	for (auto it = chunks_.begin(); it != chunks_.end(); it++) { | 	for (auto it = chunks_.begin(); it != chunks_.end(); it++) { | ||||||
| 		if (it->width > 0 && it->wire != NULL) | 		if (it->width > 0 && it->wire != NULL) | ||||||
| 			return false; | 			return false; | ||||||
|  | @ -1934,6 +2024,7 @@ bool RTLIL::SigSpec::is_fully_def() const | ||||||
| 
 | 
 | ||||||
| bool RTLIL::SigSpec::is_fully_undef() const | bool RTLIL::SigSpec::is_fully_undef() const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	for (auto it = chunks_.begin(); it != chunks_.end(); it++) { | 	for (auto it = chunks_.begin(); it != chunks_.end(); it++) { | ||||||
| 		if (it->width > 0 && it->wire != NULL) | 		if (it->width > 0 && it->wire != NULL) | ||||||
| 			return false; | 			return false; | ||||||
|  | @ -1946,6 +2037,7 @@ bool RTLIL::SigSpec::is_fully_undef() const | ||||||
| 
 | 
 | ||||||
| bool RTLIL::SigSpec::has_marked_bits() const | bool RTLIL::SigSpec::has_marked_bits() const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	for (auto it = chunks_.begin(); it != chunks_.end(); it++) | 	for (auto it = chunks_.begin(); it != chunks_.end(); it++) | ||||||
| 		if (it->width > 0 && it->wire == NULL) { | 		if (it->width > 0 && it->wire == NULL) { | ||||||
| 			for (size_t i = 0; i < it->data.bits.size(); i++) | 			for (size_t i = 0; i < it->data.bits.size(); i++) | ||||||
|  | @ -1957,6 +2049,7 @@ bool RTLIL::SigSpec::has_marked_bits() const | ||||||
| 
 | 
 | ||||||
| bool RTLIL::SigSpec::as_bool() const | bool RTLIL::SigSpec::as_bool() const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	assert(is_fully_const()); | 	assert(is_fully_const()); | ||||||
| 	SigSpec sig = *this; | 	SigSpec sig = *this; | ||||||
| 	sig.optimize(); | 	sig.optimize(); | ||||||
|  | @ -1967,6 +2060,7 @@ bool RTLIL::SigSpec::as_bool() const | ||||||
| 
 | 
 | ||||||
| int RTLIL::SigSpec::as_int() const | int RTLIL::SigSpec::as_int() const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	assert(is_fully_const()); | 	assert(is_fully_const()); | ||||||
| 	SigSpec sig = *this; | 	SigSpec sig = *this; | ||||||
| 	sig.optimize(); | 	sig.optimize(); | ||||||
|  | @ -1977,6 +2071,7 @@ int RTLIL::SigSpec::as_int() const | ||||||
| 
 | 
 | ||||||
| std::string RTLIL::SigSpec::as_string() const | std::string RTLIL::SigSpec::as_string() const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	std::string str; | 	std::string str; | ||||||
| 	for (size_t i = chunks_.size(); i > 0; i--) { | 	for (size_t i = chunks_.size(); i > 0; i--) { | ||||||
| 		const RTLIL::SigChunk &chunk = chunks_[i-1]; | 		const RTLIL::SigChunk &chunk = chunks_[i-1]; | ||||||
|  | @ -1991,6 +2086,7 @@ std::string RTLIL::SigSpec::as_string() const | ||||||
| 
 | 
 | ||||||
| RTLIL::Const RTLIL::SigSpec::as_const() const | RTLIL::Const RTLIL::SigSpec::as_const() const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	assert(is_fully_const()); | 	assert(is_fully_const()); | ||||||
| 	SigSpec sig = *this; | 	SigSpec sig = *this; | ||||||
| 	sig.optimize(); | 	sig.optimize(); | ||||||
|  | @ -2001,6 +2097,7 @@ RTLIL::Const RTLIL::SigSpec::as_const() const | ||||||
| 
 | 
 | ||||||
| bool RTLIL::SigSpec::match(std::string pattern) const | bool RTLIL::SigSpec::match(std::string pattern) const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	std::string str = as_string(); | 	std::string str = as_string(); | ||||||
| 	assert(pattern.size() == str.size()); | 	assert(pattern.size() == str.size()); | ||||||
| 
 | 
 | ||||||
|  | @ -2021,6 +2118,7 @@ bool RTLIL::SigSpec::match(std::string pattern) const | ||||||
| 
 | 
 | ||||||
| std::set<RTLIL::SigBit> RTLIL::SigSpec::to_sigbit_set() const | std::set<RTLIL::SigBit> RTLIL::SigSpec::to_sigbit_set() const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	std::set<RTLIL::SigBit> sigbits; | 	std::set<RTLIL::SigBit> sigbits; | ||||||
| 	for (auto &c : chunks_) | 	for (auto &c : chunks_) | ||||||
| 		for (int i = 0; i < c.width; i++) | 		for (int i = 0; i < c.width; i++) | ||||||
|  | @ -2030,16 +2128,13 @@ std::set<RTLIL::SigBit> RTLIL::SigSpec::to_sigbit_set() const | ||||||
| 
 | 
 | ||||||
| std::vector<RTLIL::SigBit> RTLIL::SigSpec::to_sigbit_vector() const | std::vector<RTLIL::SigBit> RTLIL::SigSpec::to_sigbit_vector() const | ||||||
| { | { | ||||||
| 	std::vector<RTLIL::SigBit> sigbits; | 	unpack(); | ||||||
| 	sigbits.reserve(width_); | 	return bits_; | ||||||
| 	for (auto &c : chunks_) |  | ||||||
| 		for (int i = 0; i < c.width; i++) |  | ||||||
| 			sigbits.push_back(RTLIL::SigBit(c, i)); |  | ||||||
| 	return sigbits; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| RTLIL::SigBit RTLIL::SigSpec::to_single_sigbit() const | RTLIL::SigBit RTLIL::SigSpec::to_single_sigbit() const | ||||||
| { | { | ||||||
|  | 	pack(); | ||||||
| 	log_assert(width_ == 1); | 	log_assert(width_ == 1); | ||||||
| 	for (auto &c : chunks_) | 	for (auto &c : chunks_) | ||||||
| 		if (c.width) | 		if (c.width) | ||||||
|  |  | ||||||
|  | @ -498,14 +498,14 @@ struct RTLIL::SigBit { | ||||||
| struct RTLIL::SigSpec { | struct RTLIL::SigSpec { | ||||||
| private: | private: | ||||||
| 	std::vector<RTLIL::SigChunk> chunks_; // LSB at index 0
 | 	std::vector<RTLIL::SigChunk> chunks_; // LSB at index 0
 | ||||||
|  | 	std::vector<RTLIL::SigBit> bits_; // LSB at index 0
 | ||||||
| 	int width_; | 	int width_; | ||||||
| 
 | 
 | ||||||
|  | 	void pack() const; | ||||||
|  | 	void unpack() const; | ||||||
|  | 	bool packed() const; | ||||||
|  | 
 | ||||||
| public: | public: | ||||||
| 	std::vector<RTLIL::SigChunk> &chunks_rw() { return chunks_; } |  | ||||||
| 	const std::vector<RTLIL::SigChunk> &chunks() const { return chunks_; } |  | ||||||
| 
 |  | ||||||
| 	int size() const { return width_; } |  | ||||||
| 
 |  | ||||||
| 	SigSpec(); | 	SigSpec(); | ||||||
| 	SigSpec(const RTLIL::Const &data); | 	SigSpec(const RTLIL::Const &data); | ||||||
| 	SigSpec(const RTLIL::SigChunk &chunk); | 	SigSpec(const RTLIL::SigChunk &chunk); | ||||||
|  | @ -516,46 +516,68 @@ public: | ||||||
| 	SigSpec(RTLIL::SigBit bit, int width = 1); | 	SigSpec(RTLIL::SigBit bit, int width = 1); | ||||||
| 	SigSpec(std::vector<RTLIL::SigBit> bits); | 	SigSpec(std::vector<RTLIL::SigBit> bits); | ||||||
| 	SigSpec(std::set<RTLIL::SigBit> bits); | 	SigSpec(std::set<RTLIL::SigBit> bits); | ||||||
|  | 
 | ||||||
|  | 	std::vector<RTLIL::SigChunk> &chunks_rw() { pack(); return chunks_; } | ||||||
|  | 	const std::vector<RTLIL::SigChunk> &chunks() const { pack(); return chunks_; } | ||||||
|  | 	const std::vector<RTLIL::SigBit> &bits() const { unpack(); return bits_; } | ||||||
|  | 
 | ||||||
|  | 	int size() const { return width_; } | ||||||
|  | 
 | ||||||
| 	void expand(); | 	void expand(); | ||||||
| 	void optimize(); | 	void optimize(); | ||||||
| 	RTLIL::SigSpec optimized() const; | 	RTLIL::SigSpec optimized() const; | ||||||
|  | 
 | ||||||
| 	void sort(); | 	void sort(); | ||||||
| 	void sort_and_unify(); | 	void sort_and_unify(); | ||||||
|  | 
 | ||||||
| 	void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with); | 	void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with); | ||||||
| 	void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with, RTLIL::SigSpec *other) const; | 	void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with, RTLIL::SigSpec *other) const; | ||||||
|  | 	void replace(int offset, const RTLIL::SigSpec &with); | ||||||
|  | 
 | ||||||
| 	void remove(const RTLIL::SigSpec &pattern); | 	void remove(const RTLIL::SigSpec &pattern); | ||||||
| 	void remove(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other) const; | 	void remove(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other) const; | ||||||
| 	void remove2(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other); | 	void remove2(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other); | ||||||
| 	RTLIL::SigSpec extract(RTLIL::SigSpec pattern, RTLIL::SigSpec *other = NULL) const; | 	void remove(int offset, int length = 1); | ||||||
| 	void replace(int offset, const RTLIL::SigSpec &with); |  | ||||||
| 	void remove_const(); | 	void remove_const(); | ||||||
| 	void remove(int offset, int length); | 
 | ||||||
|  | 	RTLIL::SigSpec extract(RTLIL::SigSpec pattern, RTLIL::SigSpec *other = NULL) const; | ||||||
| 	RTLIL::SigSpec extract(int offset, int length) const; | 	RTLIL::SigSpec extract(int offset, int length) const; | ||||||
|  | 
 | ||||||
| 	void append(const RTLIL::SigSpec &signal); | 	void append(const RTLIL::SigSpec &signal); | ||||||
| 	void append_bit(const RTLIL::SigBit &bit); | 	void append_bit(const RTLIL::SigBit &bit); | ||||||
| 	bool combine(RTLIL::SigSpec signal, RTLIL::State freeState = RTLIL::State::Sz, bool override = false); | 
 | ||||||
|  | 	bool combine(RTLIL::SigSpec signal, RTLIL::State freeState = RTLIL::State::Sz, bool do_override = false); | ||||||
|  | 
 | ||||||
| 	void extend(int width, bool is_signed = false); | 	void extend(int width, bool is_signed = false); | ||||||
| 	void extend_u0(int width, bool is_signed = false); | 	void extend_u0(int width, bool is_signed = false); | ||||||
| 	void check() const; | 
 | ||||||
| 	bool operator <(const RTLIL::SigSpec &other) const; | 	bool operator <(const RTLIL::SigSpec &other) const; | ||||||
| 	bool operator ==(const RTLIL::SigSpec &other) const; | 	bool operator ==(const RTLIL::SigSpec &other) const; | ||||||
| 	bool operator !=(const RTLIL::SigSpec &other) const; | 	bool operator !=(const RTLIL::SigSpec &other) const; | ||||||
|  | 
 | ||||||
| 	bool is_fully_const() const; | 	bool is_fully_const() const; | ||||||
| 	bool is_fully_def() const; | 	bool is_fully_def() const; | ||||||
| 	bool is_fully_undef() const; | 	bool is_fully_undef() const; | ||||||
| 	bool has_marked_bits() const; | 	bool has_marked_bits() const; | ||||||
|  | 
 | ||||||
| 	bool as_bool() const; | 	bool as_bool() const; | ||||||
| 	int as_int() const; | 	int as_int() const; | ||||||
| 	std::string as_string() const; | 	std::string as_string() const; | ||||||
| 	RTLIL::Const as_const() const; | 	RTLIL::Const as_const() const; | ||||||
|  | 
 | ||||||
| 	bool match(std::string pattern) const; | 	bool match(std::string pattern) const; | ||||||
|  | 
 | ||||||
| 	std::set<RTLIL::SigBit> to_sigbit_set() const; | 	std::set<RTLIL::SigBit> to_sigbit_set() const; | ||||||
| 	std::vector<RTLIL::SigBit> to_sigbit_vector() const; | 	std::vector<RTLIL::SigBit> to_sigbit_vector() const; | ||||||
| 	RTLIL::SigBit to_single_sigbit() const; | 	RTLIL::SigBit to_single_sigbit() const; | ||||||
|  | 
 | ||||||
| 	static bool parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str); | 	static bool parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str); | ||||||
| 	static bool parse_sel(RTLIL::SigSpec &sig, RTLIL::Design *design, RTLIL::Module *module, std::string str); | 	static bool parse_sel(RTLIL::SigSpec &sig, RTLIL::Design *design, RTLIL::Module *module, std::string str); | ||||||
| 	static bool parse_rhs(const RTLIL::SigSpec &lhs, RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str); | 	static bool parse_rhs(const RTLIL::SigSpec &lhs, RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str); | ||||||
|  | 
 | ||||||
| 	operator std::vector<RTLIL::SigBit>() const { return to_sigbit_vector(); } | 	operator std::vector<RTLIL::SigBit>() const { return to_sigbit_vector(); } | ||||||
|  | 
 | ||||||
|  | 	void check() const; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| inline RTLIL::SigBit::SigBit(const RTLIL::SigSpec &sig) { | inline RTLIL::SigBit::SigBit(const RTLIL::SigSpec &sig) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue