@@ -420,6 +420,31 @@ public let WasmCodeGenerators: [CodeGenerator] = [
420420 function. wasmMemoryGrow ( memory: memory, growByPages: growBy)
421421 } ,
422422
423+ CodeGenerator ( " WasmMemoryCopyGenerator " , inContext: . wasmFunction, inputs: . required( . object( ofGroup: " WasmMemory " ) ) ) { b, srcMemory in
424+ let function = b. currentWasmModule. currentWasmFunction
425+ let srcMemoryTypeInfo = b. type ( of: srcMemory) . wasmMemoryType!
426+ let dstMemory = b. findVariable { v in
427+ let type = b. type ( of: v)
428+ return type. Is ( . object( ofGroup: " WasmMemory " ) )
429+ && type. wasmMemoryType!. isMemory64 == srcMemoryTypeInfo. isMemory64
430+ } !
431+ let dstMemoryTypeInfo = b. type ( of: srcMemory) . wasmMemoryType!
432+ let memArg = { v in function. memoryArgument ( v, dstMemoryTypeInfo) }
433+
434+ let srcMemSize = srcMemoryTypeInfo. limits. min * WasmConstants. specWasmMemPageSize
435+ let dstMemSize = dstMemoryTypeInfo. limits. min * WasmConstants. specWasmMemPageSize
436+ let srcOffsetValue = b. randomNonNegativeIndex ( upTo: Int64 ( srcMemSize) )
437+ let srcOffset = memArg ( srcOffsetValue)
438+ let dstOffsetValue = b. randomNonNegativeIndex ( upTo: Int64 ( dstMemSize) )
439+ let dstOffset = memArg ( dstOffsetValue)
440+
441+ let maxCopySize = min ( Int64 ( srcMemSize) - srcOffsetValue, Int64 ( dstMemSize) - dstOffsetValue)
442+ let copySizeValue = b. randomSize ( upTo: maxCopySize)
443+ let copySize = memArg ( copySizeValue)
444+
445+ function. wasmMemoryCopy ( dstMemory: dstMemory, srcMemory: srcMemory, dstOffset: dstOffset, srcOffset: srcOffset, size: copySize)
446+ } ,
447+
423448 CodeGenerator ( " WasmMemoryFillGenerator " , inContext: . wasmFunction, inputs: . required( . object( ofGroup: " WasmMemory " ) ) ) { b, memory in
424449 if ( b. hasZeroPages ( memory: memory) ) { return }
425450
@@ -446,7 +471,7 @@ public let WasmCodeGenerators: [CodeGenerator] = [
446471 let memoryOffset = function. memoryArgument ( memoryOffsetValue, memoryTypeInfo)
447472
448473 let dataSegmentTypeInfo = b. type ( of: dataSegment) . wasmDataSegmentType!
449- let dataSegmentOffsetValue = b. randomSize ( upTo: Int64 ( dataSegmentTypeInfo. segmentLength) )
474+ let dataSegmentOffsetValue = b. randomNonNegativeIndex ( upTo: Int64 ( dataSegmentTypeInfo. segmentLength) )
450475 let dataSegmentOffset = function. consti32 ( Int32 ( dataSegmentOffsetValue) )
451476
452477 let maxNrOfBytesToUpdate = min ( memSize - memoryOffsetValue, Int64 ( dataSegmentTypeInfo. segmentLength) - dataSegmentOffsetValue)
0 commit comments