summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/RemoveImports.cpp36
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
+