about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm
diff options
context:
space:
mode:
authorDenis Merigoux <denis.merigoux@gmail.com>2018-08-29 16:40:47 +0200
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2018-11-16 14:11:59 +0200
commit3aee77277efbac0b9b14b2097ea8a2c449fb1fc3 (patch)
tree665945d226ace05cc576c73fbde486c37d249c2a /src/librustc_codegen_llvm
parent83e07f9fe9b7237fd48f79112686b886ae56a920 (diff)
downloadrust-3aee77277efbac0b9b14b2097ea8a2c449fb1fc3.tar.gz
rust-3aee77277efbac0b9b14b2097ea8a2c449fb1fc3.zip
Split CommonMethods to accomodate for use in back/write.rs
Diffstat (limited to 'src/librustc_codegen_llvm')
-rw-r--r--src/librustc_codegen_llvm/back/write.rs2
-rw-r--r--src/librustc_codegen_llvm/base.rs2
-rw-r--r--src/librustc_codegen_llvm/builder.rs2
-rw-r--r--src/librustc_codegen_llvm/callee.rs2
-rw-r--r--src/librustc_codegen_llvm/common.rs29
-rw-r--r--src/librustc_codegen_llvm/consts.rs2
-rw-r--r--src/librustc_codegen_llvm/interfaces/common.rs10
-rw-r--r--src/librustc_codegen_llvm/interfaces/mod.rs2
-rw-r--r--src/librustc_codegen_llvm/mir/rvalue.rs2
9 files changed, 29 insertions, 24 deletions
diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs
index 47a5bc25fd8..5d23ff27c49 100644
--- a/src/librustc_codegen_llvm/back/write.rs
+++ b/src/librustc_codegen_llvm/back/write.rs
@@ -46,7 +46,7 @@ use syntax_pos::MultiSpan;
 use syntax_pos::symbol::Symbol;
 use type_::Type;
 use context::{is_pie_binary, get_reloc_model, CodegenCx};
-use interfaces::CommonMethods;
+use interfaces::CommonWriteMethods;
 use jobserver::{Client, Acquired};
 use rustc_demangle;
 
diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs
index 9fcb7bfd506..2a4d549adcb 100644
--- a/src/librustc_codegen_llvm/base.rs
+++ b/src/librustc_codegen_llvm/base.rs
@@ -74,7 +74,7 @@ use rustc_data_structures::small_c_str::SmallCStr;
 use rustc_data_structures::sync::Lrc;
 use rustc_data_structures::indexed_vec::Idx;
 
-use interfaces::{BuilderMethods, CommonMethods};
+use interfaces::{BuilderMethods, CommonMethods, CommonWriteMethods};
 
 use std::any::Any;
 use std::cmp;
diff --git a/src/librustc_codegen_llvm/builder.rs b/src/librustc_codegen_llvm/builder.rs
index 7f700b3314d..8a6cf1335cd 100644
--- a/src/librustc_codegen_llvm/builder.rs
+++ b/src/librustc_codegen_llvm/builder.rs
@@ -19,7 +19,7 @@ use rustc::ty::TyCtxt;
 use rustc::ty::layout::{Align, Size};
 use rustc::session::{config, Session};
 use rustc_data_structures::small_c_str::SmallCStr;
-use interfaces::{BuilderMethods, Backend, CommonMethods};
+use interfaces::{BuilderMethods, Backend, CommonMethods, CommonWriteMethods};
 use syntax;
 
 use std::borrow::Cow;
diff --git a/src/librustc_codegen_llvm/callee.rs b/src/librustc_codegen_llvm/callee.rs
index ce3743bb8cb..a593cd64efe 100644
--- a/src/librustc_codegen_llvm/callee.rs
+++ b/src/librustc_codegen_llvm/callee.rs
@@ -22,7 +22,7 @@ use llvm;
 use monomorphize::Instance;
 use type_of::LayoutLlvmExt;
 use value::Value;
-use interfaces::CommonMethods;
+use interfaces::CommonWriteMethods;
 
 use rustc::hir::def_id::DefId;
 use rustc::ty::{self, TypeFoldable};
diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs
index 11940e9b0af..cf88a973162 100644
--- a/src/librustc_codegen_llvm/common.rs
+++ b/src/librustc_codegen_llvm/common.rs
@@ -24,7 +24,7 @@ use declare;
 use type_::Type;
 use type_of::LayoutLlvmExt;
 use value::Value;
-use interfaces::{Backend, CommonMethods};
+use interfaces::{Backend, CommonMethods, CommonWriteMethods};
 
 use rustc::ty::{self, Ty, TyCtxt};
 use rustc::ty::layout::{HasDataLayout, LayoutOf};
