summaryrefslogtreecommitdiff
path: root/src/wasm-binary.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-07-06 08:48:12 -0700
committerGitHub <noreply@github.com>2022-07-06 08:48:12 -0700
commit876638f8fb5bfc8b264eddc6c0c0d54ed40d0095 (patch)
tree40138beab484617d5b3af474f8e1bd485ffc603e /src/wasm-binary.h
parentb69d3a8fa0d6d7588811ef92067a48eed576e03f (diff)
downloadbinaryen-876638f8fb5bfc8b264eddc6c0c0d54ed40d0095.tar.gz
binaryen-876638f8fb5bfc8b264eddc6c0c0d54ed40d0095.tar.bz2
binaryen-876638f8fb5bfc8b264eddc6c0c0d54ed40d0095.zip
[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.
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r--src/wasm-binary.h14
1 files changed, 13 insertions, 1 deletions
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<Name, MappedLocals> funcMappedLocals;
+ // Indexes in the string literal section of each StringConst in the wasm.
+ std::unordered_map<Name, Index> stringIndexes;
+
void prepare();
};
@@ -1534,6 +1541,10 @@ public:
std::vector<Export*> exportOrder;
void readExports();
+ // The strings in the strings section (which are referred to by StringConst).
+ std::vector<Name> 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);