diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-11-18 07:54:30 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-11-18 07:55:23 +0100 |
commit | bc79e04df9302636045a507c466ed4995da0aadf (patch) | |
tree | 1368968f8e7573fcd0a5474612ca79d833d3834d /src/ghdl.cc | |
parent | 913308142d295231c69f73dcac8a2cb5dfc0728a (diff) | |
download | ghdl-yosys-plugin-bc79e04df9302636045a507c466ed4995da0aadf.tar.gz ghdl-yosys-plugin-bc79e04df9302636045a507c466ed4995da0aadf.tar.bz2 ghdl-yosys-plugin-bc79e04df9302636045a507c466ed4995da0aadf.zip |
Try to convert extended name to a name
Diffstat (limited to 'src/ghdl.cc')
-rw-r--r-- | src/ghdl.cc | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/ghdl.cc b/src/ghdl.cc index dcebf55..2ddab7d 100644 --- a/src/ghdl.cc +++ b/src/ghdl.cc @@ -31,6 +31,36 @@ USING_YOSYS_NAMESPACE using namespace GhdlSynth; +// Convert an Sname_User to a string. Deals with extended names +// Subroutine of to_str +static std::string user_to_str(Name_Id id) +{ + const char *s = get_cstr(id); + + if (s[0] != '\\') + return string(s); + + // Extended name + // Case it can be converted to a name without the + // escape sequence. + int len = 1; + while (1) { + char c = s[len]; + if (c == 0) + break; + if (c == '\\' && s[len + 1] == 0 && len > 2) + break; + if (!((c >= 'a' && c <= 'z') + || (c >= 'A' && c <= 'Z') + || (c >= '0' && c <= '9') + || (c == '_' || c == '.'))) + // Unexpected character, return the name as is. + return string(s); + len++; + } + return string(s + 1, len - 1); +} + // Convert an Sname to a string. static std::string to_str(Sname name) { @@ -45,7 +75,7 @@ static std::string to_str(Sname name) is_sys = true; // fallthrough case Sname_User: - res = '.' + string(get_cstr(get_sname_suffix(pfx))) + res; + res = '.' + user_to_str(get_sname_suffix(pfx)) + res; break; case Sname_Version: // Use '$' for versions. '%' is not supported by Xilinx ISE edif2ngc. |