]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_ssa/src/traits/mod.rs
Rollup merge of #103701 - WaffleLapkin:__points-at-implementation__--this-can-be...
[rust.git] / compiler / rustc_codegen_ssa / src / 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 //! Finally, a third `Backend` structure has to implement methods related to how codegen information
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
17 mod abi;
18 mod asm;
19 mod backend;
20 mod builder;
21 mod consts;
22 mod coverageinfo;
23 mod debuginfo;
24 mod declare;
25 mod intrinsic;
26 mod misc;
27 mod statics;
28 mod type_;
29 mod write;
30
31 pub use self::abi::AbiBuilderMethods;
32 pub use self::asm::{AsmBuilderMethods, AsmMethods, GlobalAsmOperandRef, InlineAsmOperandRef};
33 pub use self::backend::{Backend, BackendTypes, CodegenBackend, ExtraBackendMethods};
34 pub use self::builder::{BuilderMethods, OverflowOp};
35 pub use self::consts::ConstMethods;
36 pub use self::coverageinfo::{CoverageInfoBuilderMethods, CoverageInfoMethods};
37 pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
38 pub use self::declare::PreDefineMethods;
39 pub use self::intrinsic::IntrinsicCallMethods;
40 pub use self::misc::MiscMethods;
41 pub use self::statics::{StaticBuilderMethods, StaticMethods};
42 pub use self::type_::{
43     ArgAbiMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMembershipMethods,
44     TypeMethods,
45 };
46 pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
47
48 use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt};
49 use rustc_target::spec::HasTargetSpec;
50
51 use std::fmt;
52
53 pub trait CodegenObject: Copy + PartialEq + fmt::Debug {}
54 impl<T: Copy + PartialEq + fmt::Debug> CodegenObject for T {}
55
56 pub trait CodegenMethods<'tcx>:
57     Backend<'tcx>
58     + TypeMethods<'tcx>
59     + MiscMethods<'tcx>
60     + ConstMethods<'tcx>
61     + StaticMethods
62     + CoverageInfoMethods<'tcx>
63     + DebugInfoMethods<'tcx>
64     + AsmMethods<'tcx>
65     + PreDefineMethods<'tcx>
66     + HasParamEnv<'tcx>
67     + HasTyCtxt<'tcx>
68     + HasTargetSpec
69 {
70 }
71
72 impl<'tcx, T> CodegenMethods<'tcx> for T where
73     Self: Backend<'tcx>
74         + TypeMethods<'tcx>
75         + MiscMethods<'tcx>
76         + ConstMethods<'tcx>
77         + StaticMethods
78         + CoverageInfoMethods<'tcx>
79         + DebugInfoMethods<'tcx>
80         + AsmMethods<'tcx>
81         + PreDefineMethods<'tcx>
82         + HasParamEnv<'tcx>
83         + HasTyCtxt<'tcx>
84         + HasTargetSpec
85 {
86 }
87
88 pub trait HasCodegen<'tcx>:
89     Backend<'tcx> + std::ops::Deref<Target = <Self as HasCodegen<'tcx>>::CodegenCx>
90 {
91     type CodegenCx: CodegenMethods<'tcx>
92         + BackendTypes<
93             Value = Self::Value,
94             Function = Self::Function,
95             BasicBlock = Self::BasicBlock,
96             Type = Self::Type,
97             Funclet = Self::Funclet,
98             DIScope = Self::DIScope,
99             DILocation = Self::DILocation,
100             DIVariable = Self::DIVariable,
101         >;
102 }