oak_vampire/ast/
mod.rs

1#![doc = include_str!("readme.md")]
2
3/// Valkyrie 根节#[derive(Clone, Debug)]
4pub struct ValkyrieRoot {
5    pub items: Vec<ValkyrieItem>,
6}
7
8/// Valkyrie 项目
9#[derive(Clone, Debug)]
10pub enum ValkyrieItem {
11    Module(ValkyrieModule),
12    Function(ValkyrieFunction),
13    Memory(ValkyrieMemory),
14    Export(ValkyrieExport),
15    Import(ValkyrieImport),
16}
17
18/// Valkyrie 模块
19#[derive(Clone, Debug)]
20pub struct ValkyrieModule {
21    pub name: Option<String>,
22    pub items: Vec<ValkyrieItem>,
23}
24
25/// Valkyrie 函数
26#[derive(Clone, Debug)]
27pub struct ValkyrieFunction {
28    pub name: Option<String>,
29    pub params: Vec<ValkyrieParam>,
30    pub result: Option<ValkyrieType>,
31    pub locals: Vec<ValkyrieLocal>,
32    pub body: Vec<ValkyrieInstruction>,
33}
34
35/// Valkyrie 参数
36#[derive(Clone, Debug)]
37pub struct ValkyrieParam {
38    pub name: Option<String>,
39    pub param_type: ValkyrieType,
40}
41
42/// Valkyrie 局部变量
43#[derive(Clone, Debug)]
44pub struct ValkyrieLocal {
45    pub name: Option<String>,
46    pub local_type: ValkyrieType,
47}
48
49/// Valkyrie 类型
50#[derive(Clone, Debug)]
51pub enum ValkyrieType {
52    I32,
53    I64,
54    F32,
55    F64,
56}
57
58/// Valkyrie 内存
59#[derive(Clone, Debug)]
60pub struct ValkyrieMemory {
61    pub name: Option<String>,
62    pub min: u32,
63    pub max: Option<u32>,
64}
65
66/// Valkyrie 导出
67#[derive(Clone, Debug)]
68pub struct ValkyrieExport {
69    pub name: String,
70    pub kind: ValkyrieExportKind,
71}
72
73/// Valkyrie 导出类型
74#[derive(Clone, Debug)]
75pub enum ValkyrieExportKind {
76    Function(String),
77    Memory(String),
78    Global(String),
79    Table(String),
80}
81
82/// Valkyrie 导入
83#[derive(Clone, Debug)]
84pub struct ValkyrieImport {
85    pub module: String,
86    pub name: String,
87    pub kind: ValkyrieImportKind,
88}
89
90/// Valkyrie 导入类型
91#[derive(Clone, Debug)]
92pub enum ValkyrieImportKind {
93    Function(ValkyrieFunctionType),
94    Memory(ValkyrieMemoryType),
95    Global(ValkyrieGlobalType),
96    Table(ValkyrieTableType),
97}
98
99/// Valkyrie 函数类型
100#[derive(Clone, Debug)]
101pub struct ValkyrieFunctionType {
102    pub params: Vec<ValkyrieType>,
103    pub results: Vec<ValkyrieType>,
104}
105
106/// Valkyrie 内存类型
107#[derive(Clone, Debug)]
108pub struct ValkyrieMemoryType {
109    pub min: u32,
110    pub max: Option<u32>,
111}
112
113/// Valkyrie 全局类型
114#[derive(Clone, Debug)]
115pub struct ValkyrieGlobalType {
116    pub value_type: ValkyrieType,
117    pub mutable: bool,
118}
119
120/// Valkyrie 表类型
121#[derive(Clone, Debug)]
122pub struct ValkyrieTableType {
123    pub element_type: ValkyrieType,
124    pub min: u32,
125    pub max: Option<u32>,
126}
127
128/// Valkyrie 指令
129#[derive(Clone, Debug)]
130pub enum ValkyrieInstruction {
131    /// 简单指令(nop, drop)
132    Simple(String),
133    /// 带参数的指令(如 i32.const 42)
134    WithOperand { opcode: String, operand: String },
135    /// 控制流指令(if, loop, block)
136    Control { opcode: String, label: Option<String> },
137    /// 函数调用指令(如 call $func)
138    Call { function: String },
139}