mirror of
https://github.com/revanced/smali.git
synced 2025-05-09 02:44:29 +02:00
Use code offsets rather than indexes for instructions
I had initially wanted to use instruction indexes at the dexlib level, rather than the actual code unit offsets/addresses. But after additional thought, I decided to stick with code units, and then provide a utility for easily mapping between indexes/offsets (not implemented yet).
This commit is contained in:
parent
8b1508ee58
commit
ccc4c13ae6
@ -31,16 +31,13 @@
|
||||
|
||||
package org.jf.dexlib2.dexbacked;
|
||||
|
||||
import org.jf.dexlib2.dexbacked.util.InstructionOffsetMap;
|
||||
import org.jf.dexlib2.immutable.ImmutableExceptionHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class DexBackedCatchAllExceptionHandler extends ImmutableExceptionHandler {
|
||||
public DexBackedCatchAllExceptionHandler(@Nonnull DexReader reader,
|
||||
@Nonnull InstructionOffsetMap instructionOffsetMap) {
|
||||
super(null,
|
||||
instructionOffsetMap.getInstructionIndexAtOffsetExact(reader.readSmallUleb128()));
|
||||
public DexBackedCatchAllExceptionHandler(@Nonnull DexReader reader) {
|
||||
super(null, reader.readSmallUleb128());
|
||||
}
|
||||
|
||||
public static void skipFrom(@Nonnull DexReader reader) {
|
||||
|
@ -31,17 +31,14 @@
|
||||
|
||||
package org.jf.dexlib2.dexbacked;
|
||||
|
||||
import org.jf.dexlib2.dexbacked.util.InstructionOffsetMap;
|
||||
import org.jf.dexlib2.immutable.ImmutableExceptionHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class DexBackedExceptionHandler extends ImmutableExceptionHandler {
|
||||
public DexBackedExceptionHandler(@Nonnull DexReader reader,
|
||||
@Nonnull InstructionOffsetMap instructionOffsetMap) {
|
||||
public DexBackedExceptionHandler(@Nonnull DexReader reader) {
|
||||
// TODO: verify dalvik doesn't accept an exception handler that points in the middle of an instruction
|
||||
super(reader.getType(reader.readSmallUleb128()),
|
||||
instructionOffsetMap.getInstructionIndexAtOffsetExact(reader.readSmallUleb128()));
|
||||
super(reader.getType(reader.readSmallUleb128()), reader.readSmallUleb128());
|
||||
}
|
||||
|
||||
public static void skipFrom(@Nonnull DexReader reader) {
|
||||
|
@ -34,7 +34,6 @@ package org.jf.dexlib2.dexbacked;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jf.dexlib2.dexbacked.instruction.DexBackedInstruction;
|
||||
import org.jf.dexlib2.dexbacked.util.FixedSizeList;
|
||||
import org.jf.dexlib2.dexbacked.util.InstructionOffsetMap;
|
||||
import org.jf.dexlib2.iface.MethodImplementation;
|
||||
import org.jf.dexlib2.iface.TryBlock;
|
||||
import org.jf.dexlib2.iface.instruction.Instruction;
|
||||
@ -50,7 +49,6 @@ public class DexBackedMethodImplementation implements MethodImplementation {
|
||||
|
||||
public final int registerCount;
|
||||
@Nonnull public final ImmutableList<? extends Instruction> instructions;
|
||||
@Nonnull private final InstructionOffsetMap instructionOffsetMap;
|
||||
|
||||
// code_item offsets
|
||||
private static final int TRIES_SIZE_OFFSET = 6;
|
||||
@ -66,7 +64,6 @@ public class DexBackedMethodImplementation implements MethodImplementation {
|
||||
this.registerCount = dexBuf.readUshort(codeOffset);
|
||||
|
||||
instructions = buildInstructionList();
|
||||
instructionOffsetMap = buildInstructionOffsetMap();
|
||||
}
|
||||
|
||||
@Override public int getRegisterCount() { return registerCount; }
|
||||
@ -88,8 +85,7 @@ public class DexBackedMethodImplementation implements MethodImplementation {
|
||||
public TryBlock readItem(int index) {
|
||||
return new DexBackedTryBlock(dexBuf,
|
||||
triesStartOffset + index*TRY_ITEM_SIZE,
|
||||
handlersStartOffset,
|
||||
instructionOffsetMap);
|
||||
handlersStartOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -118,23 +114,4 @@ public class DexBackedMethodImplementation implements MethodImplementation {
|
||||
|
||||
return ImmutableList.copyOf(instructions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an InstructionOffsetMap that maps an instruction offset to its index.
|
||||
*
|
||||
* This must be called after the instructions field has been set
|
||||
*
|
||||
* @return An InstructionOffsetMap object
|
||||
*/
|
||||
@Nonnull
|
||||
private InstructionOffsetMap buildInstructionOffsetMap() {
|
||||
int[] offsets = new int[instructions.size()];
|
||||
int currentOffset = 0;
|
||||
for (int i=0; i<offsets.length; i++) {
|
||||
offsets[i] = currentOffset;
|
||||
// TODO: need to handle variable size instructions
|
||||
currentOffset += instructions.get(i).getOpcode().format.size;
|
||||
}
|
||||
return new InstructionOffsetMap(offsets);
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,6 @@
|
||||
|
||||
package org.jf.dexlib2.dexbacked;
|
||||
|
||||
import org.jf.dexlib2.dexbacked.util.InstructionOffsetMap;
|
||||
import org.jf.dexlib2.iface.ExceptionHandler;
|
||||
import org.jf.dexlib2.iface.TryBlock;
|
||||
import org.jf.dexlib2.dexbacked.util.VariableSizeList;
|
||||
@ -41,10 +40,9 @@ import java.util.List;
|
||||
|
||||
public class DexBackedTryBlock implements TryBlock {
|
||||
@Nonnull public final DexBuffer dexBuf;
|
||||
@Nonnull private final InstructionOffsetMap instructionOffsetMap;
|
||||
|
||||
public final int startIndex;
|
||||
public final int instructionCount;
|
||||
public final int startCodeOffset;
|
||||
public final int codeUnitCount;
|
||||
|
||||
private final int exceptionHandlersOffset;
|
||||
|
||||
@ -54,29 +52,15 @@ public class DexBackedTryBlock implements TryBlock {
|
||||
|
||||
public DexBackedTryBlock(@Nonnull DexBuffer dexBuf,
|
||||
int tryItemOffset,
|
||||
int handlersStartOffset,
|
||||
@Nonnull InstructionOffsetMap instructionOffsetMap) {
|
||||
int handlersStartOffset) {
|
||||
this.dexBuf = dexBuf;
|
||||
this.instructionOffsetMap = instructionOffsetMap;
|
||||
|
||||
int startOffset = dexBuf.readSmallUint(tryItemOffset + START_ADDRESS_OFFSET);
|
||||
// map the code unit offset to the instruction index
|
||||
this.startIndex = instructionOffsetMap.getInstructionIndexAtOffsetExact(startOffset);
|
||||
|
||||
int codeUnitCount = dexBuf.readUshort(tryItemOffset + CODE_UNIT_COUNT_OFFSET);
|
||||
// TODO: check if dalivk accepts insns_size = 0
|
||||
if (codeUnitCount == 0) {
|
||||
this.instructionCount = 0;
|
||||
} else {
|
||||
int lastIndex = instructionOffsetMap.getInstructionIndexAtOffset(startOffset + codeUnitCount - 1);
|
||||
this.instructionCount = lastIndex - startIndex + 1;
|
||||
}
|
||||
|
||||
this.startCodeOffset = dexBuf.readSmallUint(tryItemOffset + START_ADDRESS_OFFSET);
|
||||
this.codeUnitCount = dexBuf.readUshort(tryItemOffset + CODE_UNIT_COUNT_OFFSET);
|
||||
this.exceptionHandlersOffset = handlersStartOffset + dexBuf.readUshort(tryItemOffset + HANDLER_OFFSET_OFFSET);
|
||||
}
|
||||
|
||||
@Override public int getStartIndex() { return startIndex; }
|
||||
@Override public int getInstructionCount() { return instructionCount; }
|
||||
@Override public int getStartCodeOffset() { return startCodeOffset; }
|
||||
@Override public int getCodeUnitCount() { return codeUnitCount; }
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@ -90,7 +74,7 @@ public class DexBackedTryBlock implements TryBlock {
|
||||
@Nonnull
|
||||
@Override
|
||||
protected ExceptionHandler readItem(@Nonnull DexReader reader, int index) {
|
||||
return new DexBackedExceptionHandler(reader, instructionOffsetMap);
|
||||
return new DexBackedExceptionHandler(reader);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -108,9 +92,9 @@ public class DexBackedTryBlock implements TryBlock {
|
||||
@Override
|
||||
protected ExceptionHandler readItem(@Nonnull DexReader dexReader, int index) {
|
||||
if (index == sizeWithCatchAll-1) {
|
||||
return new DexBackedCatchAllExceptionHandler(dexReader, instructionOffsetMap);
|
||||
return new DexBackedCatchAllExceptionHandler(dexReader);
|
||||
} else {
|
||||
return new DexBackedExceptionHandler(dexReader, instructionOffsetMap);
|
||||
return new DexBackedExceptionHandler(dexReader);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012, Google Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Google Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.jf.dexlib2.dexbacked.util;
|
||||
|
||||
import org.jf.util.ExceptionWithContext;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class InstructionOffsetMap {
|
||||
@Nonnull private final int[] instructionOffsets;
|
||||
|
||||
public InstructionOffsetMap(@Nonnull int[] instructionOffsets) {
|
||||
this.instructionOffsets = instructionOffsets;
|
||||
}
|
||||
|
||||
public int getInstructionIndexAtOffsetExact(int offset) {
|
||||
int index = Arrays.binarySearch(instructionOffsets, offset);
|
||||
if (index < 0) {
|
||||
throw new ExceptionWithContext("No instruction at offset %d", offset);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
public int getInstructionIndexAtOffset(int offset) {
|
||||
int index = Arrays.binarySearch(instructionOffsets, offset);
|
||||
if (index < 0) {
|
||||
// This would fail if index was -1 (i.e. insertion point of 0). Luckily, we can ignore this case, because
|
||||
// offset will always be non-negative, and the offset of the first instruction will always be 0.
|
||||
return (~index) - 1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
}
|
@ -35,5 +35,5 @@ import javax.annotation.Nullable;
|
||||
|
||||
public interface ExceptionHandler {
|
||||
@Nullable String getExceptionType();
|
||||
int getHandlerIndex();
|
||||
int getHandlerCodeOffset();
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
public interface TryBlock {
|
||||
int getStartIndex();
|
||||
int getInstructionCount();
|
||||
int getStartCodeOffset();
|
||||
int getCodeUnitCount();
|
||||
@Nonnull List<? extends ExceptionHandler> getExceptionHandlers();
|
||||
}
|
||||
|
@ -32,5 +32,5 @@
|
||||
package org.jf.dexlib2.iface.instruction;
|
||||
|
||||
public interface OffsetInstruction extends Instruction {
|
||||
int getOffset();
|
||||
int getCodeOffset();
|
||||
}
|
||||
|
@ -41,12 +41,12 @@ import java.util.List;
|
||||
|
||||
public class ImmutableExceptionHandler implements ExceptionHandler {
|
||||
@Nullable public final String exceptionType;
|
||||
public final int handlerIndex;
|
||||
public final int handlerCodeOffset;
|
||||
|
||||
public ImmutableExceptionHandler(@Nullable String exceptionType,
|
||||
int handlerIndex) {
|
||||
int handlerCodeOffset) {
|
||||
this.exceptionType = exceptionType;
|
||||
this.handlerIndex = handlerIndex;
|
||||
this.handlerCodeOffset = handlerCodeOffset;
|
||||
}
|
||||
|
||||
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) {
|
||||
@ -55,11 +55,11 @@ public class ImmutableExceptionHandler implements ExceptionHandler {
|
||||
}
|
||||
return new ImmutableExceptionHandler(
|
||||
exceptionHandler.getExceptionType(),
|
||||
exceptionHandler.getHandlerIndex());
|
||||
exceptionHandler.getHandlerCodeOffset());
|
||||
}
|
||||
|
||||
@Nullable @Override public String getExceptionType() { return exceptionType; }
|
||||
@Override public int getHandlerIndex() { return handlerIndex; }
|
||||
@Override public int getHandlerCodeOffset() { return handlerCodeOffset; }
|
||||
|
||||
@Nonnull
|
||||
public static ImmutableList<ImmutableExceptionHandler> immutableListOf(List<? extends ExceptionHandler> list) {
|
||||
|
@ -42,23 +42,23 @@ import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class ImmutableTryBlock implements TryBlock {
|
||||
public final int startIndex;
|
||||
public final int instructionCount;
|
||||
public final int startCodeOffset;
|
||||
public final int codeUnitCount;
|
||||
@Nonnull public final ImmutableList<? extends ImmutableExceptionHandler> exceptionHandlers;
|
||||
|
||||
public ImmutableTryBlock(int startIndex,
|
||||
int instructionCount,
|
||||
public ImmutableTryBlock(int startCodeOffset,
|
||||
int codeUnitCount,
|
||||
@Nullable List<? extends ExceptionHandler> exceptionHandlers) {
|
||||
this.startIndex = startIndex;
|
||||
this.instructionCount = instructionCount;
|
||||
this.startCodeOffset = startCodeOffset;
|
||||
this.codeUnitCount = codeUnitCount;
|
||||
this.exceptionHandlers = ImmutableExceptionHandler.immutableListOf(exceptionHandlers);
|
||||
}
|
||||
|
||||
public ImmutableTryBlock(int startIndex,
|
||||
int instructionCount,
|
||||
public ImmutableTryBlock(int startCodeOffset,
|
||||
int codeUnitCount,
|
||||
@Nullable ImmutableList<? extends ImmutableExceptionHandler> exceptionHandlers) {
|
||||
this.startIndex = startIndex;
|
||||
this.instructionCount = instructionCount;
|
||||
this.startCodeOffset = startCodeOffset;
|
||||
this.codeUnitCount = codeUnitCount;
|
||||
this.exceptionHandlers = Objects.firstNonNull(exceptionHandlers, ImmutableList.<ImmutableExceptionHandler>of());
|
||||
}
|
||||
|
||||
@ -67,13 +67,13 @@ public class ImmutableTryBlock implements TryBlock {
|
||||
return (ImmutableTryBlock)tryBlock;
|
||||
}
|
||||
return new ImmutableTryBlock(
|
||||
tryBlock.getStartIndex(),
|
||||
tryBlock.getInstructionCount(),
|
||||
tryBlock.getStartCodeOffset(),
|
||||
tryBlock.getCodeUnitCount(),
|
||||
tryBlock.getExceptionHandlers());
|
||||
}
|
||||
|
||||
@Override public int getStartIndex() { return startIndex; }
|
||||
@Override public int getInstructionCount() { return instructionCount; }
|
||||
@Override public int getStartCodeOffset() { return startCodeOffset; }
|
||||
@Override public int getCodeUnitCount() { return codeUnitCount; }
|
||||
|
||||
@Nonnull @Override public ImmutableList<? extends ImmutableExceptionHandler> getExceptionHandlers() {
|
||||
return exceptionHandlers;
|
||||
|
@ -41,13 +41,13 @@ import javax.annotation.Nonnull;
|
||||
public class ImmutableInstruction10t extends ImmutableInstruction implements Instruction10t {
|
||||
public static final Format FORMAT = Format.Format12x;
|
||||
|
||||
public final int offset;
|
||||
public final int codeOffset;
|
||||
|
||||
public ImmutableInstruction10t(@Nonnull Opcode opcode,
|
||||
int offset) {
|
||||
int codeOffset) {
|
||||
super(opcode);
|
||||
Preconditions.checkFormat(opcode, FORMAT);
|
||||
this.offset = Preconditions.checkByteOffset(offset);
|
||||
this.codeOffset = Preconditions.checkByteCodeOffset(codeOffset);
|
||||
}
|
||||
|
||||
public static ImmutableInstruction10t of(Instruction10t instruction) {
|
||||
@ -56,9 +56,9 @@ public class ImmutableInstruction10t extends ImmutableInstruction implements Ins
|
||||
}
|
||||
return new ImmutableInstruction10t(
|
||||
instruction.getOpcode(),
|
||||
instruction.getOffset());
|
||||
instruction.getCodeOffset());
|
||||
}
|
||||
|
||||
@Override public int getOffset() { return offset; }
|
||||
@Override public int getCodeOffset() { return codeOffset; }
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
||||
|
@ -41,13 +41,13 @@ import javax.annotation.Nonnull;
|
||||
public class ImmutableInstruction20t extends ImmutableInstruction implements Instruction20t {
|
||||
public static final Format FORMAT = Format.Format12x;
|
||||
|
||||
public final int offset;
|
||||
public final int codeOffset;
|
||||
|
||||
public ImmutableInstruction20t(@Nonnull Opcode opcode,
|
||||
int offset) {
|
||||
int codeOffset) {
|
||||
super(opcode);
|
||||
Preconditions.checkFormat(opcode, FORMAT);
|
||||
this.offset = Preconditions.checkShortOffset(offset);
|
||||
this.codeOffset = Preconditions.checkShortCodeOffset(codeOffset);
|
||||
}
|
||||
|
||||
public static ImmutableInstruction20t of(Instruction20t instruction) {
|
||||
@ -56,9 +56,9 @@ public class ImmutableInstruction20t extends ImmutableInstruction implements Ins
|
||||
}
|
||||
return new ImmutableInstruction20t(
|
||||
instruction.getOpcode(),
|
||||
(byte)instruction.getOffset());
|
||||
(byte)instruction.getCodeOffset());
|
||||
}
|
||||
|
||||
@Override public int getOffset() { return offset; }
|
||||
@Override public int getCodeOffset() { return codeOffset; }
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
||||
|
@ -42,15 +42,15 @@ public class ImmutableInstruction21t extends ImmutableInstruction implements Ins
|
||||
public static final Format FORMAT = Format.Format21t;
|
||||
|
||||
public final int registerA;
|
||||
public final int offset;
|
||||
public final int codeOffset;
|
||||
|
||||
public ImmutableInstruction21t(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int offset) {
|
||||
int codeOffset) {
|
||||
super(opcode);
|
||||
Preconditions.checkFormat(opcode, FORMAT);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
this.offset = Preconditions.checkShortOffset(offset);
|
||||
this.codeOffset = Preconditions.checkShortCodeOffset(codeOffset);
|
||||
}
|
||||
|
||||
public static ImmutableInstruction21t of(Instruction21t instruction) {
|
||||
@ -60,11 +60,11 @@ public class ImmutableInstruction21t extends ImmutableInstruction implements Ins
|
||||
return new ImmutableInstruction21t(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getOffset());
|
||||
instruction.getCodeOffset());
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getOffset() { return offset; }
|
||||
@Override public int getCodeOffset() { return codeOffset; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
||||
|
@ -43,17 +43,17 @@ public class ImmutableInstruction22t extends ImmutableInstruction implements Ins
|
||||
|
||||
public final int registerA;
|
||||
public final int registerB;
|
||||
public final int offset;
|
||||
public final int codeOffset;
|
||||
|
||||
public ImmutableInstruction22t(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int registerB,
|
||||
int offset) {
|
||||
int codeOffset) {
|
||||
super(opcode);
|
||||
Preconditions.checkFormat(opcode, Format.Format35c);
|
||||
this.registerA = Preconditions.checkNibbleRegister(registerA);
|
||||
this.registerB = Preconditions.checkNibbleRegister(registerB);
|
||||
this.offset = Preconditions.checkShortOffset(offset);
|
||||
this.codeOffset = Preconditions.checkShortCodeOffset(codeOffset);
|
||||
}
|
||||
|
||||
public static ImmutableInstruction22t of(Instruction22t instruction) {
|
||||
@ -64,12 +64,12 @@ public class ImmutableInstruction22t extends ImmutableInstruction implements Ins
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getRegisterB(),
|
||||
instruction.getOffset());
|
||||
instruction.getCodeOffset());
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getRegisterB() { return registerB; }
|
||||
@Override public int getOffset() { return offset; }
|
||||
@Override public int getCodeOffset() { return codeOffset; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
||||
|
@ -41,13 +41,13 @@ import javax.annotation.Nonnull;
|
||||
public class ImmutableInstruction30t extends ImmutableInstruction implements Instruction30t {
|
||||
public static final Format FORMAT = Format.Format12x;
|
||||
|
||||
public final int offset;
|
||||
public final int codeOffset;
|
||||
|
||||
public ImmutableInstruction30t(@Nonnull Opcode opcode,
|
||||
int offset) {
|
||||
int codeOffset) {
|
||||
super(opcode);
|
||||
Preconditions.checkFormat(opcode, FORMAT);
|
||||
this.offset = offset;
|
||||
this.codeOffset = codeOffset;
|
||||
}
|
||||
|
||||
public static ImmutableInstruction30t of(Instruction30t instruction) {
|
||||
@ -56,10 +56,10 @@ public class ImmutableInstruction30t extends ImmutableInstruction implements Ins
|
||||
}
|
||||
return new ImmutableInstruction30t(
|
||||
instruction.getOpcode(),
|
||||
instruction.getOffset());
|
||||
instruction.getCodeOffset());
|
||||
}
|
||||
|
||||
@Override public int getOffset() { return offset; }
|
||||
@Override public int getCodeOffset() { return codeOffset; }
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
||||
|
||||
|
@ -42,15 +42,15 @@ public class ImmutableInstruction31t extends ImmutableInstruction implements Ins
|
||||
public static final Format FORMAT = Format.Format31t;
|
||||
|
||||
public final int registerA;
|
||||
public final int offset;
|
||||
public final int codeOffset;
|
||||
|
||||
public ImmutableInstruction31t(@Nonnull Opcode opcode,
|
||||
int registerA,
|
||||
int offset) {
|
||||
int codeOffset) {
|
||||
super(opcode);
|
||||
Preconditions.checkFormat(opcode, FORMAT);
|
||||
this.registerA = Preconditions.checkByteRegister(registerA);
|
||||
this.offset = offset;
|
||||
this.codeOffset = codeOffset;
|
||||
}
|
||||
|
||||
public static ImmutableInstruction31t of(Instruction31t instruction) {
|
||||
@ -60,11 +60,11 @@ public class ImmutableInstruction31t extends ImmutableInstruction implements Ins
|
||||
return new ImmutableInstruction31t(
|
||||
instruction.getOpcode(),
|
||||
instruction.getRegisterA(),
|
||||
instruction.getOffset());
|
||||
instruction.getCodeOffset());
|
||||
}
|
||||
|
||||
@Override public int getRegisterA() { return registerA; }
|
||||
@Override public int getOffset() { return offset; }
|
||||
@Override public int getCodeOffset() { return codeOffset; }
|
||||
|
||||
@Override public Format getFormat() { return FORMAT; }
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ public class Preconditions {
|
||||
return literal;
|
||||
}
|
||||
|
||||
public static int checkByteOffset(int register) {
|
||||
public static int checkByteCodeOffset(int register) {
|
||||
if ((register & 0xFFFFFF00) != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Invalid code offset: %d. Must be between -8 and 7, inclusive.", register));
|
||||
@ -115,7 +115,7 @@ public class Preconditions {
|
||||
return register;
|
||||
}
|
||||
|
||||
public static int checkShortOffset(int register) {
|
||||
public static int checkShortCodeOffset(int register) {
|
||||
if ((register & 0xFFFF0000) != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Invalid code offset: %d. Must be between -32768 and 32767, inclusive.", register));
|
||||
|
Loading…
x
Reference in New Issue
Block a user