summaryrefslogtreecommitdiff
path: root/src/wasm-stack.h
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2020-03-05 15:52:44 -0800
committerGitHub <noreply@github.com>2020-03-05 15:52:44 -0800
commit9e3dbb1f668a14341e9aebae479537d4a26095a5 (patch)
tree9857d50c3373c3f6320ca3f2586bd499bc40b224 /src/wasm-stack.h
parent3a275d0627da443cce93631a64d78e7b3f441416 (diff)
downloadbinaryen-9e3dbb1f668a14341e9aebae479537d4a26095a5.tar.gz
binaryen-9e3dbb1f668a14341e9aebae479537d4a26095a5.tar.bz2
binaryen-9e3dbb1f668a14341e9aebae479537d4a26095a5.zip
Initial multivalue support (#2675)
Implements parsing and emitting of tuple creation and extraction and tuple-typed control flow for both the text and binary formats. TODO: - Extend Precompute/interpreter to handle tuple values - C and JS API support/testing - Figure out how to lower in stack IR - Fuzzing
Diffstat (limited to 'src/wasm-stack.h')
-rw-r--r--src/wasm-stack.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/wasm-stack.h b/src/wasm-stack.h
index b42ae1253..8662e7835 100644
--- a/src/wasm-stack.h
+++ b/src/wasm-stack.h
@@ -143,7 +143,10 @@ public:
void visitDrop(Drop* curr);
void visitPush(Push* curr);
void visitPop(Pop* curr);
+ void visitTupleMake(TupleMake* curr);
+ void visitTupleExtract(TupleExtract* curr);
+ void emitResultType(Type type);
void emitIfElse(If* curr);
void emitCatch(Try* curr);
// emit an end at the end of a block/loop/if/try
@@ -168,6 +171,12 @@ private:
std::map<Type, size_t> numLocalsByType;
// (local index, tuple index) => binary local index
std::map<std::pair<Index, Index>, size_t> mappedLocals;
+
+ // Keeps track of the binary index of the scratch locals used to lower
+ // tuple.extract.
+ std::map<Type, Index> scratchLocals;
+ void countScratchLocals();
+ void setScratchLocals();
};
// Takes binaryen IR and converts it to something else (binary or stack IR)
@@ -227,6 +236,8 @@ public:
void visitDrop(Drop* curr);
void visitPush(Push* curr);
void visitPop(Pop* curr);
+ void visitTupleMake(TupleMake* curr);
+ void visitTupleExtract(TupleExtract* curr);
protected:
Function* func = nullptr;
@@ -793,6 +804,25 @@ template<typename SubType> void BinaryenIRWriter<SubType>::visitPop(Pop* curr) {
emit(curr);
}
+template<typename SubType>
+void BinaryenIRWriter<SubType>::visitTupleMake(TupleMake* curr) {
+ for (auto* operand : curr->operands) {
+ visit(operand);
+ }
+ // No need to handle unreachable since we don't actually emit an instruction
+ emit(curr);
+}
+
+template<typename SubType>
+void BinaryenIRWriter<SubType>::visitTupleExtract(TupleExtract* curr) {
+ visit(curr->tuple);
+ if (curr->type == Type::unreachable) {
+ emitUnreachable();
+ return;
+ }
+ emit(curr);
+}
+
// Binaryen IR to binary writer
class BinaryenIRToBinaryWriter
: public BinaryenIRWriter<BinaryenIRToBinaryWriter> {