|
| 1 | +/* |
| 2 | + * Copyright 2023 WebAssembly Community Group participants |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#ifndef wasm_analysis_lattices_int_h |
| 18 | +#define wasm_analysis_lattices_int_h |
| 19 | + |
| 20 | +#include <cstdint> |
| 21 | +#include <limits> |
| 22 | + |
| 23 | +#include "../lattice.h" |
| 24 | + |
| 25 | +namespace wasm::analysis { |
| 26 | + |
| 27 | +#if __cplusplus >= 202002L |
| 28 | +template<std::integral T> |
| 29 | +#else |
| 30 | +template<typename T> |
| 31 | +#endif |
| 32 | +struct Integer { |
| 33 | + using Element = T; |
| 34 | + Element getBottom() const noexcept { return std::numeric_limits<T>::min(); } |
| 35 | + LatticeComparison compare(Element a, Element b) const noexcept { |
| 36 | + return a > b ? GREATER : a == b ? EQUAL : LESS; |
| 37 | + } |
| 38 | + bool join(Element& self, Element other) const noexcept { |
| 39 | + if (self < other) { |
| 40 | + self = other; |
| 41 | + return true; |
| 42 | + } |
| 43 | + return false; |
| 44 | + } |
| 45 | +}; |
| 46 | + |
| 47 | +using Int32 = Integer<int32_t>; |
| 48 | +using UInt32 = Integer<uint32_t>; |
| 49 | +using Int64 = Integer<int64_t>; |
| 50 | +using UInt64 = Integer<uint64_t>; |
| 51 | + |
| 52 | +#if __cplusplus >= 202002L |
| 53 | +static_assert(Lattice<Int32>); |
| 54 | +static_assert(Lattice<Int64>); |
| 55 | +static_assert(Lattice<UInt32>); |
| 56 | +static_assert(Lattice<UInt64>); |
| 57 | +#endif // __cplusplus >= 202002L |
| 58 | + |
| 59 | +} // namespace wasm::analysis |
| 60 | + |
| 61 | +#endif // wasm_analysis_lattices_int_h |
0 commit comments