mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	Improvements to $display system task
This commit is contained in:
		
							parent
							
								
									598a475724
								
							
						
					
					
						commit
						c469f22144
					
				
					 1 changed files with 22 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -212,6 +212,19 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
 | 
			
		|||
			// format specifier
 | 
			
		||||
			if(sformat[i] == '%')
 | 
			
		||||
			{
 | 
			
		||||
				// If there's no next character, that's a problem
 | 
			
		||||
				if(i+1 >= sformat.length())
 | 
			
		||||
					log_error("System task `%s' called with `%%' at end of string at %s:%d.\n", str.c_str(), filename.c_str(), linenum);
 | 
			
		||||
 | 
			
		||||
				char cformat = sformat[++i];
 | 
			
		||||
 | 
			
		||||
				// %% is special, does not need a matching argument
 | 
			
		||||
				if(cformat == '%')
 | 
			
		||||
				{
 | 
			
		||||
					sout += '%';
 | 
			
		||||
					continue;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// If we're out of arguments, that's a problem!
 | 
			
		||||
				if(next_arg >= nargs)
 | 
			
		||||
					log_error("System task `%s' called with more format specifiers than arguments at %s:%d.\n", str.c_str(), filename.c_str(), linenum);
 | 
			
		||||
| 
						 | 
				
			
			@ -222,18 +235,9 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
 | 
			
		|||
				if (node_arg->type != AST_CONSTANT)
 | 
			
		||||
					log_error("Failed to evaluate system task `%s' with non-constant argument at %s:%d.\n", str.c_str(), filename.c_str(), linenum);
 | 
			
		||||
 | 
			
		||||
				// If there's no next character, that's a problem
 | 
			
		||||
				if(i+1 >= sformat.length())
 | 
			
		||||
					log_error("System task `%s' called with `%%' at end of string at %s:%d.\n", str.c_str(), filename.c_str(), linenum);
 | 
			
		||||
 | 
			
		||||
				// Everything from here on depends on the format specifier
 | 
			
		||||
				char cformat = sformat[++i];
 | 
			
		||||
				switch(cformat)
 | 
			
		||||
				{
 | 
			
		||||
					case '%':
 | 
			
		||||
						sout += '%';
 | 
			
		||||
						break;
 | 
			
		||||
 | 
			
		||||
					case 's':
 | 
			
		||||
					case 'S':
 | 
			
		||||
						sout += node_arg->bitsAsConst().decode_string();
 | 
			
		||||
| 
						 | 
				
			
			@ -248,6 +252,15 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
 | 
			
		|||
						}
 | 
			
		||||
						break;
 | 
			
		||||
 | 
			
		||||
					case 'x':
 | 
			
		||||
					case 'X':
 | 
			
		||||
						{
 | 
			
		||||
							char tmp[128];
 | 
			
		||||
							snprintf(tmp, sizeof(tmp), "%x", node_arg->bitsAsConst().as_int());
 | 
			
		||||
							sout += tmp;
 | 
			
		||||
						}
 | 
			
		||||
						break;
 | 
			
		||||
 | 
			
		||||
					default:
 | 
			
		||||
						log_error("System task `%s' called with invalid format specifier at %s:%d.\n", str.c_str(), filename.c_str(), linenum);
 | 
			
		||||
						break;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue