]>
Commit | Line | Data |
---|---|---|
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 | ||
17 | mod abi; | |
18 | mod asm; | |
19 | mod backend; | |
20 | mod builder; | |
21 | mod consts; | |
f035d41b | 22 | mod coverageinfo; |
a1dfa0c6 XL |
23 | mod debuginfo; |
24 | mod declare; | |
25 | mod intrinsic; | |
26 | mod misc; | |
27 | mod statics; | |
28 | mod type_; | |
29 | mod write; | |
30 | ||
dfeec247 | 31 | pub use self::abi::AbiBuilderMethods; |
17df50a5 | 32 | pub use self::asm::{AsmBuilderMethods, AsmMethods, GlobalAsmOperandRef, InlineAsmOperandRef}; |
ba9703b0 | 33 | pub use self::backend::{Backend, BackendTypes, CodegenBackend, ExtraBackendMethods}; |
a1dfa0c6 XL |
34 | pub use self::builder::{BuilderMethods, OverflowOp}; |
35 | pub use self::consts::ConstMethods; | |
f035d41b | 36 | pub use self::coverageinfo::{CoverageInfoBuilderMethods, CoverageInfoMethods}; |
a1dfa0c6 | 37 | pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods}; |
1b1a35ee | 38 | pub use self::declare::PreDefineMethods; |
a1dfa0c6 XL |
39 | pub use self::intrinsic::IntrinsicCallMethods; |
40 | pub use self::misc::MiscMethods; | |
dfeec247 | 41 | pub use self::statics::{StaticBuilderMethods, StaticMethods}; |
a1dfa0c6 | 42 | pub use self::type_::{ |
60c5eb7d | 43 | ArgAbiMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMethods, |
a1dfa0c6 XL |
44 | }; |
45 | pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods}; | |
48663c56 | 46 | |
ba9703b0 | 47 | use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt}; |
60c5eb7d | 48 | use rustc_target::spec::HasTargetSpec; |
a1dfa0c6 XL |
49 | |
50 | use std::fmt; | |
51 | ||
52 | pub trait CodegenObject: Copy + PartialEq + fmt::Debug {} | |
53 | impl<T: Copy + PartialEq + fmt::Debug> CodegenObject for T {} | |
54 | ||
55 | pub 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 | ||
71 | impl<'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 | ||
87 | pub 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 | } |