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 use super::backend::Backend;
13 use rustc::ty::layout::TyLayout;
14 use rustc::ty::layout::{self, Align, Size};
16 use rustc::util::nodemap::FxHashMap;
17 use std::cell::RefCell;
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;
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;
49 fn val_ty(&self, v: Self::Value) -> Self::Type;
50 fn scalar_lltypes(&self) -> &RefCell<FxHashMap<Ty<'tcx>, Self::Type>>;
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;
66 pub trait LayoutTypeMethods<'tcx>: Backend<'tcx> {
67 fn backend_type(&self, ty: TyLayout<'tcx>) -> Self::Type;
70 pub trait TypeMethods<'tcx>:
71 BaseTypeMethods<'tcx> + DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx>
75 impl<T> TypeMethods<'tcx> for T where
76 Self: BaseTypeMethods<'tcx> + DerivedTypeMethods<'tcx> + LayoutTypeMethods<'tcx>