MCInstrInfo.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #ifndef LLVM_MC_MCINSTRINFO_H
  14. #define LLVM_MC_MCINSTRINFO_H
  15. #include "llvm/MC/MCInstrDesc.h"
  16. #include <cassert>
  17. namespace llvm {
  18. //---------------------------------------------------------------------------
  19. /// \brief Interface to description of machine instruction set.
  20. class MCInstrInfo {
  21. const MCInstrDesc *Desc; // Raw array to allow static init'n
  22. const unsigned *InstrNameIndices; // Array for name indices in InstrNameData
  23. const char *InstrNameData; // Instruction name string pool
  24. unsigned NumOpcodes; // Number of entries in the desc array
  25. public:
  26. /// \brief Initialize MCInstrInfo, called by TableGen auto-generated routines.
  27. /// *DO NOT USE*.
  28. void InitMCInstrInfo(const MCInstrDesc *D, const unsigned *NI, const char *ND,
  29. unsigned NO) {
  30. Desc = D;
  31. InstrNameIndices = NI;
  32. InstrNameData = ND;
  33. NumOpcodes = NO;
  34. }
  35. unsigned getNumOpcodes() const { return NumOpcodes; }
  36. /// \brief Return the machine instruction descriptor that corresponds to the
  37. /// specified instruction opcode.
  38. const MCInstrDesc &get(unsigned Opcode) const {
  39. assert(Opcode < NumOpcodes && "Invalid opcode!");
  40. return Desc[Opcode];
  41. }
  42. /// \brief Returns the name for the instructions with the given opcode.
  43. const char *getName(unsigned Opcode) const {
  44. assert(Opcode < NumOpcodes && "Invalid opcode!");
  45. return &InstrNameData[InstrNameIndices[Opcode]];
  46. }
  47. };
  48. } // End llvm namespace
  49. #endif