Expand description
§Class File View Module
The view module provides a low-level, structured view of a JVM Class file. Unlike the JvmProgram IR which is designed for manipulation and conversion, ClassInfo is a read-only representation that closely mirrors the physical structure of the .class file.
§Why use Class View?
- Metadata Extraction: Quickly access class names, superclasses, and interfaces without parsing the entire method bytecode.
- Constant Pool Access: Directly inspect constant pool entries by their original indices.
- Performance: More efficient than full IR parsing when you only need high-level metadata.
- Verification: Useful for tools that need to verify the exact binary structure of a class file.
§Core Structure: ClassInfo
ClassInfo contains:
- Version: Major and minor version numbers.
- Constant Pool: A raw list of constant pool entries.
- Access Flags: Class-level access modifiers.
- Class Names: Indices and resolved names for this class and its superclass.
- Interfaces: List of implemented interfaces.
- Fields & Methods: High-level metadata for members (without full instruction parsing).
§Usage Example
use jvm_assembler::formats::class::ClassReadConfig;
use jvm_assembler::formats::class::reader::ClassReader;
use std::fs::File;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = File::open("MyClass.class")?;
let config = ClassReadConfig::default();
let reader = ClassReader::new(file, &config);
// Get the low-level view instead of the full program
let info = reader.get_info()?;
println!("Class Name: {}", info.this_class_name);
println!("Super Class: {}", info.super_class_name.as_deref().unwrap_or("None"));
println!("Version: {}.{}", info.major_version, info.minor_version);
Ok(())
}Structs§
- Class
Info - Information about a JVM class file