]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_codegen_ssa/src/traits/mod.rs
New upstream version 1.62.1+dfsg1
[rustc.git] / compiler / rustc_codegen_ssa / src / traits / mod.rs
CommitLineData
a1dfa0c6
XL
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//!
74b04a01 11//! Finally, a third `Backend` structure has to implement methods related to how codegen information
a1dfa0c6
XL
12//! is passed to the backend, especially for asynchronous compilation.
13//!
14//! The traits contain associated types that are backend-specific, such as the backend's value or
15//! basic blocks.
16
17mod abi;
18mod asm;
19mod backend;
20mod builder;
21mod consts;
f035d41b 22mod coverageinfo;
a1dfa0c6
XL
23mod debuginfo;
24mod declare;
25mod intrinsic;
26mod misc;
27mod statics;
28mod type_;
29mod write;
30
dfeec247 31pub use self::abi::AbiBuilderMethods;
17df50a5 32pub use self::asm::{AsmBuilderMethods, AsmMethods, GlobalAsmOperandRef, InlineAsmOperandRef};
ba9703b0 33pub use self::backend::{Backend, BackendTypes, CodegenBackend, ExtraBackendMethods};
a1dfa0c6
XL
34pub use self::builder::{BuilderMethods, OverflowOp};
35pub use self::consts::ConstMethods;
f035d41b 36pub use self::coverageinfo::{CoverageInfoBuilderMethods, CoverageInfoMethods};
a1dfa0c6 37pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
1b1a35ee 38pub use self::declare::PreDefineMethods;
a1dfa0c6
XL
39pub use self::intrinsic::IntrinsicCallMethods;
40pub use self::misc::MiscMethods;
dfeec247 41pub use self::statics::{StaticBuilderMethods, StaticMethods};
a1dfa0c6 42pub use self::type_::{
60c5eb7d 43 ArgAbiMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMethods,
a1dfa0c6
XL
44};
45pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
48663c56 46
ba9703b0 47use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt};
60c5eb7d 48use rustc_target::spec::HasTargetSpec;
a1dfa0c6
XL
49
50use std::fmt;
51
52pub trait CodegenObject: Copy + PartialEq + fmt::Debug {}
53impl<T: Copy + PartialEq + fmt::Debug> CodegenObject for T {}
54
55pub trait CodegenMethods<'tcx>:
56 Backend<'tcx>
57 + TypeMethods<'tcx>
58 + MiscMethods<'tcx>
59 + ConstMethods<'tcx>
60 + StaticMethods
cdc7bbd5 61 + CoverageInfoMethods<'tcx>
a1dfa0c6 62 + DebugInfoMethods<'tcx>
04454e1e 63 + AsmMethods<'tcx>
a1dfa0c6 64 + PreDefineMethods<'tcx>
48663c56
XL
65 + HasParamEnv<'tcx>
66 + HasTyCtxt<'tcx>
67 + HasTargetSpec
a1dfa0c6
XL
68{
69}
70
71impl<'tcx, T> CodegenMethods<'tcx> for T where
72 Self: Backend<'tcx>
73 + TypeMethods<'tcx>
74 + MiscMethods<'tcx>
75 + ConstMethods<'tcx>
76 + StaticMethods
cdc7bbd5 77 + CoverageInfoMethods<'tcx>
a1dfa0c6 78 + DebugInfoMethods<'tcx>
04454e1e 79 + AsmMethods<'tcx>
a1dfa0c6 80 + PreDefineMethods<'tcx>
48663c56
XL
81 + HasParamEnv<'tcx>
82 + HasTyCtxt<'tcx>
83 + HasTargetSpec
a1dfa0c6
XL
84{
85}
86
87pub trait HasCodegen<'tcx>:
29967ef6 88 Backend<'tcx> + std::ops::Deref<Target = <Self as HasCodegen<'tcx>>::CodegenCx>
a1dfa0c6
XL
89{
90 type CodegenCx: CodegenMethods<'tcx>
91 + BackendTypes<
92 Value = Self::Value,
e74abb32 93 Function = Self::Function,
a1dfa0c6
XL
94 BasicBlock = Self::BasicBlock,
95 Type = Self::Type,
96 Funclet = Self::Funclet,
97 DIScope = Self::DIScope,
29967ef6 98 DILocation = Self::DILocation,
74b04a01 99 DIVariable = Self::DIVariable,
a1dfa0c6
XL
100 >;
101}