]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_llvm/interfaces/type_.rs
Generalized base::unsize_thin_ptr
[rust.git] / src / librustc_codegen_llvm / 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::Backend;
12 use common::TypeKind;
13 use rustc::ty::layout::TyLayout;
14 use rustc::ty::layout::{self, Align, Size};
15 use rustc::ty::Ty;
16 use rustc::util::nodemap::FxHashMap;
17 use std::cell::RefCell;
18 use syntax::ast;
19
20 pub trait BaseTypeMethods<'tcx>: Backend<'tcx> {
21     fn type_void(&self) -> Self::Type;
22     fn type_metadata(&self) -> Self::Type;
23     fn type_i1(&self) -> Self::Type;
24     fn type_i8(&self) -> Self::Type;
25     fn type_i16(&self) -> Self::Type;
26     fn type_i32(&self) -> Self::Type;
27     fn type_i64(&self) -> Self::Type;
28     fn type_i128(&self) -> Self::Type;
29     fn type_ix(&self, num_bits: u64) -> Self::Type;
30     fn type_f32(&self) -> Self::Type;
31     fn type_f64(&self) -> Self::Type;
32     fn type_x86_mmx(&self) -> Self::Type;
33
34     fn type_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
35     fn type_variadic_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
36     fn type_struct(&self, els: &[Self::Type], packed: bool) -> Self::Type;
37     fn type_named_struct(&self, name: &str) -> Self::Type;
38     fn type_array(&self, ty: Self::Type, len: u64) -> Self::Type;
39     fn type_vector(&self, ty: Self::Type, len: u64) -> Self::Type;
40     fn type_kind(&self, ty: Self::Type) -> TypeKind;
41     fn set_struct_body(&self, ty: Self::Type, els: &[Self::Type], packed: bool);
42     fn type_ptr_to(&self, ty: Self::Type) -> Self::Type;
43     fn element_type(&self, ty: Self::Type) -> Self::Type;
44     fn vector_length(&self, ty: Self::Type) -> usize;
45     fn func_params_types(&self, ty: Self::Type) -> Vec<Self::Type>;
46     fn float_width(&self, ty: Self::Type) -> usize;
47     fn int_width(&self, ty: Self::Type) -> u64;
48
49     fn val_ty(&self, v: Self::Value) -> Self::Type;
50     fn scalar_lltypes(&self) -> &RefCell<FxHashMap<Ty<'tcx>, Self::Type>>;
51 }
52
53 pub trait DerivedTypeMethods<'tcx>: Backend<'tcx> {
54     fn type_bool(&self) -> Self::Type;
55     fn type_i8p(&self) -> Self::Type;
56     fn type_isize(&self) -> Self::Type;
57     fn type_int(&self) -> Self::Type;
58     fn type_int_from_ty(&self, t: ast::IntTy) -> Self::Type;
59     fn type_uint_from_ty(&self, t: ast::UintTy) -> Self::Type;
60     fn type_float_from_ty(&self, t: ast::FloatTy) -> Self::Type;
61     fn type_from_integer(&self, i: layout::Integer) -> Self::Type;
62     fn type_pointee_for_abi_align(&self, align: Align) -> Self::Type;
63     fn type_padding_filler(&self, size: Size, align: Align) -> Self::Type;
64
65     fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool;
66     fn type_is_sized(&self, ty: Ty<'tcx>) -> bool;
67     fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool;
68     fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool;
69 }
70
71 pub trait LayoutTypeMethods<'tcx>: Backend<'tcx> {
72     fn backend_type(&self, ty: &TyLayout<'tcx>) -> Self::Type;
73     fn scalar_pair_element_backend_type<'a>(
74         &self,
75         ty: &TyLayout<'tcx>,
76         index: usize,
77         immediate: bool
78     ) -> Self::Type;
79 }
80
81 pub trait TypeMethods<'tcx>:
82     BaseTypeMethods<'tcx> + DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx>
83 {
84 }
85
86 impl<T> TypeMethods<'tcx> for T where
87     Self: BaseTypeMethods<'tcx> + DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx>
88 {}