diff options
author | Thomas Lively <tlively@google.com> | 2024-04-15 14:02:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-15 14:02:24 -0700 |
commit | b1245577ba92b77a97e266cf4c7f7cd15e6e7f28 (patch) | |
tree | 333e17f651e6ed9d24fa13aa86f38fcc907541cf /src/support/string.h | |
parent | 8c834e8257b03ea87b639ddac9adefec64fcad00 (diff) | |
download | binaryen-b1245577ba92b77a97e266cf4c7f7cd15e6e7f28.tar.gz binaryen-b1245577ba92b77a97e266cf4c7f7cd15e6e7f28.tar.bz2 binaryen-b1245577ba92b77a97e266cf4c7f7cd15e6e7f28.zip |
[Strings] Add a string lowering pass using magic imports (#6497)
The latest idea for efficient string constants is to encode the constants in
the import names of their globals and implement fast paths in the engines for
materializing those constants at instantiation time without needing to parse
anything in JS. This strategy only works for valid strings (i.e. strings without
unpaired surrogates) because only valid strings can be used as import names in
the WebAssembly syntax.
Add a new configuration of the StringLowering pass that encodes valid string
contents in import names, falling back to the JSON custom section approach for
invalid strings.
To test this chang, update the printer to escape import and export names
properly and update the legacy parser to parse escapes in import and export
names properly. As a drive-by, remove the incorrect check in the parser that the
import module and base names are non-empty.
Diffstat (limited to 'src/support/string.h')
-rw-r--r-- | src/support/string.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/support/string.h b/src/support/string.h index be2c3c6a3..af120ab4e 100644 --- a/src/support/string.h +++ b/src/support/string.h @@ -94,6 +94,11 @@ bool convertWTF8ToWTF16(std::ostream& os, std::string_view str); // Returns `true` iff the input was valid WTF-16. bool convertWTF16ToWTF8(std::ostream& os, std::string_view str); +// Writes the UTF-8 encoding of the given UTF-16LE string to `os`, inserting a +// replacement character in place of any unpaired surrogate or incomplete code +// unit. Returns `true` if the input was valid UTF-16. +bool convertUTF16ToUTF8(std::ostream& os, std::string_view str); + } // namespace wasm::String #endif // wasm_support_string_h |