Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===-- llvm/MC/MCInstrInfo.h - Target Instruction Info ---------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file describes the target machine instruction set. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_MC_MCINSTRINFO_H |
| 15 | #define LLVM_MC_MCINSTRINFO_H |
| 16 | |
| 17 | #include "llvm/MC/MCInstrDesc.h" |
| 18 | #include <cassert> |
| 19 | |
| 20 | namespace llvm { |
| 21 | |
| 22 | //--------------------------------------------------------------------------- |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 23 | /// Interface to description of machine instruction set. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 24 | class MCInstrInfo { |
| 25 | const MCInstrDesc *Desc; // Raw array to allow static init'n |
| 26 | const unsigned *InstrNameIndices; // Array for name indices in InstrNameData |
| 27 | const char *InstrNameData; // Instruction name string pool |
| 28 | unsigned NumOpcodes; // Number of entries in the desc array |
| 29 | |
| 30 | public: |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 31 | /// Initialize MCInstrInfo, called by TableGen auto-generated routines. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 32 | /// *DO NOT USE*. |
| 33 | void InitMCInstrInfo(const MCInstrDesc *D, const unsigned *NI, const char *ND, |
| 34 | unsigned NO) { |
| 35 | Desc = D; |
| 36 | InstrNameIndices = NI; |
| 37 | InstrNameData = ND; |
| 38 | NumOpcodes = NO; |
| 39 | } |
| 40 | |
| 41 | unsigned getNumOpcodes() const { return NumOpcodes; } |
| 42 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 43 | /// Return the machine instruction descriptor that corresponds to the |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 44 | /// specified instruction opcode. |
| 45 | const MCInstrDesc &get(unsigned Opcode) const { |
| 46 | assert(Opcode < NumOpcodes && "Invalid opcode!"); |
| 47 | return Desc[Opcode]; |
| 48 | } |
| 49 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 50 | /// Returns the name for the instructions with the given opcode. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 51 | StringRef getName(unsigned Opcode) const { |
| 52 | assert(Opcode < NumOpcodes && "Invalid opcode!"); |
| 53 | return StringRef(&InstrNameData[InstrNameIndices[Opcode]]); |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | } // End llvm namespace |
| 58 | |
| 59 | #endif |