Skip to content

Commit 258dc0b

Browse files
committed
Support std::string parameters to stringf().
1 parent 7d3547e commit 258dc0b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

backends/verilog/verilog_backend.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,10 +1395,10 @@ bool dump_cell_expr(std::ostream &f, std::string indent, RTLIL::Cell *cell)
13951395
int s_width = cell->getPort(ID::S).size();
13961396
std::string func_name = cellname(cell);
13971397

1398-
f << stringf("%s" "function [%d:0] %s;\n", indent.c_str(), width-1, func_name.c_str());
1399-
f << stringf("%s" " input [%d:0] a;\n", indent.c_str(), width-1);
1400-
f << stringf("%s" " input [%d:0] b;\n", indent.c_str(), s_width*width-1);
1401-
f << stringf("%s" " input [%d:0] s;\n", indent.c_str(), s_width-1);
1398+
f << stringf("%s" "function [%d:0] %s;\n", indent, width-1, func_name);
1399+
f << stringf("%s" " input [%d:0] a;\n", indent, width-1);
1400+
f << stringf("%s" " input [%d:0] b;\n", indent, s_width*width-1);
1401+
f << stringf("%s" " input [%d:0] s;\n", indent, s_width-1);
14021402

14031403
dump_attributes(f, indent + " ", cell->attributes);
14041404
if (noparallelcase)

kernel/io.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ constexpr void check_format(std::string_view fmt, int fmt_start, FoundFormatSpec
197197
*specs = found;
198198
break;
199199
case ConversionSpecifier::CHAR_PTR:
200-
if constexpr (!std::is_convertible_v<Arg, const char *>) {
200+
if constexpr (!std::is_convertible_v<Arg, const char *> &&
201+
!std::is_convertible_v<Arg, const std::string &>) {
201202
YOSYS_ABORT("Expected type convertible to char *");
202203
}
203204
*specs = found;
@@ -259,8 +260,17 @@ inline void format_emit_one(std::string &result, std::string_view fmt, const Fou
259260
format_emit_type<Arg, double>(result, spec, dynamic_ints, num_dynamic_ints, arg);
260261
return;
261262
case ConversionSpecifier::CHAR_PTR:
262-
format_emit_type<Arg, const char *>(result, spec, dynamic_ints, num_dynamic_ints, arg);
263-
return;
263+
if constexpr (std::is_convertible_v<Arg, const char *>) {
264+
format_emit_type<Arg, const char *>(result, spec, dynamic_ints, num_dynamic_ints, arg);
265+
return;
266+
}
267+
if constexpr (std::is_convertible_v<Arg, const std::string &>) {
268+
const std::string &s = arg;
269+
format_emit_type<const char *, const char *>(result, spec, dynamic_ints, num_dynamic_ints,
270+
s.c_str());
271+
return;
272+
}
273+
break;
264274
case ConversionSpecifier::VOID_PTR:
265275
format_emit_type<Arg, void *>(result, spec, dynamic_ints, num_dynamic_ints, arg);
266276
return;

0 commit comments

Comments
 (0)