Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:22

0001 //===- BitCodes.h - Enum values for the bitstream format --------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This header defines bitstream enum values.
0010 //
0011 // The enum values defined in this file should be considered permanent.  If
0012 // new features are added, they should have values added at the end of the
0013 // respective lists.
0014 //
0015 //===----------------------------------------------------------------------===//
0016 
0017 #ifndef LLVM_BITSTREAM_BITCODES_H
0018 #define LLVM_BITSTREAM_BITCODES_H
0019 
0020 #include "llvm/ADT/SmallVector.h"
0021 #include "llvm/ADT/StringExtras.h"
0022 #include "llvm/Bitstream/BitCodeEnums.h"
0023 #include "llvm/Support/DataTypes.h"
0024 #include "llvm/Support/ErrorHandling.h"
0025 #include <cassert>
0026 
0027 namespace llvm {
0028 /// BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
0029 /// This is actually a union of two different things:
0030 ///   1. It could be a literal integer value ("the operand is always 17").
0031 ///   2. It could be an encoding specification ("this operand encoded like so").
0032 ///
0033 class BitCodeAbbrevOp {
0034   uint64_t Val;           // A literal value or data for an encoding.
0035   bool IsLiteral : 1;     // Indicate whether this is a literal value or not.
0036   unsigned Enc   : 3;     // The encoding to use.
0037 public:
0038   enum Encoding {
0039     Fixed = 1,  // A fixed width field, Val specifies number of bits.
0040     VBR   = 2,  // A VBR field where Val specifies the width of each chunk.
0041     Array = 3,  // A sequence of fields, next field species elt encoding.
0042     Char6 = 4,  // A 6-bit fixed field which maps to [a-zA-Z0-9._].
0043     Blob  = 5   // 32-bit aligned array of 8-bit characters.
0044   };
0045 
0046   static bool isValidEncoding(uint64_t E) {
0047     return E >= 1 && E <= 5;
0048   }
0049 
0050   explicit BitCodeAbbrevOp(uint64_t V) :  Val(V), IsLiteral(true) {}
0051   explicit BitCodeAbbrevOp(Encoding E, uint64_t Data = 0)
0052     : Val(Data), IsLiteral(false), Enc(E) {}
0053 
0054   bool isLiteral() const  { return IsLiteral; }
0055   bool isEncoding() const { return !IsLiteral; }
0056 
0057   // Accessors for literals.
0058   uint64_t getLiteralValue() const { assert(isLiteral()); return Val; }
0059 
0060   // Accessors for encoding info.
0061   Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; }
0062   uint64_t getEncodingData() const {
0063     assert(isEncoding() && hasEncodingData());
0064     return Val;
0065   }
0066 
0067   bool hasEncodingData() const { return hasEncodingData(getEncoding()); }
0068   static bool hasEncodingData(Encoding E) {
0069     switch (E) {
0070     case Fixed:
0071     case VBR:
0072       return true;
0073     case Array:
0074     case Char6:
0075     case Blob:
0076       return false;
0077     }
0078     report_fatal_error("Invalid encoding");
0079   }
0080 
0081   /// isChar6 - Return true if this character is legal in the Char6 encoding.
0082   static bool isChar6(char C) { return isAlnum(C) || C == '.' || C == '_'; }
0083   static unsigned EncodeChar6(char C) {
0084     if (C >= 'a' && C <= 'z') return C-'a';
0085     if (C >= 'A' && C <= 'Z') return C-'A'+26;
0086     if (C >= '0' && C <= '9') return C-'0'+26+26;
0087     if (C == '.')             return 62;
0088     if (C == '_')             return 63;
0089     llvm_unreachable("Not a value Char6 character!");
0090   }
0091 
0092   static char DecodeChar6(unsigned V) {
0093     assert((V & ~63) == 0 && "Not a Char6 encoded character!");
0094     return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._"
0095         [V];
0096   }
0097 
0098 };
0099 
0100 /// BitCodeAbbrev - This class represents an abbreviation record.  An
0101 /// abbreviation allows a complex record that has redundancy to be stored in a
0102 /// specialized format instead of the fully-general, fully-vbr, format.
0103 class BitCodeAbbrev {
0104   SmallVector<BitCodeAbbrevOp, 32> OperandList;
0105 
0106 public:
0107   BitCodeAbbrev() = default;
0108 
0109   explicit BitCodeAbbrev(std::initializer_list<BitCodeAbbrevOp> OperandList)
0110       : OperandList(OperandList) {}
0111 
0112   unsigned getNumOperandInfos() const {
0113     return static_cast<unsigned>(OperandList.size());
0114   }
0115   const BitCodeAbbrevOp &getOperandInfo(unsigned N) const {
0116     return OperandList[N];
0117   }
0118 
0119   void Add(const BitCodeAbbrevOp &OpInfo) {
0120     OperandList.push_back(OpInfo);
0121   }
0122 };
0123 } // namespace llvm
0124 
0125 #endif