diff options
author | Alon Zakai <azakai@google.com> | 2019-07-03 12:45:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-03 12:45:16 -0700 |
commit | 23d8497ce605b41652e97aea06150c9d59b93796 (patch) | |
tree | 43a613319aaf47122ae37a0096f2173ce0741060 /src/wasm-interpreter.h | |
parent | 7d1ff56acafae9c769bc8dd8da2c8ef3c66a2aa6 (diff) | |
download | binaryen-23d8497ce605b41652e97aea06150c9d59b93796.tar.gz binaryen-23d8497ce605b41652e97aea06150c9d59b93796.tar.bz2 binaryen-23d8497ce605b41652e97aea06150c9d59b93796.zip |
Minimal Push/Pop support (#2207)
This is the first stage of adding support for stacky/multivaluey things. It adds new push/pop instructions, and so far just shows that they can be read and written, and that the optimizer doesn't do anything immediately wrong on them.
No fuzzer support, since there isn't a "correct" way to use these yet. The current test shows some "incorrect" usages of them, which is nice to see that we can parse/emit them, but we should replace them with proper usages of push/pop once we actually have those (see comments in the tests).
This should be enough to unblock exceptions (which needs a pop in try-catches). It is also a step towards multivalue (I added some docs about that), but most of multivalue is left to be done.
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r-- | src/wasm-interpreter.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 560051917..890e1a844 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -1046,6 +1046,8 @@ public: Flow visitAtomicCmpxchg(AtomicCmpxchg*) { WASM_UNREACHABLE(); } Flow visitAtomicWait(AtomicWait*) { WASM_UNREACHABLE(); } Flow visitAtomicNotify(AtomicNotify*) { WASM_UNREACHABLE(); } + Flow visitPush(Push*) { WASM_UNREACHABLE(); } + Flow visitPop(Pop*) { WASM_UNREACHABLE(); } virtual void trap(const char* why) { WASM_UNREACHABLE(); } }; @@ -1227,6 +1229,9 @@ public: // Values of globals GlobalManager globals; + // Multivalue ABI support (see push/pop). + std::vector<Literal> multiValues; + ModuleInstanceBase(Module& wasm, ExternalInterface* externalInterface) : wasm(wasm), externalInterface(externalInterface) { // import globals from the outside @@ -1776,6 +1781,22 @@ private: } return {}; } + Flow visitPush(Push* curr) { + NOTE_ENTER("Push"); + Flow value = this->visit(curr->value); + if (value.breaking()) { + return value; + } + instance.multiValues.push_back(value.value); + return Flow(); + } + Flow visitPop(Pop* curr) { + NOTE_ENTER("Pop"); + assert(!instance.multiValues.empty()); + auto ret = instance.multiValues.back(); + instance.multiValues.pop_back(); + return ret; + } void trap(const char* why) override { instance.externalInterface->trap(why); |