| 1 | //=== MC/MCRegisterInfo.cpp - Target Register Description -------*- C++ -*-===//cxx . . $ `<file>/MCRegisterInfo.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 implements MCRegisterInfo functions. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | /* Capstone Disassembly Engine */ |
| 15 | /* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */ |
| 16 | |
| 17 | #include "MCRegisterInfo.h"cxx . . $ `<file>/MCRegisterInfo.h`/ |
| 18 | |
| 19 | /// DiffListIterator - Base iterator class that can traverse the |
| 20 | /// differentially encoded register and regunit lists in DiffLists. |
| 21 | /// Don't use this class directly, use one of the specialized sub-classes |
| 22 | /// defined below. |
| 23 | typedef struct DiffListIteratorcxx . . $ DiffListIterator# { |
| 24 | uint16_tcxx . . $ uint16_t# Valcxx . . $ DiffListIterator#Val.; |
| 25 | const MCPhysRegcxx . . $ MCPhysReg# *Listcxx . . $ DiffListIterator#List.; |
| 26 | } DiffListIteratorcxx . . $ DiffListIterator#; |
| 27 | |
| 28 | void MCRegisterInfo_InitMCRegisterInfocxx . . $ MCRegisterInfo_InitMCRegisterInfo(5e86a0227010d6ff).(MCRegisterInfocxx . . $ MCRegisterInfo# *RI, |
| 29 | const MCRegisterDesccxx . . $ MCRegisterDesc# *D, unsigned NR, |
| 30 | unsigned RA, unsigned PC, |
| 31 | const MCRegisterClasscxx . . $ MCRegisterClass# *C, unsigned NC, |
| 32 | uint16_tcxx . . $ uint16_t# (*RURoots)[2], unsigned NRU, |
| 33 | const MCPhysRegcxx . . $ MCPhysReg# *DL, |
| 34 | const char *Strings, |
| 35 | const uint16_tcxx . . $ uint16_t# *SubIndices, unsigned NumIndices, |
| 36 | const uint16_tcxx . . $ uint16_t# *RET) |
| 37 | { |
| 38 | RI->Desccxx . . $ MCRegisterInfo#Desc. = D; |
| 39 | RI->NumRegscxx . . $ MCRegisterInfo#NumRegs. = NR; |
| 40 | RI->RARegcxx . . $ MCRegisterInfo#RAReg. = RA; |
| 41 | RI->PCRegcxx . . $ MCRegisterInfo#PCReg. = PC; |
| 42 | RI->Classescxx . . $ MCRegisterInfo#Classes. = C; |
| 43 | RI->DiffListscxx . . $ MCRegisterInfo#DiffLists. = DL; |
| 44 | RI->RegStringscxx . . $ MCRegisterInfo#RegStrings. = Strings; |
| 45 | RI->NumClassescxx . . $ MCRegisterInfo#NumClasses. = NC; |
| 46 | RI->RegUnitRootscxx . . $ MCRegisterInfo#RegUnitRoots. = RURoots; |
| 47 | RI->NumRegUnitscxx . . $ MCRegisterInfo#NumRegUnits. = NRU; |
| 48 | RI->SubRegIndicescxx . . $ MCRegisterInfo#SubRegIndices. = SubIndices; |
| 49 | RI->NumSubRegIndicescxx . . $ MCRegisterInfo#NumSubRegIndices. = NumIndices; |
| 50 | RI->RegEncodingTablecxx . . $ MCRegisterInfo#RegEncodingTable. = RET; |
| 51 | } |
| 52 | |
| 53 | static void DiffListIterator_initcxx . . $ DiffListIterator_init(8828e3799e1cf26c).(DiffListIteratorcxx . . $ DiffListIterator# *d, MCPhysRegcxx . . $ MCPhysReg# InitVal, const MCPhysRegcxx . . $ MCPhysReg# *DiffList) |
| 54 | { |
| 55 | d->Valcxx . . $ DiffListIterator#Val. = InitVal; |
| 56 | d->Listcxx . . $ DiffListIterator#List. = DiffList; |
| 57 | } |
| 58 | |
| 59 | static uint16_tcxx . . $ uint16_t# DiffListIterator_getValcxx . . $ DiffListIterator_getVal(52d12d0fda16419b).(DiffListIteratorcxx . . $ DiffListIterator# *d) |
| 60 | { |
| 61 | return d->Valcxx . . $ DiffListIterator#Val.; |
| 62 | } |
| 63 | |
| 64 | static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! DiffListIterator_nextcxx . . $ DiffListIterator_next(36f9cc7fa9bafe67).(DiffListIteratorcxx . . $ DiffListIterator# *d) |
| 65 | { |
| 66 | MCPhysRegcxx . . $ MCPhysReg# D; |
| 67 | |
| 68 | if (d->Listcxx . . $ DiffListIterator#List. == 0) |
| 69 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 70 | |
| 71 | D = *d->Listcxx . . $ DiffListIterator#List.; |
| 72 | d->Listcxx . . $ DiffListIterator#List.++; |
| 73 | d->Valcxx . . $ DiffListIterator#Val. += D; |
| 74 | |
| 75 | if (!D) |
| 76 | d->Listcxx . . $ DiffListIterator#List. = 0; |
| 77 | |
| 78 | return (D != 0); |
| 79 | } |
| 80 | |
| 81 | static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! DiffListIterator_isValidcxx . . $ DiffListIterator_isValid(36f9cc7fa9bafe67).(DiffListIteratorcxx . . $ DiffListIterator# *d) |
| 82 | { |
| 83 | return (d->Listcxx . . $ DiffListIterator#List. != 0); |
| 84 | } |
| 85 | |
| 86 | unsigned MCRegisterInfo_getMatchingSuperRegcxx . . $ MCRegisterInfo_getMatchingSuperReg(3ade1747ec5307e4).(const MCRegisterInfocxx . . $ MCRegisterInfo# *RI, unsigned Reg, unsigned SubIdx, const MCRegisterClasscxx . . $ MCRegisterClass# *RC) |
| 87 | { |
| 88 | DiffListIteratorcxx . . $ DiffListIterator# iter; |
| 89 | |
| 90 | if (Reg >= RI->NumRegscxx . . $ MCRegisterInfo#NumRegs.) { |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | DiffListIterator_initcxx . . $ DiffListIterator_init(8828e3799e1cf26c).(&iter, (MCPhysRegcxx . . $ MCPhysReg#)Reg, RI->DiffListscxx . . $ MCRegisterInfo#DiffLists. + RI->Desccxx . . $ MCRegisterInfo#Desc.[Reg].SuperRegscxx . . $ MCRegisterDesc#SuperRegs.); |
| 95 | DiffListIterator_nextcxx . . $ DiffListIterator_next(36f9cc7fa9bafe67).(&iter); |
| 96 | |
| 97 | while(DiffListIterator_isValidcxx . . $ DiffListIterator_isValid(36f9cc7fa9bafe67).(&iter)) { |
| 98 | uint16_tcxx . . $ uint16_t# val = DiffListIterator_getValcxx . . $ DiffListIterator_getVal(52d12d0fda16419b).(&iter); |
| 99 | if (MCRegisterClass_containscxx . . $ MCRegisterClass_contains(606e0a92b949c89f).(RC, val) && Reg == MCRegisterInfo_getSubRegcxx . . $ MCRegisterInfo_getSubReg(5122505b0a81e722).(RI, val, SubIdx)) |
| 100 | return val; |
| 101 | |
| 102 | DiffListIterator_nextcxx . . $ DiffListIterator_next(36f9cc7fa9bafe67).(&iter); |
| 103 | } |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | unsigned MCRegisterInfo_getSubRegcxx . . $ MCRegisterInfo_getSubReg(5122505b0a81e722).(const MCRegisterInfocxx . . $ MCRegisterInfo# *RI, unsigned Reg, unsigned Idx) |
| 109 | { |
| 110 | DiffListIteratorcxx . . $ DiffListIterator# iter; |
| 111 | const uint16_tcxx . . $ uint16_t# *SRI = RI->SubRegIndicescxx . . $ MCRegisterInfo#SubRegIndices. + RI->Desccxx . . $ MCRegisterInfo#Desc.[Reg].SubRegIndicescxx . . $ MCRegisterDesc#SubRegIndices.; |
| 112 | |
| 113 | DiffListIterator_initcxx . . $ DiffListIterator_init(8828e3799e1cf26c).(&iter, (MCPhysRegcxx . . $ MCPhysReg#)Reg, RI->DiffListscxx . . $ MCRegisterInfo#DiffLists. + RI->Desccxx . . $ MCRegisterInfo#Desc.[Reg].SubRegscxx . . $ MCRegisterDesc#SubRegs.); |
| 114 | DiffListIterator_nextcxx . . $ DiffListIterator_next(36f9cc7fa9bafe67).(&iter); |
| 115 | |
| 116 | while(DiffListIterator_isValidcxx . . $ DiffListIterator_isValid(36f9cc7fa9bafe67).(&iter)) { |
| 117 | if (*SRI == Idx) |
| 118 | return DiffListIterator_getValcxx . . $ DiffListIterator_getVal(52d12d0fda16419b).(&iter); |
| 119 | DiffListIterator_nextcxx . . $ DiffListIterator_next(36f9cc7fa9bafe67).(&iter); |
| 120 | ++SRI; |
| 121 | } |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | const MCRegisterClasscxx . . $ MCRegisterClass#* MCRegisterInfo_getRegClasscxx . . $ MCRegisterInfo_getRegClass(43e5681d1534da22).(const MCRegisterInfocxx . . $ MCRegisterInfo# *RI, unsigned i) |
| 127 | { |
| 128 | //assert(i < getNumRegClasses() && "Register Class ID out of range"); |
| 129 | if (i >= RI->NumClassescxx . . $ MCRegisterInfo#NumClasses.) |
| 130 | return 0; |
| 131 | return &(RI->Classescxx . . $ MCRegisterInfo#Classes.[i]); |
| 132 | } |
| 133 | |
| 134 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! MCRegisterClass_containscxx . . $ MCRegisterClass_contains(606e0a92b949c89f).(const MCRegisterClasscxx . . $ MCRegisterClass# *c, unsigned Reg) |
| 135 | { |
| 136 | unsigned InByte = 0; |
| 137 | unsigned Byte = 0; |
| 138 | |
| 139 | // Make sure that MCRegisterInfo_getRegClass didn't return 0 |
| 140 | // (for calls to GETREGCLASS_CONTAIN0) |
| 141 | if(!c) |
| 142 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 143 | |
| 144 | InByte = Reg % 8; |
| 145 | Byte = Reg / 8; |
| 146 | |
| 147 | if (Byte >= c->RegSetSizecxx . . $ MCRegisterClass#RegSetSize.) |
| 148 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 149 | |
| 150 | return (c->RegSetcxx . . $ MCRegisterClass#RegSet.[Byte] & (1 << InByte)) != 0; |
| 151 | } |