MCPcopy Index your code
hub / github.com/apache/tvm / makePackedFunc

Method makePackedFunc

web/src/runtime.ts:2206–2239  ·  view source on GitHub ↗
(handle: Pointer)

Source from the content-addressed store, hash-verified

2204 }
2205
2206 private makePackedFunc(handle: Pointer): PackedFunc {
2207 const cell = new PackedFuncCell(handle, this.lib, this.ctx);
2208 const packedFunc = (...args: any): any => {
2209 const stack = this.lib.getOrAllocCallStack();
2210 const argsOffset = stack.allocRawBytes(SizeOf.TVMFFIAny * args.length);
2211 this.setPackedArguments(stack, args, argsOffset);
2212 const retOffset = stack.allocRawBytes(SizeOf.TVMFFIAny);
2213 // pre-store the result to be null
2214 stack.storeI32(retOffset, TypeIndex.kTVMFFINone);
2215 // clear off the extra zero padding before ptr storage
2216 stack.storeI32(retOffset + SizeOf.I32, 0);
2217 stack.commitToWasmMemory();
2218 this.lib.checkCall(
2219 (this.exports.TVMFFIFunctionCall as ctypes.FTVMFFIFunctionCall)(
2220 cell.getHandle(),
2221 stack.ptrFromOffset(argsOffset),
2222 args.length,
2223 stack.ptrFromOffset(retOffset)
2224 )
2225 );
2226
2227 const ret = this.retValueToJS(stack.ptrFromOffset(retOffset), false);
2228 this.lib.recycleCallStack(stack);
2229 return ret;
2230 };
2231 // Attach attributes to the function type.
2232 // This is because javascript do not allow us to overload call.
2233 const ret: any = packedFunc;
2234 ret.dispose = (): void => {
2235 cell.dispose();
2236 };
2237 ret._tvmPackedCell = cell;
2238 return ret as PackedFunc;
2239 }
2240
2241 /**
2242 * Creaye return value of the packed func. The value us auto-tracked for dispose.

Callers 3

getGlobalFuncInternalMethod · 0.95
retValueToJSMethod · 0.95

Calls 1

disposeMethod · 0.45

Tested by

no test coverage detected