Skip to content

Commit 2e40f91

Browse files
authored
Merge pull request rust-lang#34 from Michael-F-Bryan/impl-debug
Impl debug
2 parents 2db8ce1 + c25aed6 commit 2e40f91

14 files changed

+66
-16
lines changed

src/basic_block.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ impl fmt::Debug for BasicBlock {
421421
LLVMIsConstant(self.basic_block as LLVMValueRef) == 1
422422
};
423423

424-
write!(f, "BasicBlock {{\n address: {:?}\n is_const: {:?}\n llvm_value: {:?}\n llvm_type: {:?}\n}}", self.basic_block, is_const, llvm_value, llvm_type)
424+
f.debug_struct("BasicBlock")
425+
.field("address", &self.basic_block)
426+
.field("is_const", &is_const)
427+
.field("llvm_value", &llvm_value)
428+
.field("llvm_type", &llvm_type)
429+
.finish()
425430
}
426431
}

src/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use types::{AsTypeRef, BasicType, PointerType, IntType, FloatType};
1010

1111
use std::ffi::CString;
1212

13+
#[derive(Debug)]
1314
pub struct Builder {
1415
builder: LLVMBuilderRef,
1516
}

src/data_layout.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ impl PartialEq for DataLayout {
3636

3737
impl fmt::Debug for DataLayout {
3838
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39-
write!(f, "DataLayout {{\n ")?;
40-
write!(f, "address: {:?}\n ", self.data_layout.get())?;
41-
write!(f, "repr: {:?}\n}}", self.as_str())
39+
f.debug_struct("DataLayout")
40+
.field("address", &self.data_layout.get())
41+
.field("repr", &self.as_str())
42+
.finish()
4243
}
4344
}
4445

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(missing_debug_implementations)]
12
extern crate either;
23
#[macro_use]
34
extern crate enum_methods;

src/memory_buffer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::mem::zeroed;
99
use std::path::Path;
1010
use std::ptr;
1111

12+
#[derive(Debug)]
1213
pub struct MemoryBuffer {
1314
pub(crate) memory_buffer: LLVMMemoryBufferRef
1415
}

src/object_file.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ffi::CStr;
55
// REVIEW: Make sure SectionIterator's object_file ptr doesn't outlive ObjectFile
66
// REVIEW: This module is very untested
77
// TODO: More references to account for lifetimes
8-
8+
#[derive(Debug)]
99
pub struct ObjectFile {
1010
object_file: LLVMObjectFileRef
1111
}
@@ -44,6 +44,7 @@ impl Drop for ObjectFile {
4444
}
4545
}
4646

47+
#[derive(Debug)]
4748
pub struct SectionIterator {
4849
section_iterator: LLVMSectionIteratorRef,
4950
object_file: LLVMObjectFileRef,
@@ -91,6 +92,7 @@ impl Drop for SectionIterator {
9192
}
9293
}
9394

95+
#[derive(Debug)]
9496
pub struct Section {
9597
section: LLVMSectionIteratorRef,
9698
object_file: LLVMObjectFileRef,
@@ -139,6 +141,7 @@ impl Section {
139141
}
140142
}
141143

144+
#[derive(Debug)]
142145
pub struct RelocationIterator {
143146
relocation_iterator: LLVMRelocationIteratorRef,
144147
section_iterator: LLVMSectionIteratorRef,
@@ -188,6 +191,7 @@ impl Drop for RelocationIterator {
188191
}
189192
}
190193

194+
#[derive(Debug)]
191195
pub struct Relocation {
192196
relocation: LLVMRelocationIteratorRef,
193197
object_file: LLVMObjectFileRef,
@@ -236,6 +240,7 @@ impl Relocation {
236240
}
237241
}
238242

243+
#[derive(Debug)]
239244
pub struct SymbolIterator {
240245
symbol_iterator: LLVMSymbolIteratorRef,
241246
object_file: LLVMObjectFileRef,
@@ -283,6 +288,7 @@ impl Drop for SymbolIterator {
283288
}
284289
}
285290

291+
#[derive(Debug)]
286292
pub struct Symbol {
287293
symbol: LLVMSymbolIteratorRef,
288294
}

src/passes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use values::{AsValueRef, FunctionValue};
1818

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

