]> git.proxmox.com Git - rustc.git/blob - src/librustc_codegen_ssa/traits/mod.rs
New upstream version 1.32.0~beta.2+dfsg1
[rustc.git] / src / librustc_codegen_ssa / traits / mod.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Interface of a Rust codegen backend
12 //!
13 //! This crate defines all the traits that have to be implemented by a codegen backend in order to
14 //! use the backend-agnostic codegen code in `rustc_codegen_ssa`.
15 //!
16 //! The interface is designed around two backend-specific data structures, the codegen context and
17 //! the builder. The codegen context is supposed to be read-only after its creation and during the
18 //! actual codegen, while the builder stores the information about the function during codegen and
19 //! is used to produce the instructions of the backend IR.
20 //!
21 //! Finaly, a third `Backend` structure has to implement methods related to how codegen information
22 //! is passed to the backend, especially for asynchronous compilation.
23 //!
24 //! The traits contain associated types that are backend-specific, such as the backend's value or
25 //! basic blocks.
26
27 mod abi;
28 mod asm;
29 mod backend;
30 mod builder;
31 mod consts;
32 mod debuginfo;
33 mod declare;
34 mod intrinsic;
35 mod misc;
36 mod statics;
37 mod type_;
38 mod write;
39
40 pub use self::abi::{AbiBuilderMethods, AbiMethods};
41 pub use self::asm::{AsmBuilderMethods, AsmMethods};
42 pub use self::backend::{Backend, BackendTypes, ExtraBackendMethods};
43 pub use self::builder::{BuilderMethods, OverflowOp};
44 pub use self::consts::ConstMethods;
45 pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
46 pub use self::declare::{DeclareMethods, PreDefineMethods};
47 pub use self::intrinsic::IntrinsicCallMethods;
48 pub use self::misc::MiscMethods;
49 pub use self::statics::{StaticMethods, StaticBuilderMethods};
50 pub use self::type_::{
51 ArgTypeMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMethods,
52 };
53 pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
54
55 use std::fmt;
56
57 pub trait CodegenObject: Copy + PartialEq + fmt::Debug {}
58 impl<T: Copy + PartialEq + fmt::Debug> CodegenObject for T {}
59
60 pub trait CodegenMethods<'tcx>:
61 Backend<'tcx>
62 + TypeMethods<'tcx>
63 + MiscMethods<'tcx>
64 + ConstMethods<'tcx>
65 + StaticMethods
66 + DebugInfoMethods<'tcx>
67 + AbiMethods<'tcx>
68 + DeclareMethods<'tcx>
69 + AsmMethods<'tcx>
70 + PreDefineMethods<'tcx>
71 {
72 }
73
74 impl<'tcx, T> CodegenMethods<'tcx> for T where
75 Self: Backend<'tcx>
76 + TypeMethods<'tcx>
77 + MiscMethods<'tcx>
78 + ConstMethods<'tcx>
79 + StaticMethods
80 + DebugInfoMethods<'tcx>
81 + AbiMethods<'tcx>
82 + DeclareMethods<'tcx>
83 + AsmMethods<'tcx>
84 + PreDefineMethods<'tcx>
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 BasicBlock = Self::BasicBlock,
95 Type = Self::Type,
96 Funclet = Self::Funclet,
97 DIScope = Self::DIScope,
98 >;
99 }