]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/traits/consts.rs
319f4b4e5e4b5c6b0013328baaab7e9fc370943e
[rust.git] / src / librustc_codegen_ssa / traits / consts.rs
1 use super::BackendTypes;
2 use crate::mir::place::PlaceRef;
3 use rustc::mir::interpret::Allocation;
4 use rustc::mir::interpret::Scalar;
5 use rustc::ty::layout;
6 use syntax::symbol::LocalInternedString;
7
8 pub trait ConstMethods<'tcx>: BackendTypes {
9     // Constant constructors
10     fn const_null(&self, t: Self::Type) -> Self::Value;
11     fn const_undef(&self, t: Self::Type) -> Self::Value;
12     fn const_int(&self, t: Self::Type, i: i64) -> Self::Value;
13     fn const_uint(&self, t: Self::Type, i: u64) -> Self::Value;
14     fn const_uint_big(&self, t: Self::Type, u: u128) -> Self::Value;
15     fn const_bool(&self, val: bool) -> Self::Value;
16     fn const_i32(&self, i: i32) -> Self::Value;
17     fn const_u32(&self, i: u32) -> Self::Value;
18     fn const_u64(&self, i: u64) -> Self::Value;
19     fn const_usize(&self, i: u64) -> Self::Value;
20     fn const_u8(&self, i: u8) -> Self::Value;
21
22     // This is a 'c-like' raw string, which differs from
23     // our boxed-and-length-annotated strings.
24     fn const_cstr(&self, s: LocalInternedString, null_terminated: bool) -> Self::Value;
25
26     fn const_str_slice(&self, s: LocalInternedString) -> Self::Value;
27     fn const_fat_ptr(&self, ptr: Self::Value, meta: Self::Value) -> Self::Value;
28     fn const_struct(&self, elts: &[Self::Value], packed: bool) -> Self::Value;
29     fn const_array(&self, ty: Self::Type, elts: &[Self::Value]) -> Self::Value;
30     fn const_vector(&self, elts: &[Self::Value]) -> Self::Value;
31     fn const_bytes(&self, bytes: &[u8]) -> Self::Value;
32
33     fn const_get_elt(&self, v: Self::Value, idx: u64) -> Self::Value;
34     fn const_get_real(&self, v: Self::Value) -> Option<(f64, bool)>;
35     fn const_to_uint(&self, v: Self::Value) -> u64;
36     fn const_to_opt_u128(&self, v: Self::Value, sign_ext: bool) -> Option<u128>;
37
38     fn is_const_integral(&self, v: Self::Value) -> bool;
39     fn is_const_real(&self, v: Self::Value) -> bool;
40
41     fn scalar_to_backend(
42         &self,
43         cv: Scalar,
44         layout: &layout::Scalar,
45         llty: Self::Type,
46     ) -> Self::Value;
47     fn from_const_alloc(
48         &self,
49         layout: layout::TyLayout<'tcx>,
50         alloc: &Allocation,
51         offset: layout::Size,
52     ) -> PlaceRef<'tcx, Self::Value>;
53
54     fn const_ptrcast(&self, val: Self::Value, ty: Self::Type) -> Self::Value;
55 }