@@ -34,6 +34,9 @@ enum VMGen {
3434 + ExecutionParameter. allCases. map { ( $0. label, $0. type, true ) }
3535 var output = """
3636 extension Execution {
37+
38+ /// Execute an instruction identified by the opcode.
39+ /// Note: This function is only used when using token threading model.
3740 @inline(__always)
3841 mutating func doExecute(_ \( doExecuteParams. map { " \( $0. label) : \( $0. isInout ? " inout " : " " ) \( $0. type) " } . joined ( separator: " , " ) ) ) throws -> CodeSlot {
3942 switch opcode {
@@ -427,19 +430,30 @@ enum VMGen {
427430 let generatedFiles = [
428431 GeneratedFile (
429432 projectSources + [ " WasmKit " , " Execution " , " DispatchInstruction.swift " ] ,
430- header + generateDispatcher( instructions: instructions)
431- + " \n \n "
432- + generateDirectThreadedCode( instructions: instructions, inlineImpls: inlineImpls)
433+ header
433434 + """
435+ // Include the C inline code to codegen together with the Swift code.
436+ import _CWasmKit.InlineCode
434437
438+ // MARK: - Token Threaded Code
435439
436- import _CWasmKit.InlineCode
440+ """
441+ + generateDispatcher( instructions: instructions)
442+ + """
443+
444+
445+ // MARK: - Direct Threaded Code
446+
447+ """
448+ + generateDirectThreadedCode( instructions: instructions, inlineImpls: inlineImpls)
449+ + """
437450
438451 extension Instruction {
439- var handler: UInt64 {
452+ /// The tail-calling execution handler for the instruction.
453+ var handler: UInt {
440454 return withUnsafePointer(to: wasmkit_tc_exec_handlers) {
441455 let count = MemoryLayout.size(ofValue: wasmkit_tc_exec_handlers) / MemoryLayout<wasmkit_tc_exec>.size
442- return $0.withMemoryRebound(to: UInt64 .self, capacity: count) {
456+ return $0.withMemoryRebound(to: UInt .self, capacity: count) {
443457 $0[Int(self.opcodeID)]
444458 }
445459 }
0 commit comments