diff options
Diffstat (limited to 'src/ir')
-rw-r--r-- | src/ir/manipulation.h | 4 | ||||
-rw-r--r-- | src/ir/module-utils.cpp | 11 | ||||
-rw-r--r-- | src/ir/module-utils.h | 7 |
3 files changed, 21 insertions, 1 deletions
diff --git a/src/ir/manipulation.h b/src/ir/manipulation.h index 33c7d1bd7..64cd15dc3 100644 --- a/src/ir/manipulation.h +++ b/src/ir/manipulation.h @@ -64,6 +64,10 @@ inline OutputType* convert(InputType* input, MixedArena& allocator) { return output; } +// Copy using a flexible custom copy function. This function is called on each +// expression before copying it. If it returns a non-null value then that is +// used (effectively overriding the normal copy), and if it is null then we do a +// normal copy. using CustomCopier = std::function<Expression*(Expression*)>; Expression* flexibleCopy(Expression* original, Module& wasm, CustomCopier custom); diff --git a/src/ir/module-utils.cpp b/src/ir/module-utils.cpp index 5791ed77c..8ad127086 100644 --- a/src/ir/module-utils.cpp +++ b/src/ir/module-utils.cpp @@ -46,6 +46,15 @@ Function* copyFunction(Function* func, Module& out, Name newName, std::optional<std::vector<Index>> fileIndexMap) { + auto ret = copyFunctionWithoutAdd(func, out, newName, fileIndexMap); + return out.addFunction(std::move(ret)); +} + +std::unique_ptr<Function> +copyFunctionWithoutAdd(Function* func, + Module& out, + Name newName, + std::optional<std::vector<Index>> fileIndexMap) { auto ret = std::make_unique<Function>(); ret->name = newName.is() ? newName : func->name; ret->hasExplicitName = func->hasExplicitName; @@ -71,7 +80,7 @@ Function* copyFunction(Function* func, ret->base = func->base; ret->noFullInline = func->noFullInline; ret->noPartialInline = func->noPartialInline; - return out.addFunction(std::move(ret)); + return ret; } Global* copyGlobal(Global* global, Module& out) { diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h index 0a101e5da..d9fd69428 100644 --- a/src/ir/module-utils.h +++ b/src/ir/module-utils.h @@ -33,6 +33,13 @@ copyFunction(Function* func, Name newName = Name(), std::optional<std::vector<Index>> fileIndexMap = std::nullopt); +// As above, but does not add the copy to the module. +std::unique_ptr<Function> copyFunctionWithoutAdd( + Function* func, + Module& out, + Name newName = Name(), + std::optional<std::vector<Index>> fileIndexMap = std::nullopt); + Global* copyGlobal(Global* global, Module& out); Tag* copyTag(Tag* tag, Module& out); |