Skip to content

Commit

Permalink
Fix computed sizes of WideInstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicPlayerA10 committed Nov 18, 2024
1 parent 50392e2 commit 17aba1e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ public Instruction getBacking() {

@Override
public int computeSize() {
switch (backing.getOpcode()) {
case Opcodes.IINC:
return 6;
case Opcodes.LLOAD:
case Opcodes.DLOAD:
case Opcodes.LSTORE:
case Opcodes.DSTORE:
return 4;
default:
return 3;
if (backing.getOpcode() == Opcodes.IINC) {
// opcode
// iinc
// indexbyte1
// indexbyte2
// constbyte1
// constbyte2
return 6;
}
// opcode
// input opcode
// indexbyte1
// indexbyte2
return 4;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package software.coley.cafedude;

import software.coley.cafedude.classfile.ClassFile;
import software.coley.cafedude.io.ClassFileReader;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import software.coley.cafedude.io.ClassFileWriter;

import java.io.File;
import java.io.IOException;
Expand All @@ -23,7 +25,8 @@ public void testNoErrors(File sample) {
try {
byte[] code = Files.readAllBytes(sample.toPath());
assertDoesNotThrow(() -> {
new ClassFileReader().read(code);
ClassFile classFile = new ClassFileReader().read(code);
new ClassFileWriter().write(classFile);
}, "Library crashes when reading: " + sample.getName());
} catch (IOException error) {
fail("Failed to read class, IO error", error);
Expand Down
10 changes: 5 additions & 5 deletions core/src/test/java/software/coley/cafedude/SizeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ void testWideInstruction() {

// Wide type variable insns are 4
for (int op : four_byte_ops) {
instruction = new WideInstruction(new IntOperandInstruction(op, 0));
assertEquals(4, instruction.computeSize());
WideInstruction instruction1 = new WideInstruction(new IntOperandInstruction(op, 0));
assertEquals(4, instruction1.computeSize());
}
// Normal variable insns are 3
// Normal variable insns are 2
for (int op : three_byte_ops) {
instruction = new WideInstruction(new IntOperandInstruction(op, 0));
assertEquals(3, instruction.computeSize());
IntOperandInstruction instruction2 = new IntOperandInstruction(op, 0);
assertEquals(2, instruction2.computeSize());
}
}

Expand Down
Binary file not shown.

0 comments on commit 17aba1e

Please sign in to comment.