]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/MC/MCInstrInfo.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / MC / MCInstrInfo.h
1 //===-- llvm/MC/MCInstrInfo.h - Target Instruction Info ---------*- 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 // This file describes the target machine instruction set.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_MC_MCINSTRINFO_H
14 #define LLVM_MC_MCINSTRINFO_H
15
16 #include "llvm/MC/MCInstrDesc.h"
17 #include <cassert>
18
19 namespace llvm {
20
21 //---------------------------------------------------------------------------
22 /// Interface to description of machine instruction set.
23 class MCInstrInfo {
24   const MCInstrDesc *Desc;          // Raw array to allow static init'n
25   const unsigned *InstrNameIndices; // Array for name indices in InstrNameData
26   const char *InstrNameData;        // Instruction name string pool
27   unsigned NumOpcodes;              // Number of entries in the desc array
28
29 public:
30   /// Initialize MCInstrInfo, called by TableGen auto-generated routines.
31   /// *DO NOT USE*.
32   void InitMCInstrInfo(const MCInstrDesc *D, const unsigned *NI, const char *ND,
33                        unsigned NO) {
34     Desc = D;
35     InstrNameIndices = NI;
36     InstrNameData = ND;
37     NumOpcodes = NO;
38   }
39
40   unsigned getNumOpcodes() const { return NumOpcodes; }
41
42   /// Return the machine instruction descriptor that corresponds to the
43   /// specified instruction opcode.
44   const MCInstrDesc &get(unsigned Opcode) const {
45     assert(Opcode < NumOpcodes && "Invalid opcode!");
46     return Desc[Opcode];
47   }
48
49   /// Returns the name for the instructions with the given opcode.
50   StringRef getName(unsigned Opcode) const {
51     assert(Opcode < NumOpcodes && "Invalid opcode!");
52     return StringRef(&InstrNameData[InstrNameIndices[Opcode]]);
53   }
54 };
55
56 } // End llvm namespace
57
58 #endif