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
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
,
53 pub use self::write
::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods}
;
57 pub trait CodegenObject
: Copy
+ PartialEq
+ fmt
::Debug {}
58 impl<T
: Copy
+ PartialEq
+ fmt
::Debug
> CodegenObject
for T {}
60 pub trait CodegenMethods
<'tcx
>:
66 + DebugInfoMethods
<'tcx
>
68 + DeclareMethods
<'tcx
>
70 + PreDefineMethods
<'tcx
>
74 impl<'tcx
, T
> CodegenMethods
<'tcx
> for T
where
80 + DebugInfoMethods
<'tcx
>
82 + DeclareMethods
<'tcx
>
84 + PreDefineMethods
<'tcx
>
88 pub trait HasCodegen
<'tcx
>:
89 Backend
<'tcx
> + ::std
::ops
::Deref
<Target
= <Self as HasCodegen
<'tcx
>>::CodegenCx
>
91 type CodegenCx
: CodegenMethods
<'tcx
>
94 BasicBlock
= Self::BasicBlock
,
96 Funclet
= Self::Funclet
,
97 DIScope
= Self::DIScope
,