mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	Merge pull request #2469 from whitequark/cxxrtl-no-clk
cxxrtl: fix crashes caused by a floating or constant clock input
This commit is contained in:
		
						commit
						3cb109f54b
					
				
					 1 changed files with 14 additions and 6 deletions
				
			
		| 
						 | 
					@ -1036,8 +1036,12 @@ struct CxxrtlWorker {
 | 
				
			||||||
				// Edge-sensitive logic
 | 
									// Edge-sensitive logic
 | 
				
			||||||
				RTLIL::SigBit clk_bit = cell->getPort(ID::CLK)[0];
 | 
									RTLIL::SigBit clk_bit = cell->getPort(ID::CLK)[0];
 | 
				
			||||||
				clk_bit = sigmaps[clk_bit.wire->module](clk_bit);
 | 
									clk_bit = sigmaps[clk_bit.wire->module](clk_bit);
 | 
				
			||||||
 | 
									if (clk_bit.wire) {
 | 
				
			||||||
					f << indent << "if (" << (cell->getParam(ID::CLK_POLARITY).as_bool() ? "posedge_" : "negedge_")
 | 
										f << indent << "if (" << (cell->getParam(ID::CLK_POLARITY).as_bool() ? "posedge_" : "negedge_")
 | 
				
			||||||
					            << mangle(clk_bit) << ") {\n";
 | 
										            << mangle(clk_bit) << ") {\n";
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										f << indent << "if (false) {\n";
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
				inc_indent();
 | 
									inc_indent();
 | 
				
			||||||
					if (cell->hasPort(ID::EN)) {
 | 
										if (cell->hasPort(ID::EN)) {
 | 
				
			||||||
						f << indent << "if (";
 | 
											f << indent << "if (";
 | 
				
			||||||
| 
						 | 
					@ -1130,8 +1134,12 @@ struct CxxrtlWorker {
 | 
				
			||||||
			if (cell->getParam(ID::CLK_ENABLE).as_bool()) {
 | 
								if (cell->getParam(ID::CLK_ENABLE).as_bool()) {
 | 
				
			||||||
				RTLIL::SigBit clk_bit = cell->getPort(ID::CLK)[0];
 | 
									RTLIL::SigBit clk_bit = cell->getPort(ID::CLK)[0];
 | 
				
			||||||
				clk_bit = sigmaps[clk_bit.wire->module](clk_bit);
 | 
									clk_bit = sigmaps[clk_bit.wire->module](clk_bit);
 | 
				
			||||||
 | 
									if (clk_bit.wire) {
 | 
				
			||||||
					f << indent << "if (" << (cell->getParam(ID::CLK_POLARITY).as_bool() ? "posedge_" : "negedge_")
 | 
										f << indent << "if (" << (cell->getParam(ID::CLK_POLARITY).as_bool() ? "posedge_" : "negedge_")
 | 
				
			||||||
					            << mangle(clk_bit) << ") {\n";
 | 
										            << mangle(clk_bit) << ") {\n";
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										f << indent << "if (false) {\n";
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
				inc_indent();
 | 
									inc_indent();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			RTLIL::Memory *memory = cell->module->memories[cell->getParam(ID::MEMID).decode_string()];
 | 
								RTLIL::Memory *memory = cell->module->memories[cell->getParam(ID::MEMID).decode_string()];
 | 
				
			||||||
| 
						 | 
					@ -2145,14 +2153,14 @@ struct CxxrtlWorker {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// Various DFF cells are treated like posedge/negedge processes, see above for details.
 | 
									// Various DFF cells are treated like posedge/negedge processes, see above for details.
 | 
				
			||||||
				if (cell->type.in(ID($dff), ID($dffe), ID($adff), ID($adffe), ID($dffsr), ID($dffsre), ID($sdff), ID($sdffe), ID($sdffce))) {
 | 
									if (cell->type.in(ID($dff), ID($dffe), ID($adff), ID($adffe), ID($dffsr), ID($dffsre), ID($sdff), ID($sdffe), ID($sdffce))) {
 | 
				
			||||||
					if (cell->getPort(ID::CLK).is_wire())
 | 
										if (sigmap(cell->getPort(ID::CLK)).is_wire())
 | 
				
			||||||
						register_edge_signal(sigmap, cell->getPort(ID::CLK),
 | 
											register_edge_signal(sigmap, cell->getPort(ID::CLK),
 | 
				
			||||||
							cell->parameters[ID::CLK_POLARITY].as_bool() ? RTLIL::STp : RTLIL::STn);
 | 
												cell->parameters[ID::CLK_POLARITY].as_bool() ? RTLIL::STp : RTLIL::STn);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				// Similar for memory port cells.
 | 
									// Similar for memory port cells.
 | 
				
			||||||
				if (cell->type.in(ID($memrd), ID($memwr))) {
 | 
									if (cell->type.in(ID($memrd), ID($memwr))) {
 | 
				
			||||||
					if (cell->getParam(ID::CLK_ENABLE).as_bool()) {
 | 
										if (cell->getParam(ID::CLK_ENABLE).as_bool()) {
 | 
				
			||||||
						if (cell->getPort(ID::CLK).is_wire())
 | 
											if (sigmap(cell->getPort(ID::CLK)).is_wire())
 | 
				
			||||||
							register_edge_signal(sigmap, cell->getPort(ID::CLK),
 | 
												register_edge_signal(sigmap, cell->getPort(ID::CLK),
 | 
				
			||||||
								cell->parameters[ID::CLK_POLARITY].as_bool() ? RTLIL::STp : RTLIL::STn);
 | 
													cell->parameters[ID::CLK_POLARITY].as_bool() ? RTLIL::STp : RTLIL::STn);
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue