test-signatures.h 5.82 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef TEST_SIGNATURES_H
#define TEST_SIGNATURES_H

8
#include "src/codegen/signature.h"
9
#include "src/wasm/value-type.h"
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include "src/wasm/wasm-opcodes.h"

namespace v8 {
namespace internal {
namespace wasm {

// A helper class with many useful signatures in order to simplify tests.
class TestSignatures {
 public:
  TestSignatures()
      : sig_i_v(1, 0, kIntTypes4),
        sig_i_i(1, 1, kIntTypes4),
        sig_i_ii(1, 2, kIntTypes4),
        sig_i_iii(1, 3, kIntTypes4),
        sig_i_f(1, 1, kIntFloatTypes4),
        sig_i_ff(1, 2, kIntFloatTypes4),
        sig_i_d(1, 1, kIntDoubleTypes4),
        sig_i_dd(1, 2, kIntDoubleTypes4),
28 29 30
        sig_i_e(1, 1, kIntExternRefTypes4),
        sig_i_ee(1, 2, kIntExternRefTypes4),
        sig_i_c(1, 1, kIntFuncRefTypes4),
31
        sig_i_s(1, 1, kIntSimd128Types4),
32 33 34 35
        sig_l_v(1, 0, kLongTypes4),
        sig_l_l(1, 1, kLongTypes4),
        sig_l_ll(1, 2, kLongTypes4),
        sig_i_ll(1, 2, kIntLongTypes4),
36
        sig_f_f(1, 1, kFloatTypes4),
37
        sig_f_ff(1, 2, kFloatTypes4),
38
        sig_d_d(1, 1, kDoubleTypes4),
39
        sig_d_dd(1, 2, kDoubleTypes4),
40 41 42 43
        sig_e_v(1, 0, kExternRefTypes4),
        sig_c_v(1, 0, kFuncTypes4),
        sig_e_e(1, 1, kExternRefTypes4),
        sig_c_c(1, 1, kFuncTypes4),
44 45 46
        sig_v_v(0, 0, kIntTypes4),
        sig_v_i(0, 1, kIntTypes4),
        sig_v_ii(0, 2, kIntTypes4),
47
        sig_v_iii(0, 3, kIntTypes4),
48 49
        sig_v_e(0, 1, kExternRefTypes4),
        sig_v_c(0, 1, kFuncTypes4),
50 51 52
        sig_s_i(1, 1, kSimd128IntTypes4),
        sig_ii_v(2, 0, kIntTypes4),
        sig_iii_v(3, 0, kIntTypes4) {
53
    // I used C++ and you won't believe what happened next....
54 55 56 57
    for (int i = 0; i < 4; i++) kIntTypes4[i] = kWasmI32;
    for (int i = 0; i < 4; i++) kLongTypes4[i] = kWasmI64;
    for (int i = 0; i < 4; i++) kFloatTypes4[i] = kWasmF32;
    for (int i = 0; i < 4; i++) kDoubleTypes4[i] = kWasmF64;
58
    for (int i = 0; i < 4; i++) kExternRefTypes4[i] = kWasmExternRef;
59
    for (int i = 0; i < 4; i++) kFuncTypes4[i] = kWasmFuncRef;
60 61 62
    for (int i = 1; i < 4; i++) kIntLongTypes4[i] = kWasmI64;
    for (int i = 1; i < 4; i++) kIntFloatTypes4[i] = kWasmF32;
    for (int i = 1; i < 4; i++) kIntDoubleTypes4[i] = kWasmF64;
63
    for (int i = 1; i < 4; i++) kIntExternRefTypes4[i] = kWasmExternRef;
64
    for (int i = 1; i < 4; i++) kIntFuncRefTypes4[i] = kWasmFuncRef;
65
    for (int i = 1; i < 4; i++) kIntSimd128Types4[i] = kWasmS128;
66 67 68 69
    for (int i = 0; i < 4; i++) kSimd128IntTypes4[i] = kWasmS128;
    kIntLongTypes4[0] = kWasmI32;
    kIntFloatTypes4[0] = kWasmI32;
    kIntDoubleTypes4[0] = kWasmI32;
70
    kIntExternRefTypes4[0] = kWasmI32;
71
    kIntFuncRefTypes4[0] = kWasmI32;
72
    kIntSimd128Types4[0] = kWasmI32;
73
    kSimd128IntTypes4[1] = kWasmI32;
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
  }

  FunctionSig* i_v() { return &sig_i_v; }
  FunctionSig* i_i() { return &sig_i_i; }
  FunctionSig* i_ii() { return &sig_i_ii; }
  FunctionSig* i_iii() { return &sig_i_iii; }

