Skip to content

Commit fed567a

Browse files
committed
Removing LLVM content from CommonMethods -> ConstMethods
1 parent 23562c1 commit fed567a

File tree

23 files changed

+49
-119
lines changed

23 files changed

+49
-119
lines changed

src/librustc_codegen_llvm/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use type_::Type;
1919
use type_of::{LayoutLlvmExt, PointerKind};
2020
use value::Value;
2121

22-
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
22+
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
2323

2424
use rustc_target::abi::{LayoutOf, Size, TyLayout};
2525
use rustc::ty::{self, Ty};

src/librustc_codegen_llvm/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use builder::Builder;
1515
use value::Value;
1616

1717
use rustc::hir;
18-
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
18+
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
1919

2020
use mir::place::PlaceRef;
2121
use mir::operand::OperandValue;

src/librustc_codegen_llvm/back/write.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ use context::{is_pie_binary, get_reloc_model};
4848
use common;
4949
use jobserver::{Client, Acquired};
5050
use rustc_demangle;
51-
use value::Value;
5251
use std::marker::PhantomData;
5352

5453
use std::any::Any;
@@ -419,24 +418,6 @@ impl CodegenContext<'ll> {
419418
}
420419
}
421420

422-
423-
impl CodegenContext<'ll> {
424-
fn val_ty(&self, v: &'ll Value) -> &'ll Type {
425-
common::val_ty(v)
426-
}
427-
428-
fn const_bytes_in_context(&self, llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
429-
common::const_bytes_in_context(llcx, bytes)
430-
}
431-
432-
pub fn type_ptr_to(&self, ty: &'ll Type) -> &'ll Type {
433-
unsafe {
434-
llvm::LLVMPointerType(ty, 0)
435-
}
436-
}
437-
}
438-
439-
440421
pub struct DiagnosticHandlers<'a> {
441422
data: *mut (&'a CodegenContext<'a>, &'a Handler),
442423
llcx: &'a llvm::Context,
@@ -907,10 +888,10 @@ unsafe fn embed_bitcode(cgcx: &CodegenContext,
907888
llcx: &llvm::Context,
908889
llmod: &llvm::Module,
909890
bitcode: Option<&[u8]>) {
910-
let llconst = cgcx.const_bytes_in_context(llcx, bitcode.unwrap_or(&[]));
891+
let llconst = common::bytes_in_context(llcx, bitcode.unwrap_or(&[]));
911892
let llglobal = llvm::LLVMAddGlobal(
912893
llmod,
913-
cgcx.val_ty(llconst),
894+
common::val_ty(llconst),
914895
"rustc.embedded.module\0".as_ptr() as *const _,
915896
);
916897
llvm::LLVMSetInitializer(llglobal, llconst);
@@ -927,10 +908,10 @@ unsafe fn embed_bitcode(cgcx: &CodegenContext,
927908
llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);
928909
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);
929910

930-
let llconst = cgcx.const_bytes_in_context(llcx, &[]);
911+
let llconst = common::bytes_in_context(llcx, &[]);
931912
let llglobal = llvm::LLVMAddGlobal(
932913
llmod,
933-
cgcx.val_ty(llconst),
914+
common::val_ty(llconst),
934915
"rustc.embedded.cmdline\0".as_ptr() as *const _,
935916
);
936917
llvm::LLVMSetInitializer(llglobal, llconst);
@@ -2561,7 +2542,7 @@ fn create_msvc_imps(cgcx: &CodegenContext, llcx: &llvm::Context, llmod: &llvm::M
25612542
"\x01__imp_"
25622543
};
25632544
unsafe {
2564-
let i8p_ty = Type::i8p_llcx(cgcx, llcx);
2545+
let i8p_ty = Type::i8p_llcx(llcx);
25652546
let globals = base::iter_globals(llmod)
25662547
.filter(|&val| {
25672548
llvm::LLVMRustGetLinkage(val) == llvm::Linkage::ExternalLinkage &&

src/librustc_codegen_llvm/base.rs

Lines changed: 4 additions & 4 deletions
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, CommonWriteMethods, TypeMethods};
76+
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
7777

7878
use std::any::Any;
7979
use std::ffi::CString;
@@ -654,12 +654,12 @@ fn write_metadata<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
654654
DeflateEncoder::new(&mut compressed, Compression::fast())
655655
.write_all(&metadata.raw_data).unwrap();
656656

657-
let llmeta = llvm_module.const_bytes_in_context(metadata_llcx, &compressed);
658-
let llconst = llvm_module.const_struct_in_context(metadata_llcx, &[llmeta], false);
657+
let llmeta = common::bytes_in_context(metadata_llcx, &compressed);
658+
let llconst = common::struct_in_context(metadata_llcx, &[llmeta], false);
659659
let name = exported_symbols::metadata_symbol_name(tcx);
660660
let buf = CString::new(name).unwrap();
661661
let llglobal = unsafe {
662-
llvm::LLVMAddGlobal(metadata_llmod, llvm_module.val_ty(llconst), buf.as_ptr())
662+
llvm::LLVMAddGlobal(metadata_llmod, common::val_ty(llconst), buf.as_ptr())
663663
};
664664
unsafe {
665665
llvm::LLVMSetInitializer(llglobal, llconst);

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, CommonWriteMethods, TypeMethods};
22+
use interfaces::{BuilderMethods, Backend, ConstMethods, TypeMethods};
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::CommonWriteMethods;
25+
use interfaces::TypeMethods;
2626

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

src/librustc_codegen_llvm/common.rs

Lines changed: 6 additions & 26 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, CommonWriteMethods, TypeMethods};
27+
use interfaces::{Backend, ConstMethods, TypeMethods};
2828

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

206-
impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
206+
impl<'ll, 'tcx : 'll> ConstMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
207207

208208
// LLVM constant constructors.
209209
fn const_null(&self, t: &'ll Type) -> &'ll Value {
@@ -321,7 +321,7 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
321321
elts: &[&'ll Value],
322322
packed: bool
323323
) -> &'ll Value {
324-
&self.const_struct_in_context(&self.llcx, elts, packed)
324+
struct_in_context(&self.llcx, elts, packed)
325325
}
326326

327327
fn const_array(&self, ty: &'ll Type, elts: &[&'ll Value]) -> &'ll Value {
@@ -337,7 +337,7 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
337337
}
338338

339339
fn const_bytes(&self, bytes: &[u8]) -> &'ll Value {
340-
&self.const_bytes_in_context(&self.llcx, bytes)
340+
bytes_in_context(&self.llcx, bytes)
341341
}
342342

343343
fn const_get_elt(&self, v: &'ll Value, idx: u64) -> &'ll Value {
@@ -408,14 +408,14 @@ pub fn val_ty(v: &'ll Value) -> &'ll Type {
408408
}
409409
}
410410

411-
pub fn const_bytes_in_context(llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
411+
pub fn bytes_in_context(llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
412412
unsafe {
413413
let ptr = bytes.as_ptr() as *const c_char;
414414
return llvm::LLVMConstStringInContext(llcx, ptr, bytes.len() as c_uint, True);
415415
}
416416
}
417417

418-
pub fn const_struct_in_context(
418+
pub fn struct_in_context(
419419
llcx: &'a llvm::Context,
420420
elts: &[&'a Value],
421421
packed: bool,
@@ -427,26 +427,6 @@ pub fn const_struct_in_context(
427427
}
428428
}
429429

430-
impl<'ll, 'tcx : 'll> CommonWriteMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
431-
fn val_ty(&self, v: &'ll Value) -> &'ll Type {
432-
val_ty(v)
433-
}
434-
435-
fn const_bytes_in_context(&self, llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
436-
const_bytes_in_context(llcx, bytes)
437-
}
438-
439-
fn const_struct_in_context(
440-
&self,
441-
llcx: &'a llvm::Context,
442-
elts: &[&'a Value],
443-
packed: bool,
444-
) -> &'a Value {
445-
const_struct_in_context(llcx, elts, packed)
446-
}
447-
}
448-
449-
450430
#[inline]
451431
fn hi_lo_to_u128(lo: u64, hi: u64) -> u128 {
452432
((hi as u128) << 64) | (lo as u128)

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::{CommonWriteMethods, TypeMethods};
27+
use interfaces::TypeMethods;
2828

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

src/librustc_codegen_llvm/debuginfo/gdb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use builder::Builder;
1717
use declare;
1818
use rustc::session::config::DebugInfo;
1919
use value::Value;
20-
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
20+
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
2121

2222
use syntax::attr;
2323

src/librustc_codegen_llvm/glue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use meth;
2020
use rustc::ty::layout::LayoutOf;
2121
use rustc::ty::{self, Ty};
2222
use value::Value;
23-
use interfaces::{BuilderMethods, CommonMethods};
23+
use interfaces::{BuilderMethods, ConstMethods};
2424

2525
pub fn size_and_align_of_dst(
2626
bx: &Builder<'_, 'll, 'tcx, &'ll Value>,

src/librustc_codegen_llvm/interfaces/common.rs renamed to src/librustc_codegen_llvm/interfaces/consts.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use super::Backend;
1212
use syntax::symbol::LocalInternedString;
1313

14-
pub trait CommonMethods : Backend + CommonWriteMethods {
14+
pub trait ConstMethods : Backend {
1515
// Constant constructors
1616
fn const_null(&self, t: Self::Type) -> Self::Value;
1717
fn const_undef(&self, t: Self::Type) -> Self::Value;
@@ -52,14 +52,3 @@ pub trait CommonMethods : Backend + CommonWriteMethods {
5252
fn is_const_integral(&self, v: Self::Value) -> bool;
5353
fn is_const_real(&self, v: Self::Value) -> bool;
5454
}
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-
}

src/librustc_codegen_llvm/interfaces/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
mod builder;
1212
mod backend;
13-
mod common;
13+
mod consts;
1414
mod type_;
1515

1616
pub use self::builder::BuilderMethods;
1717
pub use self::backend::Backend;
18-
pub use self::common::{CommonMethods, CommonWriteMethods};
18+
pub use self::consts::ConstMethods;
1919
pub use self::type_::TypeMethods;

src/librustc_codegen_llvm/interfaces/type_.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ pub trait TypeMethods : Backend {
3838
fn func_params_types(&self, ty: Self::Type) -> Vec<Self::Type>;
3939
fn float_width(&self, ty: Self::Type) -> usize;
4040
fn int_width(&self, ty: Self::Type) -> u64;
41+
42+
fn val_ty(&self, v: Self::Value) -> Self::Type;
4143
}

src/librustc_codegen_llvm/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use syntax::symbol::Symbol;
3131
use builder::Builder;
3232
use value::Value;
3333

34-
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
34+
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
3535

3636
use rustc::session::Session;
3737
use syntax_pos::Span;

src/librustc_codegen_llvm/lib.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ extern crate tempfile;
6969
extern crate memmap;
7070

7171
use back::bytecode::RLIB_BYTECODE_EXTENSION;
72-
use interfaces::{Backend, CommonWriteMethods};
73-
use value::Value;
74-
use type_::Type;
7572

7673
pub use llvm_util::target_features;
7774
use std::any::Any;
@@ -347,14 +344,6 @@ struct ModuleLlvm<'ll> {
347344
phantom: PhantomData<&'ll ()>
348345
}
349346

350-
impl<'ll> Backend for ModuleLlvm<'ll> {
351-
type Value = &'ll Value;
352-
type BasicBlock = &'ll llvm::BasicBlock;
353-
type Type = &'ll Type;
354-
type TypeKind = llvm::TypeKind;
355-
type Context = &'ll llvm::Context;
356-
}
357-
358347
unsafe impl Send for ModuleLlvm<'ll> { }
359348
unsafe impl Sync for ModuleLlvm<'ll> { }
360349

@@ -380,25 +369,6 @@ impl ModuleLlvm<'ll> {
380369
}
381370
}
382371

383-
impl CommonWriteMethods for ModuleLlvm<'ll> {
384-
fn val_ty(&self, v: &'ll Value) -> &'ll Type {
385-
common::val_ty(v)
386-
}
387-
388-
fn const_bytes_in_context(&self, llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
389-
common::const_bytes_in_context(llcx, bytes)
390-
}
391-
392-
fn const_struct_in_context(
393-
&self,
394-
llcx: &'a llvm::Context,
395-
elts: &[&'a Value],
396-
packed: bool,
397-
) -> &'a Value {
398-
common::const_struct_in_context(llcx, elts, packed)
399-
}
400-
}
401-
402372
impl Drop for ModuleLlvm<'ll> {
403373
fn drop(&mut self) {
404374
unsafe {

src/librustc_codegen_llvm/meth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use consts;
1616
use monomorphize;
1717
use value::Value;
1818

19-
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
19+
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
2020

2121
use rustc::ty::{self, Ty};
2222
use rustc::ty::layout::HasDataLayout;

src/librustc_codegen_llvm/mir/block.rs

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

29-
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
29+
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
3030

3131
use syntax::symbol::Symbol;
3232
use syntax_pos::Pos;

src/librustc_codegen_llvm/mir/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use type_::Type;
2626
use syntax::ast::Mutability;
2727
use syntax::source_map::Span;
2828
use value::Value;
29-
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
29+
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
3030

3131
use super::super::callee;
3232
use super::FunctionCx;

src/librustc_codegen_llvm/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use debuginfo::{self, declare_local, VariableAccess, VariableKind, FunctionDebug
2323
use monomorphize::Instance;
2424
use abi::{ArgTypeExt, FnType, FnTypeExt, PassMode};
2525
use value::Value;
26-
use interfaces::{BuilderMethods, CommonMethods};
26+
use interfaces::{BuilderMethods, ConstMethods};
2727

2828
use syntax_pos::{DUMMY_SP, NO_EXPANSION, BytePos, Span};
2929
use syntax::symbol::keywords;

src/librustc_codegen_llvm/mir/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use value::Value;
2323
use type_of::LayoutLlvmExt;
2424
use glue;
2525

26-
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
26+
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
2727

2828
use std::fmt;
2929

src/librustc_codegen_llvm/mir/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use value::Value;
2323
use glue;
2424
use mir::constant::const_alloc_to_llvm;
2525

26-
use interfaces::{BuilderMethods, CommonMethods, TypeMethods};
26+
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
2727

2828
use super::{FunctionCx, LocalRef};
2929
use super::operand::{OperandRef, OperandValue};

0 commit comments

Comments
 (0)