summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp34
-rw-r--r--src/wasm/wasm-s-parser.cpp11
-rw-r--r--src/wasm/wasm-stack.cpp19
-rw-r--r--src/wasm/wasm.cpp17
-rw-r--r--src/wasm/wat-parser.cpp16
5 files changed, 97 insertions, 0 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index e61fd1e27..59276124e 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -3951,6 +3951,12 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
if (maybeVisitStringIterMove(curr, opcode)) {
break;
}
+ if (maybeVisitStringSliceWTF(curr, opcode)) {
+ break;
+ }
+ if (maybeVisitStringSliceIter(curr, opcode)) {
+ break;
+ }
if (opcode == BinaryConsts::RefIsFunc ||
opcode == BinaryConsts::RefIsData ||
opcode == BinaryConsts::RefIsI31) {
@@ -7329,6 +7335,34 @@ bool WasmBinaryBuilder::maybeVisitStringIterMove(Expression*& out,
return true;
}
+bool WasmBinaryBuilder::maybeVisitStringSliceWTF(Expression*& out,
+ uint32_t code) {
+ StringSliceWTFOp op;
+ if (code == BinaryConsts::StringViewWTF8Slice) {
+ op = StringSliceWTF8;
+ } else if (code == BinaryConsts::StringViewWTF16Slice) {
+ op = StringSliceWTF16;
+ } else {
+ return false;
+ }
+ auto* end = popNonVoidExpression();
+ auto* start = popNonVoidExpression();
+ auto* ref = popNonVoidExpression();
+ out = Builder(wasm).makeStringSliceWTF(op, ref, start, end);
+ return true;
+}
+
+bool WasmBinaryBuilder::maybeVisitStringSliceIter(Expression*& out,
+ uint32_t code) {
+ if (code != BinaryConsts::StringViewIterSlice) {
+ return false;
+ }
+ auto* num = popNonVoidExpression();
+ auto* ref = popNonVoidExpression();
+ out = Builder(wasm).makeStringSliceIter(ref, num);
+ return true;
+}
+
void WasmBinaryBuilder::visitRefAs(RefAs* curr, uint8_t code) {
BYN_TRACE("zz node: RefAs\n");
switch (code) {
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 905c77523..f3bafe3de 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -3024,6 +3024,17 @@ Expression* SExpressionWasmBuilder::makeStringIterMove(Element& s,
op, parseExpression(s[1]), parseExpression(s[2]));
}
+Expression* SExpressionWasmBuilder::makeStringSliceWTF(Element& s,
+ StringSliceWTFOp op) {
+ return Builder(wasm).makeStringSliceWTF(
+ op, parseExpression(s[1]), parseExpression(s[2]), parseExpression(s[3]));
+}
+
+Expression* SExpressionWasmBuilder::makeStringSliceIter(Element& s) {
+ return Builder(wasm).makeStringSliceIter(parseExpression(s[1]),
+ parseExpression(s[2]));
+}
+
// converts an s-expression string representing binary data into an output
// sequence of raw bytes this appends to data, which may already contain
// content.
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index 731f47568..3707848d1 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -2357,6 +2357,25 @@ void BinaryInstWriter::visitStringIterMove(StringIterMove* curr) {
}
}
+void BinaryInstWriter::visitStringSliceWTF(StringSliceWTF* curr) {
+ o << int8_t(BinaryConsts::GCPrefix);
+ switch (curr->op) {
+ case StringSliceWTF8:
+ o << U32LEB(BinaryConsts::StringViewWTF8Slice);
+ break;
+ case StringSliceWTF16:
+ o << U32LEB(BinaryConsts::StringViewWTF16Slice);
+ break;
+ default:
+ WASM_UNREACHABLE("invalid string.move*");
+ }
+}
+
+void BinaryInstWriter::visitStringSliceIter(StringSliceIter* curr) {
+ o << int8_t(BinaryConsts::GCPrefix)
+ << U32LEB(BinaryConsts::StringViewIterSlice);
+}
+
void BinaryInstWriter::emitScopeEnd(Expression* curr) {
assert(!breakStack.empty());
breakStack.pop_back();
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index c4a5f362a..0a3ca1929 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -1269,6 +1269,23 @@ void StringIterMove::finalize() {
}
}
+void StringSliceWTF::finalize() {
+ if (ref->type == Type::unreachable || start->type == Type::unreachable ||
+ end->type == Type::unreachable) {
+ type = Type::unreachable;
+ } else {
+ type = Type(HeapType::string, NonNullable);
+ }
+}
+
+void StringSliceIter::finalize() {
+ if (ref->type == Type::unreachable || num->type == Type::unreachable) {
+ type = Type::unreachable;
+ } else {
+ type = Type(HeapType::string, NonNullable);
+ }
+}
+
size_t Function::getNumParams() { return getParams().size(); }
size_t Function::getNumVars() { return vars.size(); }
diff --git a/src/wasm/wat-parser.cpp b/src/wasm/wat-parser.cpp
index 07503974d..e3a2ab588 100644
--- a/src/wasm/wat-parser.cpp
+++ b/src/wasm/wat-parser.cpp
@@ -1027,6 +1027,11 @@ Result<typename Ctx::InstrT> makeStringIterNext(Ctx&, ParseInput&);
template<typename Ctx>
Result<typename Ctx::InstrT>
makeStringIterMove(Ctx&, ParseInput&, StringIterMoveOp op);
+template<typename Ctx>
+Result<typename Ctx::InstrT>
+makeStringSliceWTF(Ctx&, ParseInput&, StringSliceWTFOp op);
+template<typename Ctx>
+Result<typename Ctx::InstrT> makeStringSliceIter(Ctx&, ParseInput&);
// Modules
template<typename Ctx>
@@ -1924,6 +1929,17 @@ makeStringIterMove(Ctx& ctx, ParseInput& in, StringIterMoveOp op) {
return in.err("unimplemented instruction");
}
+template<typename Ctx>
+Result<typename Ctx::InstrT>
+makeStringSliceWTF(Ctx& ctx, ParseInput& in, StringSliceWTFOp op) {
+ return in.err("unimplemented instruction");
+}
+
+template<typename Ctx>
+Result<typename Ctx::InstrT> makeStringSliceIter(Ctx& ctx, ParseInput& in) {
+ return in.err("unimplemented instruction");
+}
+
// =======
// Modules
// =======