|
28 | 28 |
|
29 | 29 | #include "support/bits.h"
|
30 | 30 | #include "wasm.h"
|
| 31 | +#include "wasm-traversal.h" |
31 | 32 |
|
32 | 33 | #ifdef WASM_INTERPRETER_DEBUG
|
33 | 34 | #include "wasm-printing.h"
|
@@ -75,11 +76,33 @@ typedef std::vector<Literal> LiteralList;
|
75 | 76 |
|
76 | 77 | // Debugging helpers
|
77 | 78 | #ifdef WASM_INTERPRETER_DEBUG
|
78 |
| -#define NOTE_ENTER(x) { std::cout << "visit " << x << " : " << curr << "\n"; } |
79 |
| -#define NOTE_ENTER_(x) { std::cout << "visit " << x << "\n"; } |
80 |
| -#define NOTE_NAME(p0) { std::cout << "name " << '(' << Name(p0) << ")\n"; } |
81 |
| -#define NOTE_EVAL1(p0) { std::cout << "eval " << '(' << p0 << ")\n"; } |
82 |
| -#define NOTE_EVAL2(p0, p1) { std::cout << "eval " << '(' << p0 << ", " << p1 << ")\n"; } |
| 79 | +class Indenter { |
| 80 | + static int indentLevel; |
| 81 | + |
| 82 | + const char* entryName; |
| 83 | + |
| 84 | +public: |
| 85 | + Indenter(const char* entry); |
| 86 | + ~Indenter(); |
| 87 | + |
| 88 | + static void print(); |
| 89 | +}; |
| 90 | + |
| 91 | +#define NOTE_ENTER(x) Indenter _int_blah(x); { \ |
| 92 | + Indenter::print(); \ |
| 93 | + std::cout << "visit " << x << " : " << curr << "\n"; } |
| 94 | +#define NOTE_ENTER_(x) Indenter _int_blah(x); { \ |
| 95 | + Indenter::print(); \ |
| 96 | + std::cout << "visit " << x << "\n"; } |
| 97 | +#define NOTE_NAME(p0) { \ |
| 98 | + Indenter::print(); \ |
| 99 | + std::cout << "name " << '(' << Name(p0) << ")\n"; } |
| 100 | +#define NOTE_EVAL1(p0) { \ |
| 101 | + Indenter::print(); \ |
| 102 | + std::cout << "eval " #p0 " (" << p0 << ")\n"; } |
| 103 | +#define NOTE_EVAL2(p0, p1) { \ |
| 104 | + Indenter::print(); \ |
| 105 | + std::cout << "eval " #p0 " (" << p0 << "), " #p1 " (" << p1 << ")\n"; } |
83 | 106 | #else // WASM_INTERPRETER_DEBUG
|
84 | 107 | #define NOTE_ENTER(x)
|
85 | 108 | #define NOTE_ENTER_(x)
|
@@ -725,15 +748,23 @@ class ModuleInstance {
|
725 | 748 | NOTE_ENTER("Load");
|
726 | 749 | Flow flow = visit(curr->ptr);
|
727 | 750 | if (flow.breaking()) return flow;
|
728 |
| - return instance.externalInterface->load(curr, instance.getFinalAddress(curr, flow.value)); |
| 751 | + NOTE_EVAL1(flow); |
| 752 | + auto addr = instance.getFinalAddress(curr, flow.value); |
| 753 | + auto ret = instance.externalInterface->load(curr, addr); |
| 754 | + NOTE_EVAL1(addr); |
| 755 | + NOTE_EVAL1(ret); |
| 756 | + return ret; |
729 | 757 | }
|
730 | 758 | Flow visitStore(Store *curr) {
|
731 | 759 | NOTE_ENTER("Store");
|
732 | 760 | Flow ptr = visit(curr->ptr);
|
733 | 761 | if (ptr.breaking()) return ptr;
|
734 | 762 | Flow value = visit(curr->value);
|
735 | 763 | if (value.breaking()) return value;
|
736 |
| - instance.externalInterface->store(curr, instance.getFinalAddress(curr, ptr.value), value.value); |
| 764 | + auto addr = instance.getFinalAddress(curr, ptr.value); |
| 765 | + NOTE_EVAL1(addr); |
| 766 | + NOTE_EVAL1(value); |
| 767 | + instance.externalInterface->store(curr, addr, value.value); |
737 | 768 | return Flow();
|
738 | 769 | }
|
739 | 770 |
|
@@ -781,7 +812,11 @@ class ModuleInstance {
|
781 | 812 | FunctionScope scope(function, arguments);
|
782 | 813 |
|
783 | 814 | #ifdef WASM_INTERPRETER_DEBUG
|
784 |
| - std::cout << "entering " << function->name << '\n'; |
| 815 | + std::cout << "entering " << function->name |
| 816 | + << "\n with arguments:\n"; |
| 817 | + for (unsigned i = 0; i < arguments.size(); ++i) { |
| 818 | + std::cout << " $" << i << ": " << arguments[i] << '\n'; |
| 819 | + } |
785 | 820 | #endif
|
786 | 821 |
|
787 | 822 | Flow flow = RuntimeExpressionRunner(*this, scope).visit(function->body);
|
|
0 commit comments