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.
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.
11 //! Interface of a Rust codegen backend
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`.
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.
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.
24 //! The traits contain associated types that are backend-specific, such as the backend's value or
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,
55 pub trait CodegenObject: Copy + PartialEq + fmt::Debug {}
56 impl<T: Copy + PartialEq + fmt::Debug> CodegenObject for T {}
58 pub trait CodegenMethods<'tcx>:
64 + DebugInfoMethods<'tcx>
66 + IntrinsicDeclarationMethods<'tcx>
67 + DeclareMethods<'tcx>
69 + PreDefineMethods<'tcx>
73 impl<'tcx, T> CodegenMethods<'tcx> for T where
79 + DebugInfoMethods<'tcx>
81 + IntrinsicDeclarationMethods<'tcx>
82 + DeclareMethods<'tcx>
84 + PreDefineMethods<'tcx>
87 pub trait HasCodegen<'tcx>: Backend<'tcx> {
88 type CodegenCx: CodegenMethods<'tcx>
91 BasicBlock = Self::BasicBlock,
93 Context = Self::Context,
94 Funclet = Self::Funclet,
95 DIScope = Self::DIScope,