diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-22 14:41:30 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-22 14:41:30 -0800 |
commit | 5b590e4bbba075bba5fe87c44986939f26816549 (patch) | |
tree | 51e37ee14ba1ba9ffd3a37881f651ad6d83d2b18 /src | |
parent | 860e52c64da5200676d4226a2e48c849945f6687 (diff) | |
download | binaryen-5b590e4bbba075bba5fe87c44986939f26816549.tar.gz binaryen-5b590e4bbba075bba5fe87c44986939f26816549.tar.bz2 binaryen-5b590e4bbba075bba5fe87c44986939f26816549.zip |
add remove-imports pass
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/RemoveImports.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/passes/RemoveImports.cpp b/src/passes/RemoveImports.cpp new file mode 100644 index 000000000..07465f9d6 --- /dev/null +++ b/src/passes/RemoveImports.cpp @@ -0,0 +1,36 @@ +// +// Removeds imports, and replaces them with nops. This is useful +// for running a module through the reference interpreter, which +// does not validate imports for a JS environment (by removing +// imports, we can at least get the reference interpreter to +// look at all the rest of the code). +// + +#include <wasm.h> +#include <pass.h> + +namespace wasm { + +struct RemoveImports : public Pass { + MixedArena* allocator; + + void prepare(PassRunner* runner, Module *module) override { + allocator = runner->allocator; + } + + void visitCallImport(CallImport *curr) override { + replaceCurrent(allocator->alloc<Nop>()); + } + + void visitModule(Module *curr) { + auto imports = curr->imports; + for (auto import : imports) { + curr->removeImport(import->name); + } + } +}; + +static RegisterPass<RemoveImports> registerPass("remove-imports", "removes imports and replaces them with nops"); + +} // namespace wasm + |