Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 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 | |
Nguyen Anh Quynh | 30e4d7f | 2014-05-08 22:54:58 +0800 | [diff] [blame] | 16 | /* Capstone Disassembly Engine */ |
| 17 | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */ |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 18 | |
| 19 | #ifndef CS_LLVM_MC_MCREGISTERINFO_H |
| 20 | #define CS_LLVM_MC_MCREGISTERINFO_H |
| 21 | |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 22 | #include <stdint.h> |
Nguyen Anh Quynh | c5cad6c | 2014-05-15 21:40:24 +0800 | [diff] [blame] | 23 | #include "include/platform.h" |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 24 | |
| 25 | /// An unsigned integer type large enough to represent all physical registers, |
| 26 | /// but not necessarily virtual registers. |
| 27 | typedef uint16_t MCPhysReg; |
| 28 | typedef MCPhysReg* iterator; |
| 29 | |
| 30 | typedef struct MCRegisterClass { |
| 31 | char *Name; |
| 32 | iterator RegsBegin; |
| 33 | uint8_t *RegSet; |
| 34 | uint16_t RegsSize; |
| 35 | uint16_t RegSetSize; |
| 36 | uint16_t ID; |
| 37 | uint16_t RegSize, Alignment; // Size & Alignment of register in bytes |
| 38 | int8_t CopyCost; |
| 39 | bool Allocatable; |
| 40 | } MCRegisterClass; |
| 41 | |
Nguyen Anh Quynh | 462f291 | 2013-12-11 17:35:27 +0800 | [diff] [blame] | 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 the specific register, e.g. RAX, EAX, are |
| 47 | /// super-registers of AX. |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 48 | /// |
| 49 | typedef struct MCRegisterDesc { |
| 50 | uint32_t Name; // Printable name for the reg (for debugging) |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 51 | uint32_t SubRegs; // Sub-register set, described above |
| 52 | uint32_t SuperRegs; // Super-register set, described above |
| 53 | |
| 54 | // Offset into MCRI::SubRegIndices of a list of sub-register indices for each |
| 55 | // sub-register in SubRegs. |
| 56 | uint32_t SubRegIndices; |
| 57 | |
| 58 | // RegUnits - Points to the list of register units. The low 4 bits holds the |
| 59 | // Scale, the high bits hold an offset into DiffLists. See MCRegUnitIterator. |
| 60 | uint32_t RegUnits; |
| 61 | } MCRegisterDesc; |
| 62 | |
| 63 | /// MCRegisterInfo base class - We assume that the target defines a static |
| 64 | /// array of MCRegisterDesc objects that represent all of the machine |
| 65 | /// registers that the target has. As such, we simply have to track a pointer |
| 66 | /// to this array so that we can turn register number into a register |
| 67 | /// descriptor. |
| 68 | /// |
| 69 | /// Note this class is designed to be a base class of TargetRegisterInfo, which |
| 70 | /// is the interface used by codegen. However, specific targets *should never* |
| 71 | /// specialize this class. MCRegisterInfo should only contain getters to access |
| 72 | /// TableGen generated physical register data. It must not be extended with |
| 73 | /// virtual methods. |
| 74 | /// |
| 75 | typedef struct MCRegisterInfo { |
| 76 | MCRegisterDesc *Desc; // Pointer to the descriptor array |
| 77 | unsigned NumRegs; // Number of entries in the array |
| 78 | unsigned RAReg; // Return address register |
| 79 | unsigned PCReg; // Program counter register |
| 80 | MCRegisterClass *Classes; // Pointer to the regclass array |
| 81 | unsigned NumClasses; // Number of entries in the array |
| 82 | unsigned NumRegUnits; // Number of regunits. |
| 83 | uint16_t (*RegUnitRoots)[2]; // Pointer to regunit root table. |
| 84 | MCPhysReg *DiffLists; // Pointer to the difflists array |
| 85 | char *RegStrings; // Pointer to the string table. |
| 86 | uint16_t *SubRegIndices; // Pointer to the subreg lookup |
| 87 | // array. |
| 88 | unsigned NumSubRegIndices; // Number of subreg indices. |
| 89 | uint16_t *RegEncodingTable; // Pointer to array of register |
| 90 | // encodings. |
| 91 | } MCRegisterInfo; |
| 92 | |
| 93 | void MCRegisterInfo_InitMCRegisterInfo(MCRegisterInfo *RI, |
| 94 | MCRegisterDesc *D, unsigned NR, unsigned RA, |
| 95 | unsigned PC, |
| 96 | MCRegisterClass *C, unsigned NC, |
| 97 | uint16_t (*RURoots)[2], |
| 98 | unsigned NRU, |
| 99 | MCPhysReg *DL, |
| 100 | char *Strings, |
| 101 | uint16_t *SubIndices, |
| 102 | unsigned NumIndices, |
| 103 | uint16_t *RET); |
| 104 | |
| 105 | |
| 106 | unsigned MCRegisterInfo_getMatchingSuperReg(MCRegisterInfo *RI, unsigned Reg, unsigned SubIdx, MCRegisterClass *RC); |
| 107 | |
| 108 | unsigned MCRegisterInfo_getSubReg(MCRegisterInfo *RI, unsigned Reg, unsigned Idx); |
| 109 | |
| 110 | MCRegisterClass* MCRegisterInfo_getRegClass(MCRegisterInfo *RI, unsigned i); |
| 111 | |
| 112 | bool MCRegisterClass_contains(MCRegisterClass *c, unsigned Reg); |
| 113 | |
| 114 | #endif |