Skip to main content

wasm_pvm/translate/
stats.rs

1/// Compilation statistics collected during the WASM-to-PVM pipeline.
2#[derive(Debug, Clone)]
3pub struct CompileStats {
4    // ── Input ──
5    pub local_functions: usize,
6    pub imported_functions: usize,
7    pub globals: usize,
8    pub active_data_segments: usize,
9    pub passive_data_segments: usize,
10    pub function_table_entries: usize,
11    pub initial_memory_pages: u32,
12    pub max_memory_pages: u32,
13    /// The max pages declared in the WASM module (None = module didn't specify, default was used).
14    pub wasm_declared_max_pages: Option<u32>,
15    pub import_resolutions: Vec<ImportResolution>,
16
17    // ── Memory Layout ──
18    pub wasm_memory_base: i32,
19    pub globals_region_bytes: usize,
20    pub ro_data_bytes: usize,
21    pub rw_data_bytes: usize,
22    pub heap_pages: u16,
23    pub stack_size: u32,
24
25    // ── Output ──
26    pub pvm_instructions: usize,
27    pub code_bytes: usize,
28    pub jump_table_entries: usize,
29    pub dead_functions_eliminated: usize,
30    pub spi_blob_bytes: usize,
31
32    // ── Per-function ──
33    pub functions: Vec<FunctionStats>,
34}
35
36/// How an imported function was resolved.
37#[derive(Debug, Clone)]
38pub struct ImportResolution {
39    pub name: String,
40    pub action: String,
41}
42
43/// Per-function compilation statistics.
44#[derive(Debug, Clone)]
45pub struct FunctionStats {
46    pub name: String,
47    pub index: usize,
48    pub instruction_count: usize,
49    pub frame_size: i32,
50    pub is_leaf: bool,
51    pub is_entry: bool,
52    pub is_dead: bool,
53    pub regalloc: FunctionRegAllocStats,
54    /// Instructions before dead store elimination (0 if DSE disabled).
55    pub pre_dse_instructions: usize,
56    /// Instructions before peephole (0 if peephole disabled).
57    pub pre_peephole_instructions: usize,
58}
59
60/// Register allocation statistics for a single function.
61#[derive(Debug, Clone, Default)]
62pub struct FunctionRegAllocStats {
63    pub total_values: usize,
64    pub allocated_values: usize,
65    pub registers_used: Vec<String>,
66    pub skipped_reason: Option<String>,
67    pub load_hits: usize,
68    pub load_reloads: usize,
69    pub load_moves: usize,
70    pub store_hits: usize,
71    pub store_moves: usize,
72}