about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm/interfaces
diff options
context:
space:
mode:
authorDenis Merigoux <denis.merigoux@gmail.com>2018-08-28 17:03:46 +0200
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2018-11-16 14:11:59 +0200
commit8714e6bce6b04482723f0b735879533c82c114fa (patch)
tree1c30b12dc5fa7bd6a37092af6ce87b77faa880e7 /src/librustc_codegen_llvm/interfaces
parent3889c2dcfb2968226bad79b4c04b987e031f9c0d (diff)
downloadrust-8714e6bce6b04482723f0b735879533c82c114fa.tar.gz
rust-8714e6bce6b04482723f0b735879533c82c114fa.zip
Traitification of common.rs methods
Diffstat (limited to 'src/librustc_codegen_llvm/interfaces')
-rw-r--r--src/librustc_codegen_llvm/interfaces/backend.rs1
-rw-r--r--src/librustc_codegen_llvm/interfaces/common.rs61
-rw-r--r--src/librustc_codegen_llvm/interfaces/mod.rs2
3 files changed, 64 insertions, 0 deletions
diff --git a/src/librustc_codegen_llvm/interfaces/backend.rs b/src/librustc_codegen_llvm/interfaces/backend.rs
index b2a6bf2dd8c..648ae15eb3f 100644
--- a/src/librustc_codegen_llvm/interfaces/backend.rs
+++ b/src/librustc_codegen_llvm/interfaces/backend.rs
@@ -12,4 +12,5 @@ pub trait Backend {
     type Value;
     type BasicBlock;
     type Type;
+    type Context;
 }
diff --git a/src/librustc_codegen_llvm/interfaces/common.rs b/src/librustc_codegen_llvm/interfaces/common.rs
new file mode 100644
index 00000000000..c43e3b7504a
--- /dev/null
+++ b/src/librustc_codegen_llvm/interfaces/common.rs
@@ -0,0 +1,61 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use super::Backend;
+use syntax::symbol::LocalInternedString;
+
+pub trait CommonMethods : Backend {
+    fn val_ty(v: Self::Value) -> Self::Type;
+
+    // Constant constructors
+    fn c_null(t: Self::Type) -> Self::Value;
+    fn c_undef(t: Self::Type) -> Self::Value;
+    fn c_int(t: Self::Type, i: i64) -> Self::Value;
+    fn c_uint(t: Self::Type, i: u64) -> Self::Value;
+    fn c_uint_big(t: Self::Type, u: u128) -> Self::Value;
+    fn c_bool(&self, val: bool) -> Self::Value;
+    fn c_i32(&self, i: i32) -> Self::Value;
+    fn c_u32(&self, i: u32) -> Self::Value;
+    fn c_u64(&self, i: u64) -> Self::Value;
+    fn c_usize(&self, i: u64) -> Self::Value;
+    fn c_u8(&self, i: u8) -> Self::Value;
+    fn c_cstr(
+        &self,
+        s: LocalInternedString,
+        null_terminated: bool,
+    ) -> Self::Value;
+    fn c_str_slice(&self, s: LocalInternedString) -> Self::Value;
+    fn c_fat_ptr(
+        &self,
+        ptr: Self::Value,
+        meta: Self::Value
+    ) -> Self::Value;
+    fn c_struct(
+        &self,
+        elts: &[Self::Value],
+        packed: bool
+    ) -> Self::Value;
+    fn c_struct_in_context(
+        llcx: Self::Context,
+        elts: &[Self::Value],
+        packed: bool,
+    ) -> Self::Value;
+    fn c_array(ty: Self::Type, elts: &[Self::Value]) -> Self::Value;
+    fn c_vector(elts: &[Self::Value]) -> Self::Value;
+    fn c_bytes(&self, bytes: &[u8]) -> Self::Value;
+    fn c_bytes_in_context(llcx: Self::Context, bytes: &[u8]) -> Self::Value;
+
+    fn const_get_elt(v: Self::Value, idx: u64) -> Self::Value;
+    fn const_get_real(v: Self::Value) -> Option<(f64, bool)>;
+    fn const_to_uint(v: Self::Value) -> u64;
+    fn is_const_integral(v: Self::Value) -> bool;
+    fn is_const_real(v: Self::Value) -> bool;
+    fn const_to_opt_u128(v: Self::Value, sign_ext: bool) -> Option<u128>;
+}
diff --git a/src/librustc_codegen_llvm/interfaces/mod.rs b/src/librustc_codegen_llvm/interfaces/mod.rs
index b9a356874ba..77db6393f6c 100644
--- a/src/librustc_codegen_llvm/interfaces/mod.rs
+++ b/src/librustc_codegen_llvm/interfaces/mod.rs
@@ -10,6 +10,8 @@
 
 mod builder;
 mod backend;
+mod common;
 
 pub use self::builder::BuilderMethods;
 pub use self::backend::Backend;
+pub use self::common::CommonMethods;