]> git.proxmox.com Git - rustc.git/blame - src/librustc_codegen_ssa/traits/mod.rs
New upstream version 1.36.0+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//!
11//! Finaly, 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
17mod abi;
18mod asm;
19mod backend;
20mod builder;
21mod consts;
22mod debuginfo;
23mod declare;
24mod intrinsic;
25mod misc;
26mod statics;
27mod type_;
28mod write;
29
48663c56 30pub use self::abi::{AbiBuilderMethods};
a1dfa0c6
XL
31pub use self::asm::{AsmBuilderMethods, AsmMethods};
32pub use self::backend::{Backend, BackendTypes, ExtraBackendMethods};
33pub use self::builder::{BuilderMethods, OverflowOp};
34pub use self::consts::ConstMethods;
35pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
36pub use self::declare::{DeclareMethods, PreDefineMethods};
37pub use self::intrinsic::IntrinsicCallMethods;
38pub use self::misc::MiscMethods;
39pub use self::statics::{StaticMethods, StaticBuilderMethods};
40pub use self::type_::{
41 ArgTypeMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMethods,
42};
43pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
48663c56
XL
44use rustc::ty::layout::{HasParamEnv, HasTyCtxt};
45use rustc_target::spec::{HasTargetSpec};
46
a1dfa0c6
XL
47
48use std::fmt;
49
50pub trait CodegenObject: Copy + PartialEq + fmt::Debug {}
51impl<T: Copy + PartialEq + fmt::Debug> CodegenObject for T {}
52
53pub trait CodegenMethods<'tcx>:
54 Backend<'tcx>
55 + TypeMethods<'tcx>
56 + MiscMethods<'tcx>
57 + ConstMethods<'tcx>
58 + StaticMethods
59 + DebugInfoMethods<'tcx>
a1dfa0c6
XL
60 + DeclareMethods<'tcx>
61 + AsmMethods<'tcx>
62 + PreDefineMethods<'tcx>
48663c56
XL
63 + HasParamEnv<'tcx>
64 + HasTyCtxt<'tcx>
65 + HasTargetSpec
a1dfa0c6
XL
66{
67}
68
69impl<'tcx, T> CodegenMethods<'tcx> for T where
70 Self: Backend<'tcx>
71 + TypeMethods<'tcx>
72 + MiscMethods<'tcx>
73 + ConstMethods<'tcx>
74 + StaticMethods
75 + DebugInfoMethods<'tcx>
a1dfa0c6
XL
76 + DeclareMethods<'tcx>
77 + AsmMethods<'tcx>
78 + PreDefineMethods<'tcx>
48663c56
XL
79 + HasParamEnv<'tcx>
80 + HasTyCtxt<'tcx>
81 + HasTargetSpec
a1dfa0c6
XL
82{
83}
84
85pub trait HasCodegen<'tcx>:
86 Backend<'tcx> + ::std::ops::Deref<Target = <Self as HasCodegen<'tcx>>::CodegenCx>
87{
88 type CodegenCx: CodegenMethods<'tcx>
89 + BackendTypes<
90 Value = Self::Value,
91 BasicBlock = Self::BasicBlock,
92 Type = Self::Type,
93 Funclet = Self::Funclet,
94 DIScope = Self::DIScope,
95 >;
96}