File tree Expand file tree Collapse file tree 3 files changed +61
-3
lines changed Expand file tree Collapse file tree 3 files changed +61
-3
lines changed Original file line number Diff line number Diff line change 24
24
25
25
#include < algorithm>
26
26
#include < cstdlib>
27
+ #include < iomanip>
27
28
#include < sstream>
28
29
29
30
/* ******************************************************************\
@@ -1208,6 +1209,54 @@ expr2verilogt::resultt expr2verilogt::convert_constant(
1208
1209
ieee_float.from_expr (tmp);
1209
1210
return {precedence, ieee_float.to_ansi_c_string ()};
1210
1211
}
1212
+ else if (type.id () == ID_string)
1213
+ {
1214
+ dest = ' "' ;
1215
+
1216
+ for (auto &ch : id2string (src.get_value ()))
1217
+ {
1218
+ // Follows Table Table 5-1 in 1800-2017.
1219
+ switch (ch)
1220
+ {
1221
+ case ' \n ' :
1222
+ dest += " \\ n" ;
1223
+ break ;
1224
+ case ' \t ' :
1225
+ dest += " \\ t" ;
1226
+ break ;
1227
+ case ' \\ ' :
1228
+ dest += " \\\\ " ;
1229
+ break ;
1230
+ case ' "' :
1231
+ dest += " \\\" " ;
1232
+ break ;
1233
+ case ' \v ' :
1234
+ dest += " \\ v" ;
1235
+ break ;
1236
+ case ' \f ' :
1237
+ dest += " \\ f" ;
1238
+ break ;
1239
+ case ' \a ' :
1240
+ dest += " \\ a" ;
1241
+ break ;
1242
+ default :
1243
+ if (
1244
+ (unsigned (ch) >= ' ' && unsigned (ch) <= 126 ) ||
1245
+ (unsigned (ch) >= 128 && unsigned (ch) <= 254 ))
1246
+ {
1247
+ dest += ch;
1248
+ }
1249
+ else
1250
+ {
1251
+ std::ostringstream oss;
1252
+ oss << " \\ x" << std::setw (2 ) << std::setfill (' 0' ) << std::hex << ch;
1253
+ dest += oss.str ();
1254
+ }
1255
+ }
1256
+ }
1257
+
1258
+ dest += ' "' ;
1259
+ }
1211
1260
else
1212
1261
return convert_norep (src, precedence);
1213
1262
Original file line number Diff line number Diff line change 15
15
#include < util/ieee_float.h>
16
16
17
17
#include " aval_bval_encoding.h"
18
+ #include " convert_literals.h"
18
19
#include " verilog_bits.h"
19
20
#include " verilog_expr.h"
20
21
@@ -167,12 +168,14 @@ exprt verilog_lowering(exprt expr)
167
168
168
169
if (expr.id () == ID_constant)
169
170
{
171
+ auto &constant_expr = to_constant_expr (expr);
172
+
170
173
if (
171
174
expr.type ().id () == ID_verilog_unsignedbv ||
172
175
expr.type ().id () == ID_verilog_signedbv)
173
176
{
174
177
// encode into aval/bval
175
- return lower_to_aval_bval (to_constant_expr (expr) );
178
+ return lower_to_aval_bval (constant_expr );
176
179
}
177
180
else if (
178
181
expr.type ().id () == ID_verilog_real ||
@@ -183,6 +186,12 @@ exprt verilog_lowering(exprt expr)
183
186
// no need to change value
184
187
expr.type () = lower_verilog_real_types (expr.type ());
185
188
}
189
+ else if (expr.type ().id () == ID_string)
190
+ {
191
+ auto result = convert_string_literal (constant_expr.get_value ());
192
+ result.add_source_location () = expr.source_location ();
193
+ expr = std::move (result);
194
+ }
186
195
187
196
return expr;
188
197
}
Original file line number Diff line number Diff line change @@ -1278,8 +1278,8 @@ exprt verilog_typecheck_exprt::convert_constant(constant_exprt expr)
1278
1278
if (expr.type ().id ()==ID_string)
1279
1279
{
1280
1280
auto result = convert_string_literal (expr.get_value ());
1281
- result. add_source_location () = source_location;
1282
- return std::move (result) ;
1281
+ // only add a typecast for now
1282
+ return typecast_exprt{ std::move (expr), std::move ( result. type ())} ;
1283
1283
}
1284
1284
else if (expr.type ().id ()==ID_unsignedbv ||
1285
1285
expr.type ().id ()==ID_signedbv ||
You can’t perform that action at this time.
0 commit comments