solar_codegen/backend/mod.rs
1//! The backend protocol.
2//!
3//! MIR is the target-agnostic middle-end boundary; a backend consumes a
4//! [`Module`] and lowers it to a target artifact. Other backends implement
5//! [`Backend`] to plug in; [`EvmCodegen`](crate::EvmCodegen) is the reference.
6
7use crate::mir::Module;
8
9pub mod evm;
10
11/// A code generation backend that lowers MIR to a target artifact.
12pub trait Backend {
13 /// The artifact this backend produces from a module.
14 type Output;
15
16 /// A short identifier for this backend, e.g. `"evm"`.
17 fn name(&self) -> &str;
18
19 /// Lowers a module to this backend's output artifact. Takes `&mut` so the
20 /// backend can run its own target-specific passes over the MIR first.
21 fn lower_module(&mut self, module: &mut Module) -> Self::Output;
22}