diff options
Diffstat (limited to 'src/ir/module-utils.h')
-rw-r--r-- | src/ir/module-utils.h | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h index 83625809f..4205514e5 100644 --- a/src/ir/module-utils.h +++ b/src/ir/module-utils.h @@ -52,6 +52,23 @@ struct BinaryIndexes { } }; +inline Function* copyFunction(Function* func, Module& out) { + auto* ret = new Function(); + ret->name = func->name; + ret->result = func->result; + ret->params = func->params; + ret->vars = func->vars; + ret->type = Name(); // start with no named type; the names in the other module may differ + ret->localNames = func->localNames; + ret->localIndices = func->localIndices; + ret->debugLocations = func->debugLocations; + ret->body = ExpressionManipulator::copy(func->body, out); + // TODO: copy Stack IR + assert(!func->stackIR); + out.addFunction(ret); + return ret; +} + inline void copyModule(Module& in, Module& out) { // we use names throughout, not raw points, so simple copying is fine // for everything *but* expressions @@ -65,9 +82,7 @@ inline void copyModule(Module& in, Module& out) { out.addExport(new Export(*curr)); } for (auto& curr : in.functions) { - auto* func = new Function(*curr); - func->body = ExpressionManipulator::copy(func->body, out); - out.addFunction(func); + copyFunction(curr.get(), out); } for (auto& curr : in.globals) { out.addGlobal(new Global(*curr)); @@ -85,19 +100,6 @@ inline void copyModule(Module& in, Module& out) { out.debugInfoFileNames = in.debugInfoFileNames; } -inline Function* copyFunction(Module& in, Module& out, Name name) { - Function *ret = out.getFunctionOrNull(name); - if (ret != nullptr) { - return ret; - } - auto* curr = in.getFunction(name); - auto* func = new Function(*curr); - func->body = ExpressionManipulator::copy(func->body, out); - func->type = Name(); - out.addFunction(func); - return func; -} - } // namespace ModuleUtils } // namespace wasm |