Skip to content

Commit

Permalink
feat(#678): use lowercase in opcode names
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Aug 26, 2024
1 parent 93e2f5d commit a4c72f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.objectweb.asm.Opcodes;
Expand All @@ -47,6 +48,11 @@ public final class OpcodeName {
*/
private static final AtomicInteger DEFAULT = new AtomicInteger(0);

/**
* Unknown opcode name.
*/
private static final String UNKNOWN = "unknown";

/**
* Bytecode operation code.
*/
Expand Down Expand Up @@ -80,15 +86,15 @@ public OpcodeName(final int opcode, final AtomicInteger counter) {
* @return Simplified opcode name.
*/
public String simplified() {
return OpcodeName.NAMES.getOrDefault(this.opcode, "UNKNOWN");
return OpcodeName.NAMES.getOrDefault(this.opcode, OpcodeName.UNKNOWN);
}

/**
* Get string representation of a bytecode.
* @return String representation of a bytecode.
*/
public String asString() {
final String opc = OpcodeName.NAMES.getOrDefault(this.opcode, "UNKNOWN");
final String opc = OpcodeName.NAMES.getOrDefault(this.opcode, OpcodeName.UNKNOWN);
return String.format("%s-%X", opc, this.counter.incrementAndGet());
}

Expand All @@ -101,7 +107,7 @@ private static Map<Integer, String> init() {
final Map<Integer, String> res = new HashMap<>();
for (final Field field : Opcodes.class.getFields()) {
if (field.getType() == int.class) {
res.put(field.getInt(Opcodes.class), field.getName());
res.put(field.getInt(Opcodes.class), field.getName().toLowerCase(Locale.ROOT));
}
}
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ void transformsBytecodeIntoEoWithoutCountingOpcodes() {
),
xmir.toString(),
XhtmlMatchers.hasXPaths(
"//o[@base='opcode' and @name='GETSTATIC']",
"//o[@base='opcode' and @name='LDC']",
"//o[@base='opcode' and @name='INVOKEVIRTUAL']",
"//o[@base='opcode' and @name='RETURN']"
"//o[@base='opcode' and @name='getstatic']",
"//o[@base='opcode' and @name='ldc']",
"//o[@base='opcode' and @name='invokevirtual']",
"//o[@base='opcode' and @name='return']"
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void visitsMultiArrayInstructionSuccessfully() throws ImpossibleModificationExce
"MultiArray instruction wasn't visited successfully.",
new Xembler(method).xml(),
Matchers.allOf(
Matchers.containsString("MULTIANEWARRAY"),
Matchers.containsString("multianewarray"),
Matchers.containsString("2")
)
);
Expand Down Expand Up @@ -409,7 +409,7 @@ void visitsLookupSwitchInstructionSuccessfully() throws ImpossibleModificationEx
"LookupSwitch instruction wasn't visited successfully.",
new Xembler(method).xml(),
Matchers.allOf(
Matchers.containsString("LOOKUPSWITCH"),
Matchers.containsString("lookupswitch"),
Matchers.containsString("1"),
Matchers.containsString("2"),
Matchers.containsString("3"),
Expand All @@ -428,7 +428,7 @@ void visitsTableSwitchInstructionSuccessfully() throws ImpossibleModificationExc
"TableSwitch instruction wasn't visited successfully.",
new Xembler(method).xml(),
Matchers.allOf(
Matchers.containsString("TABLESWITCH"),
Matchers.containsString("tableswitch"),
Matchers.containsString("1"),
Matchers.containsString("3"),
Matchers.containsString("label")
Expand Down

0 comments on commit a4c72f4

Please sign in to comment.