Skip to content

Commit 458d922

Browse files
committed
Add Initial support for compact imports proposal. NFC.
So far this is binary-only. We can add the text format support as a followup I think. https://github.com/WebAssembly/compact-import-section
1 parent 37cf5df commit 458d922

11 files changed

Lines changed: 400 additions & 115 deletions

src/binaryen-c.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ BinaryenFeatures BinaryenFeatureCustomPageSizes(void) {
511511
BinaryenFeatures BinaryenFeatureWideArithmetic(void) {
512512
return static_cast<BinaryenFeatures>(FeatureSet::WideArithmetic);
513513
}
514+
BinaryenFeatures BinaryenFeatureCompactImports(void) {
515+
return static_cast<BinaryenFeatures>(FeatureSet::CompactImports);
516+
}
514517
BinaryenFeatures BinaryenFeatureAll(void) {
515518
return static_cast<BinaryenFeatures>(FeatureSet::All);
516519
}

src/binaryen-c.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ BINARYEN_API BinaryenFeatures BinaryenFeatureRelaxedAtomics(void);
247247
BINARYEN_API BinaryenFeatures BinaryenFeatureMultibyte(void);
248248
BINARYEN_API BinaryenFeatures BinaryenFeatureCustomPageSizes(void);
249249
BINARYEN_API BinaryenFeatures BinaryenFeatureWideArithmetic(void);
250+
BINARYEN_API BinaryenFeatures BinaryenFeatureCompactImports(void);
250251
BINARYEN_API BinaryenFeatures BinaryenFeatureAll(void);
251252

252253
// Modules

src/js/binaryen.js-post.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ function initializeConstants() {
195195
'RelaxedAtomics',
196196
'CustomPageSizes',
197197
'WideArithmetic',
198+
'CompactImports',
198199
'All'
199200
].forEach(name => {
200201
Module['Features'][name] = Module['_BinaryenFeature' + name]();

src/tools/tool-options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct ToolOptions : public Options {
113113
"acquire/release atomic memory operations")
114114
.addFeature(FeatureSet::CustomPageSizes, "custom page sizes")
115115
.addFeature(FeatureSet::WideArithmetic, "wide arithmetic")
116+
.addFeature(FeatureSet::CompactImports, "compact import section")
116117
.add("--enable-typed-function-references",
117118
"",
118119
"Deprecated compatibility flag",

src/wasm-binary.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ extern const char* RelaxedAtomicsFeature;
475475
extern const char* MultibyteFeature;
476476
extern const char* CustomPageSizesFeature;
477477
extern const char* WideArithmeticFeature;
478+
extern const char* CompactImportsFeature;
478479

479480
enum Subsection {
480481
NameModule = 0,
@@ -1671,6 +1672,12 @@ class WasmBinaryReader {
16711672
Address defaultIfNoMax);
16721673
void readImports();
16731674

1675+
void addImport(uint32_t kind, std::unique_ptr<Importable> importable);
1676+
std::unique_ptr<Importable>
1677+
readImportDetails(Name module, Name field, uint32_t kind);
1678+
std::unique_ptr<Importable> copyImportable(uint32_t kind,
1679+
Importable& details);
1680+
16741681
// The signatures of each function, including imported functions, given in the
16751682
// import and function sections. Store HeapTypes instead of Signatures because
16761683
// reconstructing the HeapTypes from the Signatures is expensive.

src/wasm-features.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ struct FeatureSet {
5959
CustomPageSizes = 1 << 23,
6060
Multibyte = 1 << 24,
6161
WideArithmetic = 1 << 25,
62+
CompactImports = 1 << 26,
6263
MVP = None,
6364
// Keep in sync with llvm default features:
6465
// https://github.com/llvm/llvm-project/blob/c7576cb89d6c95f03968076e902d3adfd1996577/clang/lib/Basic/Targets/WebAssembly.cpp#L150-L153
6566
Default = SignExt | MutableGlobals,
66-
All = (1 << 26) - 1,
67+
All = (1 << 27) - 1,
6768
};
6869

6970
static std::string toString(Feature f) {
@@ -120,6 +121,8 @@ struct FeatureSet {
120121
return "multibyte";
121122
case WideArithmetic:
122123
return "wide-arithmetic";
124+
case CompactImports:
125+
return "compact-imports";
123126
case MVP:
124127
case Default:
125128
case All:
@@ -184,6 +187,7 @@ struct FeatureSet {
184187
bool hasCustomPageSizes() const { return (features & CustomPageSizes) != 0; }
185188
bool hasMultibyte() const { return (features & Multibyte) != 0; }
186189
bool hasWideArithmetic() const { return (features & WideArithmetic) != 0; }
190+
bool hasCompactImports() const { return (features & CompactImports) != 0; }
187191
bool hasAll() const { return (features & All) != 0; }
188192

189193
void set(FeatureSet f, bool v = true) {
@@ -213,6 +217,7 @@ struct FeatureSet {
213217
void setRelaxedAtomics(bool v = true) { set(RelaxedAtomics, v); }
214218
void setMultibyte(bool v = true) { set(Multibyte, v); }
215219
void setWideArithmetic(bool v = true) { set(WideArithmetic, v); }
220+
void setCompactImports(bool v = true) { set(CompactImports, v); }
216221
void setMVP() { features = MVP; }
217222
void setAll() { features = All; }
218223

0 commit comments

Comments
 (0)