• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
75  private:
76   LocalType kIntTypes4[4];
77   LocalType kLongTypes4[4];
78   LocalType kFloatTypes4[4];
79   LocalType kDoubleTypes4[4];
80   LocalType kIntLongTypes4[4];
81   LocalType kIntFloatTypes4[4];
82   LocalType kIntDoubleTypes4[4];
83 
84   FunctionSig sig_i_v;
85   FunctionSig sig_i_i;
86   FunctionSig sig_i_ii;
87   FunctionSig sig_i_iii;
88 
89   FunctionSig sig_i_f;
90   FunctionSig sig_i_ff;
91   FunctionSig sig_i_d;
92   FunctionSig sig_i_dd;
93 
94   FunctionSig sig_l_v;
95   FunctionSig sig_l_l;
96   FunctionSig sig_l_ll;
97   FunctionSig sig_i_ll;
98 
99   FunctionSig sig_f_ff;
100   FunctionSig sig_d_dd;
101 
102   FunctionSig sig_v_v;
103   FunctionSig sig_v_i;
104   FunctionSig sig_v_ii;
105   FunctionSig sig_v_iii;
106 };
107 }  // namespace wasm
108 }  // namespace internal
109 }  // namespace v8
110 
111 #endif  // TEST_SIGNATURES_H
112