mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 03:32:29 +00:00 
			
		
		
		
	frontends/ast.cc: special-case zero width strings as "\0"
* Fixes #4696
This commit is contained in:
		
							parent
							
								
									b2d78589e2
								
							
						
					
					
						commit
						dbfca1bdff
					
				
					 1 changed files with 17 additions and 8 deletions
				
			
		|  | @ -877,6 +877,13 @@ AstNode *AstNode::mkconst_str(const std::vector<RTLIL::State> &v) | ||||||
| // create an AST node for a constant (using a string as value)
 | // create an AST node for a constant (using a string as value)
 | ||||||
| AstNode *AstNode::mkconst_str(const std::string &str) | AstNode *AstNode::mkconst_str(const std::string &str) | ||||||
| { | { | ||||||
|  | 	AstNode *node; | ||||||
|  | 
 | ||||||
|  | 	// LRM 1364-2005 5.2.3.3 The empty string literal ("") shall be considered
 | ||||||
|  | 	// equivalent to the ASCII NUL ("\0")
 | ||||||
|  | 	if (str.empty()) { | ||||||
|  | 		node = AstNode::mkconst_int(0, false, 8); | ||||||
|  | 	} else { | ||||||
| 		std::vector<RTLIL::State> data; | 		std::vector<RTLIL::State> data; | ||||||
| 		data.reserve(str.size() * 8); | 		data.reserve(str.size() * 8); | ||||||
| 		for (size_t i = 0; i < str.size(); i++) { | 		for (size_t i = 0; i < str.size(); i++) { | ||||||
|  | @ -886,7 +893,9 @@ AstNode *AstNode::mkconst_str(const std::string &str) | ||||||
| 				ch = ch >> 1; | 				ch = ch >> 1; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	AstNode *node = AstNode::mkconst_bits(data, false); | 		node = AstNode::mkconst_bits(data, false); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	node->is_string = true; | 	node->is_string = true; | ||||||
| 	node->str = str; | 	node->str = str; | ||||||
| 	return node; | 	return node; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue