Skip to content

Commit

Permalink
Merge pull request rust-lang#34 from Michael-F-Bryan/impl-debug
Browse files Browse the repository at this point in the history
Impl debug
  • Loading branch information
TheDan64 committed Mar 12, 2018
2 parents 2db8ce1 + c25aed6 commit 2e40f91
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 16 deletions.
7 changes: 6 additions & 1 deletion src/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ impl fmt::Debug for BasicBlock {
LLVMIsConstant(self.basic_block as LLVMValueRef) == 1
};

write!(f, "BasicBlock {{\n address: {:?}\n is_const: {:?}\n llvm_value: {:?}\n llvm_type: {:?}\n}}", self.basic_block, is_const, llvm_value, llvm_type)
f.debug_struct("BasicBlock")
.field("address", &self.basic_block)
.field("is_const", &is_const)
.field("llvm_value", &llvm_value)
.field("llvm_type", &llvm_type)
.finish()
}
}
1 change: 1 addition & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use types::{AsTypeRef, BasicType, PointerType, IntType, FloatType};

use std::ffi::CString;

#[derive(Debug)]
pub struct Builder {
builder: LLVMBuilderRef,
}
Expand Down
7 changes: 4 additions & 3 deletions src/data_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ impl PartialEq for DataLayout {

impl fmt::Debug for DataLayout {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "DataLayout {{\n ")?;
write!(f, "address: {:?}\n ", self.data_layout.get())?;
write!(f, "repr: {:?}\n}}", self.as_str())
f.debug_struct("DataLayout")
.field("address", &self.data_layout.get())
.field("repr", &self.as_str())
.finish()
}
}

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(missing_debug_implementations)]
extern crate either;
#[macro_use]
extern crate enum_methods;
Expand Down
1 change: 1 addition & 0 deletions src/memory_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::mem::zeroed;
use std::path::Path;
use std::ptr;

#[derive(Debug)]
pub struct MemoryBuffer {
pub(crate) memory_buffer: LLVMMemoryBufferRef
}
Expand Down
8 changes: 7 additions & 1 deletion src/object_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::ffi::CStr;
// REVIEW: Make sure SectionIterator's object_file ptr doesn't outlive ObjectFile
// REVIEW: This module is very untested
// TODO: More references to account for lifetimes

#[derive(Debug)]
pub struct ObjectFile {
object_file: LLVMObjectFileRef
}
Expand Down Expand Up @@ -44,6 +44,7 @@ impl Drop for ObjectFile {
}
}

#[derive(Debug)]
pub struct SectionIterator {
section_iterator: LLVMSectionIteratorRef,
object_file: LLVMObjectFileRef,
Expand Down Expand Up @@ -91,6 +92,7 @@ impl Drop for SectionIterator {
}
}

#[derive(Debug)]
pub struct Section {
section: LLVMSectionIteratorRef,
object_file: LLVMObjectFileRef,
Expand Down Expand Up @@ -139,6 +141,7 @@ impl Section {
}
}

#[derive(Debug)]
pub struct RelocationIterator {
relocation_iterator: LLVMRelocationIteratorRef,
section_iterator: LLVMSectionIteratorRef,
Expand Down Expand Up @@ -188,6 +191,7 @@ impl Drop for RelocationIterator {
}
}

#[derive(Debug)]
pub struct Relocation {
relocation: LLVMRelocationIteratorRef,
object_file: LLVMObjectFileRef,
Expand Down Expand Up @@ -236,6 +240,7 @@ impl Relocation {
}
}

#[derive(Debug)]
pub struct SymbolIterator {
symbol_iterator: LLVMSymbolIteratorRef,
object_file: LLVMObjectFileRef,
Expand Down Expand Up @@ -283,6 +288,7 @@ impl Drop for SymbolIterator {
}
}

#[derive(Debug)]
pub struct Symbol {
symbol: LLVMSymbolIteratorRef,
}
Expand Down
3 changes: 3 additions & 0 deletions src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use values::{AsValueRef, FunctionValue};

// REVIEW: Opt Level might be identical to targets::Option<CodeGenOptLevel>
// REVIEW: size_level 0-2 according to llvmlite
#[derive(Debug)]
pub struct PassManagerBuilder {
pass_manager_builder: LLVMPassManagerBuilderRef,
}
Expand Down Expand Up @@ -107,6 +108,7 @@ impl Drop for PassManagerBuilder {
}

// SubTypes: PassManager<Module>, PassManager<FunctionValue>
#[derive(Debug)]
pub struct PassManager {
pub(crate) pass_manager: LLVMPassManagerRef,
}
Expand Down Expand Up @@ -525,6 +527,7 @@ impl Drop for PassManager {
}
}

