Skip to content

Commit

Permalink
Merge branch 'main' into wasm-split-remove-unused
Browse files Browse the repository at this point in the history
  • Loading branch information
tlively committed Sep 16, 2024
2 parents 9dccd15 + 9292310 commit b73586a
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 337 deletions.
10 changes: 10 additions & 0 deletions src/parser/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ struct LexStrResult : LexResult {
// Allocate a string only if there are escape sequences, otherwise just use
// the original string_view.
std::optional<std::string> str;

std::string_view getStr() {
if (str) {
return *str;
}
return span;
}
};

struct LexStrCtx : LexCtx {
Expand Down Expand Up @@ -860,6 +867,9 @@ std::optional<LexIdResult> ident(std::string_view in) {
return {};
}
if (auto s = str(ctx.next())) {
if (!String::isUTF8(s->getStr())) {
return {};
}
ctx.isStr = true;
ctx.str = s->str;
ctx.take(*s);
Expand Down
7 changes: 5 additions & 2 deletions src/passes/StringLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ struct StringGathering : public Pass {
[[maybe_unused]] bool valid =
String::convertWTF16ToWTF8(wtf8, string.str);
assert(valid);
// TODO: Use wtf8.view() once we have C++20.
// Then escape it because identifiers must be valid UTF-8.
// TODO: Use wtf8.view() and escaped.view() once we have C++20.
std::stringstream escaped;
String::printEscaped(escaped, wtf8.str());
auto name = Names::getValidGlobalName(
*module, std::string("string.const_") + std::string(wtf8.str()));
*module, std::string("string.const_") + std::string(escaped.str()));
globalName = name;
newNames.insert(name);
auto* stringConst = builder.makeStringConst(string);
Expand Down
Loading

0 comments on commit b73586a

Please sign in to comment.