| 1 | //=== MC/MCRegisterInfo.h - Target Register Description ---------*- 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 an abstract interface used to get information about a |
| 11 | // target machines register file. This information is used for a variety of |
| 12 | // purposed, especially register allocation. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | /* Capstone Disassembly Engine */ |
| 17 | /* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */ |
| 18 | |
| 19 | #ifndef CS_LLVM_MC_MCREGISTERINFO_H |
| 20 | #define CS_LLVM_MC_MCREGISTERINFO_H |
| 21 | |
| 22 | #include "capstone/platform.h" |
| 23 | |
| 24 | /// An unsigned integer type large enough to represent all physical registers, |
| 25 | /// but not necessarily virtual registers. |
| 26 | typedef uint16_t MCPhysReg; |
| 27 | typedef const MCPhysReg* iterator; |
| 28 | |
| 29 | typedef struct MCRegisterClass2 { |
| 30 | iterator RegsBegin; |
| 31 | const uint8_t *RegSet; |
| 32 | uint8_t RegsSize; |
| 33 | uint8_t RegSetSize; |
| 34 | } MCRegisterClass2; |
| 35 | |
| 36 | typedef struct MCRegisterClass { |
| 37 | iterator RegsBegin; |
| 38 | const uint8_t *RegSet; |
| 39 | uint16_t RegSetSize; |
| 40 | } MCRegisterClass; |
| 41 | |
| 42 | /// MCRegisterDesc - This record contains information about a particular |
| 43 | /// register. The SubRegs field is a zero terminated array of registers that |
| 44 | /// are sub-registers of the specific register, e.g. AL, AH are sub-registers |
| 45 | /// of AX. The SuperRegs field is a zero terminated array of registers that are |
| 46 | /// super-registers of AX. |
| 47 | typedef struct MCRegisterDesc { |
| 48 | uint32_t Name; // Printable name for the reg (for debugging) |
| 49 | uint32_t SubRegs; // Sub-register set, described above |
| 50 | uint32_t SuperRegs; // Super-register set, described above |
| 51 | |
| 52 | // Offset into MCRI::SubRegIndices of a list of sub-register indices for each |
| 53 | // sub-register in SubRegs. |
| 54 | uint32_t SubRegIndices; |
| 55 | |
| 56 | // RegUnits - Points to the list of register units. The low 4 bits holds the |
| 57 | // Scale, the high bits hold an offset into DiffLists. See MCRegUnitIterator. |
| 58 | uint32_t RegUnits; |
| 59 | |
| 60 | /// Index into list with lane mask sequences. The sequence contains a lanemask |
| 61 | /// for every register unit. |
| 62 | uint16_t RegUnitLaneMasks; // ??? |
| 63 | } MCRegisterDesc; |
| 64 | |
| 65 | /// MCRegisterInfo base class - We assume that the target defines a static |
| 66 | /// array of MCRegisterDesc objects that represent all of the machine |
| 67 | /// registers that the target has. As such, we simply have to track a pointer |
| 68 | /// to this array so that we can turn register number into a register |
| 69 | /// descriptor. |
| 70 | /// |
| 71 | /// Note this class is designed to be a base class of TargetRegisterInfo, which |
| 72 | /// is the interface used by codegen. However, specific targets *should never* |
| 73 | /// specialize this class. MCRegisterInfo should only contain getters to access |
| 74 | /// TableGen generated physical register data. It must not be extended with |
| 75 | /// virtual methods. |
| 76 | typedef struct MCRegisterInfo { |
| 77 | const MCRegisterDesc *Desc; // Pointer to the descriptor array |
| 78 | unsigned NumRegs; // Number of entries in the array |
| 79 | unsigned RAReg; // Return address register |
| 80 | unsigned PCReg; // Program counter register |
| 81 | const MCRegisterClass *Classes; // Pointer to the regclass array |
| 82 | unsigned NumClasses; // Number of entries in the array |
| 83 | unsigned NumRegUnits; // Number of regunits. |
| 84 | uint16_t (*RegUnitRoots)[2]; // Pointer to regunit root table. |
| 85 | const MCPhysReg *DiffLists; // Pointer to the difflists array |
| 86 | // const LaneBitmask *RegUnitMaskSequences; // Pointer to lane mask sequences |
| 87 | const char *RegStrings; // Pointer to the string table. |
| 88 | // const char *RegClassStrings; // Pointer to the class strings. |
| 89 | const uint16_t *SubRegIndices; // Pointer to the subreg lookup |
| 90 | // array. |
| 91 | unsigned NumSubRegIndices; // Number of subreg indices. |
| 92 | const uint16_t *RegEncodingTable; // Pointer to array of register |
| 93 | // encodings. |
| 94 | } MCRegisterInfo; |
| 95 | |
| 96 | void MCRegisterInfo_InitMCRegisterInfo(MCRegisterInfo *RI, |
| 97 | const MCRegisterDesc *D, unsigned NR, unsigned RA, |
| 98 | unsigned PC, |
| 99 | const MCRegisterClass *C, unsigned NC, |
| 100 | uint16_t (*RURoots)[2], |
| 101 | unsigned NRU, |
| 102 | const MCPhysReg *DL, |
| 103 | const char *Strings, |
| 104 | const uint16_t *SubIndices, |
| 105 | unsigned NumIndices, |
| 106 | const uint16_t *RET); |
| 107 | |
| 108 | unsigned MCRegisterInfo_getMatchingSuperReg(const MCRegisterInfo *RI, unsigned Reg, unsigned SubIdx, const MCRegisterClass *RC); |
| 109 | |
| 110 | unsigned MCRegisterInfo_getSubReg(const MCRegisterInfo *RI, unsigned Reg, unsigned Idx); |
| 111 | |
| 112 | const MCRegisterClass* MCRegisterInfo_getRegClass(const MCRegisterInfo *RI, unsigned i); |
| 113 | |
| 114 | bool MCRegisterClass_contains(const MCRegisterClass *c, unsigned Reg); |
| 115 | |
| 116 | #endif |