summaryrefslogtreecommitdiff
path: root/src/wasm-interpreter.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-03-14 16:32:00 -0700
committerGitHub <noreply@github.com>2024-03-14 16:32:00 -0700
commit419b65ce2cb145dc781a32a565bb75496b7ac668 (patch)
tree95b72b462b7d50b8a7e3dab2246a5584295a0318 /src/wasm-interpreter.h
parent17823cdc7f639e889b1be8e028492cd2cd835c43 (diff)
downloadbinaryen-419b65ce2cb145dc781a32a565bb75496b7ac668.tar.gz
binaryen-419b65ce2cb145dc781a32a565bb75496b7ac668.tar.bz2
binaryen-419b65ce2cb145dc781a32a565bb75496b7ac668.zip
[Strings] Implement string.encode_wtf16_array (#6402)
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r--src/wasm-interpreter.h38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 46e5c1752..31039cf28 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -1919,7 +1919,43 @@ public:
}
return Literal(int32_t(data->values.size()));
}
- Flow visitStringEncode(StringEncode* curr) { return Flow(NONCONSTANT_FLOW); }
+ Flow visitStringEncode(StringEncode* curr) {
+ // For now we only support JS-style strings into arrays.
+ if (curr->op != StringEncodeWTF16Array) {
+ return Flow(NONCONSTANT_FLOW);
+ }
+
+ Flow ref = visit(curr->ref);
+ if (ref.breaking()) {
+ return ref;
+ }
+ Flow ptr = visit(curr->ptr);
+ if (ptr.breaking()) {
+ return ptr;
+ }
+ Flow start = visit(curr->start);
+ if (start.breaking()) {
+ return start;
+ }
+
+ auto refData = ref.getSingleValue().getGCData();
+ auto ptrData = ptr.getSingleValue().getGCData();
+ if (!refData || !ptrData) {
+ trap("null ref");
+ }
+ auto startVal = start.getSingleValue().getInteger();
+ auto& refValues = refData->values;
+ auto& ptrValues = ptrData->values;
+ if (startVal + refValues.size() > ptrValues.size()) {
+ trap("oob");
+ }
+
+ for (Index i = 0; i < refValues.size(); i++) {
+ ptrValues[startVal + i] = refValues[i];
+ }
+
+ return Literal(int32_t(refData->values.size()));
+ }
Flow visitStringConcat(StringConcat* curr) { return Flow(NONCONSTANT_FLOW); }
Flow visitStringEq(StringEq* curr) {
NOTE_ENTER("StringEq");