Expand description
Support for various JVM class file formats (binary, etc.)
§Formats Module
The formats module handles the translation between external representations (binary .class files, text .jasm files) and the internal JvmProgram model.
§Overview
This module is the I/O hub of the library. It provides specialized sub-modules for different JVM-related formats:
- Class: Binary Java Class file format (JVMS Chapter 4).
- JASM: Human-readable assembly language for JVM bytecode.
§Core Capabilities
§1. Java Class File Support (class)
- Reading: Parse complex binary structures into a high-level IR.
- Writing: Serialize the IR back to binary, handling constant pool generation and instruction encoding.
- Viewing: Fast metadata access without full bytecode parsing.
§2. JASM Assembly Support (jasm)
- Parsing: Convert
.jasmtext files intoJvmProgram. - Generation: Disassemble a
JvmProgramor binary.classfile into readable.jasmsource code.
§Unified Workflow
The library is designed to allow seamless conversion between formats:
// .class -> JvmProgram -> .jasm
let program = ClassReader::new(class_file, &config).read().result?;
let jasm_code = JasmWriter::new().write(&program)?;
// .jasm -> JvmProgram -> .class
let program = JasmParser::new(jasm_source).parse()?;
ClassWriter::new(&mut output_buffer).write(&program).result?;§Error Handling
All format operations return GaiaDiagnostics<T>, which includes:
result: The successfully parsed/written object or aGaiaError.diagnostics: A list of warnings or non-fatal errors encountered during the process.