| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#ifndef jit_ABIFunctionType_h |
| 8 |
#define jit_ABIFunctionType_h |
| 9 |
|
| 10 |
#include <initializer_list> |
| 11 |
#include <stdint.h> |
| 12 |
|
| 13 |
#include "jit/ABIFunctionTypeGenerated.h" |
| 14 |
|
| 15 |
namespace js { |
| 16 |
namespace jit { |
| 17 |
|
| 18 |
enum class ABIType { |
| 19 |
// A pointer sized integer |
| 20 |
General = 0x1, |
| 21 |
// A 32-bit integer |
| 22 |
Int32 = 0x2, |
| 23 |
// A 64-bit integer |
| 24 |
Int64 = 0x3, |
| 25 |
// A 32-bit floating point number |
| 26 |
Float32 = 0x4, |
| 27 |
// A 64-bit floating point number |
| 28 |
Float64 = 0x5, |
| 29 |
// No result |
| 30 |
Void = 0x6, |
| 31 |
}; |
| 32 |
|
| 33 |
const size_t ABITypeArgShift = 0x3; |
| 34 |
const size_t ABITypeArgMask = (1 << ABITypeArgShift) - 1; |
| 35 |
|
| 36 |
namespace detail { |
| 37 |
|
| 38 |
static constexpr uint64_t MakeABIFunctionType( |
| 39 |
ABIType ret, std::initializer_list<ABIType> args) { |
| 40 |
uint64_t abiType = 0; |
| 41 |
for (auto arg : args) { |
| 42 |
abiType <<= ABITypeArgShift; |
| 43 |
abiType |= (uint64_t)arg; |
| 44 |
} |
| 45 |
abiType <<= ABITypeArgShift; |
| 46 |
abiType |= (uint64_t)ret; |
| 47 |
return abiType; |
| 48 |
} |
| 49 |
|
| 50 |
} // namespace detail |
| 51 |
|
| 52 |
enum ABIFunctionType : uint64_t { |
| 53 |
// The enum must be explicitly typed to avoid UB: some validly constructed |
| 54 |
// members are larger than any explicitly declared members. |
| 55 |
ABI_FUNCTION_TYPE_ENUM |
| 56 |
}; |
| 57 |
|
| 58 |
static constexpr ABIFunctionType MakeABIFunctionType( |
| 59 |
ABIType ret, std::initializer_list<ABIType> args) { |
| 60 |
return ABIFunctionType(detail::MakeABIFunctionType(ret, args)); |
| 61 |
} |
| 62 |
|
| 63 |
} // namespace jit |
| 64 |
} // namespace js |
| 65 |
|
| 66 |
#endif /* jit_ABIFunctionType_h */ |