mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	Added support for "file names with blanks"
This commit is contained in:
		
							parent
							
								
									aa0ab975b9
								
							
						
					
					
						commit
						21a1cc1b60
					
				
					 7 changed files with 43 additions and 33 deletions
				
			
		| 
						 | 
					@ -150,7 +150,7 @@ void Pass::call(RTLIL::Design *design, std::string command)
 | 
				
			||||||
	std::vector<std::string> args;
 | 
						std::vector<std::string> args;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::string cmd_buf = command;
 | 
						std::string cmd_buf = command;
 | 
				
			||||||
	std::string tok = next_token(cmd_buf, " \t\r\n");
 | 
						std::string tok = next_token(cmd_buf, " \t\r\n", true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (tok.empty())
 | 
						if (tok.empty())
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					@ -201,7 +201,7 @@ void Pass::call(RTLIL::Design *design, std::string command)
 | 
				
			||||||
			call(design, args);
 | 
								call(design, args);
 | 
				
			||||||
			args.clear();
 | 
								args.clear();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		tok = next_token(cmd_buf, " \t\r\n");
 | 
							tok = next_token(cmd_buf, " \t\r\n", true);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	call(design, args);
 | 
						call(design, args);
 | 
				
			||||||
| 
						 | 
					@ -359,8 +359,7 @@ void Frontend::extra_args(std::istream *&f, std::string &filename, std::vector<s
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			f = new std::istringstream(last_here_document);
 | 
								f = new std::istringstream(last_here_document);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			if (filename.substr(0, 2) == "+/")
 | 
								rewrite_filename(filename);
 | 
				
			||||||
				filename = proc_share_dirname() + filename.substr(1);
 | 
					 | 
				
			||||||
			std::ifstream *ff = new std::ifstream;
 | 
								std::ifstream *ff = new std::ifstream;
 | 
				
			||||||
			ff->open(filename.c_str());
 | 
								ff->open(filename.c_str());
 | 
				
			||||||
			if (ff->fail())
 | 
								if (ff->fail())
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -182,13 +182,23 @@ int readsome(std::istream &f, char *s, int n)
 | 
				
			||||||
	return rc;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::string next_token(std::string &text, const char *sep)
 | 
					std::string next_token(std::string &text, const char *sep, bool long_strings)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	size_t pos_begin = text.find_first_not_of(sep);
 | 
						size_t pos_begin = text.find_first_not_of(sep);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (pos_begin == std::string::npos)
 | 
						if (pos_begin == std::string::npos)
 | 
				
			||||||
		pos_begin = text.size();
 | 
							pos_begin = text.size();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (long_strings && pos_begin != text.size() && text[pos_begin] == '"') {
 | 
				
			||||||
 | 
							string sep_string = sep;
 | 
				
			||||||
 | 
							for (size_t i = pos_begin+1; i < text.size(); i++)
 | 
				
			||||||
 | 
								if (text[i] == '"' && (i+1 == text.size() || sep_string.find(text[i+1]) != std::string::npos)) {
 | 
				
			||||||
 | 
									std::string token = text.substr(pos_begin, i-pos_begin+1);
 | 
				
			||||||
 | 
									text = text.substr(i+1);
 | 
				
			||||||
 | 
									return token;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	size_t pos_end = text.find_first_of(sep, pos_begin);
 | 
						size_t pos_end = text.find_first_of(sep, pos_begin);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (pos_end == std::string::npos)
 | 
						if (pos_end == std::string::npos)
 | 
				
			||||||
| 
						 | 
					@ -505,6 +515,14 @@ const char *create_prompt(RTLIL::Design *design, int recursion_counter)
 | 
				
			||||||
	return buffer;
 | 
						return buffer;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void rewrite_filename(std::string &filename)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (filename.substr(0, 1) == "\"" && filename.substr(GetSize(filename)-1) == "\"")
 | 
				
			||||||
 | 
							filename = filename.substr(1, GetSize(filename)-2);
 | 
				
			||||||
 | 
						if (filename.substr(0, 2) == "+/")
 | 
				
			||||||
 | 
							filename = proc_share_dirname() + filename.substr(2);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef YOSYS_ENABLE_TCL
 | 
					#ifdef YOSYS_ENABLE_TCL
 | 
				
			||||||
static int tcl_yosys_cmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[])
 | 
					static int tcl_yosys_cmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -204,7 +204,7 @@ void yosys_banner();
 | 
				
			||||||
std::string stringf(const char *fmt, ...) YS_ATTRIBUTE(format(printf, 1, 2));
 | 
					std::string stringf(const char *fmt, ...) YS_ATTRIBUTE(format(printf, 1, 2));
 | 
				
			||||||
std::string vstringf(const char *fmt, va_list ap);
 | 
					std::string vstringf(const char *fmt, va_list ap);
 | 
				
			||||||
int readsome(std::istream &f, char *s, int n);
 | 
					int readsome(std::istream &f, char *s, int n);
 | 
				
			||||||
std::string next_token(std::string &text, const char *sep = " \t\r\n");
 | 
					std::string next_token(std::string &text, const char *sep = " \t\r\n", bool long_strings = false);
 | 
				
			||||||
bool patmatch(const char *pattern, const char *string);
 | 
					bool patmatch(const char *pattern, const char *string);
 | 
				
			||||||
int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
 | 
					int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
 | 
				
			||||||
std::string make_temp_file(std::string template_str = "/tmp/yosys_XXXXXX");
 | 
					std::string make_temp_file(std::string template_str = "/tmp/yosys_XXXXXX");
 | 
				
			||||||
| 
						 | 
					@ -254,6 +254,7 @@ RTLIL::Design *yosys_get_design();
 | 
				
			||||||
std::string proc_self_dirname();
 | 
					std::string proc_self_dirname();
 | 
				
			||||||
std::string proc_share_dirname();
 | 
					std::string proc_share_dirname();
 | 
				
			||||||
const char *create_prompt(RTLIL::Design *design, int recursion_counter);
 | 
					const char *create_prompt(RTLIL::Design *design, int recursion_counter);
 | 
				
			||||||
 | 
					void rewrite_filename(std::string &filename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void run_pass(std::string command, RTLIL::Design *design = nullptr);
 | 
					void run_pass(std::string command, RTLIL::Design *design = nullptr);
 | 
				
			||||||
void run_frontend(std::string filename, std::string command, std::string *backend_command, std::string *from_to_label = nullptr, RTLIL::Design *design = nullptr);
 | 
					void run_frontend(std::string filename, std::string command, std::string *backend_command, std::string *from_to_label = nullptr, RTLIL::Design *design = nullptr);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,19 +32,14 @@ struct setunset_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	setunset_t(std::string unset_name) : name(RTLIL::escape_id(unset_name)), value(), unset(true) { }
 | 
						setunset_t(std::string unset_name) : name(RTLIL::escape_id(unset_name)), value(), unset(true) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	setunset_t(std::string set_name, std::vector<std::string> args, size_t &argidx) : name(RTLIL::escape_id(set_name)), value(), unset(false)
 | 
						setunset_t(std::string set_name, std::string set_value) : name(RTLIL::escape_id(set_name)), value(), unset(false)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (!args[argidx].empty() && args[argidx][0] == '"') {
 | 
							if (set_value.substr(0, 1) == "\"" && set_value.substr(GetSize(set_value)-1) == "\"") {
 | 
				
			||||||
			std::string str = args[argidx++].substr(1);
 | 
								value = RTLIL::Const(set_value.substr(1, GetSize(set_value)-2));
 | 
				
			||||||
			while (str.size() != 0 && str[str.size()-1] != '"' && argidx < args.size())
 | 
					 | 
				
			||||||
				str += args[argidx++];
 | 
					 | 
				
			||||||
			if (str.size() != 0 && str[str.size()-1] == '"')
 | 
					 | 
				
			||||||
				str = str.substr(0, str.size()-1);
 | 
					 | 
				
			||||||
			value = RTLIL::Const(str);
 | 
					 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			RTLIL::SigSpec sig_value;
 | 
								RTLIL::SigSpec sig_value;
 | 
				
			||||||
			if (!RTLIL::SigSpec::parse(sig_value, NULL, args[argidx++]))
 | 
								if (!RTLIL::SigSpec::parse(sig_value, NULL, set_value))
 | 
				
			||||||
				log_cmd_error("Can't decode value '%s'!\n", args[argidx-1].c_str());
 | 
									log_cmd_error("Can't decode value '%s'!\n", set_value.c_str());
 | 
				
			||||||
			value = sig_value.as_const();
 | 
								value = sig_value.as_const();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -84,9 +79,9 @@ struct SetattrPass : public Pass {
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			std::string arg = args[argidx];
 | 
								std::string arg = args[argidx];
 | 
				
			||||||
			if (arg == "-set" && argidx+2 < args.size()) {
 | 
								if (arg == "-set" && argidx+2 < args.size()) {
 | 
				
			||||||
				argidx += 2;
 | 
									string set_key = args[++argidx];
 | 
				
			||||||
				setunset_list.push_back(setunset_t(args[argidx-1], args, argidx));
 | 
									string set_val = args[++argidx];
 | 
				
			||||||
				argidx--;
 | 
									setunset_list.push_back(setunset_t(set_key, set_val));
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (arg == "-unset" && argidx+1 < args.size()) {
 | 
								if (arg == "-unset" && argidx+1 < args.size()) {
 | 
				
			||||||
| 
						 | 
					@ -154,9 +149,9 @@ struct SetparamPass : public Pass {
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			std::string arg = args[argidx];
 | 
								std::string arg = args[argidx];
 | 
				
			||||||
			if (arg == "-set" && argidx+2 < args.size()) {
 | 
								if (arg == "-set" && argidx+2 < args.size()) {
 | 
				
			||||||
				argidx += 2;
 | 
									string set_key = args[++argidx];
 | 
				
			||||||
				setunset_list.push_back(setunset_t(args[argidx-1], args, argidx));
 | 
									string set_val = args[++argidx];
 | 
				
			||||||
				argidx--;
 | 
									setunset_list.push_back(setunset_t(set_key, set_val));
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (arg == "-unset" && argidx+1 < args.size()) {
 | 
								if (arg == "-unset" && argidx+1 < args.size()) {
 | 
				
			||||||
| 
						 | 
					@ -209,10 +204,9 @@ struct ChparamPass : public Pass {
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			std::string arg = args[argidx];
 | 
								std::string arg = args[argidx];
 | 
				
			||||||
			if (arg == "-set" && argidx+2 < args.size()) {
 | 
								if (arg == "-set" && argidx+2 < args.size()) {
 | 
				
			||||||
				argidx += 2;
 | 
									string set_key = args[++argidx];
 | 
				
			||||||
				setunset_t new_param(args[argidx-1], args, argidx);
 | 
									string set_val = args[++argidx];
 | 
				
			||||||
				new_parameters[new_param.name] = new_param.value;
 | 
									setunset_list.push_back(setunset_t(set_key, set_val));
 | 
				
			||||||
				argidx--;
 | 
					 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (arg == "-list") {
 | 
								if (arg == "-list") {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -320,9 +320,7 @@ struct rules_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void parse(string filename)
 | 
						void parse(string filename)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (filename.substr(0, 2) == "+/")
 | 
							rewrite_filename(filename);
 | 
				
			||||||
			filename = proc_share_dirname() + filename.substr(1);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		infile.open(filename);
 | 
							infile.open(filename);
 | 
				
			||||||
		linecount = 0;
 | 
							linecount = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -607,6 +607,7 @@ struct ExtractPass : public Pass {
 | 
				
			||||||
				else
 | 
									else
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					std::ifstream f;
 | 
										std::ifstream f;
 | 
				
			||||||
 | 
										rewrite_filename(filename);
 | 
				
			||||||
					f.open(filename.c_str());
 | 
										f.open(filename.c_str());
 | 
				
			||||||
					if (f.fail()) {
 | 
										if (f.fail()) {
 | 
				
			||||||
						delete map;
 | 
											delete map;
 | 
				
			||||||
| 
						 | 
					@ -746,6 +747,7 @@ struct ExtractPass : public Pass {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			std::ofstream f;
 | 
								std::ofstream f;
 | 
				
			||||||
 | 
								rewrite_filename(mine_outfile);
 | 
				
			||||||
			f.open(mine_outfile.c_str(), std::ofstream::trunc);
 | 
								f.open(mine_outfile.c_str(), std::ofstream::trunc);
 | 
				
			||||||
			if (f.fail())
 | 
								if (f.fail())
 | 
				
			||||||
				log_error("Can't open output file `%s'.\n", mine_outfile.c_str());
 | 
									log_error("Can't open output file `%s'.\n", mine_outfile.c_str());
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -951,10 +951,7 @@ struct TechmapPass : public Pass {
 | 
				
			||||||
		size_t argidx;
 | 
							size_t argidx;
 | 
				
			||||||
		for (argidx = 1; argidx < args.size(); argidx++) {
 | 
							for (argidx = 1; argidx < args.size(); argidx++) {
 | 
				
			||||||
			if (args[argidx] == "-map" && argidx+1 < args.size()) {
 | 
								if (args[argidx] == "-map" && argidx+1 < args.size()) {
 | 
				
			||||||
				if (args[argidx+1].substr(0, 2) == "+/")
 | 
									map_files.push_back(args[++argidx]);
 | 
				
			||||||
					map_files.push_back(proc_share_dirname() + args[++argidx].substr(2));
 | 
					 | 
				
			||||||
				else
 | 
					 | 
				
			||||||
					map_files.push_back(args[++argidx]);
 | 
					 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (args[argidx] == "-max_iter" && argidx+1 < args.size()) {
 | 
								if (args[argidx] == "-max_iter" && argidx+1 < args.size()) {
 | 
				
			||||||
| 
						 | 
					@ -1005,6 +1002,7 @@ struct TechmapPass : public Pass {
 | 
				
			||||||
							map->add(mod->clone());
 | 
												map->add(mod->clone());
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					std::ifstream f;
 | 
										std::ifstream f;
 | 
				
			||||||
 | 
										rewrite_filename(fn);
 | 
				
			||||||
					f.open(fn.c_str());
 | 
										f.open(fn.c_str());
 | 
				
			||||||
					if (f.fail())
 | 
										if (f.fail())
 | 
				
			||||||
						log_cmd_error("Can't open map file `%s'\n", fn.c_str());
 | 
											log_cmd_error("Can't open map file `%s'\n", fn.c_str());
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue