mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 04:04:06 +00:00
Split CommonMethods to accomodate for use in back/write.rs
This commit is contained in:
parent
83e07f9fe9
commit
3aee77277e
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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};
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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};
|
||||
|
@ -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};
|
||||
|
Loading…
Reference in New Issue
Block a user