1 // Copyright 2015 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef TEST_SIGNATURES_H 6 #define TEST_SIGNATURES_H 7 8 #include "src/signature.h" 9 #include "src/wasm/wasm-opcodes.h" 10 11 namespace v8 { 12 namespace internal { 13 namespace wasm { 14 15 typedef Signature<LocalType> FunctionSig; 16 17 // A helper class with many useful signatures in order to simplify tests. 18 class TestSignatures { 19 public: TestSignatures()20 TestSignatures() 21 : sig_i_v(1, 0, kIntTypes4), 22 sig_i_i(1, 1, kIntTypes4), 23 sig_i_ii(1, 2, kIntTypes4), 24 sig_i_iii(1, 3, kIntTypes4), 25 sig_i_f(1, 1, kIntFloatTypes4), 26 sig_i_ff(1, 2, kIntFloatTypes4), 27 sig_i_d(1, 1, kIntDoubleTypes4), 28 sig_i_dd(1, 2, kIntDoubleTypes4), 29 sig_l_v(1, 0, kLongTypes4), 30 sig_l_l(1, 1, kLongTypes4), 31 sig_l_ll(1, 2, kLongTypes4), 32 sig_i_ll(1, 2, kIntLongTypes4), 33 sig_f_ff(1, 2, kFloatTypes4), 34 sig_d_dd(1, 2, kDoubleTypes4), 35 sig_v_v(0, 0, kIntTypes4), 36 sig_v_i(0, 1, kIntTypes4), 37 sig_v_ii(0, 2, kIntTypes4), 38 sig_v_iii(0, 3, kIntTypes4) { 39 // I used C++ and you won't believe what happened next.... 40 for (int i = 0; i < 4; i++) kIntTypes4[i] = kAstI32; 41 for (int i = 0; i < 4; i++) kLongTypes4[i] = kAstI64; 42 for (int i = 0; i < 4; i++) kFloatTypes4[i] = kAstF32; 43 for (int i = 0; i < 4; i++) kDoubleTypes4[i] = kAstF64; 44 for (int i = 0; i < 4; i++) kIntLongTypes4[i] = kAstI64; 45 for (int i = 0; i < 4; i++) kIntFloatTypes4[i] = kAstF32; 46 for (int i = 0; i < 4; i++) kIntDoubleTypes4[i] = kAstF64; 47 kIntLongTypes4[0] = kAstI32; 48 kIntFloatTypes4[0] = kAstI32; 49 kIntDoubleTypes4[0] = kAstI32; 50 } 51 i_v()52 FunctionSig* i_v() { return &sig_i_v; } i_i()53 FunctionSig* i_i() { return &sig_i_i; } i_ii()54 FunctionSig* i_ii() { return &sig_i_ii; } i_iii()55 FunctionSig* i_iii() { return &sig_i_iii; } 56 i_f()57 FunctionSig* i_f() { return &sig_i_f; } i_ff()58 FunctionSig* i_ff() { return &sig_i_ff; } i_d()59 FunctionSig* i_d() { return &sig_i_d; } i_dd()60 FunctionSig* i_dd() { return &sig_i_dd; } 61 l_v()62 FunctionSig* l_v() { return &sig_l_v; } l_l()63 FunctionSig* l_l() { return &sig_l_l; } l_ll()64 FunctionSig* l_ll() { return &sig_l_ll; } i_ll()65 FunctionSig* i_ll() { return &sig_i_ll; } 66 f_ff()67 FunctionSig* f_ff() { return &sig_f_ff; } d_dd()68 FunctionSig* d_dd() { return &sig_d_dd; } 69 v_v()70 FunctionSig* v_v() { return &sig_v_v; } v_i()71 FunctionSig* v_i() { return &sig_v_i; } v_ii()72 FunctionSig* v_ii() { return &sig_v_ii; } v_iii()73 FunctionSig* v_iii() { return &sig_v_iii; } 74 many(Zone * zone,LocalType ret,LocalType param,int count)75 FunctionSig* many(Zone* zone, LocalType ret, LocalType param, int count) { 76 FunctionSig::Builder builder(zone, ret == kAstStmt ? 0 : 1, count); 77 if (ret != kAstStmt) builder.AddReturn(ret); 78 for (int i = 0; i < count; i++) { 79 builder.AddParam(param); 80 } 81 return builder.Build(); 82 } 83 84 private: 85 LocalType kIntTypes4[4]; 86 LocalType kLongTypes4[4]; 87 LocalType kFloatTypes4[4]; 88 LocalType kDoubleTypes4[4]; 89 LocalType kIntLongTypes4[4]; 90 LocalType kIntFloatTypes4[4]; 91 LocalType kIntDoubleTypes4[4]; 92 93 FunctionSig sig_i_v; 94 FunctionSig sig_i_i; 95 FunctionSig sig_i_ii; 96 FunctionSig sig_i_iii; 97 98 FunctionSig sig_i_f; 99 FunctionSig sig_i_ff; 100 FunctionSig sig_i_d; 101 FunctionSig sig_i_dd; 102 103 FunctionSig sig_l_v; 104 FunctionSig sig_l_l; 105 FunctionSig sig_l_ll; 106 FunctionSig sig_i_ll; 107 108 FunctionSig sig_f_ff; 109 FunctionSig sig_d_dd; 110 111 FunctionSig sig_v_v; 112 FunctionSig sig_v_i; 113 FunctionSig sig_v_ii; 114 FunctionSig sig_v_iii; 115 }; 116 } // namespace wasm 117 } // namespace internal 118 } // namespace v8 119 120 #endif // TEST_SIGNATURES_H 121