]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/interfaces/mod.rs
Added some docs + start to &mut self builder methods
[rust.git] / src / librustc_codegen_ssa / interfaces / 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
39 pub use self::abi::{AbiBuilderMethods, AbiMethods};
40 pub use self::asm::{AsmBuilderMethods, AsmMethods};
41 pub use self::backend::{Backend, BackendTypes, ExtraBackendMethods};
42 pub use self::builder::BuilderMethods;
43 pub use self::consts::ConstMethods;
44 pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
45 pub use self::declare::{DeclareMethods, PreDefineMethods};
46 pub use self::intrinsic::{IntrinsicCallMethods, IntrinsicDeclarationMethods};
47 pub use self::misc::MiscMethods;
48 pub use self::statics::StaticMethods;
49 pub use self::type_::{
50     ArgTypeMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMethods,
51 };
52
53 use std::fmt;
54
55 pub trait CodegenObject: Copy + PartialEq + fmt::Debug {}
56 impl<T: Copy + PartialEq + fmt::Debug> CodegenObject for T {}
57
58 pub trait CodegenMethods<'tcx>:
59     Backend<'tcx>
60     + TypeMethods<'tcx>
61     + MiscMethods<'tcx>
62     + ConstMethods<'tcx>
63     + StaticMethods<'tcx>
64     + DebugInfoMethods<'tcx>
65     + AbiMethods<'tcx>
66     + IntrinsicDeclarationMethods<'tcx>
67     + DeclareMethods<'tcx>
68     + AsmMethods<'tcx>
69     + PreDefineMethods<'tcx>
70 {
71 }
72
73 impl<'tcx, T> CodegenMethods<'tcx> for T where
74     Self: Backend<'tcx>
75         + TypeMethods<'tcx>
76         + MiscMethods<'tcx>
77         + ConstMethods<'tcx>
78         + StaticMethods<'tcx>
79         + DebugInfoMethods<'tcx>
80         + AbiMethods<'tcx>
81         + IntrinsicDeclarationMethods<'tcx>
82         + DeclareMethods<'tcx>
83         + AsmMethods<'tcx>
84         + PreDefineMethods<'tcx>
85 {}
86
87 pub trait HasCodegen<'tcx>: Backend<'tcx> {
88     type CodegenCx: CodegenMethods<'tcx>
89         + BackendTypes<
90             Value = Self::Value,
91             BasicBlock = Self::BasicBlock,
92             Type = Self::Type,
93             Context = Self::Context,
94             Funclet = Self::Funclet,
95             DIScope = Self::DIScope,
96         >;
97 }