Skip to content

Commit bf1cdb8

Browse files
tlivelyradekdoulik
authored andcommitted
Remove support for legacy stringref text syntax (WebAssembly#6289)
Removing support for the legacy syntax will allow us to avoid implementing support for it in the new text parser.
1 parent 2154ddf commit bf1cdb8

File tree

2 files changed

+25
-274
lines changed

2 files changed

+25
-274
lines changed

src/wasm/wasm-s-parser.cpp

Lines changed: 16 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3253,55 +3253,28 @@ Expression* SExpressionWasmBuilder::makeRefAs(Element& s, RefAsOp op) {
32533253

32543254
Expression*
32553255
SExpressionWasmBuilder::makeStringNew(Element& s, StringNewOp op, bool try_) {
3256-
size_t i = 1;
32573256
Expression* length = nullptr;
32583257
if (op == StringNewWTF8) {
3259-
if (s[i]->isStr()) {
3260-
// legacy syntax
3261-
std::string_view str = s[i++]->str().str;
3262-
if (str == "utf8") {
3263-
op = StringNewUTF8;
3264-
} else if (str == "wtf8") {
3265-
op = StringNewWTF8;
3266-
} else if (str == "replace") {
3267-
op = StringNewLossyUTF8;
3268-
} else {
3269-
throw SParseException("bad string.new op", s);
3270-
}
3271-
}
3272-
length = parseExpression(s[i + 1]);
3273-
return Builder(wasm).makeStringNew(op, parseExpression(s[i]), length, try_);
3258+
length = parseExpression(s[2]);
3259+
return Builder(wasm).makeStringNew(op, parseExpression(s[1]), length, try_);
32743260
} else if (op == StringNewUTF8 || op == StringNewLossyUTF8 ||
32753261
op == StringNewWTF16) {
3276-
length = parseExpression(s[i + 1]);
3277-
return Builder(wasm).makeStringNew(op, parseExpression(s[i]), length, try_);
3262+
length = parseExpression(s[2]);
3263+
return Builder(wasm).makeStringNew(op, parseExpression(s[1]), length, try_);
32783264
} else if (op == StringNewWTF8Array) {
3279-
if (s[i]->isStr()) {
3280-
// legacy syntax
3281-
std::string_view str = s[i++]->str().str;
3282-
if (str == "utf8") {
3283-
op = StringNewUTF8Array;
3284-
} else if (str == "wtf8") {
3285-
op = StringNewWTF8Array;
3286-
} else if (str == "replace") {
3287-
op = StringNewLossyUTF8Array;
3288-
} else {
3289-
throw SParseException("bad string.new op", s);
3290-
}
3291-
}
3292-
auto* start = parseExpression(s[i + 1]);
3293-
auto* end = parseExpression(s[i + 2]);
3265+
auto* start = parseExpression(s[2]);
3266+
auto* end = parseExpression(s[3]);
32943267
return Builder(wasm).makeStringNew(
3295-
op, parseExpression(s[i]), start, end, try_);
3268+
op, parseExpression(s[1]), start, end, try_);
32963269
} else if (op == StringNewUTF8Array || op == StringNewLossyUTF8Array ||
32973270
op == StringNewWTF16Array) {
3298-
auto* start = parseExpression(s[i + 1]);
3299-
auto* end = parseExpression(s[i + 2]);
3271+
auto* start = parseExpression(s[2]);
3272+
auto* end = parseExpression(s[3]);
33003273
return Builder(wasm).makeStringNew(
3301-
op, parseExpression(s[i]), start, end, try_);
3274+
op, parseExpression(s[1]), start, end, try_);
33023275
} else if (op == StringNewFromCodePoint) {
33033276
return Builder(wasm).makeStringNew(
3304-
op, parseExpression(s[i]), nullptr, try_);
3277+
op, parseExpression(s[1]), nullptr, try_);
33053278
} else {
33063279
throw SParseException("bad string.new op", s);
33073280
}
@@ -3316,60 +3289,18 @@ Expression* SExpressionWasmBuilder::makeStringConst(Element& s) {
33163289

33173290
Expression* SExpressionWasmBuilder::makeStringMeasure(Element& s,
33183291
StringMeasureOp op) {
3319-
size_t i = 1;
3320-
if (op == StringMeasureWTF8 && s[i]->isStr()) {
3321-
// legacy syntax
3322-
std::string_view str = s[i++]->str().str;
3323-
if (str == "utf8") {
3324-
op = StringMeasureUTF8;
3325-
} else if (str == "wtf8") {
3326-
op = StringMeasureWTF8;
3327-
} else {
3328-
throw SParseException("bad string.measure op", s);
3329-
}
3330-
}
3331-
return Builder(wasm).makeStringMeasure(op, parseExpression(s[i]));
3292+
return Builder(wasm).makeStringMeasure(op, parseExpression(s[1]));
33323293
}
33333294

33343295
Expression* SExpressionWasmBuilder::makeStringEncode(Element& s,
33353296
StringEncodeOp op) {
3336-
size_t i = 1;
33373297
Expression* start = nullptr;
3338-
if (op == StringEncodeWTF8) {
3339-
if (s[i]->isStr()) {
3340-
// legacy syntax
3341-
std::string_view str = s[i++]->str().str;
3342-
if (str == "utf8") {
3343-
op = StringEncodeUTF8;
3344-
} else if (str == "replace") {
3345-
op = StringEncodeLossyUTF8;
3346-
} else if (str == "wtf8") {
3347-
op = StringEncodeWTF8;
3348-
} else {
3349-
throw SParseException("bad string.new op", s);
3350-
}
3351-
}
3352-
} else if (op == StringEncodeWTF8Array) {
3353-
if (s[i]->isStr()) {
3354-
// legacy syntax
3355-
std::string_view str = s[i++]->str().str;
3356-
if (str == "utf8") {
3357-
op = StringEncodeUTF8Array;
3358-
} else if (str == "replace") {
3359-
op = StringEncodeLossyUTF8Array;
3360-
} else if (str == "wtf8") {
3361-
op = StringEncodeWTF8Array;
3362-
} else {
3363-
throw SParseException("bad string.new op", s);
3364-
}
3365-
}
3366-
start = parseExpression(s[i + 2]);
3367-
} else if (op == StringEncodeUTF8Array || op == StringEncodeLossyUTF8Array ||
3368-
op == StringEncodeWTF16Array) {
3369-
start = parseExpression(s[i + 2]);
3298+
if (op == StringEncodeWTF8Array || op == StringEncodeUTF8Array ||
3299+
op == StringEncodeLossyUTF8Array || op == StringEncodeWTF16Array) {
3300+
start = parseExpression(s[3]);
33703301
}
33713302
return Builder(wasm).makeStringEncode(
3372-
op, parseExpression(s[i]), parseExpression(s[i + 1]), start);
3303+
op, parseExpression(s[1]), parseExpression(s[2]), start);
33733304
}
33743305

33753306
Expression* SExpressionWasmBuilder::makeStringConcat(Element& s) {

0 commit comments

Comments
 (0)