98 lines
3.0 KiB
Rust
Raw Normal View History

//! Interface of a Rust codegen backend
//!
//! This crate defines all the traits that have to be implemented by a codegen backend in order to
//! use the backend-agnostic codegen code in `rustc_codegen_ssa`.
//!
//! The interface is designed around two backend-specific data structures, the codegen context and
//! the builder. The codegen context is supposed to be read-only after its creation and during the
//! actual codegen, while the builder stores the information about the function during codegen and
//! is used to produce the instructions of the backend IR.
//!
//! Finaly, a third `Backend` structure has to implement methods related to how codegen information
//! is passed to the backend, especially for asynchronous compilation.
//!
//! The traits contain associated types that are backend-specific, such as the backend's value or
//! basic blocks.
mod abi;
mod asm;
mod backend;
mod builder;
mod consts;
mod debuginfo;
mod declare;
mod intrinsic;
mod misc;
mod statics;
mod type_;
mod write;
2019-12-22 17:42:04 -05:00
pub use self::abi::AbiBuilderMethods;
pub use self::asm::{AsmBuilderMethods, AsmMethods};
pub use self::backend::{Backend, BackendTypes, ExtraBackendMethods};
pub use self::builder::{BuilderMethods, OverflowOp};
pub use self::consts::ConstMethods;
pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
pub use self::declare::{DeclareMethods, PreDefineMethods};
pub use self::intrinsic::IntrinsicCallMethods;
pub use self::misc::MiscMethods;
2019-12-22 17:42:04 -05:00
pub use self::statics::{StaticBuilderMethods, StaticMethods};
pub use self::type_::{
ArgAbiMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMethods,
};
pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
2019-05-04 15:02:22 +05:30
use rustc::ty::layout::{HasParamEnv, HasTyCtxt};
use rustc_target::spec::HasTargetSpec;
use std::fmt;
pub trait CodegenObject: Copy + PartialEq + fmt::Debug {}
impl<T: Copy + PartialEq + fmt::Debug> CodegenObject for T {}
pub trait CodegenMethods<'tcx>:
Backend<'tcx>
+ TypeMethods<'tcx>
+ MiscMethods<'tcx>
+ ConstMethods<'tcx>
+ StaticMethods
+ DebugInfoMethods<'tcx>
+ DeclareMethods<'tcx>
+ AsmMethods
+ PreDefineMethods<'tcx>
2019-05-04 15:02:22 +05:30
+ HasParamEnv<'tcx>
2019-05-14 21:23:01 +05:30
+ HasTyCtxt<'tcx>
+ HasTargetSpec
{
}
impl<'tcx, T> CodegenMethods<'tcx> for T where
Self: Backend<'tcx>
+ TypeMethods<'tcx>
+ MiscMethods<'tcx>
+ ConstMethods<'tcx>
+ StaticMethods
+ DebugInfoMethods<'tcx>
+ DeclareMethods<'tcx>
+ AsmMethods
+ PreDefineMethods<'tcx>
2019-05-04 15:02:22 +05:30
+ HasParamEnv<'tcx>
2019-05-14 21:23:01 +05:30
+ HasTyCtxt<'tcx>
+ HasTargetSpec
2018-11-24 16:15:26 +01:00
{
}
pub trait HasCodegen<'tcx>:
Backend<'tcx> + ::std::ops::Deref<Target = <Self as HasCodegen<'tcx>>::CodegenCx>
{
type CodegenCx: CodegenMethods<'tcx>
+ BackendTypes<
Value = Self::Value,
2019-10-13 11:28:19 +02:00
Function = Self::Function,
BasicBlock = Self::BasicBlock,
Type = Self::Type,
Funclet = Self::Funclet,
DIScope = Self::DIScope,
2019-05-05 23:39:04 +05:30
>;
}