diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-04-22 22:01:43 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-04-26 19:50:14 -0700 |
commit | d9096704dfa84aea94bb6ac2ffa02d88fa546bfa (patch) | |
tree | 817992a1e811af71087a228b20f3c35df9485b96 /src/ast_utils.h | |
parent | 7fd8aac5084223c48901ca20f9d233e9764d536a (diff) | |
download | binaryen-d9096704dfa84aea94bb6ac2ffa02d88fa546bfa.tar.gz binaryen-d9096704dfa84aea94bb6ac2ffa02d88fa546bfa.tar.bz2 binaryen-d9096704dfa84aea94bb6ac2ffa02d88fa546bfa.zip |
add an ArenaVector for internal array allocations in expression nodes
Diffstat (limited to 'src/ast_utils.h')
-rw-r--r-- | src/ast_utils.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h index 66dbf039a..5b569435e 100644 --- a/src/ast_utils.h +++ b/src/ast_utils.h @@ -136,6 +136,16 @@ struct ExpressionManipulator { static void nop(InputType* target) { convert<InputType, Nop>(target); } + + // Convert a node that allocates + template<typename InputType, typename OutputType> + static OutputType* convert(InputType *input, MixedArena& allocator) { + assert(sizeof(OutputType) <= sizeof(InputType)); + input->~InputType(); // arena-allocaed, so no destructor, but avoid UB. + OutputType* output = (OutputType*)(input); + new (output) OutputType(allocator); + return output; + } }; struct ExpressionAnalyzer { |