@@ -118,6 +118,20 @@ constant_exprt convert_real_literal(const irep_idt &value)
118
118
return result;
119
119
}
120
120
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
+
121
135
constant_exprt convert_integral_literal (const irep_idt &value)
122
136
{
123
137
// first, get rid of whitespace and underscores
@@ -135,19 +149,19 @@ constant_exprt convert_integral_literal(const irep_idt &value)
135
149
// special case the "unbased unsized literals"
136
150
if (rest == " '0" )
137
151
{
138
- return from_integer (0 , unsignedbv_typet{1 });
152
+ return unsized ( from_integer (0 , unsignedbv_typet{1 }) );
139
153
}
140
154
else if (rest == " '1" )
141
155
{
142
- return from_integer (1 , unsignedbv_typet{1 });
156
+ return unsized ( from_integer (1 , unsignedbv_typet{1 }) );
143
157
}
144
158
else if (rest == " 'x" || rest == " 'X" )
145
159
{
146
- return constant_exprt{" x" , verilog_unsignedbv_typet{1 }};
160
+ return unsized ( constant_exprt{" x" , verilog_unsignedbv_typet{1 }}) ;
147
161
}
148
162
else if (rest == " 'z" || rest == " 'Z" )
149
163
{
150
- return constant_exprt{" z" , verilog_unsignedbv_typet{1 }};
164
+ return unsized ( constant_exprt{" z" , verilog_unsignedbv_typet{1 }}) ;
151
165
}
152
166
153
167
std::string::size_type pos = rest.find (' \' ' );
@@ -183,15 +197,17 @@ constant_exprt convert_integral_literal(const irep_idt &value)
183
197
auto type = s_flag_given
184
198
? static_cast <typet>(verilog_signedbv_typet{final_bits})
185
199
: 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);
187
202
}
188
203
else if (rest == " dz" || rest == " dZ" )
189
204
{
190
205
std::size_t final_bits = bits_given ? bits : 32 ;
191
206
auto type = s_flag_given
192
207
? static_cast <typet>(verilog_signedbv_typet{final_bits})
193
208
: 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);
195
211
}
196
212
197
213
unsigned base = 10 ;
@@ -353,7 +369,7 @@ constant_exprt convert_integral_literal(const irep_idt &value)
353
369
type = verilog_unsignedbv_typet (bits);
354
370
355
371
// stored as individual bits
356
- return constant_exprt{fvalue, type};
372
+ return cond_unsized ( constant_exprt{fvalue, type}, !bits_given) ;
357
373
}
358
374
else // two valued
359
375
{
@@ -372,7 +388,8 @@ constant_exprt convert_integral_literal(const irep_idt &value)
372
388
type = unsignedbv_typet (bits);
373
389
374
390
// 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);
376
393
}
377
394
}
378
395
else
@@ -395,7 +412,8 @@ constant_exprt convert_integral_literal(const irep_idt &value)
395
412
else
396
413
type = unsignedbv_typet (bits);
397
414
398
- return constant_exprt{integer2bvrep (int_value, bits), type};
415
+ return cond_unsized (
416
+ constant_exprt{integer2bvrep (int_value, bits), type}, !bits_given);
399
417
}
400
418
401
419
UNREACHABLE;
0 commit comments