Skip to content

Commit fea11e9

Browse files
authored
[Strings] string.is_usv_sequence (#4783)
This implements it as a StringMeasure opcode. They do have the same number of operands, same trapping behavior, and same return type. They both get a string and do some inspection of it to return an i32. Perhaps the name could be StringInspect or something like that, rather than StringMeasure..? But I think for now this might be good enough, and the spec may change anyhow later.
1 parent 75d059a commit fea11e9

File tree

8 files changed

+33
-0
lines changed

8 files changed

+33
-0
lines changed

scripts/gen-s-parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@
619619
("string.const", "makeStringConst(s)"),
620620
("string.measure_wtf8", "makeStringMeasure(s, StringMeasureWTF8)"),
621621
("string.measure_wtf16", "makeStringMeasure(s, StringMeasureWTF16)"),
622+
("string.is_usv_sequence", "makeStringMeasure(s, StringMeasureIsUSV)"),
622623
("string.encode_wtf8", "makeStringEncode(s, StringEncodeWTF8)"),
623624
("string.encode_wtf16", "makeStringEncode(s, StringEncodeWTF16)"),
624625
("string.concat", "makeStringConcat(s)"),

src/gen-s-parser.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3159,6 +3159,9 @@ switch (op[0]) {
31593159
default: goto parse_error;
31603160
}
31613161
}
3162+
case 'i':
3163+
if (strcmp(op, "string.is_usv_sequence") == 0) { return makeStringMeasure(s, StringMeasureIsUSV); }
3164+
goto parse_error;
31623165
case 'm': {
31633166
switch (op[18]) {
31643167
case '1':

src/passes/Print.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,6 +2253,9 @@ struct PrintExpressionContents
22532253
case StringMeasureWTF16:
22542254
printMedium(o, "string.measure_wtf16");
22552255
break;
2256+
case StringMeasureIsUSV:
2257+
printMedium(o, "string.is_usv_sequence");
2258+
break;
22562259
default:
22572260
WASM_UNREACHABLE("invalid string.measure*");
22582261
}

src/wasm-binary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ enum ASTNodes {
11461146
StringEncodeWTF16 = 0x87,
11471147
StringConcat = 0x88,
11481148
StringEq = 0x89,
1149+
StringIsUSV = 0x8a,
11491150
};
11501151

11511152
enum MemoryAccess {

src/wasm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ enum StringMeasureOp {
594594
StringMeasureUTF8,
595595
StringMeasureWTF8,
596596
StringMeasureWTF16,
597+
StringMeasureIsUSV,
597598
};
598599

599600
enum StringEncodeOp {

src/wasm/wasm-binary.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7191,6 +7191,8 @@ bool WasmBinaryBuilder::maybeVisitStringMeasure(Expression*& out,
71917191
}
71927192
} else if (code == BinaryConsts::StringMeasureWTF16) {
71937193
op = StringMeasureWTF16;
7194+
} else if (code == BinaryConsts::StringIsUSV) {
7195+
op = StringMeasureIsUSV;
71947196
} else {
71957197
return false;
71967198
}

src/wasm/wasm-stack.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,6 +2276,9 @@ void BinaryInstWriter::visitStringMeasure(StringMeasure* curr) {
22762276
case StringMeasureWTF16:
22772277
o << U32LEB(BinaryConsts::StringMeasureWTF16);
22782278
break;
2279+
case StringMeasureIsUSV:
2280+
o << U32LEB(BinaryConsts::StringIsUSV);
2281+
break;
22792282
default:
22802283
WASM_UNREACHABLE("invalid string.new*");
22812284
}

test/lit/strings.wast

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,23 @@
225225
)
226226
)
227227
)
228+
229+
;; CHECK: (func $string.is_usv_sequence (param $ref stringref)
230+
;; CHECK-NEXT: (drop
231+
;; CHECK-NEXT: (i32.eqz
232+
;; CHECK-NEXT: (string.is_usv_sequence
233+
;; CHECK-NEXT: (local.get $ref)
234+
;; CHECK-NEXT: )
235+
;; CHECK-NEXT: )
236+
;; CHECK-NEXT: )
237+
;; CHECK-NEXT: )
238+
(func $string.is_usv_sequence (param $ref stringref)
239+
(drop
240+
(i32.eqz ;; validate the output is i32
241+
(string.is_usv_sequence
242+
(local.get $ref)
243+
)
244+
)
245+
)
246+
)
228247
)

0 commit comments

Comments
 (0)