@@ -201,11 +201,6 @@ impl Backend for CodegenCx<'ll, 'tcx> {
 }
 
 impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx> {
-    fn val_ty(v: &'ll Value) -> &'ll Type {
-        unsafe {
-            llvm::LLVMTypeOf(v)
-        }
-    }
 
     // LLVM constant constructors.
     fn c_null(&self, t: &'ll Type) -> &'ll Value {
@@ -354,13 +349,6 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx> {
         Self::c_bytes_in_context(&self.llcx, bytes)
     }
 
-    fn c_bytes_in_context(llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
-        unsafe {
-            let ptr = bytes.as_ptr() as *const c_char;
-            return llvm::LLVMConstStringInContext(llcx, ptr, bytes.len() as c_uint, True);
-        }
-    }
-
     fn const_get_elt(v: &'ll Value, idx: u64) -> &'ll Value {
         unsafe {
             assert_eq!(idx as c_uint as u64, idx);
@@ -501,3 +489,18 @@ pub fn shift_mask_val(
         _ => bug!("shift_mask_val: expected Integer or Vector, found {:?}", kind),
     }
 }
+
+impl<'ll, 'tcx : 'll> CommonWriteMethods for CodegenCx<'ll, 'tcx> {
+    fn val_ty(v: &'ll Value) -> &'ll Type {
+        unsafe {
+            llvm::LLVMTypeOf(v)
+        }
+    }
+
+    fn c_bytes_in_context(llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
+        unsafe {
+            let ptr = bytes.as_ptr() as *const c_char;
+            return llvm::LLVMConstStringInContext(llcx, ptr, bytes.len() as c_uint, True);
+        }
+    }
+}
diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs
index eb43aa012aa..a97614e4e50 100644
--- a/src/librustc_codegen_llvm/consts.rs
+++ b/src/librustc_codegen_llvm/consts.rs
@@ -24,7 +24,7 @@ use type_::Type;
 use type_of::LayoutLlvmExt;
 use value::Value;
 use rustc::ty::{self, Ty};
-use interfaces::CommonMethods;
+use interfaces::CommonWriteMethods;
 
 use rustc::ty::layout::{Align, LayoutOf};
 
diff --git a/src/librustc_codegen_llvm/interfaces/common.rs b/src/librustc_codegen_llvm/interfaces/common.rs
index fe587bd8f83..f58338f384f 100644
--- a/src/librustc_codegen_llvm/interfaces/common.rs
+++ b/src/librustc_codegen_llvm/interfaces/common.rs
@@ -11,9 +11,7 @@
 use super::Backend;
 use syntax::symbol::LocalInternedString;
 
-pub trait CommonMethods : Backend {
-    fn val_ty(v: Self::Value) -> Self::Type;
-
+pub trait CommonMethods : Backend + CommonWriteMethods {
     // Constant constructors
     fn c_null(&self, t: Self::Type) -> Self::Value;
     fn c_undef(&self, t: Self::Type) -> Self::Value;
@@ -50,7 +48,6 @@ pub trait CommonMethods : Backend {
     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)>;
@@ -59,3 +56,8 @@ pub trait CommonMethods : Backend {
     fn is_const_real(v: Self::Value) -> bool;
     fn const_to_opt_u128(v: Self::Value, sign_ext: bool) -> Option<u128>;
 }
+
+pub trait CommonWriteMethods : Backend {
+        fn val_ty(v: Self::Value) -> Self::Type;
+        fn c_bytes_in_context(llcx: Self::Context, bytes: &[u8]) -> Self::Value;
+}
diff --git a/src/librustc_codegen_llvm/interfaces/mod.rs b/src/librustc_codegen_llvm/interfaces/mod.rs
index 77db6393f6c..e8ece54718e 100644
--- a/src/librustc_codegen_llvm/interfaces/mod.rs
+++ b/src/librustc_codegen_llvm/interfaces/mod.rs
@@ -14,4 +14,4 @@ mod common;
 
 pub use self::builder::BuilderMethods;
 pub use self::backend::Backend;
-pub use self::common::CommonMethods;
+pub use self::common::{CommonMethods, CommonWriteMethods};
diff --git a/src/librustc_codegen_llvm/mir/rvalue.rs b/src/librustc_codegen_llvm/mir/rvalue.rs
index 90d47205c6f..889bfeeb8ca 100644
--- a/src/librustc_codegen_llvm/mir/rvalue.rs
+++ b/src/librustc_codegen_llvm/mir/rvalue.rs
@@ -27,7 +27,7 @@ use type_::Type;
 use type_of::LayoutLlvmExt;
 use value::Value;
 
-use interfaces::{BuilderMethods, CommonMethods};
+use interfaces::{BuilderMethods, CommonMethods, CommonWriteMethods};
 
 use super::{FunctionCx, LocalRef};
 use super::operand::{OperandRef, OperandValue};