@Nonnull private BuilderInstruction11n newBuilderInstruction11n(@Nonnull Instruction11n instruction) { return new BuilderInstruction11n( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
public static BuilderInstruction buildConstant(int value, int register) { BuilderInstruction result; int bitCount = value == 0 ? 1 : 1 + Integer.numberOfTrailingZeros(Integer.highestOneBit(value)); if (bitCount < 4 && (register & 0xFFFFFFF0) == 0) { result = new BuilderInstruction11n(Opcode.CONST_4, register, value); } else if (bitCount < 16 && (register & 0xFFFFFF00) == 0) { result = new BuilderInstruction21s(Opcode.CONST_16, register, value); } else { result = new BuilderInstruction31i(Opcode.CONST, register, value); } return result; }
@Override protected BuilderInstruction getRealInsn0(LabelAssigner assigner) { return new BuilderInstruction11n(opc, (byte) getRegA().getNumber(), getLitB()); }
@Test public void with4BitLiteral() { int value = 7; Instruction expected = new BuilderInstruction11n(Opcode.CONST_4, REGISTER, value); Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); testEquals(expected, actual); }
@Test public void with4BitLiteral() { byte value = 7; Instruction expected = new BuilderInstruction11n(Opcode.CONST_4, REGISTER, value); Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); testEquals(expected, actual); }
@Test public void withTrue() { Boolean value = Boolean.TRUE; Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); Instruction expected = new BuilderInstruction11n(Opcode.CONST_4, REGISTER, 1); testEquals(expected, actual); } }
@Test public void with4BitLiteral() { short value = 7; Instruction expected = new BuilderInstruction11n(Opcode.CONST_4, REGISTER, value); Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); testEquals(expected, actual); }
@Test public void withFalse() { Boolean value = Boolean.FALSE; Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); Instruction expected = new BuilderInstruction11n(Opcode.CONST_4, REGISTER, 0); testEquals(expected, actual); }
@Test public void withHeapItemWitByteTypeAndIntegerValue() { int intValue = 5; Instruction expected = new BuilderInstruction11n(Opcode.CONST_4, REGISTER, intValue); HeapItem value = new HeapItem(intValue, "B"); int address = 0; ExecutionGraphManipulator manipulator = getMockedGraph(address, value); Instruction actual = ConstantBuilder.buildConstant(address, manipulator); testEquals(expected, actual); } }
@Test public void withHeapItemWitFloatTypeAndIntegerValue() { int intValue = 5; Instruction expected = new BuilderInstruction11n(Opcode.CONST_4, REGISTER, intValue); HeapItem value = new HeapItem(intValue, "F"); int address = 0; ExecutionGraphManipulator manipulator = getMockedGraph(address, value); Instruction actual = ConstantBuilder.buildConstant(address, manipulator); testEquals(expected, actual); }
@Test public void withHeapItemWithBooleanTypeAndIntegerValue() { int intValue = 1; Instruction expected = new BuilderInstruction11n(Opcode.CONST_4, REGISTER, intValue); HeapItem value = new HeapItem(intValue, "Z"); int address = 0; ExecutionGraphManipulator manipulator = getMockedGraph(address, value); Instruction actual = ConstantBuilder.buildConstant(address, manipulator); testEquals(expected, actual); }
@Test public void withHeapItemWitShortTypeAndIntegerValue() { int intValue = 5; Instruction expected = new BuilderInstruction11n(Opcode.CONST_4, REGISTER, intValue); HeapItem value = new HeapItem(intValue, "S"); int address = 0; ExecutionGraphManipulator manipulator = getMockedGraph(address, value); Instruction actual = ConstantBuilder.buildConstant(address, manipulator); testEquals(expected, actual); }
@Test public void replacingInstructionGetsLabelsAtInsertionAddress() { manipulator = OptimizerTester.getGraphManipulator(CLASS_NAME, "hasLabelOnConstantizableOp(I)I"); BuilderInstruction addition = new BuilderInstruction11n(Opcode.CONST_4, 0, 2); assertEquals(1, manipulator.getInstruction(3).getLocation().getLabels().size()); manipulator.replaceInstruction(3, addition); assertEquals(1, manipulator.getInstruction(3).getLocation().getLabels().size()); }
LiteralTools.checkNibble(litB); method_stack.peek().methodBuilder.addInstruction(new BuilderInstruction11n(opcode, regA, litB));
@Nonnull private BuilderInstruction11n newBuilderInstruction11n(@Nonnull Instruction11n instruction) { return new BuilderInstruction11n( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
@Nonnull private BuilderInstruction11n newBuilderInstruction11n(@Nonnull Instruction11n instruction) { return new BuilderInstruction11n( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
@Nonnull private BuilderInstruction11n newBuilderInstruction11n(@Nonnull Instruction11n instruction) { return new BuilderInstruction11n( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
@Nonnull private BuilderInstruction11n newBuilderInstruction11n(@Nonnull Instruction11n instruction) { return new BuilderInstruction11n( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
LiteralTools.checkNibble(litB); method_stack.peek().methodBuilder.addInstruction(new BuilderInstruction11n(opcode, regA, litB));
LiteralTools.checkNibble(litB); method_stack.peek().methodBuilder.addInstruction(new BuilderInstruction11n(opcode, regA, litB));