#ifndef wasm_ir_manipulation_h
#define wasm_ir_manipulation_h
#include "wasm.h"
namespace wasm {
namespace ExpressionManipulator {
template<typename InputType, typename OutputType>
inline OutputType* convert(InputType* input) {
static_assert(sizeof(OutputType) <= sizeof(InputType),
"Can only convert to a smaller size Expression node");
input->~InputType(); OutputType* output = (OutputType*)(input);
new (output) OutputType;
return output;
}
template<typename InputType> inline Nop* nop(InputType* target) {
auto* ret = convert<InputType, Nop>(target);
ret->finalize();
return ret;
}
template<typename InputType>
inline RefNull* refNull(InputType* target, Type type) {
auto* ret = convert<InputType, RefNull>(target);
ret->finalize(type);
return ret;
}
template<typename InputType>
inline Unreachable* unreachable(InputType* target) {
auto* ret = convert<InputType, Unreachable>(target);
ret->finalize();
return ret;
}
template<typename InputType, typename OutputType>
inline OutputType* convert(InputType* input, MixedArena& allocator) {
assert(sizeof(OutputType) <= sizeof(InputType));
input->~InputType(); OutputType* output = (OutputType*)(input);
new (output) OutputType(allocator);
return output;
}
using CustomCopier = std::function<Expression*(Expression*)>;
Expression*
flexibleCopy(Expression* original, Module& wasm, CustomCopier custom);
inline Expression* copy(Expression* original, Module& wasm) {
auto copy = [](Expression* curr) { return nullptr; };
return flexibleCopy(original, wasm, copy);
}
void spliceIntoBlock(Block* block, Index index, Expression* add);
}
}
#endif