#[derive(Debug)]
pub struct PassRegistry {
pass_registry: LLVMPassRegistryRef,
}
Expand Down
5 changes: 4 additions & 1 deletion src/types/fn_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ impl fmt::Debug for FunctionType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let llvm_type = self.print_to_string();

write!(f, "FunctionType {{\n address: {:?}\n llvm_type: {:?}\n}}", self.as_type_ref(), llvm_type)
f.debug_struct("FunctionType")
.field("address", &self.as_type_ref())
.field("llvm_type", &llvm_type)
.finish()
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ impl fmt::Debug for Type {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let llvm_type = self.print_to_string();

write!(f, "Type {{\n address: {:?}\n llvm_type: {:?}\n}}", self.type_, llvm_type)
f.debug_struct("Type")
.field("address", &self.type_)
.field("llvm_type", &llvm_type)
.finish()
}
}
11 changes: 10 additions & 1 deletion src/values/array_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ impl fmt::Debug for ArrayValue {
!LLVMIsAConstantDataArray(self.as_value_ref()).is_null()
};

write!(f, "Value {{\n name: {:?}\n address: {:?}\n is_const: {:?}\n is_const_array: {:?}\n is_const_data_array: {:?}\n is_null: {:?}\n llvm_value: {:?}\n llvm_type: {:?}\n}}", name, self.as_value_ref(), is_const, is_const_array, is_const_data_array, is_null, llvm_value, llvm_type.print_to_string())
f.debug_struct("Value")
.field("name", &name)
.field("address", &self.as_value_ref())
.field("is_const", &is_const)
.field("is_const_array", &is_const_array)
.field("is_const_data_array", &is_const_data_array)
.field("is_null", &is_null)
.field("llvm_value", &llvm_value)
.field("llvm_type", &llvm_type)
.finish()
}
}
10 changes: 9 additions & 1 deletion src/values/fn_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,18 @@ impl fmt::Debug for FunctionValue {
};
let is_null = self.is_null();

write!(f, "FunctionValue {{\n name: {:?}\n address: {:?}\n is_const: {:?}\n is_null: {:?}\n llvm_value: {:?}\n llvm_type: {:?}\n}}", name, self.as_value_ref(), is_const, is_null, llvm_value, llvm_type.print_to_string())
f.debug_struct("FunctionValue")
.field("name", &name)
.field("address", &self.as_value_ref())
.field("is_const", &is_const)
.field("is_null", &is_null)
.field("llvm_value", &llvm_value)
.field("llvm_type", &llvm_type.print_to_string())
.finish()
}
}

#[derive(Debug)]
pub struct ParamValueIter {
param_iter_value: LLVMValueRef,
start: bool,
Expand Down
1 change: 1 addition & 0 deletions src/values/generic_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use llvm_sys::execution_engine::{LLVMCreateGenericValueOfPointer, LLVMDisposeGen
use types::{AsTypeRef, FloatType};

// SubTypes: GenericValue<IntValue, FloatValue, or PointerValue>
#[derive(Debug)]
pub struct GenericValue {
pub(crate) generic_value: LLVMGenericValueRef,
}
Expand Down
12 changes: 6 additions & 6 deletions src/values/metadata_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@ impl AsValueRef for MetadataValue {

impl fmt::Debug for MetadataValue {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "MetadataValue {{\n ")?;
write!(f, "address: {:?}\n", self.as_value_ref())?;
let mut d = f.debug_struct("MetadataValue");
d.field("address", &self.as_value_ref());

if self.is_string() {
write!(f, "value: {:?}\n", self.get_string_value().unwrap())?;
d.field("value", &self.get_string_value().unwrap());
} else {
write!(f, "values: {:?}\n", self.get_node_values())?;
d.field("values", &self.get_node_values());
}

write!(f, "repr: {:?}", self.print_to_string())?;
d.field("repr", &self.print_to_string());

write!(f, "\n}}")
d.finish()
}
}
10 changes: 9 additions & 1 deletion src/values/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ impl fmt::Debug for Value {
let is_null = self.is_null();
let is_undef = self.is_undef();

write!(f, "Value {{\n name: {:?}\n address: {:?}\n is_const: {:?}\n is_null: {:?}\n is_undef: {:?}\n llvm_value: {:?}\n llvm_type: {:?}\n}}", name, self.value, is_const, is_null, is_undef, llvm_value, llvm_type)
f.debug_struct("Value")
.field("name", &name)
.field("address", &self.value)
.field("is_const", &is_const)
.field("is_null", &is_null)
.field("is_undef", &is_undef)
.field("llvm_value", &llvm_value)
.field("llvm_type", &llvm_type)
.finish()
}
}

0 comments on commit 2e40f91

Please sign in to comment.