]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_llvm/interfaces/common.rs
Prefixed const methods with "const" instead of "c"
[rust.git] / src / librustc_codegen_llvm / interfaces / common.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 syntax::symbol::LocalInternedString;
13
14 pub trait CommonMethods: Backend + CommonWriteMethods {
15     // Constant constructors
16     fn const_null(&self, t: Self::Type) -> Self::Value;
17     fn const_undef(&self, t: Self::Type) -> Self::Value;
18     fn const_int(&self, t: Self::Type, i: i64) -> Self::Value;
19     fn const_uint(&self, t: Self::Type, i: u64) -> Self::Value;
20     fn const_uint_big(&self, t: Self::Type, u: u128) -> Self::Value;
21     fn const_bool(&self, val: bool) -> Self::Value;
22     fn const_i32(&self, i: i32) -> Self::Value;
23     fn const_u32(&self, i: u32) -> Self::Value;
24     fn const_u64(&self, i: u64) -> Self::Value;
25     fn const_usize(&self, i: u64) -> Self::Value;
26     fn const_u8(&self, i: u8) -> Self::Value;
27     fn const_cstr(
28         &self,
29         s: LocalInternedString,
30         null_terminated: bool,
31     ) -> Self::Value;
32     fn const_str_slice(&self, s: LocalInternedString) -> Self::Value;
33     fn const_fat_ptr(
34         &self,
35         ptr: Self::Value,
36         meta: Self::Value
37     ) -> Self::Value;
38     fn const_struct(
39         &self,
40         elts: &[Self::Value],
41         packed: bool
42     ) -> Self::Value;
43     fn const_array(&self, ty: Self::Type, elts: &[Self::Value]) -> Self::Value;
44     fn const_vector(&self, elts: &[Self::Value]) -> Self::Value;
45     fn const_bytes(&self, bytes: &[u8]) -> Self::Value;
46
47     fn const_get_elt(&self, v: Self::Value, idx: u64) -> Self::Value;
48     fn const_get_real(&self, v: Self::Value) -> Option<(f64, bool)>;
49     fn const_to_uint(&self, v: Self::Value) -> u64;
50     fn const_to_opt_u128(&self, v: Self::Value, sign_ext: bool) -> Option<u128>;
51
52     fn is_const_integral(&self, v: Self::Value) -> bool;
53     fn is_const_real(&self, v: Self::Value) -> bool;
54 }
55
56 pub trait CommonWriteMethods: Backend {
57         fn val_ty(&self, v: Self::Value) -> Self::Type;
58         fn const_bytes_in_context(&self, llcx: Self::Context, bytes: &[u8]) -> Self::Value;
59         fn const_struct_in_context(
60             &self,
61             llcx: Self::Context,
62             elts: &[Self::Value],
63             packed: bool,
64         ) -> Self::Value;
65 }