@@ -285,224 +285,6 @@ extension AnyInstructionVisitor {
285
285
public mutating func visitTableSize( table: UInt32 ) throws { return try self . visit ( . tableSize( table: table) ) }
286
286
}
287
287
288
- /// A visitor that traces the instructions visited.
289
- public struct InstructionTracingVisitor < V: InstructionVisitor > : InstructionVisitor {
290
- /// A closure that is invoked with the visited instruction.
291
- public let trace : ( Instruction ) -> Void
292
- /// The visitor to forward the instructions to.
293
- public var visitor : V
294
-
295
- /// Creates a new tracing visitor.
296
- ///
297
- /// - Parameters:
298
- /// - trace: A closure that is invoked with the visited instruction.
299
- /// - visitor: The visitor to forward the instructions to.
300
- public init ( trace: @escaping ( Instruction ) -> Void , visitor: V ) {
301
- self . trace = trace
302
- self . visitor = visitor
303
- }
304
- public mutating func visitUnreachable( ) throws {
305
- trace ( . unreachable)
306
- return try visitor. visitUnreachable ( )
307
- }
308
- public mutating func visitNop( ) throws {
309
- trace ( . nop)
310
- return try visitor. visitNop ( )
311
- }
312
- public mutating func visitBlock( blockType: BlockType ) throws {
313
- trace ( . block( blockType: blockType) )
314
- return try visitor. visitBlock ( blockType: blockType)
315
- }
316
- public mutating func visitLoop( blockType: BlockType ) throws {
317
- trace ( . loop( blockType: blockType) )
318
- return try visitor. visitLoop ( blockType: blockType)
319
- }
320
- public mutating func visitIf( blockType: BlockType ) throws {
321
- trace ( . if( blockType: blockType) )
322
- return try visitor. visitIf ( blockType: blockType)
323
- }
324
- public mutating func visitElse( ) throws {
325
- trace ( . else)
326
- return try visitor. visitElse ( )
327
- }
328
- public mutating func visitEnd( ) throws {
329
- trace ( . end)
330
- return try visitor. visitEnd ( )
331
- }
332
- public mutating func visitBr( relativeDepth: UInt32 ) throws {
333
- trace ( . br( relativeDepth: relativeDepth) )
334
- return try visitor. visitBr ( relativeDepth: relativeDepth)
335
- }
336
- public mutating func visitBrIf( relativeDepth: UInt32 ) throws {
337
- trace ( . brIf( relativeDepth: relativeDepth) )
338
- return try visitor. visitBrIf ( relativeDepth: relativeDepth)
339
- }
340
- public mutating func visitBrTable( targets: BrTable ) throws {
341
- trace ( . brTable( targets: targets) )
342
- return try visitor. visitBrTable ( targets: targets)
343
- }
344
- public mutating func visitReturn( ) throws {
345
- trace ( . return)
346
- return try visitor. visitReturn ( )
347
- }
348
- public mutating func visitCall( functionIndex: UInt32 ) throws {
349
- trace ( . call( functionIndex: functionIndex) )
350
- return try visitor. visitCall ( functionIndex: functionIndex)
351
- }
352
- public mutating func visitCallIndirect( typeIndex: UInt32 , tableIndex: UInt32 ) throws {
353
- trace ( . callIndirect( typeIndex: typeIndex, tableIndex: tableIndex) )
354
- return try visitor. visitCallIndirect ( typeIndex: typeIndex, tableIndex: tableIndex)
355
- }
356
- public mutating func visitDrop( ) throws {
357
- trace ( . drop)
358
- return try visitor. visitDrop ( )
359
- }
360
- public mutating func visitSelect( ) throws {
361
- trace ( . select)
362
- return try visitor. visitSelect ( )
363
- }
364
- public mutating func visitTypedSelect( type: ValueType ) throws {
365
- trace ( . typedSelect( type: type) )
366
- return try visitor. visitTypedSelect ( type: type)
367
- }
368
- public mutating func visitLocalGet( localIndex: UInt32 ) throws {
369
- trace ( . localGet( localIndex: localIndex) )
370
- return try visitor. visitLocalGet ( localIndex: localIndex)
371
- }
372
- public mutating func visitLocalSet( localIndex: UInt32 ) throws {
373
- trace ( . localSet( localIndex: localIndex) )
374
- return try visitor. visitLocalSet ( localIndex: localIndex)
375
- }
376
- public mutating func visitLocalTee( localIndex: UInt32 ) throws {
377
- trace ( . localTee( localIndex: localIndex) )
378
- return try visitor. visitLocalTee ( localIndex: localIndex)
379
- }
380
- public mutating func visitGlobalGet( globalIndex: UInt32 ) throws {
381
- trace ( . globalGet( globalIndex: globalIndex) )
382
- return try visitor. visitGlobalGet ( globalIndex: globalIndex)
383
- }
384
- public mutating func visitGlobalSet( globalIndex: UInt32 ) throws {
385
- trace ( . globalSet( globalIndex: globalIndex) )
386
- return try visitor. visitGlobalSet ( globalIndex: globalIndex)
387
- }
388
- public mutating func visitLoad( _ load: Instruction . Load , memarg: MemArg ) throws {
389
- trace ( . load( load, memarg: memarg) )
390
- return try visitor. visitLoad ( load, memarg: memarg)
391
- }
392
- public mutating func visitStore( _ store: Instruction . Store , memarg: MemArg ) throws {
393
- trace ( . store( store, memarg: memarg) )
394
- return try visitor. visitStore ( store, memarg: memarg)
395
- }
396
- public mutating func visitMemorySize( memory: UInt32 ) throws {
397
- trace ( . memorySize( memory: memory) )
398
- return try visitor. visitMemorySize ( memory: memory)
399
- }
400
- public mutating func visitMemoryGrow( memory: UInt32 ) throws {
401
- trace ( . memoryGrow( memory: memory) )
402
- return try visitor. visitMemoryGrow ( memory: memory)
403
- }
404
- public mutating func visitI32Const( value: Int32 ) throws {
405
- trace ( . i32Const( value: value) )
406
- return try visitor. visitI32Const ( value: value)
407
- }
408
- public mutating func visitI64Const( value: Int64 ) throws {
409
- trace ( . i64Const( value: value) )
410
- return try visitor. visitI64Const ( value: value)
411
- }
412
- public mutating func visitF32Const( value: IEEE754 . Float32 ) throws {
413
- trace ( . f32Const( value: value) )
414
- return try visitor. visitF32Const ( value: value)
415
- }
416
- public mutating func visitF64Const( value: IEEE754 . Float64 ) throws {
417
- trace ( . f64Const( value: value) )
418
- return try visitor. visitF64Const ( value: value)
419
- }
420
- public mutating func visitRefNull( type: ReferenceType ) throws {
421
- trace ( . refNull( type: type) )
422
- return try visitor. visitRefNull ( type: type)
423
- }
424
- public mutating func visitRefIsNull( ) throws {
425
- trace ( . refIsNull)
426
- return try visitor. visitRefIsNull ( )
427
- }
428
- public mutating func visitRefFunc( functionIndex: UInt32 ) throws {
429
- trace ( . refFunc( functionIndex: functionIndex) )
430
- return try visitor. visitRefFunc ( functionIndex: functionIndex)
431
- }
432
- public mutating func visitI32Eqz( ) throws {
433
- trace ( . i32Eqz)
434
- return try visitor. visitI32Eqz ( )
435
- }
436
- public mutating func visitCmp( _ cmp: Instruction . Cmp ) throws {
437
- trace ( . cmp( cmp) )
438
- return try visitor. visitCmp ( cmp)
439
- }
440
- public mutating func visitI64Eqz( ) throws {
441
- trace ( . i64Eqz)
442
- return try visitor. visitI64Eqz ( )
443
- }
444
- public mutating func visitUnary( _ unary: Instruction . Unary ) throws {
445
- trace ( . unary( unary) )
446
- return try visitor. visitUnary ( unary)
447
- }
448
- public mutating func visitBinary( _ binary: Instruction . Binary ) throws {
449
- trace ( . binary( binary) )
450
- return try visitor. visitBinary ( binary)
451
- }
452
- public mutating func visitConversion( _ conversion: Instruction . Conversion ) throws {
453
- trace ( . conversion( conversion) )
454
- return try visitor. visitConversion ( conversion)
455
- }
456
- public mutating func visitMemoryInit( dataIndex: UInt32 ) throws {
457
- trace ( . memoryInit( dataIndex: dataIndex) )
458
- return try visitor. visitMemoryInit ( dataIndex: dataIndex)
459
- }
460
- public mutating func visitDataDrop( dataIndex: UInt32 ) throws {
461
- trace ( . dataDrop( dataIndex: dataIndex) )
462
- return try visitor. visitDataDrop ( dataIndex: dataIndex)
463
- }
464
- public mutating func visitMemoryCopy( dstMem: UInt32 , srcMem: UInt32 ) throws {
465
- trace ( . memoryCopy( dstMem: dstMem, srcMem: srcMem) )
466
- return try visitor. visitMemoryCopy ( dstMem: dstMem, srcMem: srcMem)
467
- }
468
- public mutating func visitMemoryFill( memory: UInt32 ) throws {
469
- trace ( . memoryFill( memory: memory) )
470
- return try visitor. visitMemoryFill ( memory: memory)
471
- }
472
- public mutating func visitTableInit( elemIndex: UInt32 , table: UInt32 ) throws {
473
- trace ( . tableInit( elemIndex: elemIndex, table: table) )
474
- return try visitor. visitTableInit ( elemIndex: elemIndex, table: table)
475
- }
476
- public mutating func visitElemDrop( elemIndex: UInt32 ) throws {
477
- trace ( . elemDrop( elemIndex: elemIndex) )
478
- return try visitor. visitElemDrop ( elemIndex: elemIndex)
479
- }
480
- public mutating func visitTableCopy( dstTable: UInt32 , srcTable: UInt32 ) throws {
481
- trace ( . tableCopy( dstTable: dstTable, srcTable: srcTable) )
482
- return try visitor. visitTableCopy ( dstTable: dstTable, srcTable: srcTable)
483
- }
484
- public mutating func visitTableFill( table: UInt32 ) throws {
485
- trace ( . tableFill( table: table) )
486
- return try visitor. visitTableFill ( table: table)
487
- }
488
- public mutating func visitTableGet( table: UInt32 ) throws {
489
- trace ( . tableGet( table: table) )
490
- return try visitor. visitTableGet ( table: table)
491
- }
492
- public mutating func visitTableSet( table: UInt32 ) throws {
493
- trace ( . tableSet( table: table) )
494
- return try visitor. visitTableSet ( table: table)
495
- }
496
- public mutating func visitTableGrow( table: UInt32 ) throws {
497
- trace ( . tableGrow( table: table) )
498
- return try visitor. visitTableGrow ( table: table)
499
- }
500
- public mutating func visitTableSize( table: UInt32 ) throws {
501
- trace ( . tableSize( table: table) )
502
- return try visitor. visitTableSize ( table: table)
503
- }
504
- }
505
-
506
288
/// A visitor for WebAssembly instructions.
507
289
///
508
290
/// The visitor pattern is used while parsing WebAssembly expressions to allow for easy extensibility.
0 commit comments