]> git.proxmox.com Git - rustc.git/blame - src/librustc_codegen_ssa/traits/mod.rs
New upstream version 1.46.0~beta.2+dfsg1
[rustc.git] / src / librustc_codegen_ssa / 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;
f9f354fc 32pub use self::asm::{AsmBuilderMethods, AsmMethods, 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
XL
37pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
38pub use self::declare::{DeclareMethods, PreDefineMethods};
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
f035d41b 61 + CoverageInfoMethods
a1dfa0c6 62 + DebugInfoMethods<'tcx>
a1dfa0c6 63 + DeclareMethods<'tcx>
dc9dc135 64 + AsmMethods
a1dfa0c6 65 + PreDefineMethods<'tcx>
48663c56
XL
66 + HasParamEnv<'tcx>
67 + HasTyCtxt<'tcx>
68 + HasTargetSpec
a1dfa0c6
XL
69{
70}
71
72impl<'tcx, T> CodegenMethods<'tcx> for T where
73 Self: Backend<'tcx>
74 + TypeMethods<'tcx>
75 + MiscMethods<'tcx>
76 + ConstMethods<'tcx>
77 + StaticMethods
f035d41b 78 + CoverageInfoMethods
a1dfa0c6 79 + DebugInfoMethods<'tcx>
a1dfa0c6 80 + DeclareMethods<'tcx>
dc9dc135 81 + AsmMethods
a1dfa0c6 82 + PreDefineMethods<'tcx>
48663c56
XL
83 + HasParamEnv<'tcx>
84 + HasTyCtxt<'tcx>
85 + HasTargetSpec
a1dfa0c6
XL
86{
87}
88
89pub trait HasCodegen<'tcx>:
90 Backend<'tcx> + ::std::ops::Deref<Target = <Self as HasCodegen<'tcx>>::CodegenCx>
91{
92 type CodegenCx: CodegenMethods<'tcx>
93 + BackendTypes<
94 Value = Self::Value,
e74abb32 95 Function = Self::Function,
a1dfa0c6
XL
96 BasicBlock = Self::BasicBlock,
97 Type = Self::Type,
98 Funclet = Self::Funclet,
99 DIScope = Self::DIScope,
74b04a01 100 DIVariable = Self::DIVariable,
a1dfa0c6
XL
101 >;
102}