================ @@ -1200,6 +1225,36 @@ void Writer::createSyntheticInitFunctions() { } } +void Writer::createMemoryGrowFunction() { + LLVM_DEBUG(dbgs() << "createMemoryGrowFunction\n"); + assert(ctx.sym.memoryGrow); + std::string bodyContent; + { + raw_string_ostream os(bodyContent); + writeUleb128(os, 0, "num locals"); + writeU8(os, WASM_OPCODE_LOCAL_GET, "local.get"); + writeUleb128(os, 0, "local 0"); + writeU8(os, WASM_OPCODE_MEMORY_GROW, "memory grow"); + writeUleb128(os, 0, "reserved memory byte"); + writeU8(os, WASM_OPCODE_END, "END"); + } + createFunction(ctx.sym.memoryGrow, bodyContent); +} + +void Writer::createMemorySizeFunction() { + LLVM_DEBUG(dbgs() << "createMemorySizeFunction\n"); + assert(ctx.sym.memorySize); + std::string bodyContent; + { + raw_string_ostream os(bodyContent); + writeUleb128(os, 0, "num locals"); + writeU8(os, WASM_OPCODE_MEMORY_SIZE, "memory size"); + writeUleb128(os, 0, "reserved memory byte"); + writeU8(os, WASM_OPCODE_END, "END"); + } + createFunction(ctx.sym.memorySize, bodyContent); ---------------- sbc100 wrote:
I would hope you could include these functions in some kind of compiler-rt / libc that could be included when needed. I'm not sure the linker needed to create these, unless I'm missing something. https://github.com/llvm/llvm-project/pull/156087 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits