]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/interfaces/type_.rs
All Builder methods now take &mut self instead of &self
[rust.git] / src / librustc_codegen_ssa / interfaces / type_.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 use super::Backend;
12 use super::HasCodegen;
13 use common::TypeKind;
14 use mir::place::PlaceRef;
15 use rustc::ty::layout::TyLayout;
16 use rustc::ty::layout::{self, Align, Size};
17 use rustc::ty::Ty;
18 use rustc::util::nodemap::FxHashMap;
19 use rustc_target::abi::call::{ArgType, CastTarget, FnType, Reg};
20 use std::cell::RefCell;
21 use syntax::ast;
22
23 pub trait BaseTypeMethods<'tcx>: Backend<'tcx> {
24     fn type_void(&self) -> Self::Type;
25     fn type_metadata(&self) -> Self::Type;
26     fn type_i1(&self) -> Self::Type;
27     fn type_i8(&self) -> Self::Type;
28     fn type_i16(&self) -> Self::Type;
29     fn type_i32(&self) -> Self::Type;
30     fn type_i64(&self) -> Self::Type;
31     fn type_i128(&self) -> Self::Type;
32
33     // Creates an integer type with the given number of bits, e.g. i24
34     fn type_ix(&self, num_bits: u64) -> Self::Type;
35
36     fn type_f32(&self) -> Self::Type;
37     fn type_f64(&self) -> Self::Type;
38     fn type_x86_mmx(&self) -> Self::Type;
39
40     fn type_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
41     fn type_variadic_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
42     fn type_struct(&self, els: &[Self::Type], packed: bool) -> Self::Type;
43     fn type_named_struct(&self, name: &str) -> Self::Type;
44     fn type_array(&self, ty: Self::Type, len: u64) -> Self::Type;
45     fn type_vector(&self, ty: Self::Type, len: u64) -> Self::Type;
46     fn type_kind(&self, ty: Self::Type) -> TypeKind;
47     fn set_struct_body(&self, ty: Self::Type, els: &[Self::Type], packed: bool);
48     fn type_ptr_to(&self, ty: Self::Type) -> Self::Type;
49     fn element_type(&self, ty: Self::Type) -> Self::Type;
50
51     /// Return the number of elements in `self` if it is a LLVM vector type.
52     fn vector_length(&self, ty: Self::Type) -> usize;
53
54     fn func_params_types(&self, ty: Self::Type) -> Vec<Self::Type>;
55     fn float_width(&self, ty: Self::Type) -> usize;
56
57     /// Retrieve the bit width of the integer type `self`.
58     fn int_width(&self, ty: Self::Type) -> u64;
59
60     fn val_ty(&self, v: Self::Value) -> Self::Type;
61     fn scalar_lltypes(&self) -> &RefCell<FxHashMap<Ty<'tcx>, Self::Type>>;
62 }
63
64 pub trait DerivedTypeMethods<'tcx>: Backend<'tcx> {
65     fn type_bool(&self) -> Self::Type;
66     fn type_i8p(&self) -> Self::Type;
67     fn type_isize(&self) -> Self::Type;
68     fn type_int(&self) -> Self::Type;
69     fn type_int_from_ty(&self, t: ast::IntTy) -> Self::Type;
70     fn type_uint_from_ty(&self, t: ast::UintTy) -> Self::Type;
71     fn type_float_from_ty(&self, t: ast::FloatTy) -> Self::Type;
72     fn type_from_integer(&self, i: layout::Integer) -> Self::Type;
73
74     /// Return a LLVM type that has at most the required alignment,
75     /// as a conservative approximation for unknown pointee types.
76     fn type_pointee_for_abi_align(&self, align: Align) -> Self::Type;
77
78     /// Return a LLVM type that has at most the required alignment,
79     /// and exactly the required size, as a best-effort padding array.
80     fn type_padding_filler(&self, size: Size, align: Align) -> Self::Type;
81
82     fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool;
83     fn type_is_sized(&self, ty: Ty<'tcx>) -> bool;
84     fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool;
85     fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool;
86 }
87
88 pub trait LayoutTypeMethods<'tcx>: Backend<'tcx> {
89     fn backend_type(&self, layout: TyLayout<'tcx>) -> Self::Type;
90     fn cast_backend_type(&self, ty: &CastTarget) -> Self::Type;
91     fn fn_backend_type(&self, ty: &FnType<'tcx, Ty<'tcx>>) -> Self::Type;
92     fn fn_ptr_backend_type(&self, ty: &FnType<'tcx, Ty<'tcx>>) -> Self::Type;
93     fn reg_backend_type(&self, ty: &Reg) -> Self::Type;
94     fn immediate_backend_type(&self, layout: TyLayout<'tcx>) -> Self::Type;
95     fn is_backend_immediate(&self, layout: TyLayout<'tcx>) -> bool;
96     fn is_backend_scalar_pair(&self, layout: TyLayout<'tcx>) -> bool;
97     fn backend_field_index(&self, layout: TyLayout<'tcx>, index: usize) -> u64;
98     fn scalar_pair_element_backend_type<'a>(
99         &self,
100         layout: TyLayout<'tcx>,
101         index: usize,
102         immediate: bool,
103     ) -> Self::Type;
104 }
105
106 pub trait ArgTypeMethods<'tcx>: HasCodegen<'tcx> {
107     fn store_fn_arg(
108         &mut self,
109         ty: &ArgType<'tcx, Ty<'tcx>>,
110         idx: &mut usize,
111         dst: PlaceRef<'tcx, Self::Value>,
112     );
113     fn store_arg_ty(
114         &mut self,
115         ty: &ArgType<'tcx, Ty<'tcx>>,
116         val: Self::Value,
117         dst: PlaceRef<'tcx, Self::Value>,
118     );
119     fn memory_ty(&self, ty: &ArgType<'tcx, Ty<'tcx>>) -> Self::Type;
120 }
121
122 pub trait TypeMethods<'tcx>:
123     BaseTypeMethods<'tcx> + DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx>
124 {
125 }
126
127 impl<T> TypeMethods<'tcx> for T where
128     Self: BaseTypeMethods<'tcx> + DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx>
129 {}