diff options
author | Thomas Lively <tlively@google.com> | 2023-08-22 12:57:02 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-22 17:57:02 +0000 |
commit | 9eb408bf06da91838245dcda33553c356190a643 (patch) | |
tree | 5696ecdc90a2f5f76a8f23d49d2f52b4dfc72363 /src/mixed_arena.h | |
parent | 1d95fdc7805ef2f29b8b8b0cce8f7c8cc385edd0 (diff) | |
download | binaryen-9eb408bf06da91838245dcda33553c356190a643.tar.gz binaryen-9eb408bf06da91838245dcda33553c356190a643.tar.bz2 binaryen-9eb408bf06da91838245dcda33553c356190a643.zip |
Factor IRBuilder utility out of the new wat parser (#5880)
Add an IRBuilder utility in a new wasm-ir-builder.h header. IRBuilder is
extremely similar to Builder, except that it manages building full trees of
Binaryen IR from a linear sequence of instructions, whereas Builder only builds
a single IR node at a time. To build full IR trees, IRBuilder maintains an
internal stack of expressions, popping children off the stack and pushing the
new node onto the stack whenever it builds a new node.
In addition to providing makeXYZ function to allocate, initialize, and finalize
new IR nodes, IRBuilder also provides a visit() method that can be used when the
user has already allocated the IR nodes and only needs to reconstruct the
connections between them. This will be useful in outlining both for constructing
outlined functions and for reconstructing functions around arbitrary outlined
holes.
Besides the new wat parser and outlining, this new utility can also eventually
be used in the binary parser and to convert from Poppy IR back to Binaryen IR if
that ever becomes necessary.
To simplify this initial change, IRBuilder exposes the same interface as the
code it replaces in the wat parser. A future change requiring more extensive
changes to the wat parser will simplify this interface. Also, since the new code
is tested only via the new wat parser, it only supports building instructions
that were already supported by the new wat parser to avoid trying to support any
instructions without corresponding testing. Implementing support for the
remaining instructions is left as future work.
Diffstat (limited to 'src/mixed_arena.h')
-rw-r--r-- | src/mixed_arena.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/mixed_arena.h b/src/mixed_arena.h index 4d8cda0ac..530fa9daa 100644 --- a/src/mixed_arena.h +++ b/src/mixed_arena.h @@ -403,7 +403,15 @@ public: ArenaVector(MixedArena& allocator) : allocator(allocator) {} ArenaVector(ArenaVector<T>&& other) : allocator(other.allocator) { - *this = other; + swap(other); + } + + ArenaVector<T>& operator=(ArenaVector<T>&& other) { + if (this != &other) { + this->clear(); + this->swap(other); + } + return *this; } void allocate(size_t size) { |