1
Fork 0

Some refactorings

This commit is contained in:
bjorn3 2018-11-23 18:24:30 +01:00
parent 0c1dc62c1e
commit b3b6e4dd9b
7 changed files with 26 additions and 31 deletions

View file

@ -58,7 +58,6 @@ impl BackendTypes for Builder<'_, 'll, 'tcx> {
type Value = <CodegenCx<'ll, 'tcx> as BackendTypes>::Value;
type BasicBlock = <CodegenCx<'ll, 'tcx> as BackendTypes>::BasicBlock;
type Type = <CodegenCx<'ll, 'tcx> as BackendTypes>::Type;
type Context = <CodegenCx<'ll, 'tcx> as BackendTypes>::Context;
type Funclet = <CodegenCx<'ll, 'tcx> as BackendTypes>::Funclet;
type DIScope = <CodegenCx<'ll, 'tcx> as BackendTypes>::DIScope;

View file

@ -98,7 +98,6 @@ impl BackendTypes for CodegenCx<'ll, 'tcx> {
type Value = &'ll Value;
type BasicBlock = &'ll BasicBlock;
type Type = &'ll Type;
type Context = &'ll llvm::Context;
type Funclet = Funclet<'ll>;
type DIScope = &'ll llvm::debuginfo::DIScope;

View file

@ -47,6 +47,22 @@ impl fmt::Debug for Type {
}
}
impl CodegenCx<'ll, 'tcx> {
crate fn type_named_struct(&self, name: &str) -> &'ll Type {
let name = SmallCStr::new(name);
unsafe {
llvm::LLVMStructCreateNamed(self.llcx, name.as_ptr())
}
}
crate fn set_struct_body(&self, ty: &'ll Type, els: &[&'ll Type], packed: bool) {
unsafe {
llvm::LLVMStructSetBody(ty, els.as_ptr(),
els.len() as c_uint, packed as Bool)
}
}
}
impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
fn type_void(&self) -> &'ll Type {
unsafe {
@ -160,13 +176,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}
}
fn type_named_struct(&self, name: &str) -> &'ll Type {
let name = SmallCStr::new(name);
unsafe {
llvm::LLVMStructCreateNamed(self.llcx, name.as_ptr())
}
}
fn type_array(&self, ty: &'ll Type, len: u64) -> &'ll Type {
unsafe {
@ -186,13 +195,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}
}
fn set_struct_body(&self, ty: &'ll Type, els: &[&'ll Type], packed: bool) {
unsafe {
llvm::LLVMStructSetBody(ty, els.as_ptr(),
els.len() as c_uint, packed as Bool)
}
}
fn type_ptr_to(&self, ty: &'ll Type) -> &'ll Type {
assert_ne!(self.type_kind(ty), TypeKind::Function,
"don't call ptr_to on function types, use ptr_to_llvm_type on FnType instead");

View file

@ -23,22 +23,21 @@ impl<D> FunctionDebugContext<D> {
match *self {
FunctionDebugContext::RegularContext(ref data) => data,
FunctionDebugContext::DebugInfoDisabled => {
span_bug!(span, "{}", FunctionDebugContext::<D>::debuginfo_disabled_message());
span_bug!(
span,
"debuginfo: Error trying to access FunctionDebugContext \
although debug info is disabled!",
);
}
FunctionDebugContext::FunctionWithoutDebugInfo => {
span_bug!(span, "{}", FunctionDebugContext::<D>::should_be_ignored_message());
span_bug!(
span,
"debuginfo: Error trying to access FunctionDebugContext \
for function that should be ignored by debug info!",
);
}
}
}
fn debuginfo_disabled_message() -> &'static str {
"debuginfo: Error trying to access FunctionDebugContext although debug info is disabled!"
}
fn should_be_ignored_message() -> &'static str {
"debuginfo: Error trying to access FunctionDebugContext for function that should be \
ignored by debug info!"
}
}
/// Enables emitting source locations for the given functions.

View file

@ -26,7 +26,6 @@ pub trait BackendTypes {
type Value: CodegenObject;
type BasicBlock: Copy;
type Type: CodegenObject;
type Context;
type Funclet;
type DIScope: Copy;

View file

@ -92,7 +92,6 @@ pub trait HasCodegen<'tcx>: Backend<'tcx> {
Value = Self::Value,
BasicBlock = Self::BasicBlock,
Type = Self::Type,
Context = Self::Context,
Funclet = Self::Funclet,
DIScope = Self::DIScope,
>;

View file

@ -41,11 +41,9 @@ pub trait BaseTypeMethods<'tcx>: Backend<'tcx> {
fn type_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
fn type_variadic_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
fn type_struct(&self, els: &[Self::Type], packed: bool) -> Self::Type;
fn type_named_struct(&self, name: &str) -> Self::Type;
fn type_array(&self, ty: Self::Type, len: u64) -> Self::Type;
fn type_vector(&self, ty: Self::Type, len: u64) -> Self::Type;
fn type_kind(&self, ty: Self::Type) -> TypeKind;
fn set_struct_body(&self, ty: Self::Type, els: &[Self::Type], packed: bool);
fn type_ptr_to(&self, ty: Self::Type) -> Self::Type;
fn element_type(&self, ty: Self::Type) -> Self::Type;