@@ -5,9 +5,16 @@ import SystemPackage
55import Foundation
66
77protocol Engine {
8+ var name : String { get }
89 func run( moduleBytes: [ UInt8 ] ) throws -> ExecResult
910}
1011
12+ extension Engine {
13+ var name : String {
14+ return String ( describing: type ( of: self ) )
15+ }
16+ }
17+
1118struct ExecResult {
1219 let values : [ Value ] ?
1320 let trap : String ?
@@ -17,30 +24,32 @@ struct ExecResult {
1724 return trap != nil
1825 }
1926
20- static func check( _ lhs: ExecResult , _ rhs: ExecResult ) -> Bool {
27+ static func check( _ lhs: ( result: ExecResult , name: String ) , _ rhs: ( result: ExecResult , name: String ) ) -> Bool {
28+ let ( lhsName, rhsName) = ( lhs. name, rhs. name)
29+ let ( lhs, rhs) = ( lhs. result, rhs. result)
2130 guard lhs. hasTrap == rhs. hasTrap else {
22- print ( " Traps do not match: \( lhs. trap ?? " nil " ) vs \( rhs. trap ?? " nil " ) " )
31+ print ( " Traps do not match: \( lhsName ) : \( lhs. trap ?? " nil " ) vs \( rhsName ) : \( rhs. trap ?? " nil " ) " )
2332 return false
2433 }
2534 guard lhs. memory == rhs. memory else {
2635 guard lhs. memory? . count == rhs. memory? . count else {
27- print ( " Memory sizes do not match: \( lhs. memory? . count ?? 0 ) vs \( rhs. memory? . count ?? 0 ) " )
36+ print ( " Memory sizes do not match: \( lhsName ) : \( lhs. memory? . count ?? 0 ) vs \( rhsName ) : \( rhs. memory? . count ?? 0 ) " )
2837 return false
2938 }
3039 for (i, ( lhsByte, rhsByte) ) in zip ( lhs. memory ?? [ ] , rhs. memory ?? [ ] ) . enumerated ( ) {
3140 if lhsByte != rhsByte {
32- print ( " Memory byte \( i) does not match: \( lhsByte) vs \( rhsByte) " )
41+ print ( " Memory byte \( i) does not match: \( lhsName ) : \( lhsByte) vs \( rhsName ) : \( rhsByte) " )
3342 }
3443 }
3544 return false
3645 }
3746 guard lhs. values? . count == rhs. values? . count else {
38- print ( " Value counts do not match: \( lhs. values? . count ?? 0 ) vs \( rhs. values? . count ?? 0 ) " )
47+ print ( " Value counts do not match: \( lhsName ) : \( lhs. values? . count ?? 0 ) vs \( rhsName ) : \( rhs. values? . count ?? 0 ) " )
3948 return false
4049 }
4150 for (i, ( lhsValue, rhsValue) ) in zip ( lhs. values ?? [ ] , rhs. values ?? [ ] ) . enumerated ( ) {
4251 if !Value. bitwiseEqual ( lhsValue, rhsValue) {
43- print ( " Value \( i) does not match: \( lhsValue) vs \( rhsValue) " )
52+ print ( " Value \( i) does not match: \( lhsName ) : \( lhsValue) vs \( rhsName ) : \( rhsValue) " )
4453 return false
4554 }
4655 }
@@ -90,6 +99,7 @@ extension wasm_name_t {
9099}
91100
92101struct WasmKitEngine : Engine {
102+ var name : String { return " wasmkit " }
93103 func run( moduleBytes: [ UInt8 ] ) throws -> ExecResult {
94104 let module = try WasmKit . parseWasm ( bytes: moduleBytes)
95105 let engine = WasmKit . Engine ( )
@@ -127,6 +137,7 @@ struct WasmKitEngine: Engine {
127137}
128138
129139struct ReferenceEngine : Engine {
140+ var name : String { return " reference " }
130141 func run( moduleBytes: [ UInt8 ] ) throws -> ExecResult {
131142 return try moduleBytes. withUnsafeBytes { ( module: UnsafeRawBufferPointer ) -> ExecResult in
132143 try run ( module: module)
@@ -275,7 +286,7 @@ struct ReferenceEngine: Engine {
275286 } else {
276287 moduleBytes = try Array ( Data ( contentsOf: URL ( fileURLWithPath: moduleFile) ) )
277288 }
278- let results = try engines. map { try $0. run ( moduleBytes: moduleBytes) }
289+ let results = try engines. map { try ( $0. run ( moduleBytes: moduleBytes) , $0 . name ) }
279290 guard results. count > 1 else {
280291 throw ExecError ( " Expected at least two engines " )
281292 }
0 commit comments