Xyce/ADMS: Display system task formatting solution

15 views
Skip to first unread message

Neal Wood

unread,
Sep 13, 2022, 1:05:53 PM9/13/22
to xyce-users
Hi Xyce Team.

Xyce/ADMS currently doesn't apply display system task formatting. For example in N_DEV_ADMSbsim6.C we see lines like

UserInfo(*this) << "Warning: VSAT(%f) = %e is less than 100, setting it to 100." << " " << DevTemp << " " << VSAT_t << " " << std::endl;

which is not what we want. One way to improve things would be to something like the following.

template<typename ... Args>
std::string string_format(const std::string &fmt, Args ... args)
{
    int tmp = std::snprintf(nullptr, 0, fmt.c_str(), args ...) + 1;
    auto len = static_cast<size_t>(tmp);
    std::unique_ptr<char[]> buf(new char[len]);
    std::snprintf(buf.get(), len, fmt.c_str(), args ...);
    return std::string(buf.get(), buf.get() + len - 1);
}
UserInfo(*this) << string_format("Warning: VSAT(%f) = %e is less than 100, setting it to 100.", DevTemp, VSAT_t) << std::endl;


There are some differences between the printf-like and Verilog-AMS format strings though, so this isn't a complete solution; however, it should be straight forward to sanitise the format string at the top of the string_format function to account for the discrepancies. To help demonstrate these limitations I put together a test programme; see attached for code and below for output (gcc version 10.4.0).

The newline character: (
)
The tab character: (    )
The backslash character: (\)
An octal digit: (X)
The percent character: (%)
Display in hexadecimal format: (%H) <--- FIXME: %h => %x, %H => %X
Display in decimal format: (88 88)
Display in octal format: (130 130)
Display in binary format: (b B) <--- FIXME
Display in ASCII character format: (X X)
Display library binding information: (%L) <--- FIXME
Display hierarchical name: (m M) <--- FIXME
Display as a string: (X ) <--- FIXME: %S => %s
Display 'real' in an exponential format: (8.800000e+01 8.800000E+01)
Display 'real' in an decimal format: (88.000000 88.000000)
Display 'real' in exponential or decimal format: (88 88)
Display 'real' in engineering notation: (r R) <--- FIXME


Inside Xyce/ADMS all that would be required is to have the string_format function defined somewhere and to change

<admst:for-each select="function/arguments">
<admst:text format=" &lt;&lt; %(printTerm(.)) &lt;&lt; &quot; &quot;"/>
</admst:for-each>


to something like

<admst:text format=" &lt;&lt; string_format(...)"/>

were ... is the comma separated argument list as found in the Verilog-A statement.

Thanks in advance for your thoughts.

Neal
string_format_test.cpp
Reply all
Reply to author
Forward
0 new messages