mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 13:29:12 +00:00 
			
		
		
		
	More intuitive handling of "cd .." for singleton modules
This commit is contained in:
		
							parent
							
								
									bbdf7d9c66
								
							
						
					
					
						commit
						d38a64b1cf
					
				
					 1 changed files with 38 additions and 2 deletions
				
			
		| 
						 | 
					@ -1482,20 +1482,56 @@ struct CdPass : public Pass {
 | 
				
			||||||
		log("\n");
 | 
							log("\n");
 | 
				
			||||||
		log("    cd ..\n");
 | 
							log("    cd ..\n");
 | 
				
			||||||
		log("\n");
 | 
							log("\n");
 | 
				
			||||||
 | 
							log("Remove trailing substrings that start with '.' in current module name until\n");
 | 
				
			||||||
 | 
							log("the name of a module in the current design is generated, then switch to that\n");
 | 
				
			||||||
 | 
							log("module. Otherwise clear the current selection.\n");
 | 
				
			||||||
 | 
							log("\n");
 | 
				
			||||||
 | 
							log("    cd\n");
 | 
				
			||||||
 | 
							log("\n");
 | 
				
			||||||
		log("This is just a shortcut for 'select -clear'.\n");
 | 
							log("This is just a shortcut for 'select -clear'.\n");
 | 
				
			||||||
		log("\n");
 | 
							log("\n");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
 | 
						virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (args.size() != 2)
 | 
							if (args.size() != 1 && args.size() != 2)
 | 
				
			||||||
			log_cmd_error("Invalid number of arguments.\n");
 | 
								log_cmd_error("Invalid number of arguments.\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (args[1] == "..") {
 | 
							if (args.size() == 1 || args[1] == "/") {
 | 
				
			||||||
			design->selection_stack.back() = RTLIL::Selection(true);
 | 
								design->selection_stack.back() = RTLIL::Selection(true);
 | 
				
			||||||
			design->selected_active_module = std::string();
 | 
								design->selected_active_module = std::string();
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (args[1] == "..")
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								string modname = design->selected_active_module;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								design->selection_stack.back() = RTLIL::Selection(true);
 | 
				
			||||||
 | 
								design->selected_active_module = std::string();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								while (1)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									size_t pos = modname.rfind('.');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (pos == string::npos)
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									modname = modname.substr(0, pos);
 | 
				
			||||||
 | 
									Module *mod = design->module(modname);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (mod == nullptr)
 | 
				
			||||||
 | 
										continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									design->selected_active_module = modname;
 | 
				
			||||||
 | 
									design->selection_stack.back() = RTLIL::Selection();
 | 
				
			||||||
 | 
									select_filter_active_mod(design, design->selection_stack.back());
 | 
				
			||||||
 | 
									design->selection_stack.back().optimize(design);
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		std::string modname = RTLIL::escape_id(args[1]);
 | 
							std::string modname = RTLIL::escape_id(args[1]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (design->modules_.count(modname) == 0 && !design->selected_active_module.empty()) {
 | 
							if (design->modules_.count(modname) == 0 && !design->selected_active_module.empty()) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue