From 93a70959f3f67ffcee8159b18a5f68904e32a074 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Wed, 4 Dec 2013 14:14:05 +0100 Subject: Replaced RTLIL::Const::str with generic decoder method --- backends/edif/edif.cc | 4 ++-- backends/ilang/ilang_backend.cc | 19 +++++++++++-------- backends/verilog/verilog_backend.cc | 19 +++++++++++-------- 3 files changed, 24 insertions(+), 18 deletions(-) (limited to 'backends') diff --git a/backends/edif/edif.cc b/backends/edif/edif.cc index 8843b394..1748ed81 100644 --- a/backends/edif/edif.cc +++ b/backends/edif/edif.cc @@ -280,8 +280,8 @@ struct EdifBackend : public Backend { fprintf(f, " (viewRef VIEW_NETLIST (cellRef %s%s))", EDIF_NAME(cell->type), lib_cell_ports.count(cell->type) > 0 ? " (libraryRef LIB)" : ""); for (auto &p : cell->parameters) - if (!p.second.str.empty()) - fprintf(f, "\n (property %s (string \"%s\"))", EDIF_NAME(p.first), p.second.str.c_str()); + if ((p.second.flags & RTLIL::CONST_FLAG_STRING) != 0) + fprintf(f, "\n (property %s (string \"%s\"))", EDIF_NAME(p.first), p.second.decode_string().c_str()); else if (p.second.bits.size() <= 32 && RTLIL::SigSpec(p.second).is_fully_def()) fprintf(f, "\n (property %s (integer %u))", EDIF_NAME(p.first), p.second.as_int()); else { diff --git a/backends/ilang/ilang_backend.cc b/backends/ilang/ilang_backend.cc index 46f411ce..a37c7330 100644 --- a/backends/ilang/ilang_backend.cc +++ b/backends/ilang/ilang_backend.cc @@ -36,7 +36,7 @@ void ILANG_BACKEND::dump_const(FILE *f, const RTLIL::Const &data, int width, int { if (width < 0) width = data.bits.size() - offset; - if (data.str.empty() || width != (int)data.bits.size()) { + if ((data.flags & RTLIL::CONST_FLAG_STRING) == 0 || width != (int)data.bits.size()) { if (width == 32 && autoint) { int32_t val = 0; for (int i = 0; i < width; i++) { @@ -66,17 +66,20 @@ void ILANG_BACKEND::dump_const(FILE *f, const RTLIL::Const &data, int width, int } } else { fprintf(f, "\""); - for (size_t i = 0; i < data.str.size(); i++) { - if (data.str[i] == '\n') + std::string str = data.decode_string(); + for (size_t i = 0; i < str.size(); i++) { + if (str[i] == '\n') fprintf(f, "\\n"); - else if (data.str[i] == '\t') + else if (str[i] == '\t') fprintf(f, "\\t"); - else if (data.str[i] < 32) - fprintf(f, "\\%03o", data.str[i]); - else if (data.str[i] == '"') + else if (str[i] < 32) + fprintf(f, "\\%03o", str[i]); + else if (str[i] == '"') fprintf(f, "\\\""); + else if (str[i] == '\\') + fprintf(f, "\\\\"); else - fputc(data.str[i], f); + fputc(str[i], f); } fprintf(f, "\""); } diff --git a/backends/verilog/verilog_backend.cc b/backends/verilog/verilog_backend.cc index 4edf0392..e62a7014 100644 --- a/backends/verilog/verilog_backend.cc +++ b/backends/verilog/verilog_backend.cc @@ -153,7 +153,7 @@ void dump_const(FILE *f, RTLIL::Const &data, int width = -1, int offset = 0, boo { if (width < 0) width = data.bits.size() - offset; - if (data.str.empty() || width != (int)data.bits.size()) { + if ((data.flags & RTLIL::CONST_FLAG_STRING) == 0 || width != (int)data.bits.size()) { if (width == 32 && !no_decimal) { int32_t val = 0; for (int i = offset+width-1; i >= offset; i--) { @@ -184,17 +184,20 @@ void dump_const(FILE *f, RTLIL::Const &data, int width = -1, int offset = 0, boo } } else { fprintf(f, "\""); - for (size_t i = 0; i < data.str.size(); i++) { - if (data.str[i] == '\n') + std::string str = data.decode_string(); + for (size_t i = 0; i < str.size(); i++) { + if (str[i] == '\n') fprintf(f, "\\n"); - else if (data.str[i] == '\t') + else if (str[i] == '\t') fprintf(f, "\\t"); - else if (data.str[i] < 32) - fprintf(f, "\\%03o", data.str[i]); - else if (data.str[i] == '"') + else if (str[i] < 32) + fprintf(f, "\\%03o", str[i]); + else if (str[i] == '"') fprintf(f, "\\\""); + else if (str[i] == '\\') + fprintf(f, "\\\\"); else - fputc(data.str[i], f); + fputc(str[i], f); } fprintf(f, "\""); } -- cgit v1.2.3