| 1 |
// |
| 2 |
// Copyright (C) 2010 Wayne Meissner |
| 3 |
// |
| 4 |
// Permission is hereby granted, free of charge, to any person |
| 5 |
// obtaining a copy of this software and associated documentation |
| 6 |
// files (the "Software"), to deal in the Software without |
| 7 |
// restriction, including without limitation the rights to use, |
| 8 |
// copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
// copies of the Software, and to permit persons to whom the |
| 10 |
// Software is furnished to do so, subject to the following |
| 11 |
// conditions: |
| 12 |
// |
| 13 |
// The above copyright notice and this permission notice shall be |
| 14 |
// included in all copies or substantial portions of the Software. |
| 15 |
// |
| 16 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 |
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 18 |
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 |
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 20 |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 21 |
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 23 |
// OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
|
| 25 |
package com.kenai.jnr.x86asm; |
| 26 |
|
| 27 |
import static com.kenai.jnr.x86asm.REG.*; |
| 28 |
import static com.kenai.jnr.x86asm.SIZE.*; |
| 29 |
|
| 30 |
@Deprecated |
| 31 |
public final class Register extends BaseReg { |
| 32 |
private static final Register[] gpb = new Register[16]; |
| 33 |
private static final Register[] gpw = new Register[16]; |
| 34 |
private static final Register[] gpd = new Register[16]; |
| 35 |
private static final Register[] gpq = new Register[16]; |
| 36 |
|
| 37 |
static { |
| 38 |
for (int i = 0; i < 16; ++i) { |
| 39 |
gpb[i] = new Register(REG_GPB | i, SIZE_BYTE); |
| 40 |
gpw[i] = new Register(REG_GPW | i, SIZE_WORD); |
| 41 |
gpd[i] = new Register(REG_GPD | i, SIZE_DWORD); |
| 42 |
gpq[i] = new Register(REG_GPQ | i, SIZE_QWORD); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
Register(int code, int size) { |
| 47 |
super(code, size); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
public static final Register gpr(int reg) { |
| 52 |
|
| 53 |
switch (reg & REGTYPE_MASK) { |
| 54 |
case REG_GPB: |
| 55 |
return gpb[reg & REGCODE_MASK]; |
| 56 |
|
| 57 |
case REG_GPW: |
| 58 |
return gpw[reg & REGCODE_MASK]; |
| 59 |
|
| 60 |
case REG_GPD: |
| 61 |
return gpd[reg & REGCODE_MASK]; |
| 62 |
|
| 63 |
case REG_GPQ: |
| 64 |
return gpq[reg & REGCODE_MASK]; |
| 65 |
} |
| 66 |
|
| 67 |
throw new IllegalArgumentException("invalid register 0x" + Integer.toHexString(reg)); |
| 68 |
} |
| 69 |
|
| 70 |
private static final Register gpr(Register[] cache, int idx) { |
| 71 |
if (idx >= 0 && idx < 16) { |
| 72 |
return cache[idx]; |
| 73 |
} |
| 74 |
|
| 75 |
throw new IllegalArgumentException("invalid register index " + idx); |
| 76 |
} |
| 77 |
|
| 78 |
public static final Register gpb(int idx) { |
| 79 |
return gpr(gpb, idx); |
| 80 |
} |
| 81 |
|
| 82 |
public static final Register gpw(int idx) { |
| 83 |
return gpr(gpw, idx); |
| 84 |
} |
| 85 |
|
| 86 |
public static final Register gpd(int idx) { |
| 87 |
return gpr(gpd, idx); |
| 88 |
} |
| 89 |
|
| 90 |
public static final Register gpq(int idx) { |
| 91 |
return gpr(gpq, idx); |
| 92 |
} |
| 93 |
} |