gruel_air/sema/
output.rs

1//! Output types from semantic analysis.
2//!
3//! This module contains the final outputs produced by semantic analysis:
4//! - [`AnalyzedFunction`] - A single analyzed function with typed IR
5//! - [`SemaOutput`] - Complete output from analyzing a program
6
7use crate::inst::Air;
8use crate::intern_pool::TypeInternPool;
9use crate::types::Type;
10use gruel_error::CompileWarning;
11
12/// Result of analyzing a function.
13#[derive(Debug)]
14pub struct AnalyzedFunction {
15    pub name: String,
16    pub air: Air,
17    /// Number of local variable slots needed
18    pub num_locals: u32,
19    /// Number of ABI slots used by parameters.
20    /// For scalar types (i32, bool), each parameter uses 1 slot.
21    /// For struct types, each field uses 1 slot (flattened ABI).
22    pub num_param_slots: u32,
23    /// Whether each parameter slot is passed as inout (by reference).
24    /// Length matches num_param_slots - for struct params, all slots share
25    /// the same mode as the original parameter.
26    pub param_modes: Vec<bool>,
27    /// Type of each parameter ABI slot, parallel to `param_modes`.
28    /// Preserved here so backends can declare correct function signatures
29    /// even when DCE has removed unused `Param` instructions from the body.
30    pub param_slot_types: Vec<Type>,
31    /// Whether this function is a destructor (`drop fn`).
32    /// Destructors must not auto-drop their `self` parameter, as the
33    /// destructor IS the drop logic for that value.
34    pub is_destructor: bool,
35}
36
37/// Output from semantic analysis.
38///
39/// Contains all analyzed functions, struct definitions, enum definitions, and any warnings
40/// generated during analysis.
41#[derive(Debug)]
42pub struct SemaOutput {
43    /// Analyzed functions with typed IR.
44    pub functions: Vec<AnalyzedFunction>,
45    /// String literals indexed by their AIR string_const index.
46    pub strings: Vec<String>,
47    /// Warnings collected during analysis.
48    pub warnings: Vec<CompileWarning>,
49    /// Type intern pool (contains all types including arrays).
50    pub type_pool: TypeInternPool,
51    /// Lines of `@dbg` output collected during comptime evaluation.
52    pub comptime_dbg_output: Vec<String>,
53}