Skip to content

Commit 614a6c1

Browse files
committed
Split CommonMethods to accomodate for use in back/write.rs
1 parent abfa77c commit 614a6c1

File tree

9 files changed

+29
-24
lines changed

9 files changed

+29
-24
lines changed

src/librustc_codegen_llvm/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use syntax_pos::MultiSpan;
4545
use syntax_pos::symbol::Symbol;
4646
use type_::Type;
4747
use context::{is_pie_binary, get_reloc_model, CodegenCx};
48-
use interfaces::CommonMethods;
48+
use interfaces::CommonWriteMethods;
4949
use jobserver::{Client, Acquired};
5050
use rustc_demangle;
5151

src/librustc_codegen_llvm/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use CrateInfo;
7373
use rustc_data_structures::small_c_str::SmallCStr;
7474
use rustc_data_structures::sync::Lrc;
7575

76-
use interfaces::{BuilderMethods, CommonMethods};
76+
use interfaces::{BuilderMethods, CommonMethods, CommonWriteMethods};
7777

7878
use std::any::Any;
7979
use std::ffi::CString;

src/librustc_codegen_llvm/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc::ty::TyCtxt;
1919
use rustc::ty::layout::{Align, Size};
2020
use rustc::session::{config, Session};
2121
use rustc_data_structures::small_c_str::SmallCStr;
22-
use interfaces::{BuilderMethods, Backend, CommonMethods};
22+
use interfaces::{BuilderMethods, Backend, CommonMethods, CommonWriteMethods};
2323
use syntax;
2424

2525
use std::borrow::Cow;

src/librustc_codegen_llvm/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use llvm;
2222
use monomorphize::Instance;
2323
use type_of::LayoutLlvmExt;
2424
use value::Value;
25-
use interfaces::CommonMethods;
25+
use interfaces::CommonWriteMethods;
2626

2727
use rustc::hir::def_id::DefId;
2828
use rustc::ty::{self, TypeFoldable};

src/librustc_codegen_llvm/common.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use declare;
2424
use type_::Type;
2525
use type_of::LayoutLlvmExt;
2626
use value::Value;
27-
use interfaces::{Backend, CommonMethods};
27+
use interfaces::{Backend, CommonMethods, CommonWriteMethods};
2828

2929
use rustc::ty::{self, Ty, TyCtxt};
3030
use rustc::ty::layout::{HasDataLayout, LayoutOf};
@@ -203,11 +203,6 @@ impl Backend for CodegenCx<'ll, 'tcx, &'ll Value> {
203203
}
204204

205205
impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
206-
fn val_ty(v: &'ll Value) -> &'ll Type {
207-
unsafe {
208-
llvm::LLVMTypeOf(v)
209-
}
210-
}
211206

212207
// LLVM constant constructors.
213208
fn c_null(&self, t: &'ll Type) -> &'ll Value {
@@ -356,13 +351,6 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
356351
Self::c_bytes_in_context(&self.llcx, bytes)
357352
}
358353

359-
fn c_bytes_in_context(llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
360-
unsafe {
361-
let ptr = bytes.as_ptr() as *const c_char;
362-
return llvm::LLVMConstStringInContext(llcx, ptr, bytes.len() as c_uint, True);
363-
}
364-
}
365-
366354
fn const_get_elt(v: &'ll Value, idx: u64) -> &'ll Value {
367355
unsafe {
368356
assert_eq!(idx as c_uint as u64, idx);
@@ -555,3 +543,18 @@ pub fn ty_fn_sig<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx, &'a Value>,
555543
_ => bug!("unexpected type {:?} to ty_fn_sig", ty)
556544
}
557545
}
546+
547+
impl<'ll, 'tcx : 'll> CommonWriteMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
548+
fn val_ty(v: &'ll Value) -> &'ll Type {
549+
unsafe {
550+
llvm::LLVMTypeOf(v)
551+
}
552+
}
553+
554+
fn c_bytes_in_context(llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
555+
unsafe {
556+
let ptr = bytes.as_ptr() as *const c_char;
557+
return llvm::LLVMConstStringInContext(llcx, ptr, bytes.len() as c_uint, True);
558+
}
559+
}
560+
}

src/librustc_codegen_llvm/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use type_::Type;
2424
use type_of::LayoutLlvmExt;
2525
use value::Value;
2626
use rustc::ty::{self, Ty};
27-
use interfaces::CommonMethods;
27+
use interfaces::CommonWriteMethods;
2828

2929
use rustc::ty::layout::{Align, LayoutOf};
3030

src/librustc_codegen_llvm/interfaces/common.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
use super::Backend;
1212
use syntax::symbol::LocalInternedString;
1313

14-
pub trait CommonMethods : Backend {
15-
fn val_ty(v: Self::Value) -> Self::Type;
16-
14+
pub trait CommonMethods : Backend + CommonWriteMethods {
1715
// Constant constructors
1816
fn c_null(&self, t: Self::Type) -> Self::Value;
1917
fn c_undef(&self, t: Self::Type) -> Self::Value;
@@ -50,7 +48,6 @@ pub trait CommonMethods : Backend {
5048
fn c_array(ty: Self::Type, elts: &[Self::Value]) -> Self::Value;
5149
fn c_vector(elts: &[Self::Value]) -> Self::Value;
5250
fn c_bytes(&self, bytes: &[u8]) -> Self::Value;
53-
fn c_bytes_in_context(llcx: Self::Context, bytes: &[u8]) -> Self::Value;
5451

5552
fn const_get_elt(v: Self::Value, idx: u64) -> Self::Value;
5653
fn const_get_real(v: Self::Value) -> Option<(f64, bool)>;
@@ -59,3 +56,8 @@ pub trait CommonMethods : Backend {
5956
fn is_const_real(v: Self::Value) -> bool;
6057
fn const_to_opt_u128(v: Self::Value, sign_ext: bool) -> Option<u128>;
6158
}
59+
60+
pub trait CommonWriteMethods : Backend {
61+
fn val_ty(v: Self::Value) -> Self::Type;
62+
fn c_bytes_in_context(llcx: Self::Context, bytes: &[u8]) -> Self::Value;
63+
}

src/librustc_codegen_llvm/interfaces/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ mod common;
1414

1515
pub use self::builder::BuilderMethods;
1616
pub use self::backend::Backend;
17-
pub use self::common::CommonMethods;
17+
pub use self::common::{CommonMethods, CommonWriteMethods};

src/librustc_codegen_llvm/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use type_::Type;
2727
use type_of::LayoutLlvmExt;
2828
use value::Value;
2929

30-
use interfaces::{BuilderMethods, CommonMethods};
30+
use interfaces::{BuilderMethods, CommonMethods, CommonWriteMethods};
3131

3232
use super::{FunctionCx, LocalRef};
3333
use super::operand::{OperandRef, OperandValue};

0 commit comments

Comments
 (0)