Skip to content

Commit

Permalink
Support TargetFeatures section
Browse files Browse the repository at this point in the history
Currently all features are accepted, we could add filters later.

Signed-off-by: Zoltan Herczeg [email protected]
  • Loading branch information
zherczeg committed Nov 21, 2024
1 parent bce14b0 commit 661428c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/parser/WASMParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,13 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate {

virtual void EndModule() override {}

virtual void OnFeatureCount(Index count) override {}

virtual bool OnFeature(uint8_t prefix, std::string name) override
{
return true;
}

virtual void OnTypeCount(Index count) override
{
// TODO reserve vector if possible
Expand Down
4 changes: 4 additions & 0 deletions third_party/wabt/include/wabt/walrus/binary-reader-walrus.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class WASMBinaryReaderDelegate {
virtual void BeginModule(uint32_t version) = 0;
virtual void EndModule() = 0;

virtual void OnFeatureCount(Index count) = 0;
// Returns false, if the feature is not supported.
virtual bool OnFeature(uint8_t prefix, std::string name) = 0;

virtual void OnTypeCount(Index count) = 0;
virtual void OnFuncType(Index index, Index paramCount, Type *paramTypes, Index resultCount, Type *resultTypes) = 0;

Expand Down
7 changes: 2 additions & 5 deletions third_party/wabt/src/walrus/binary-reader-walrus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1259,19 +1259,16 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate {

/* target_features section */
Result BeginTargetFeaturesSection(Offset size) override {
abort();
return Result::Ok;
}
Result OnFeatureCount(Index count) override {
abort();
m_externalDelegate->OnFeatureCount(count);
return Result::Ok;
}
Result OnFeature(uint8_t prefix, nonstd::string_view name) override {
abort();
return Result::Ok;
return m_externalDelegate->OnFeature(prefix, std::string(name)) ? Result::Ok : Result::Error;
}
Result EndTargetFeaturesSection() override {
abort();
return Result::Ok;
}

Expand Down

0 comments on commit 661428c

Please sign in to comment.