[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 11 08:36:56 PDT 2023


================
@@ -0,0 +1,253 @@
+//===--- Integral.h - Wrapper for numeric types for the VM ------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines the VM types and helpers operating on types.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H
+#define LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H
+
+#include "clang/AST/APValue.h"
+#include "clang/AST/ComparisonCategories.h"
+#include "llvm/ADT/APSInt.h"
+#include "llvm/Support/MathExtras.h"
+#include "llvm/Support/raw_ostream.h"
+#include <cstddef>
+#include <cstdint>
+
+#include "Primitives.h"
+
+namespace clang {
+namespace interp {
+
+using APInt = llvm::APInt;
+using APSInt = llvm::APSInt;
+template <unsigned Bits, bool Signed> class Integral;
+class Boolean;
+
+template <bool Signed> class IntegralAP final {
+public:
+  APSInt V;
+
+public:
+  using AsUnsigned = IntegralAP<false>;
+
+  template <typename T>
+  IntegralAP(T Value) : V(APInt(sizeof(T) * 8, Value, std::is_signed_v<T>)) {}
+
+  IntegralAP(APInt V) : V(V) {}
+  IntegralAP(APSInt V) : V(V) {}
+  IntegralAP(bool b) : V(APInt(8, b, Signed)) {}
----------------
cor3ntin wrote:

should you make this constructor explicit?

https://github.com/llvm/llvm-project/pull/65844


More information about the cfe-commits mailing list