Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions src/parser/contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -2448,9 +2448,21 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> {
StringNewOp op,
bool try_,
Name* mem) {
auto m = getMemory(pos, mem);
CHECK_ERR(m);
return withLoc(pos, irBuilder.makeStringNew(op, try_, *m));
Name memName;
switch (op) {
case StringNewUTF8:
case StringNewWTF8:
case StringNewLossyUTF8:
case StringNewWTF16: {
auto m = getMemory(pos, mem);
CHECK_ERR(m);
memName = *m;
break;
}
default:
break;
}
return withLoc(pos, irBuilder.makeStringNew(op, try_, memName));
}

Result<> makeStringConst(Index pos,
Expand All @@ -2469,9 +2481,21 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> {
const std::vector<Annotation>& annotations,
StringEncodeOp op,
Name* mem) {
auto m = getMemory(pos, mem);
CHECK_ERR(m);
return withLoc(pos, irBuilder.makeStringEncode(op, *m));
Name memName;
switch (op) {
case StringEncodeUTF8:
case StringEncodeLossyUTF8:
case StringEncodeWTF8:
case StringEncodeWTF16: {
auto m = getMemory(pos, mem);
CHECK_ERR(m);
memName = *m;
break;
}
default:
break;
}
return withLoc(pos, irBuilder.makeStringEncode(op, memName));
}

Result<> makeStringConcat(Index pos,
Expand Down
30 changes: 24 additions & 6 deletions src/parser/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2330,9 +2330,18 @@ Result<> makeStringNew(Ctx& ctx,
const std::vector<Annotation>& annotations,
StringNewOp op,
bool try_) {
auto mem = maybeMemidx(ctx);
CHECK_ERR(mem);
return ctx.makeStringNew(pos, annotations, op, try_, mem.getPtr());
switch (op) {
case StringNewUTF8:
case StringNewWTF8:
case StringNewLossyUTF8:
case StringNewWTF16: {
auto mem = maybeMemidx(ctx);
CHECK_ERR(mem);
return ctx.makeStringNew(pos, annotations, op, try_, mem.getPtr());
}
default:
return ctx.makeStringNew(pos, annotations, op, try_, nullptr);
}
}

template<typename Ctx>
Expand All @@ -2359,9 +2368,18 @@ Result<> makeStringEncode(Ctx& ctx,
Index pos,
const std::vector<Annotation>& annotations,
StringEncodeOp op) {
auto mem = maybeMemidx(ctx);
CHECK_ERR(mem);
return ctx.makeStringEncode(pos, annotations, op, mem.getPtr());
switch (op) {
case StringEncodeUTF8:
case StringEncodeLossyUTF8:
case StringEncodeWTF8:
case StringEncodeWTF16: {
auto mem = maybeMemidx(ctx);
CHECK_ERR(mem);
return ctx.makeStringEncode(pos, annotations, op, mem.getPtr());
}
default:
return ctx.makeStringEncode(pos, annotations, op, nullptr);
}
}

template<typename Ctx>
Expand Down
1 change: 1 addition & 0 deletions test/lit/passes/string-lowering-instructions.wast
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: foreach %s %t wasm-opt --string-lowering -all -S -o - | filecheck %s
;; RUN: foreach %s %t wasm-opt --new-wat-parser --string-lowering -all -S -o - | filecheck %s

(module
(rec
Expand Down