| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | //================================================================================================== | ||
| 2 | /* | ||
| 3 | SPY - C++ Informations Broker | ||
| 4 | Copyright : SPY Project Contributors | ||
| 5 | SPDX-License-Identifier: BSL-1.0 | ||
| 6 | */ | ||
| 7 | //================================================================================================== | ||
| 8 | #pragma once | ||
| 9 | |||
| 10 | namespace spy::_ | ||
| 11 | { | ||
| 12 | template<int Short, int Integer, int Long, int Pointer> struct data_model_info | ||
| 13 | { | ||
| 14 | inline constexpr explicit operator bool() const noexcept; | ||
| 15 | |||
| 16 | template<int Short2, int Integer2, int Long2, int Pointer2> | ||
| 17 | constexpr bool | ||
| 18 | 12 | operator==(data_model_info<Short2, Integer2, Long2, Pointer2> const&) const noexcept | |
| 19 | { | ||
| 20 | 12 | return (Short == Short2) && (Integer == Integer2) && (Long == Long2) && (Pointer == Pointer2); | |
| 21 | } | ||
| 22 | }; | ||
| 23 | |||
| 24 | template<_::stream OS, int Short, int Integer, int Long, int Pointer> | ||
| 25 | 1 | auto& operator<<(OS& os, data_model_info<Short, Integer, Long, Pointer> const&) | |
| 26 | { | ||
| 27 | if constexpr(Pointer == 4 && Integer == 4) return os << "ILP32"; | ||
| 28 | else if constexpr(Pointer == 4 && Integer == 2) return os << "LP32"; | ||
| 29 | else if constexpr(Pointer == 8 && Long == 8 && Integer == 8 && Short == 8) | ||
| 30 | return os << "IntegerLP64"; | ||
| 31 | else if constexpr(Pointer == 8 && Short == 8 && Integer == 8 && Short == 2) | ||
| 32 | return os << "ILP64"; | ||
| 33 | else if constexpr(Pointer == 8 && Long == 4 && Integer == 8 && Short == 2) return os << "LLP64"; | ||
| 34 | 1 | else if constexpr(Pointer == 8 && Long == 8 && Integer == 4 && Short == 2) return os << "LP64"; | |
| 35 | else return os << "Unknown data model"; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | namespace spy | ||
| 40 | { | ||
| 41 | using data_model_type = | ||
| 42 | _::data_model_info<sizeof(short), sizeof(int), sizeof(long), sizeof(void*)>; | ||
| 43 | |||
| 44 | //================================================================================================ | ||
| 45 | //! @ingroup spy_platform | ||
| 46 | //! @brief Data Model reporting value | ||
| 47 | //! | ||
| 48 | //! The `spy::data_model` object can be compared to any other data model related value to verify | ||
| 49 | //! if the code being compiled for a specific data model | ||
| 50 | //! | ||
| 51 | //! Additionally, any of the data model related value are convertible to `bool`. They evaluates to | ||
| 52 | //! `true` if they matches the correct data model currently used. | ||
| 53 | //! | ||
| 54 | //! @groupheader{Supported Value} | ||
| 55 | //! | ||
| 56 | //! Name | Data Model | ||
| 57 | //! --------------| ------------- | ||
| 58 | //! `spy::ilp32` | ILP32 | ||
| 59 | //! `spy::lp32` | LP32 | ||
| 60 | //! `spy::silp64` | SILP64 | ||
| 61 | //! `spy::ilp64` | ILP64 | ||
| 62 | //! `spy::llp64` | LLP64 | ||
| 63 | //! `spy::lp64` | LP64 | ||
| 64 | //! | ||
| 65 | //! @groupheader{Example} | ||
| 66 | //! @godbolt{samples/data_model.cpp} | ||
| 67 | //================================================================================================ | ||
| 68 | constexpr inline auto data_model = data_model_type {}; | ||
| 69 | } | ||
| 70 | |||
| 71 | namespace spy::_ | ||
| 72 | { | ||
| 73 | template<int Short, int Integer, int Long, int Pointer> | ||
| 74 | inline constexpr data_model_info<Short, Integer, Long, Pointer>::operator bool() const noexcept | ||
| 75 | { | ||
| 76 | return spy::data_model == *this; | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | namespace spy | ||
| 81 | { | ||
| 82 | //================================================================================================ | ||
| 83 | // Data model detector stand-alone instances | ||
| 84 | //================================================================================================ | ||
| 85 | constexpr inline auto ilp32_ = _::data_model_info<2, 4, sizeof(long), 4> {}; | ||
| 86 | constexpr inline auto lp32_ = _::data_model_info<2, 2, sizeof(long), 4> {}; | ||
| 87 | constexpr inline auto silp64_ = _::data_model_info<8, 8, 8, 8> {}; | ||
| 88 | constexpr inline auto ilp64_ = _::data_model_info<2, 8, 8, 8> {}; | ||
| 89 | constexpr inline auto llp64_ = _::data_model_info<2, 8, 4, 8> {}; | ||
| 90 | constexpr inline auto lp64_ = _::data_model_info<2, 4, 8, 8> {}; | ||
| 91 | } | ||
| 92 |