Skip to content
Open
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
16 changes: 16 additions & 0 deletions src/parser/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ template<typename Ctx> MaybeResult<> typedef_(Ctx&);
template<typename Ctx> MaybeResult<> rectype(Ctx&);
template<typename Ctx> MaybeResult<typename Ctx::LocalsT> locals(Ctx&);
template<typename Ctx> MaybeResult<> import_(Ctx&);
template<typename Ctx> MaybeResult<> importItem(Ctx&, Name module);
template<typename Ctx> MaybeResult<> func(Ctx&);
template<typename Ctx> MaybeResult<> table(Ctx&);
template<typename Ctx> MaybeResult<> memory(Ctx&);
Expand Down Expand Up @@ -3308,7 +3309,12 @@ template<typename Ctx> MaybeResult<typename Ctx::LocalsT> locals(Ctx& ctx) {
return {};
}

template<typename Ctx> MaybeResult<> importItem(Ctx& ctx, Name name) {
return Ok{};
}

// import ::= '(' 'import' mod:name nm:name importdesc ')'
// '(' 'import' mod:name compactimportdesc ')'
// importdesc ::= '(' 'func' id? exacttypeuse ')'
// | '(' 'table' id? tabletype ')'
// | '(' 'memory' id? memtype ')'
Expand All @@ -3326,6 +3332,16 @@ template<typename Ctx> MaybeResult<> import_(Ctx& ctx) {
return ctx.in.err("expected import module name");
}

if (ctx.in.peekSExprStart("item"sv)) {
while (ctx.in.peekSExprStart("item"sv)) {
CHECK_ERR(importItem(ctx, *mod));
}
if (!ctx.in.takeRParen()) {
return ctx.in.err("expected end of import");
}
return Ok{};
}

auto nm = ctx.in.takeName();
if (!nm) {
return ctx.in.err("expected import name");
Expand Down
7 changes: 7 additions & 0 deletions src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ extern const char* BulkMemoryOptFeature;
extern const char* CallIndirectOverlongFeature;
extern const char* CustomDescriptorsFeature;
extern const char* RelaxedAtomicsFeature;
extern const char* CompactImportsFeature;

enum Subsection {
NameModule = 0,
Expand Down Expand Up @@ -1637,6 +1638,12 @@ class WasmBinaryReader {
Address defaultIfNoMax);
void readImports();

void addImport(uint32_t kind, std::unique_ptr<Importable> importable);
std::unique_ptr<Importable>
readImportDetails(Name module, Name field, uint32_t kind);
std::unique_ptr<Importable> copyImportable(uint32_t kind,
Importable& details);

// The signatures of each function, including imported functions, given in the
// import and function sections. Store HeapTypes instead of Signatures because
// reconstructing the HeapTypes from the Signatures is expensive.
Expand Down
6 changes: 5 additions & 1 deletion src/wasm-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ struct FeatureSet {
CallIndirectOverlong = 1 << 20,
CustomDescriptors = 1 << 21,
RelaxedAtomics = 1 << 22,
CompactImports = 1 << 23,
MVP = None,
// Keep in sync with llvm default features:
// https://github.com/llvm/llvm-project/blob/c7576cb89d6c95f03968076e902d3adfd1996577/clang/lib/Basic/Targets/WebAssembly.cpp#L150-L153
Default = SignExt | MutableGlobals,
All = (1 << 23) - 1,
All = (1 << 24) - 1,
};

static std::string toString(Feature f) {
Expand Down Expand Up @@ -111,6 +112,8 @@ struct FeatureSet {
return "custom-descriptors";
case RelaxedAtomics:
return "relaxed-atomics";
case CompactImports:
return "compact-imports";
case MVP:
case Default:
case All:
Expand Down Expand Up @@ -172,6 +175,7 @@ struct FeatureSet {
return (features & CustomDescriptors) != 0;
}
bool hasRelaxedAtomics() const { return (features & RelaxedAtomics) != 0; }
bool hasCompactImports() const { return (features & CompactImports) != 0; }
bool hasAll() const { return (features & All) != 0; }

void set(FeatureSet f, bool v = true) {
Expand Down
Loading
Loading