<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.wdestroier</groupId>
<artifactId>chamomile</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
repositories {
maven("https://jitpack.io")
}
dependencies {
implementation("com.github.wdestroier:chamomile:1.0.0")
}
var assembler = new SinglePassAssembler();
var bytecode = assembler.assemble(List.of(
new Iconst1Instruction(),
new I2lInstruction(),
new AconstNullInstruction(),
new PopInstruction(),
new Fconst2Instruction(),
new F2lInstruction(),
new LaddInstruction(),
new InvokestaticInstruction(InstructionFactory.instance.getOpcode(
InvokestaticInstruction.class), 12)
));
System.out.println(Arrays.toString(bytecode));
[4, 133, 1, 87, 13, 140, 97, 184, 0, 12]
var disassembler = new LinearSweepDisassembler();
var bytecode = new short[] { 4, 133, 1, 87, 13, 140, 97, 184, 0, 12 };
var instructions = disassembler.disassemble(bytecode);
instructions.stream()
.map(instruction -> InstructionFactory.instance.getMnemonic(instruction.getOpcode()))
.forEach(System.out::println);
iconst_1
i2l
aconst_null
pop
fconst_2
f2l
ladd
invokestatic
More examples can be found here