jvm_assembler/formats/jasm/ast/
mod.rs

1pub mod to_jasm;
2pub mod to_program;
3
4#[derive(Clone, Debug)]
5pub struct JasmClass {
6    /// 访问修饰符(如 public, private 等)
7    pub modifiers: Vec<String>,
8    /// 类名
9    pub name: String,
10    /// 版本信息(如 65:0)
11    pub version: Option<String>,
12    /// 方法列表
13    pub methods: Vec<JasmMethod>,
14    /// 字段列表
15    pub fields: Vec<JasmField>,
16    /// 源文件信息
17    pub source_file: Option<String>,
18}
19
20/// JASM 方法声明的 AST 节点
21#[derive(Clone, Debug)]
22pub struct JasmMethod {
23    /// 访问修饰符(如 public, static 等)
24    pub modifiers: Vec<String>,
25    /// 方法名和类型描述符(如 "main":"([Ljava/lang/String;)V")
26    pub name_and_descriptor: String,
27    /// 栈大小
28    pub stack_size: Option<u32>,
29    /// 局部变量数量
30    pub locals_count: Option<u32>,
31    /// 方法体指令
32    pub instructions: Vec<JasmInstruction>,
33}
34
35/// JASM 字段声明的 AST 节点
36#[derive(Clone, Debug)]
37pub struct JasmField {
38    /// 访问修饰符
39    pub modifiers: Vec<String>,
40    /// 字段名和类型描述符
41    pub name_and_descriptor: String,
42}
43
44/// JASM 指令的 AST 节点
45#[derive(Clone, Debug)]
46pub enum JasmInstruction {
47    /// 简单指令(如 aload_0, return)
48    Simple(String),
49    /// 带参数的指令(如 ldc "Hello World")
50    WithArgument { instruction: String, argument: String },
51    /// 方法调用指令(如 invokespecial Method java/lang/Object."<init>":"()V")
52    MethodCall { instruction: String, method_ref: String },
53    /// 字段访问指令(如 getstatic Field java/lang/System.out:"Ljava/io/PrintStream;")
54    FieldAccess { instruction: String, field_ref: String },
55}
56
57/// JASM 根节点,表示整个 JASM 文件的 AST
58#[derive(Clone, Debug)]
59pub struct JasmRoot {
60    /// 类定义
61    pub class: JasmClass,
62}