1 //! Interface of a Rust codegen backend
3 //! This crate defines all the traits that have to be implemented by a codegen backend in order to
4 //! use the backend-agnostic codegen code in `rustc_codegen_ssa`.
6 //! The interface is designed around two backend-specific data structures, the codegen context and
7 //! the builder. The codegen context is supposed to be read-only after its creation and during the
8 //! actual codegen, while the builder stores the information about the function during codegen and
9 //! is used to produce the instructions of the backend IR.
11 //! Finally, a third `Backend` structure has to implement methods related to how codegen information
12 //! is passed to the backend, especially for asynchronous compilation.
14 //! The traits contain associated types that are backend-specific, such as the backend's value or
30 pub use self::abi::AbiBuilderMethods;
31 pub use self::asm::{AsmBuilderMethods, AsmMethods, InlineAsmOperandRef};
32 pub use self::backend::{Backend, BackendTypes, CodegenBackend, ExtraBackendMethods};
33 pub use self::builder::{BuilderMethods, OverflowOp};
34 pub use self::consts::ConstMethods;
35 pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
36 pub use self::declare::{DeclareMethods, PreDefineMethods};
37 pub use self::intrinsic::IntrinsicCallMethods;
38 pub use self::misc::MiscMethods;
39 pub use self::statics::{StaticBuilderMethods, StaticMethods};
40 pub use self::type_::{
41 ArgAbiMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMethods,
43 pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
45 use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt};
46 use rustc_target::spec::HasTargetSpec;
50 pub trait CodegenObject: Copy + PartialEq + fmt::Debug {}
51 impl<T: Copy + PartialEq + fmt::Debug> CodegenObject for T {}
53 pub trait CodegenMethods<'tcx>:
59 + DebugInfoMethods<'tcx>
60 + DeclareMethods<'tcx>
62 + PreDefineMethods<'tcx>
69 impl<'tcx, T> CodegenMethods<'tcx> for T where
75 + DebugInfoMethods<'tcx>
76 + DeclareMethods<'tcx>
78 + PreDefineMethods<'tcx>
85 pub trait HasCodegen<'tcx>:
86 Backend<'tcx> + ::std::ops::Deref<Target = <Self as HasCodegen<'tcx>>::CodegenCx>
88 type CodegenCx: CodegenMethods<'tcx>
91 Function = Self::Function,
92 BasicBlock = Self::BasicBlock,
94 Funclet = Self::Funclet,
95 DIScope = Self::DIScope,
96 DIVariable = Self::DIVariable,