https://github.com/wdestroier/chamomile
Chamomile is a Java Virtual Machine class file assembler and disassembler.
https://github.com/wdestroier/chamomile
Last synced: 5 months ago
JSON representation
Chamomile is a Java Virtual Machine class file assembler and disassembler.
- Host: GitHub
- URL: https://github.com/wdestroier/chamomile
- Owner: Wdestroier
- License: bsl-1.0
- Created: 2021-07-10T19:33:16.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-07-12T07:01:53.000Z (almost 4 years ago)
- Last Synced: 2023-08-27T21:24:00.189Z (over 1 year ago)
- Language: Java
- Homepage:
- Size: 128 KB
- Stars: 15
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
Chamomile is a Java Virtual Machine class file assembler and disassembler.
Installation
Maven
```xml
jitpack.io
https://jitpack.io
com.github.wdestroier
chamomile
1.0.0
```
Gradle
```kotlin
repositories {
maven("https://jitpack.io")
}dependencies {
implementation("com.github.wdestroier:chamomile:1.0.0")
}
```
Demonstration
Assemble a list of instructions
```java
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));
```Output
```txt
[4, 133, 1, 87, 13, 140, 97, 184, 0, 12]
```
Disassemble an array of "unsigned bytes"
```java
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);
```Output
```txt
iconst_1
i2l
aconst_null
pop
fconst_2
f2l
ladd
invokestatic
```
More examples can be found [here](/examples)