3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-10-10 09:48:06 +00:00
Commit graph

13 commits

Author SHA1 Message Date
Krystine Sherwin
d6f3ac60f1
io.cc: Support single quoted arguments
Single quoted strings have no escape character and are treated verbatim.
This is useful for minimizing the number of backslashes in (for example) `logger -expect` regexps (e.g. `"\\\""` -> `'\"'`).
`Yosys::quote()` will use single quotes by default, unless the string contains a single quote and then it will use `std::quoted()`.

Fix strange behaviour arrising from always using `std::quoted(result)`.  Because of the way the function interacts with streams, if there is only one quotation mark then the result would end at the first whitespace.
2025-09-24 17:24:40 +12:00
Krystine Sherwin
6328c808db
io.cc: Quoting fixes
Add other special characters to `needs_quote()` check.
Fix `"\" ` being treated as a complete quoted string because of the space after the `"` even though it's escaped.
2025-09-24 15:20:46 +12:00
Krystine Sherwin
0ab1d6d28c
Handle quoted arguments in passes
Use `std::quoted()` from `<iomanip>` to quote/unquote pass arguments.
In order to maintain handling of (unquoted) comments and semicolons this occurs when adding the token to the arg list, rather than in the tokenization itself.
Passes no longer receive tokenized-but-raw arguments and are instead pre-unquoted.
This will cause problems for some passes (e.g. `setparam`) which rely on arguments having quotation marks for disambiguation.
In order to maintain reproducibility with `echo on`, arguments which require quoting will automatically quote (arguments which were quoted but didn't need to be will not be quoted in the echo).
2025-09-24 14:20:12 +12:00
Robert O'Callahan
c7df6954b9 Remove .c_str() from stringf parameters 2025-09-01 23:34:42 +00:00
Robert O'Callahan
c41ba912d8 Support IdString parameters in stringf 2025-09-01 23:34:42 +00:00
Robert O'Callahan
6d62a1fff7 Fix vararg alignment 2025-08-15 05:43:53 +00:00
Robert O'Callahan
ffd52a0d8e Making stringf() use the format conversion specs as-is without widening them.
And make sure our fast-path for `%d` and `%u` narrows to `int` correctly.

Resolves #5260
2025-07-31 10:54:56 +00:00
Robert O'Callahan
6ee3cd8ffd Replace stringf() with a templated function which does compile-time format string checking.
Checking only happens at compile time if -std=c++20 (or greater) is enabled. Otherwise
the checking happens at run time.

This requires the format string to be a compile-time constant (when compiling with
C++20), so fix a few places where that isn't true.

The format string behavior is a bit more lenient than C printf. For %d/%u
you can pass any integer type and it will be converted and output without
truncating bits, i.e. any length specifier is ignored and the conversion is
always treated as 'll'. Any truncation needs to be done by casting the argument itself.
For %f/%g you can pass anything that converts to double, including integers.

Performance results with clang 19 -O3 on Linux:
```
hyperfine './yosys -dp "read_rtlil /usr/local/google/home/rocallahan/Downloads/jpeg.synth.il; dump"'
```
C++17 before: Time (mean ± σ):     101.3 ms ±   0.8 ms    [User: 85.6 ms, System: 15.6 ms]
C++17 after:  Time (mean ± σ):      98.4 ms ±   1.2 ms    [User: 82.1 ms, System: 16.1 ms]
C++20 before: Time (mean ± σ):     100.9 ms ±   1.1 ms    [User: 87.0 ms, System: 13.8 ms]
C++20 after:  Time (mean ± σ):      97.8 ms ±   1.4 ms    [User: 83.1 ms, System: 14.7 ms]

The generated code is reasonably efficient. E.g. with clang 19, `stringf()` with a format
with no %% escapes and no other parameters (a weirdly common case) often compiles to a fully
inlined `std::string` construction. In general the format string parsing is often (not always)
compiled away.
2025-07-29 05:29:33 +00:00
William D. Jones
7d4d544001 Strip trailing slashes when checking for directories on Windows. 2025-05-15 18:36:43 -04:00
Emil J. Tywoniak
b05c0c70af io: don't accept a directory when file expected 2025-05-09 22:33:30 +02:00
Emil J. Tywoniak
ceb7a923da io: smooth out non-POSIX function usage across platforms 2025-03-19 13:43:44 +01:00
Emil J. Tywoniak
813f909460 gzip: istream 2025-03-19 13:43:44 +01:00
Emil J. Tywoniak
4f3fdc8457 io: refactor string and file work into new unit 2025-03-19 13:43:42 +01:00