@@ -1797,8 +1797,54 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
17971797 }
17981798 WASM_UNREACHABLE (" unimplemented ref.as_*" );
17991799 }
1800- Flow visitStringNew (StringNew* curr) { WASM_UNREACHABLE (" unimp" ); }
1801- Flow visitStringConst (StringConst* curr) { WASM_UNREACHABLE (" unimp" ); }
1800+ Flow visitStringNew (StringNew* curr) {
1801+ Flow ptr = visit (curr->ptr );
1802+ if (ptr.breaking ()) {
1803+ return ptr;
1804+ }
1805+ switch (curr->op ) {
1806+ case StringNewWTF16Array: {
1807+ Flow start = visit (curr->start );
1808+ if (start.breaking ()) {
1809+ return start;
1810+ }
1811+ Flow end = visit (curr->end );
1812+ if (end.breaking ()) {
1813+ return end;
1814+ }
1815+ auto ptrData = ptr.getSingleValue ().getGCData ();
1816+ if (!ptrData) {
1817+ trap (" null ref" );
1818+ }
1819+ const auto & ptrDataValues = ptrData->values ;
1820+ size_t startVal = start.getSingleValue ().getUnsigned ();
1821+ size_t endVal = end.getSingleValue ().getUnsigned ();
1822+ if (endVal > ptrDataValues.size ()) {
1823+ trap (" array oob" );
1824+ }
1825+ Literals contents;
1826+ if (endVal > startVal) {
1827+ contents.reserve (endVal - startVal);
1828+ for (size_t i = startVal; i < endVal; i++) {
1829+ contents.push_back (ptrDataValues[i]);
1830+ }
1831+ }
1832+ auto heapType = curr->type .getHeapType ();
1833+ return Literal (std::make_shared<GCData>(heapType, contents), heapType);
1834+ }
1835+ default :
1836+ // TODO: others
1837+ return Flow (NONCONSTANT_FLOW);
1838+ }
1839+ }
1840+ Flow visitStringConst (StringConst* curr) {
1841+ Literals contents;
1842+ for (size_t i = 0 ; i < curr->string .size (); i++) {
1843+ contents.push_back (Literal (int32_t (curr->string [i])));
1844+ }
1845+ auto heapType = curr->type .getHeapType ();
1846+ return Literal (std::make_shared<GCData>(heapType, contents), heapType);
1847+ }
18021848 Flow visitStringMeasure (StringMeasure* curr) { WASM_UNREACHABLE (" unimp" ); }
18031849 Flow visitStringEncode (StringEncode* curr) { WASM_UNREACHABLE (" unimp" ); }
18041850 Flow visitStringConcat (StringConcat* curr) { WASM_UNREACHABLE (" unimp" ); }
@@ -2121,8 +2167,6 @@ class ConstantExpressionRunner : public ExpressionRunner<SubType> {
21212167 NOTE_ENTER (" Rethrow" );
21222168 return Flow (NONCONSTANT_FLOW);
21232169 }
2124- Flow visitStringNew (StringNew* curr) { return Flow (NONCONSTANT_FLOW); }
2125- Flow visitStringConst (StringConst* curr) { return Flow (NONCONSTANT_FLOW); }
21262170 Flow visitStringMeasure (StringMeasure* curr) {
21272171 return Flow (NONCONSTANT_FLOW);
21282172 }
0 commit comments