  FunctionSig* i_f() { return &sig_i_f; }
  FunctionSig* i_ff() { return &sig_i_ff; }
  FunctionSig* i_d() { return &sig_i_d; }
  FunctionSig* i_dd() { return &sig_i_dd; }

  FunctionSig* l_v() { return &sig_l_v; }
  FunctionSig* l_l() { return &sig_l_l; }
  FunctionSig* l_ll() { return &sig_l_ll; }
  FunctionSig* i_ll() { return &sig_i_ll; }
90 91 92
  FunctionSig* i_e() { return &sig_i_e; }
  FunctionSig* i_ee() { return &sig_i_ee; }
  FunctionSig* i_c() { return &sig_i_c; }
93
  FunctionSig* i_s() { return &sig_i_s; }
94

95
  FunctionSig* f_f() { return &sig_f_f; }
96
  FunctionSig* f_ff() { return &sig_f_ff; }
97
  FunctionSig* d_d() { return &sig_d_d; }
98 99
  FunctionSig* d_dd() { return &sig_d_dd; }

100 101 102 103
  FunctionSig* e_v() { return &sig_e_v; }
  FunctionSig* a_v() { return &sig_c_v; }
  FunctionSig* e_e() { return &sig_e_e; }
  FunctionSig* c_c() { return &sig_c_c; }
104

105 106 107 108
  FunctionSig* v_v() { return &sig_v_v; }
  FunctionSig* v_i() { return &sig_v_i; }
  FunctionSig* v_ii() { return &sig_v_ii; }
  FunctionSig* v_iii() { return &sig_v_iii; }
109 110
  FunctionSig* v_e() { return &sig_v_e; }
  FunctionSig* v_c() { return &sig_v_c; }
111
  FunctionSig* s_i() { return &sig_s_i; }
112

113 114 115
  FunctionSig* ii_v() { return &sig_ii_v; }
  FunctionSig* iii_v() { return &sig_iii_v; }

116 117 118
  FunctionSig* many(Zone* zone, ValueType ret, ValueType param, int count) {
    FunctionSig::Builder builder(zone, ret == kWasmStmt ? 0 : 1, count);
    if (ret != kWasmStmt) builder.AddReturn(ret);
119 120 121 122 123 124
    for (int i = 0; i < count; i++) {
      builder.AddParam(param);
    }
    return builder.Build();
  }

125
 private:
126 127 128 129
  ValueType kIntTypes4[4];
  ValueType kLongTypes4[4];
  ValueType kFloatTypes4[4];
  ValueType kDoubleTypes4[4];
130
  ValueType kExternRefTypes4[4];
131
  ValueType kFuncTypes4[4];
132 133 134
  ValueType kIntLongTypes4[4];
  ValueType kIntFloatTypes4[4];
  ValueType kIntDoubleTypes4[4];
135
  ValueType kIntExternRefTypes4[4];
136
  ValueType kIntFuncRefTypes4[4];
137
  ValueType kIntSimd128Types4[4];
138
  ValueType kSimd128IntTypes4[4];
139 140 141 142 143 144 145 146 147 148

  FunctionSig sig_i_v;
  FunctionSig sig_i_i;
  FunctionSig sig_i_ii;
  FunctionSig sig_i_iii;

  FunctionSig sig_i_f;
  FunctionSig sig_i_ff;
  FunctionSig sig_i_d;
  FunctionSig sig_i_dd;
149 150 151
  FunctionSig sig_i_e;
  FunctionSig sig_i_ee;
  FunctionSig sig_i_c;
152
  FunctionSig sig_i_s;
153 154 155 156 157 158

  FunctionSig sig_l_v;
  FunctionSig sig_l_l;
  FunctionSig sig_l_ll;
  FunctionSig sig_i_ll;

159
  FunctionSig sig_f_f;
160
  FunctionSig sig_f_ff;
161
  FunctionSig sig_d_d;
162 163
  FunctionSig sig_d_dd;

164 165 166 167
  FunctionSig sig_e_v;
  FunctionSig sig_c_v;
  FunctionSig sig_e_e;
  FunctionSig sig_c_c;
168

169 170 171 172
  FunctionSig sig_v_v;
  FunctionSig sig_v_i;
  FunctionSig sig_v_ii;
  FunctionSig sig_v_iii;
173 174
  FunctionSig sig_v_e;
  FunctionSig sig_v_c;
175
  FunctionSig sig_s_i;
176 177 178

  FunctionSig sig_ii_v;
  FunctionSig sig_iii_v;
179 180 181 182 183 184
};
}  // namespace wasm
}  // namespace internal
}  // namespace v8

#endif  // TEST_SIGNATURES_H