xref: /freebsd/contrib/llvm-project/llvm/utils/TableGen/Common/Types.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 //===- Types.cpp - Helper for the selection of C++ data types. ------------===//
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 #include "Types.h"
10 
11 // For LLVM_ATTRIBUTE_UNUSED
12 #include "llvm/Support/Compiler.h"
13 
14 #include <cassert>
15 
16 using namespace llvm;
17 
18 const char *
getMinimalTypeForRange(uint64_t Range,unsigned MaxSize LLVM_ATTRIBUTE_UNUSED)19 llvm::getMinimalTypeForRange(uint64_t Range,
20                              unsigned MaxSize LLVM_ATTRIBUTE_UNUSED) {
21   // TODO: The original callers only used 32 and 64 so these are the only
22   //       values permitted. Rather than widen the supported values we should
23   //       allow 64 for the callers that currently use 32 and remove the
24   //       argument altogether.
25   assert((MaxSize == 32 || MaxSize == 64) && "Unexpected size");
26   assert(MaxSize <= 64 && "Unexpected size");
27   assert(((MaxSize > 32) ? Range <= 0xFFFFFFFFFFFFFFFFULL
28                          : Range <= 0xFFFFFFFFULL) &&
29          "Enum too large");
30 
31   if (Range > 0xFFFFFFFFULL)
32     return "uint64_t";
33   if (Range > 0xFFFF)
34     return "uint32_t";
35   if (Range > 0xFF)
36     return "uint16_t";
37   return "uint8_t";
38 }
39