Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,36 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
}
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) {
Expand Down Expand Up @@ -1956,7 +1986,6 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {

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);
Expand Down
10 changes: 10 additions & 0 deletions test/lit/passes/precompute-strings.wast
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,15 @@
(string.const "ab")
)
)

;; CHECK: (func $concat (type $0) (result i32)
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
(func $concat (export "concat") (result i32)
(string.eq
(string.concat (string.const "a") (string.const "b"))
(string.const "ab")
)
)
)