| 3 | import unluac.Version; |
| 4 | |
| 5 | public class CodeExtract { |
| 6 | |
| 7 | public static class Field { |
| 8 | |
| 9 | public Field(int size, int shift) { |
| 10 | this(size, shift, 0); |
| 11 | } |
| 12 | |
| 13 | public Field(int size, int shift, int offset) { |
| 14 | this.size = size; |
| 15 | this.shift = shift; |
| 16 | this.mask = size_to_mask(size); |
| 17 | this.offset = offset; |
| 18 | } |
| 19 | |
| 20 | public int extract(int codepoint) { |
| 21 | return ((codepoint >>> shift) & mask) - offset; |
| 22 | } |
| 23 | |
| 24 | public boolean check(int x) { |
| 25 | return ((x + offset) & ~mask) == 0; |
| 26 | } |
| 27 | |
| 28 | public int encode(int x) { |
| 29 | return (x + offset) << shift; |
| 30 | } |
| 31 | |
| 32 | public int clear(int codepoint) { |
| 33 | return codepoint & ~(mask << shift); |
| 34 | } |
| 35 | |
| 36 | public int max() { |
| 37 | return mask - offset; |
| 38 | } |
| 39 | |
| 40 | public final int size; |
| 41 | private final int shift; |
| 42 | private final int mask; |
| 43 | private final int offset; |
| 44 | |
| 45 | } |
| 46 | |
| 47 | public CodeExtract(Version version, int sizeOp, int sizeA, int sizeB, int sizeC) { |
| 48 | switch(version.instructionformat.get()) { |
| 49 | case LUA50: |
| 50 | op = new Field(sizeOp, 0); |
| 51 | A = new Field(sizeA, sizeB + sizeC + sizeOp); |
| 52 | B = new Field(sizeB, sizeB + sizeOp); |
| 53 | C = new Field(sizeC, sizeOp); |
| 54 | k = null; |
| 55 | Ax = null; |
| 56 | sJ = null; |
| 57 | Bx = new Field(sizeB + sizeC, sizeOp); |
| 58 | sBx = new Field(sizeB + sizeC, sizeOp, size_to_mask(sizeB + sizeC) / 2); |
| 59 | x = new Field(32, 0); |
| 60 | break; |
| 61 | case LUA51: |
| 62 | op = new Field(6, 0); |
nothing calls this directly
no outgoing calls
no test coverage detected