vyre_driver/backend/lowering.rs
1//! Decentralized trait-owned lowering interfaces.
2//!
3//! This module defines the core trait boundaries for operations to emit
4//! themselves into backend-owned target IRs directly. This decentralizes
5//! the lowering monolith and ensures operations own their compilation rules.
6
7use vyre_foundation::ir::Program;
8
9/// Represents context provided to an operation during target expression generation.
10pub trait TargetGenCtx {
11 /// Register a target expression for the op being lowered. The
12 /// `format` string is opaque to the trait - backends interpret it
13 /// per their own emit conventions.
14 fn register_expression(&mut self, format: &str) -> Result<(), ()>;
15}
16
17/// A target-agnostic context payload bounds ops that can be lowered.
18pub trait LowerableOp: Send + Sync + 'static {
19 /// Lower the operation into the target expression context.
20 fn lower_expression(&self, ctx: &mut dyn TargetGenCtx, program: &Program)
21 -> Result<(), String>;
22
23 /// Lower the operation into a target binary context.
24 fn lower_binary(&self, ctx: &mut (), program: &Program) -> Result<(), String>;
25}