rustc_codegen_ssa/traits/
mod.rs

1//! Interface of a Rust codegen backend
2//!
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`.
5//!
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.
10//!
11//! The traits contain associated types that are backend-specific, such as the backend's value or
12//! basic blocks.
13
14mod abi;
15mod asm;
16mod backend;
17mod builder;
18mod consts;
19mod coverageinfo;
20mod debuginfo;
21mod declare;
22mod intrinsic;
23mod misc;
24mod statics;
25mod type_;
26mod write;
27
28use std::fmt;
29
30use rustc_middle::ty::Ty;
31use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
32use rustc_target::callconv::FnAbi;
33
34pub use self::abi::AbiBuilderMethods;
35pub use self::asm::{
36    AsmBuilderMethods, AsmCodegenMethods, GlobalAsmOperandRef, InlineAsmOperandRef,
37};
38pub use self::backend::{BackendTypes, CodegenBackend, ExtraBackendMethods};
39pub use self::builder::{BuilderMethods, OverflowOp};
40pub use self::consts::ConstCodegenMethods;
41pub use self::coverageinfo::CoverageInfoBuilderMethods;
42pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoCodegenMethods};
43pub use self::declare::PreDefineCodegenMethods;
44pub use self::intrinsic::IntrinsicCallBuilderMethods;
45pub use self::misc::MiscCodegenMethods;
46pub use self::statics::{StaticBuilderMethods, StaticCodegenMethods};
47pub use self::type_::{
48    ArgAbiBuilderMethods, BaseTypeCodegenMethods, DerivedTypeCodegenMethods,
49    LayoutTypeCodegenMethods, TypeCodegenMethods, TypeMembershipCodegenMethods,
50};
51pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
52
53pub trait CodegenObject = Copy + PartialEq + fmt::Debug;
54
55pub trait CodegenMethods<'tcx> = LayoutOf<'tcx, LayoutOfResult = TyAndLayout<'tcx>>
56    + FnAbiOf<'tcx, FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>>
57    + TypeCodegenMethods<'tcx>
58    + ConstCodegenMethods
59    + StaticCodegenMethods
60    + DebugInfoCodegenMethods<'tcx>
61    + AsmCodegenMethods<'tcx>
62    + PreDefineCodegenMethods<'tcx>;