109110
// SubTypes: PassManager<Module>, PassManager<FunctionValue>
111+
#[derive(Debug)]
110112
pub struct PassManager {
111113
pub(crate) pass_manager: LLVMPassManagerRef,
112114
}
@@ -525,6 +527,7 @@ impl Drop for PassManager {
525527
}
526528
}
527529

530+
#[derive(Debug)]
528531
pub struct PassRegistry {
529532
pass_registry: LLVMPassRegistryRef,
530533
}

src/types/fn_type.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ impl fmt::Debug for FunctionType {
8282
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8383
let llvm_type = self.print_to_string();
8484

85-
write!(f, "FunctionType {{\n address: {:?}\n llvm_type: {:?}\n}}", self.as_type_ref(), llvm_type)
85+
f.debug_struct("FunctionType")
86+
.field("address", &self.as_type_ref())
87+
.field("llvm_type", &llvm_type)
88+
.finish()
8689
}
8790
}
8891

src/types/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ impl fmt::Debug for Type {
171171
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
172172
let llvm_type = self.print_to_string();
173173

174-
write!(f, "Type {{\n address: {:?}\n llvm_type: {:?}\n}}", self.type_, llvm_type)
174+
f.debug_struct("Type")
175+
.field("address", &self.type_)
176+
.field("llvm_type", &llvm_type)
177+
.finish()
175178
}
176179
}

src/values/array_value.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ impl fmt::Debug for ArrayValue {
9393
!LLVMIsAConstantDataArray(self.as_value_ref()).is_null()
9494
};
9595

96-
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())
96+
f.debug_struct("Value")
97+
.field("name", &name)
98+
.field("address", &self.as_value_ref())
99+
.field("is_const", &is_const)
100+
.field("is_const_array", &is_const_array)
101+
.field("is_const_data_array", &is_const_data_array)
102+
.field("is_null", &is_null)
103+
.field("llvm_value", &llvm_value)
104+
.field("llvm_type", &llvm_type)
105+
.finish()
97106
}
98107
}

src/values/fn_value.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,18 @@ impl fmt::Debug for FunctionValue {
330330
};
331331
let is_null = self.is_null();
332332

333-
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())
333+
f.debug_struct("FunctionValue")
334+
.field("name", &name)
335+
.field("address", &self.as_value_ref())
336+
.field("is_const", &is_const)
337+
.field("is_null", &is_null)
338+
.field("llvm_value", &llvm_value)
339+
.field("llvm_type", &llvm_type.print_to_string())
340+
.finish()
334341
}
335342
}
336343

344+
#[derive(Debug)]
337345
pub struct ParamValueIter {
338346
param_iter_value: LLVMValueRef,
339347
start: bool,

src/values/generic_value.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use llvm_sys::execution_engine::{LLVMCreateGenericValueOfPointer, LLVMDisposeGen
44
use types::{AsTypeRef, FloatType};
55

66
// SubTypes: GenericValue<IntValue, FloatValue, or PointerValue>
7+
#[derive(Debug)]
78
pub struct GenericValue {
89
pub(crate) generic_value: LLVMGenericValueRef,
910
}

src/values/metadata_value.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,17 @@ impl AsValueRef for MetadataValue {
143143

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

149149
if self.is_string() {
150-
write!(f, "value: {:?}\n", self.get_string_value().unwrap())?;
150+
d.field("value", &self.get_string_value().unwrap());
151151
} else {
152-
write!(f, "values: {:?}\n", self.get_node_values())?;
152+
d.field("values", &self.get_node_values());
153153
}
154154

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

157-
write!(f, "\n}}")
157+
d.finish()
158158
}
159159
}

src/values/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ impl fmt::Debug for Value {
168168
let is_null = self.is_null();
169169
let is_undef = self.is_undef();
170170

171-
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)
171+
f.debug_struct("Value")
172+
.field("name", &name)
173+
.field("address", &self.value)
174+
.field("is_const", &is_const)
175+
.field("is_null", &is_null)
176+
.field("is_undef", &is_undef)
177+
.field("llvm_value", &llvm_value)
178+
.field("llvm_type", &llvm_type)
179+
.finish()
172180
}
173181
}

0 commit comments

Comments
 (0)