@@ -32,12 +32,12 @@ struct LibertyStubber {
3232 void liberty_prefix (std::ostream& f)
3333 {
3434 f << " /*\n " ;
35- f << stringf (" Models interfaces of select Yosys internal cell.\n " );
36- f << stringf (" Likely contains INCORRECT POLARITIES.\n " );
37- f << stringf (" Impractical for any simulation, synthesis, or timing.\n " );
38- f << stringf (" Intended purely for SDC expansion.\n " );
39- f << stringf (" Do not microwave or tumble dry.\n " );
40- f << stringf (" Generated by %s\n " , yosys_maybe_version ());
35+ f << stringf (" \t Models interfaces of select Yosys internal cell.\n " );
36+ f << stringf (" \t Likely contains INCORRECT POLARITIES.\n " );
37+ f << stringf (" \t Impractical for any simulation, synthesis, or timing.\n " );
38+ f << stringf (" \t Intended purely for SDC expansion.\n " );
39+ f << stringf (" \t Do not microwave or tumble dry.\n " );
40+ f << stringf (" \t Generated by %s\n " , yosys_maybe_version ());
4141 f << " */\n " ;
4242 f << " library (yosys) {\n " ;
4343 f << " \t input_threshold_pct_fall : 50;\n " ;
@@ -82,7 +82,13 @@ struct LibertyStubber {
8282 f << " \t cell (\" " << derived_name << " \" ) {\n " ;
8383 auto & base_type = ct.cell_types [base_name];
8484 i.indent = 3 ;
85- for (auto x : derived->ports ) {
85+ auto sorted_ports = derived->ports ;
86+ // Hack for CLK and C coming before Q does
87+ auto cmp = [](IdString l, IdString r) { return l.str () < r.str (); };
88+ std::sort (sorted_ports.begin (), sorted_ports.end (), cmp);
89+ std::string clock_pin_name = " " ;
90+ for (auto x : sorted_ports) {
91+ std::string port_name = RTLIL::unescape_id (x);
8692 bool is_input = base_type.inputs .count (x);
8793 bool is_output = base_type.outputs .count (x);
8894 f << " \t\t pin (" << RTLIL::unescape_id (x.str ()) << " ) {\n " ;
@@ -93,10 +99,19 @@ struct LibertyStubber {
9399 } else {
94100 i.item (" direction" , " inout" );
95101 }
96- if (RTLIL::unescape_id (x) == " CLK" || RTLIL::unescape_id (x) == " C" )
102+ if (port_name == " CLK" || port_name == " C" ) {
97103 i.item (" clock" , " true" );
98- if (RTLIL::unescape_id (x) == " Q" )
104+ clock_pin_name = port_name;
105+ }
106+ if (port_name == " Q" ) {
99107 i.item (" function" , " IQ" );
108+ f << " \t\t\t timing () {\n " ;
109+ i.indent ++;
110+ log_assert (clock_pin_name.size ());
111+ i.item (" related_pin" , clock_pin_name);
112+ i.indent --;
113+ f << " \t\t\t }\n " ;
114+ }
100115 f << " \t\t }\n " ;
101116 }
102117
0 commit comments