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 <aquynh@gmail.com>, 2013-2014 */ 18 19 #ifndef CS_LLVM_MC_MCREGISTERINFO_H 20 #define CS_LLVM_MC_MCREGISTERINFO_H 21 22 #if !defined(_MSC_VER) || !defined(_KERNEL_MODE) 23 #include <stdint.h> 24 #endif 25 #include "include/platform.h" 26 27 /// An unsigned integer type large enough to represent all physical registers, 28 /// but not necessarily virtual registers. 29 typedef uint16_t MCPhysReg; 30 typedef MCPhysReg* iterator; 31 32 typedef struct MCRegisterClass { 33 char *Name; 34 iterator RegsBegin; 35 uint8_t *RegSet; 36 uint16_t RegsSize; 37 uint16_t RegSetSize; 38 uint16_t ID; 39 uint16_t RegSize, Alignment; // Size & Alignment of register in bytes 40 int8_t CopyCost; 41 bool Allocatable; 42 } MCRegisterClass; 43 44 /// MCRegisterDesc - This record contains information about a particular 45 /// register. The SubRegs field is a zero terminated array of registers that 46 /// are sub-registers of the specific register, e.g. AL, AH are sub-registers 47 /// of AX. The SuperRegs field is a zero terminated array of registers that are 48 /// super-registers of the specific register, e.g. RAX, EAX, are 49 /// super-registers of AX. 50 /// 51 typedef struct MCRegisterDesc { 52 uint32_t Name; // Printable name for the reg (for debugging) 53 uint32_t SubRegs; // Sub-register set, described above 54 uint32_t SuperRegs; // Super-register set, described above 55 56 // Offset into MCRI::SubRegIndices of a list of sub-register indices for each 57 // sub-register in SubRegs. 58 uint32_t SubRegIndices; 59 60 // RegUnits - Points to the list of register units. The low 4 bits holds the 61 // Scale, the high bits hold an offset into DiffLists. See MCRegUnitIterator. 62 uint32_t RegUnits; 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 /// 77 typedef struct MCRegisterInfo { 78 MCRegisterDesc *Desc; // Pointer to the descriptor array 79 unsigned NumRegs; // Number of entries in the array 80 unsigned RAReg; // Return address register 81 unsigned PCReg; // Program counter register 82 MCRegisterClass *Classes; // Pointer to the regclass array 83 unsigned NumClasses; // Number of entries in the array 84 unsigned NumRegUnits; // Number of regunits. 85 uint16_t (*RegUnitRoots)[2]; // Pointer to regunit root table. 86 MCPhysReg *DiffLists; // Pointer to the difflists array 87 char *RegStrings; // Pointer to the string table. 88 uint16_t *SubRegIndices; // Pointer to the subreg lookup 89 // array. 90 unsigned NumSubRegIndices; // Number of subreg indices. 91 uint16_t *RegEncodingTable; // Pointer to array of register 92 // encodings. 93 } MCRegisterInfo; 94 95 void MCRegisterInfo_InitMCRegisterInfo(MCRegisterInfo *RI, 96 MCRegisterDesc *D, unsigned NR, unsigned RA, 97 unsigned PC, 98 MCRegisterClass *C, unsigned NC, 99 uint16_t (*RURoots)[2], 100 unsigned NRU, 101 MCPhysReg *DL, 102 char *Strings, 103 uint16_t *SubIndices, 104 unsigned NumIndices, 105 uint16_t *RET); 106 107 108 unsigned MCRegisterInfo_getMatchingSuperReg(MCRegisterInfo *RI, unsigned Reg, unsigned SubIdx, MCRegisterClass *RC); 109 110 unsigned MCRegisterInfo_getSubReg(MCRegisterInfo *RI, unsigned Reg, unsigned Idx); 111 112 MCRegisterClass* MCRegisterInfo_getRegClass(MCRegisterInfo *RI, unsigned i); 113 114 bool MCRegisterClass_contains(MCRegisterClass *c, unsigned Reg); 115 116 #endif 117