From 876638f8fb5bfc8b264eddc6c0c0d54ed40d0095 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 6 Jul 2022 08:48:12 -0700 Subject: [Strings] Add string.const (#4768) This is more work than a typical instruction because it also adds a new section: all the (string.const "foo") strings are put in a new "strings" section in the binary, and the instructions refer to them by index. --- src/wasm-binary.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/wasm-binary.h') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index c7ac7e7b7..c88aa3895 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -326,7 +326,8 @@ enum Section { Code = 10, Data = 11, DataCount = 12, - Tag = 13 + Tag = 13, + Strings = 14, }; // A passive segment is a segment that will not be automatically copied into a @@ -1138,6 +1139,7 @@ enum ASTNodes { BrOnNonI31 = 0x65, StringNewWTF8 = 0x80, StringNewWTF16 = 0x81, + StringConst = 0x82, }; enum MemoryAccess { @@ -1280,6 +1282,7 @@ public: void writeFunctionSignatures(); void writeExpression(Expression* curr); void writeFunctions(); + void writeStrings(); void writeGlobals(); void writeExports(); void writeDataCount(); @@ -1291,6 +1294,7 @@ public: uint32_t getGlobalIndex(Name name) const; uint32_t getTagIndex(Name name) const; uint32_t getTypeIndex(HeapType type) const; + uint32_t getStringIndex(Name string) const; void writeTableDeclarations(); void writeElementSegments(); @@ -1381,6 +1385,9 @@ private: // info here, and then use it when writing the names. std::unordered_map funcMappedLocals; + // Indexes in the string literal section of each StringConst in the wasm. + std::unordered_map stringIndexes; + void prepare(); }; @@ -1534,6 +1541,10 @@ public: std::vector exportOrder; void readExports(); + // The strings in the strings section (which are referred to by StringConst). + std::vector strings; + void readStrings(); + Expression* readExpression(); void readGlobals(); @@ -1710,6 +1721,7 @@ public: bool maybeVisitArrayLen(Expression*& out, uint32_t code); bool maybeVisitArrayCopy(Expression*& out, uint32_t code); bool maybeVisitStringNew(Expression*& out, uint32_t code); + bool maybeVisitStringConst(Expression*& out, uint32_t code); void visitSelect(Select* curr, uint8_t code); void visitReturn(Return* curr); void visitMemorySize(MemorySize* curr); -- cgit v1.2.3