diff options
author | Heejin Ahn <aheejin@gmail.com> | 2019-07-23 00:46:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-23 00:46:06 -0700 |
commit | 00d02f71cf08a16ccfe5acde25e5a54b3915d2d7 (patch) | |
tree | d86c930427a746c5c09dddf011c8081807597c79 /src/passes/StackIR.cpp | |
parent | ff2b10bd641039e2cf4eb00b767ac5139a41583e (diff) | |
download | binaryen-00d02f71cf08a16ccfe5acde25e5a54b3915d2d7.tar.gz binaryen-00d02f71cf08a16ccfe5acde25e5a54b3915d2d7.tar.bz2 binaryen-00d02f71cf08a16ccfe5acde25e5a54b3915d2d7.zip |
Refactor stack IR / binary writer (NFC) (#2250)
Previously `StackWriter` and its subclasses had routines for all three
modes (`Binaryen2Binary`, `Binaryen2Stack`, and `Stack2Binary`) within a
single class. This splits routines for each in a separate class and
also factors out binary writing into a separate class
(`BinaryInstWriter`) so other classes can make use of it.
The new classes are:
- `BinaryInstWriter`:
Binary instruction writer. Only responsible for emitting binary
contents and no other logic
- `BinaryenIRWriter`: Converts binaryen IR into something else
- `BinaryenIRToBinaryWriter`: Writes binaryen IR to binary
- `StackIRGenerator`: Converts binaryen IR to stack IR
- `StackIRToBinaryWriter`: Writes stack IR to binary
Diffstat (limited to 'src/passes/StackIR.cpp')
-rw-r--r-- | src/passes/StackIR.cpp | 23 |
1 files changed, 3 insertions, 20 deletions
diff --git a/src/passes/StackIR.cpp b/src/passes/StackIR.cpp index d834655b9..9b8b9b8b1 100644 --- a/src/passes/StackIR.cpp +++ b/src/passes/StackIR.cpp @@ -36,27 +36,10 @@ struct GenerateStackIR : public WalkerPass<PostWalker<GenerateStackIR>> { bool modifiesBinaryenIR() override { return false; } void doWalkFunction(Function* func) { - BufferWithRandomAccess buffer; - // a shim for the parent that a stackWriter expects - we don't need - // it to do anything, as we are just writing to Stack IR - struct Parent { - Module* module; - Parent(Module* module) : module(module) {} - - Module* getModule() { return module; } - void writeDebugLocation(Expression* curr, Function* func) { - WASM_UNREACHABLE(); - } - Index getFunctionIndex(Name name) { WASM_UNREACHABLE(); } - Index getFunctionTypeIndex(Name name) { WASM_UNREACHABLE(); } - Index getGlobalIndex(Name name) { WASM_UNREACHABLE(); } - } parent(getModule()); - StackWriter<StackWriterMode::Binaryen2Stack, Parent> stackWriter( - parent, buffer, false); - stackWriter.setFunction(func); - stackWriter.visitPossibleBlockContents(func->body); + StackIRGenerator stackIRGen(getModule()->allocator, func); + stackIRGen.write(); func->stackIR = make_unique<StackIR>(); - func->stackIR->swap(stackWriter.stackIR); + func->stackIR->swap(stackIRGen.getStackIR()); } }; |