Home | History | Annotate | Download | only in builder

Lines Matching refs:instruction

41 import org.jf.dexlib2.builder.instruction.*;
46 import org.jf.dexlib2.iface.instruction.Instruction;
47 import org.jf.dexlib2.iface.instruction.SwitchElement;
48 import org.jf.dexlib2.iface.instruction.formats.*;
68 for (Instruction instruction: methodImplementation.getInstructions()) {
69 codeAddress += instruction.getCodeUnits();
84 for (final Instruction instruction: methodImplementation.getInstructions()) {
86 final Opcode opcode = instruction.getOpcode();
90 convertAndSetInstruction(location, codeAddressToIndex, instruction);
94 convertAndSetInstruction(location, codeAddressToIndex, instruction);
152 return instructionList.get(i).instruction;
159 // don't include the last MethodLocation, which always has a null instruction
203 public void addInstruction(int index, BuilderInstruction instruction) {
205 // (null instruction) MethodLocation at the end. To add an instruction to the end of the list, the user would
212 addInstruction(instruction);
217 instructionList.add(index, new MethodLocation(instruction, codeAddress, index));
218 codeAddress += instruction.getCodeUnits();
224 if (location.instruction != null) {
225 codeAddress += location.instruction.getCodeUnits();
227 // only the last MethodLocation should have a null instruction
235 public void addInstruction(@Nonnull BuilderInstruction instruction) {
237 last.instruction = instruction;
238 instruction.location = last;
240 int nextCodeAddress = last.codeAddress + instruction.getCodeUnits();
253 BuilderInstruction old = replaceLocation.instruction;
256 replaceLocation.instruction = replacementInstruction;
259 int codeAddress = replaceLocation.codeAddress + replaceLocation.instruction.getCodeUnits();
264 Instruction instruction = location.getInstruction();
265 if (instruction != null) {
266 codeAddress += instruction.getCodeUnits();
281 toRemove.instruction = null;
292 Instruction instruction = location.getInstruction();
293 if (instruction != null) {
294 codeAddress += instruction.getCodeUnits();
310 // only the last MethodLocation may have a null instruction
311 assert first.instruction != null;
312 assert second.instruction != null;
314 first.instruction.location = second;
315 second.instruction.location = first;
318 BuilderInstruction tmp = second.instruction;
319 second.instruction = first.instruction;
320 first.instruction = tmp;
329 int codeAddress = first.codeAddress + first.instruction.getCodeUnits();
334 Instruction instruction = location.instruction;
335 assert instruction != null;
336 codeAddress += location.instruction.getCodeUnits();
346 BuilderInstruction instruction = instructionList.get(i).instruction;
347 assert instruction != null;
348 if (instruction.getOpcode() != Opcode.NOP) {
349 return instruction;
359 BuilderInstruction instruction = location.instruction;
360 if (instruction != null) {
361 switch (instruction.getOpcode()) {
365 ((BuilderOffsetInstruction)instruction).getTarget().getLocation();
366 BuilderInstruction targetInstruction = targetLocation.instruction;
368 throw new IllegalStateException(String.format("Switch instruction at address/index " +
376 throw new IllegalStateException(String.format("Switch instruction at address/index " +
377 "0x%x/%d does not refer to a payload instruction.",
380 if ((instruction.opcode == Opcode.PACKED_SWITCH &&
382 (instruction.opcode == Opcode.SPARSE_SWITCH &&
384 throw new IllegalStateException(String.format("Switch instruction at address/index " +
385 "0x%x/%d refers to the wrong type of payload instruction.",
407 BuilderInstruction instruction = location.instruction;
408 if (instruction != null) {
409 switch (instruction.getOpcode()) {
411 int offset = ((BuilderOffsetInstruction)instruction).internalGetCodeOffset();
416 ((BuilderOffsetInstruction)instruction).getTarget());
419 ((BuilderOffsetInstruction)instruction).getTarget());
427 int offset = ((BuilderOffsetInstruction)instruction).internalGetCodeOffset();
430 ((BuilderOffsetInstruction)instruction).getTarget());
438 if (((BuilderSwitchPayload)instruction).referrer == null) {
450 Instruction previousInstruction = previousLocation.instruction;
503 private void setInstruction(@Nonnull MethodLocation location, @Nonnull BuilderInstruction instruction) {
504 location.instruction = instruction;
505 instruction.location = location;
509 @Nonnull Instruction instruction) {
510 switch (instruction.getOpcode().format) {
513 (Instruction10t)instruction));
516 setInstruction(location, newBuilderInstruction10x((Instruction10x)instruction));
519 setInstruction(location, newBuilderInstruction11n((Instruction11n)instruction));
522 setInstruction(location, newBuilderInstruction11x((Instruction11x)instruction));
525 setInstruction(location, newBuilderInstruction12x((Instruction12x)instruction));
528 setInstruction(location, newBuilderInstruction20bc((Instruction20bc)instruction));
532 (Instruction20t)instruction));
535 setInstruction(location, newBuilderInstruction21c((Instruction21c)instruction));
538 setInstruction(location, newBuilderInstruction21ih((Instruction21ih)instruction));
541 setInstruction(location, newBuilderInstruction21lh((Instruction21lh)instruction));
544 setInstruction(location, newBuilderInstruction21s((Instruction21s)instruction));
548 (Instruction21t)instruction));
551 setInstruction(location, newBuilderInstruction22b((Instruction22b)instruction));
554 setInstruction(location, newBuilderInstruction22c((Instruction22c)instruction));
557 setInstruction(location, newBuilderInstruction22s((Instruction22s)instruction));
561 (Instruction22t)instruction));
564 setInstruction(location, newBuilderInstruction22x((Instruction22x)instruction));
567 setInstruction(location, newBuilderInstruction23x((Instruction23x)instruction));
571 (Instruction30t)instruction));
574 setInstruction(location, newBuilderInstruction31c((Instruction31c)instruction));
577 setInstruction(location, newBuilderInstruction31i((Instruction31i)instruction));
581 (Instruction31t)instruction));
584 setInstruction(location, newBuilderInstruction32x((Instruction32x)instruction));
587 setInstruction(location, newBuilderInstruction35c((Instruction35c)instruction));
590 setInstruction(location, newBuilderInstruction3rc((Instruction3rc)instruction));
593 setInstruction(location, newBuilderInstruction51l((Instruction51l)instruction));
597 newBuilderPackedSwitchPayload(location, codeAddressToIndex, (PackedSwitchPayload)instruction));
601 newBuilderSparseSwitchPayload(location, codeAddressToIndex, (SparseSwitchPayload)instruction));
604 setInstruction(location, newBuilderArrayPayload((ArrayPayload)instruction));
607 throw new ExceptionWithContext("Instruction format %s not supported", instruction.getOpcode().format);
613 @Nonnull Instruction10t instruction) {
615 instruction.getOpcode(),
616 newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset()));
620 private BuilderInstruction10x newBuilderInstruction10x(@Nonnull Instruction10x instruction) {
622 instruction.getOpcode());
626 private BuilderInstruction11n newBuilderInstruction11n(@Nonnull Instruction11n instruction) {
628 instruction.getOpcode(),
629 instruction.getRegisterA(),
630 instruction.getNarrowLiteral());
634 private BuilderInstruction11x newBuilderInstruction11x(@Nonnull Instruction11x instruction) {
636 instruction.getOpcode(),
637 instruction.getRegisterA());
641 private BuilderInstruction12x newBuilderInstruction12x(@Nonnull Instruction12x instruction) {
643 instruction.getOpcode(),
644 instruction.getRegisterA(),
645 instruction.getRegisterB());
649 private BuilderInstruction20bc newBuilderInstruction20bc(@Nonnull Instruction20bc instruction) {
651 instruction.getOpcode(),
652 instruction.getVerificationError(),
653 instruction.getReference());
658 @Nonnull Instruction20t instruction) {
660 instruction.getOpcode(),
661 newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset()));
665 private BuilderInstruction21c newBuilderInstruction21c(@Nonnull Instruction21c instruction) {
667 instruction.getOpcode(),
668 instruction.getRegisterA(),
669 instruction.getReference());
673 private BuilderInstruction21ih newBuilderInstruction21ih(@Nonnull Instruction21ih instruction) {
675 instruction.getOpcode(),
676 instruction.getRegisterA(),
677 instruction.getNarrowLiteral());
681 private BuilderInstruction21lh newBuilderInstruction21lh(@Nonnull Instruction21lh instruction) {
683 instruction.getOpcode(),
684 instruction.getRegisterA(),
685 instruction.getWideLiteral());
689 private BuilderInstruction21s newBuilderInstruction21s(@Nonnull Instruction21s instruction) {
691 instruction.getOpcode(),
692 instruction.getRegisterA(),
693 instruction.getNarrowLiteral());
698 @Nonnull Instruction21t instruction) {
700 instruction.getOpcode(),
701 instruction.getRegisterA(),
702 newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset()));
706 private BuilderInstruction22b newBuilderInstruction22b(@Nonnull Instruction22b instruction) {
708 instruction.getOpcode(),
709 instruction.getRegisterA(),
710 instruction.getRegisterB(),
711 instruction.getNarrowLiteral());
715 private BuilderInstruction22c newBuilderInstruction22c(@Nonnull Instruction22c instruction) {
717 instruction.getOpcode(),
718 instruction.getRegisterA(),
719 instruction.getRegisterB(),
720 instruction.getReference());
724 private BuilderInstruction22s newBuilderInstruction22s(@Nonnull Instruction22s instruction) {
726 instruction.getOpcode(),
727 instruction.getRegisterA(),
728 instruction.getRegisterB(),
729 instruction.getNarrowLiteral());
734 @Nonnull Instruction22t instruction) {
736 instruction.getOpcode(),
737 instruction.getRegisterA(),
738 instruction.getRegisterB(),
739 newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset()));
743 private BuilderInstruction22x newBuilderInstruction22x(@Nonnull Instruction22x instruction) {
745 instruction.getOpcode(),
746 instruction.getRegisterA(),
747 instruction.getRegisterB());
751 private BuilderInstruction23x newBuilderInstruction23x(@Nonnull Instruction23x instruction) {
753 instruction.getOpcode(),
754 instruction.getRegisterA(),
755 instruction.getRegisterB(),
756 instruction.getRegisterC());
761 @Nonnull Instruction30t instruction) {
763 instruction.getOpcode(),
764 newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset()));
768 private BuilderInstruction31c newBuilderInstruction31c(@Nonnull Instruction31c instruction) {
770 instruction.getOpcode(),
771 instruction.getRegisterA(),
772 instruction.getReference());
776 private BuilderInstruction31i newBuilderInstruction31i(@Nonnull Instruction31i instruction) {
778 instruction.getOpcode(),
779 instruction.getRegisterA(),
780 instruction.getNarrowLiteral());
785 @Nonnull Instruction31t instruction) {
788 if (instruction.getOpcode() != Opcode.FILL_ARRAY_DATA) {
790 newLabel = newSwitchPayloadReferenceLabel(location, codeAddressToIndex, codeAddress + instruction.getCodeOffset());
792 newLabel = newLabel(codeAddressToIndex, codeAddress + instruction.getCodeOffset());
795 instruction.getOpcode(),
796 instruction.getRegisterA(),
801 private BuilderInstruction32x newBuilderInstruction32x(@Nonnull Instruction32x instruction) {
803 instruction.getOpcode(),
804 instruction.getRegisterA(),
805 instruction.getRegisterB());
809 private BuilderInstruction35c newBuilderInstruction35c(@Nonnull Instruction35c instruction) {
811 instruction.getOpcode(),
812 instruction.getRegisterCount(),
813 instruction.getRegisterC(),
814 instruction.getRegisterD(),
815 instruction.getRegisterE(),
816 instruction.getRegisterF(),
817 instruction.getRegisterG(),
818 instruction.getReference());
822 private BuilderInstruction3rc newBuilderInstruction3rc(@Nonnull Instruction3rc instruction) {
824 instruction.getOpcode(),
825 instruction.getStartRegister(),
826 instruction.getRegisterCount(),
827 instruction.getReference());
831 private BuilderInstruction51l newBuilderInstruction51l(@Nonnull Instruction51l instruction) {
833 instruction.getOpcode(),
834 instruction.getRegisterA(),
835 instruction.getWideLiteral());
853 // A switch instruction can refer to the payload instruction itself, or to a nop before the payload
854 // instruction.
862 if (location.instruction == null || location.instruction.getOpcode() != Opcode.NOP) {
871 @Nonnull PackedSwitchPayload instruction) {
872 List<? extends SwitchElement> switchElements = instruction.getSwitchElements();
896 @Nonnull SparseSwitchPayload instruction) {
897 List<? extends SwitchElement> switchElements = instruction.getSwitchElements();
920 private BuilderArrayPayload newBuilderArrayPayload(@Nonnull ArrayPayload instruction) {
921 return new BuilderArrayPayload(instruction.getElementWidth(), instruction.getArrayElements());