@@ -118,6 +118,20 @@ constant_exprt convert_real_literal(const irep_idt &value)
118118 return result;
119119}
120120
121+ static constant_exprt unsized (constant_exprt expr)
122+ {
123+ expr.set (ID_C_verilog_unsized, true );
124+ return expr;
125+ }
126+
127+ static constant_exprt cond_unsized (constant_exprt expr, bool is_unsized)
128+ {
129+ if (is_unsized)
130+ return unsized (std::move (expr));
131+ else
132+ return expr;
133+ }
134+
121135constant_exprt convert_integral_literal (const irep_idt &value)
122136{
123137 // first, get rid of whitespace and underscores
@@ -135,19 +149,19 @@ constant_exprt convert_integral_literal(const irep_idt &value)
135149 // special case the "unbased unsized literals"
136150 if (rest == " '0" )
137151 {
138- return from_integer (0 , unsignedbv_typet{1 });
152+ return unsized ( from_integer (0 , unsignedbv_typet{1 }) );
139153 }
140154 else if (rest == " '1" )
141155 {
142- return from_integer (1 , unsignedbv_typet{1 });
156+ return unsized ( from_integer (1 , unsignedbv_typet{1 }) );
143157 }
144158 else if (rest == " 'x" || rest == " 'X" )
145159 {
146- return constant_exprt{" x" , verilog_unsignedbv_typet{1 }};
160+ return unsized ( constant_exprt{" x" , verilog_unsignedbv_typet{1 }}) ;
147161 }
148162 else if (rest == " 'z" || rest == " 'Z" )
149163 {
150- return constant_exprt{" z" , verilog_unsignedbv_typet{1 }};
164+ return unsized ( constant_exprt{" z" , verilog_unsignedbv_typet{1 }}) ;
151165 }
152166
153167 std::string::size_type pos = rest.find (' \' ' );
@@ -183,15 +197,17 @@ constant_exprt convert_integral_literal(const irep_idt &value)
183197 auto type = s_flag_given
184198 ? static_cast <typet>(verilog_signedbv_typet{final_bits})
185199 : verilog_unsignedbv_typet{final_bits};
186- return constant_exprt{std::string (final_bits, ' x' ), type};
200+ return cond_unsized (
201+ constant_exprt{std::string (final_bits, ' x' ), type}, !bits_given);
187202 }
188203 else if (rest == " dz" || rest == " dZ" )
189204 {
190205 std::size_t final_bits = bits_given ? bits : 32 ;
191206 auto type = s_flag_given
192207 ? static_cast <typet>(verilog_signedbv_typet{final_bits})
193208 : verilog_unsignedbv_typet{final_bits};
194- return constant_exprt{std::string (final_bits, ' z' ), type};
209+ return cond_unsized (
210+ constant_exprt{std::string (final_bits, ' z' ), type}, !bits_given);
195211 }
196212
197213 unsigned base = 10 ;
@@ -353,7 +369,7 @@ constant_exprt convert_integral_literal(const irep_idt &value)
353369 type = verilog_unsignedbv_typet (bits);
354370
355371 // stored as individual bits
356- return constant_exprt{fvalue, type};
372+ return cond_unsized ( constant_exprt{fvalue, type}, !bits_given) ;
357373 }
358374 else // two valued
359375 {
@@ -372,7 +388,8 @@ constant_exprt convert_integral_literal(const irep_idt &value)
372388 type = unsignedbv_typet (bits);
373389
374390 // stored as bvrep
375- return constant_exprt{integer2bvrep (int_value, bits), type};
391+ return cond_unsized (
392+ constant_exprt{integer2bvrep (int_value, bits), type}, !bits_given);
376393 }
377394 }
378395 else
@@ -395,7 +412,8 @@ constant_exprt convert_integral_literal(const irep_idt &value)
395412 else
396413 type = unsignedbv_typet (bits);
397414
398- return constant_exprt{integer2bvrep (int_value, bits), type};
415+ return cond_unsized (
416+ constant_exprt{integer2bvrep (int_value, bits), type}, !bits_given);
399417 }
400418
401419 UNREACHABLE;
0 commit comments