summaryrefslogtreecommitdiff
path: root/src/passes/LogExecution.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/LogExecution.cpp')
-rw-r--r--src/passes/LogExecution.cpp42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/passes/LogExecution.cpp b/src/passes/LogExecution.cpp
index 1b90842bc..f1d48012f 100644
--- a/src/passes/LogExecution.cpp
+++ b/src/passes/LogExecution.cpp
@@ -39,9 +39,18 @@ namespace wasm {
Name LOGGER("log_execution");
struct LogExecution : public WalkerPass<PostWalker<LogExecution>> {
+ // The module name the logger function is imported from.
+ IString loggerModule;
+
// Adds calls to new imports.
bool addsEffects() override { return true; }
+ void run(Module* module) override {
+ auto& options = getPassOptions();
+ loggerModule = options.getArgumentOrDefault("log-execution", "");
+ super::run(module);
+ }
+
void visitLoop(Loop* curr) { curr->body = makeLogCall(curr->body); }
void visitReturn(Return* curr) { replaceCurrent(makeLogCall(curr)); }
@@ -63,23 +72,32 @@ struct LogExecution : public WalkerPass<PostWalker<LogExecution>> {
auto import =
Builder::makeFunction(LOGGER, Signature(Type::i32, Type::none), {});
- // Import the log function from import "env" if the module
- // imports other functions from that name.
- for (auto& func : curr->functions) {
- if (func->imported() && func->module == ENV) {
- import->module = func->module;
- break;
- }
- }
-
- // If not, then pick the import name of the first function we find.
- if (!import->module) {
+ if (loggerModule != "") {
+ import->module = loggerModule;
+ } else {
+ // Import the log function from import "env" if the module
+ // imports other functions from that name.
for (auto& func : curr->functions) {
- if (func->imported()) {
+ if (func->imported() && func->module == ENV) {
import->module = func->module;
break;
}
}
+
+ // If not, then pick the import name of the first function we find.
+ if (!import->module) {
+ for (auto& func : curr->functions) {
+ if (func->imported()) {
+ import->module = func->module;
+ break;
+ }
+ }
+ }
+
+ // If no function was found, use ENV.
+ if (!import->module) {
+ import->module = ENV;
+ }
}
import->base = LOGGER;