diff options
Diffstat (limited to 'src/ir')
-rw-r--r-- | src/ir/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/ir/export-utils.cpp | 49 | ||||
-rw-r--r-- | src/ir/export-utils.h | 11 |
3 files changed, 52 insertions, 9 deletions
diff --git a/src/ir/CMakeLists.txt b/src/ir/CMakeLists.txt index 2dadb743f..15aa74053 100644 --- a/src/ir/CMakeLists.txt +++ b/src/ir/CMakeLists.txt @@ -4,6 +4,7 @@ set(ir_SOURCES ExpressionManipulator.cpp drop.cpp eh-utils.cpp + export-utils.cpp intrinsics.cpp lubs.cpp memory-utils.cpp diff --git a/src/ir/export-utils.cpp b/src/ir/export-utils.cpp new file mode 100644 index 000000000..0b19b7204 --- /dev/null +++ b/src/ir/export-utils.cpp @@ -0,0 +1,49 @@ +/* + * Copyright 2023 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 "ir/export-utils.h" +#include "wasm.h" + +namespace wasm::ExportUtils { + +namespace { + +// Returns a vector of all the things that are exported of a particular kind, +// given that kind and a way to look them up on the module. +template<typename T, ExternalKind K, typename G> +std::vector<T*> getExportedByKind(Module& wasm, G getModuleItem) { + std::vector<T*> ret; + for (auto& ex : wasm.exports) { + if (ex->kind == K) { + ret.push_back(getModuleItem(ex->value)); + } + } + return ret; +} + +} // anonymous namespace + +std::vector<Function*> getExportedFunctions(Module& wasm) { + return getExportedByKind<Function, ExternalKind::Function>( + wasm, [&](Name name) { return wasm.getFunction(name); }); +} + +std::vector<Global*> getExportedGlobals(Module& wasm) { + return getExportedByKind<Global, ExternalKind::Global>( + wasm, [&](Name name) { return wasm.getGlobal(name); }); +} + +} // namespace wasm::ExportUtils diff --git a/src/ir/export-utils.h b/src/ir/export-utils.h index 245365fbc..f50c0afa5 100644 --- a/src/ir/export-utils.h +++ b/src/ir/export-utils.h @@ -21,15 +21,8 @@ namespace wasm::ExportUtils { -inline std::vector<Function*> getExportedFunctions(Module& wasm) { - std::vector<Function*> ret; - for (auto& ex : wasm.exports) { - if (ex->kind == ExternalKind::Function) { - ret.push_back(wasm.getFunction(ex->value)); - } - } - return ret; -} +std::vector<Function*> getExportedFunctions(Module& wasm); +std::vector<Global*> getExportedGlobals(Module& wasm); } // namespace wasm::ExportUtils |