|
| 1 | +//===------- FixedPoint.h - Fixedd point types for the VM -------*- C++ -*-===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#ifndef LLVM_CLANG_AST_INTERP_FIXED_POINT_H |
| 10 | +#define LLVM_CLANG_AST_INTERP_FIXED_POINT_H |
| 11 | + |
| 12 | +#include "clang/AST/APValue.h" |
| 13 | +#include "clang/AST/ComparisonCategories.h" |
| 14 | +#include "llvm/ADT/APFixedPoint.h" |
| 15 | + |
| 16 | +namespace clang { |
| 17 | +namespace interp { |
| 18 | + |
| 19 | +using APInt = llvm::APInt; |
| 20 | + |
| 21 | +/// Wrapper around fixed point types. |
| 22 | +class FixedPoint final { |
| 23 | +private: |
| 24 | + llvm::APFixedPoint V; |
| 25 | + |
| 26 | +public: |
| 27 | + FixedPoint(APInt V) |
| 28 | + : V(V, |
| 29 | + llvm::FixedPointSemantics(V.getBitWidth(), 0, false, false, false)) {} |
| 30 | + // This needs to be default-constructible so llvm::endian::read works. |
| 31 | + FixedPoint() |
| 32 | + : V(APInt(0, 0ULL, false), |
| 33 | + llvm::FixedPointSemantics(0, 0, false, false, false)) {} |
| 34 | + |
| 35 | + operator bool() const { return V.getBoolValue(); } |
| 36 | + template <typename Ty, typename = std::enable_if_t<std::is_integral_v<Ty>>> |
| 37 | + explicit operator Ty() const { |
| 38 | + // FIXME |
| 39 | + return 0; |
| 40 | + } |
| 41 | + |
| 42 | + void print(llvm::raw_ostream &OS) const { OS << V; } |
| 43 | + |
| 44 | + APValue toAPValue(const ASTContext &) const { return APValue(V); } |
| 45 | + |
| 46 | + ComparisonCategoryResult compare(const FixedPoint &Other) const { |
| 47 | + if (Other.V == V) |
| 48 | + return ComparisonCategoryResult::Equal; |
| 49 | + return ComparisonCategoryResult::Unordered; |
| 50 | + } |
| 51 | +}; |
| 52 | + |
| 53 | +inline FixedPoint getSwappedBytes(FixedPoint F) { return F; } |
| 54 | + |
| 55 | +inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, FixedPoint F) { |
| 56 | + F.print(OS); |
| 57 | + return OS; |
| 58 | +} |
| 59 | + |
| 60 | +} // namespace interp |
| 61 | +} // namespace clang |
| 62 | + |
| 63 | +#endif |
0 commit comments