summaryrefslogtreecommitdiff
path: root/src/wasm-interpreter.h
diff options
context:
space:
mode:
authorRoberto Lublinerman <rluble@gmail.com>2024-03-14 20:48:07 -0700
committerGitHub <noreply@github.com>2024-03-15 03:48:07 +0000
commitc166ca015860b337e9ce07a5e02cb707964056ba (patch)
tree235b8420f2c72d63b81d78e30af4dc5aeb7acbf4 /src/wasm-interpreter.h
parent419b65ce2cb145dc781a32a565bb75496b7ac668 (diff)
downloadbinaryen-c166ca015860b337e9ce07a5e02cb707964056ba.tar.gz
binaryen-c166ca015860b337e9ce07a5e02cb707964056ba.tar.bz2
binaryen-c166ca015860b337e9ce07a5e02cb707964056ba.zip
[Strings] Implement string.concat in the interpreter (#6403)
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r--src/wasm-interpreter.h31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 31039cf28..c35920802 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -1919,6 +1919,36 @@ public:
}
return Literal(int32_t(data->values.size()));
}
+ Flow visitStringConcat(StringConcat* curr) {
+ NOTE_ENTER("StringConcat");
+ Flow flow = visit(curr->left);
+ if (flow.breaking()) {
+ return flow;
+ }
+ auto left = flow.getSingleValue();
+ flow = visit(curr->right);
+ if (flow.breaking()) {
+ return flow;
+ }
+ auto right = flow.getSingleValue();
+ NOTE_EVAL2(left, right);
+ auto leftData = left.getGCData();
+ auto rightData = right.getGCData();
+ if (!leftData || !rightData) {
+ trap("null ref");
+ }
+
+ Literals contents;
+ contents.reserve(leftData->values.size() + rightData->values.size());
+ for (Literal l : leftData->values) {
+ contents.push_back(l);
+ }
+ for (Literal l : rightData->values) {
+ contents.push_back(l);
+ }
+
+ return makeGCData(contents, curr->type);
+ }
Flow visitStringEncode(StringEncode* curr) {
// For now we only support JS-style strings into arrays.
if (curr->op != StringEncodeWTF16Array) {
@@ -1956,7 +1986,6 @@ public:
return Literal(int32_t(refData->values.size()));
}
- Flow visitStringConcat(StringConcat* curr) { return Flow(NONCONSTANT_FLOW); }
Flow visitStringEq(StringEq* curr) {
NOTE_ENTER("StringEq");
Flow flow = visit(curr->left);