diff options
author | Sam Clegg <sbc@chromium.org> | 2020-01-16 14:53:11 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-16 14:53:11 -0800 |
commit | 7c80d05e37dc02870c680869ae3f04ac6d9637ee (patch) | |
tree | 57645c67379d4e6ec49773b3494dc752ffcb5e68 /src/interp/binary-reader-metadata.cc | |
parent | d663c80dcb627fed3e21cfa2b47465452a83a894 (diff) | |
download | wabt-7c80d05e37dc02870c680869ae3f04ac6d9637ee.tar.gz wabt-7c80d05e37dc02870c680869ae3f04ac6d9637ee.tar.bz2 wabt-7c80d05e37dc02870c680869ae3f04ac6d9637ee.zip |
Initial WASM C API implementation. (#1250)
All tests except `threads` pass.
Diffstat (limited to 'src/interp/binary-reader-metadata.cc')
-rw-r--r-- | src/interp/binary-reader-metadata.cc | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/interp/binary-reader-metadata.cc b/src/interp/binary-reader-metadata.cc new file mode 100644 index 00000000..8cbed78e --- /dev/null +++ b/src/interp/binary-reader-metadata.cc @@ -0,0 +1,74 @@ +/* + * Copyright 2020 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "src/interp/binary-reader-metadata.h" + +#include "src/binary-reader-nop.h" +#include "src/binary-reader.h" +#include "src/interp/interp.h" +#include "src/string-view.h" + +namespace wabt { + +using namespace interp; + +namespace { + +class BinaryReaderMetadata : public BinaryReaderNop { + public: + BinaryReaderMetadata(ModuleMetadata* metadata, + Errors* errors, + const Features& features) + : metadata_(metadata) {} + wabt::Result OnImport(Index index, + ExternalKind kind, + string_view module_name, + string_view field_name) override { + metadata_->imports.emplace_back(kind, module_name, field_name); + return wabt::Result::Ok; + } + + wabt::Result OnExport(Index index, + ExternalKind kind, + Index item_index, + string_view name) override { + metadata_->exports.emplace_back(name, kind, item_index); + return wabt::Result::Ok; + } + + private: + ModuleMetadata* metadata_; +}; + +} // end anonymous namespace + +wabt::Result ReadBinaryMetadata(const void* data, + size_t size, + const ReadBinaryOptions& options, + Errors* errors, + ModuleMetadata** out_metadata) { + ModuleMetadata* metadata = new ModuleMetadata(); + BinaryReaderMetadata reader(metadata, errors, options.features); + wabt::Result result = ReadBinary(data, size, &reader, options); + if (!Succeeded(result)) { + delete metadata; + return result; + } + *out_metadata = metadata; + return result; +} + +} // namespace wabt |