Skip to content

Commit 948d2e3

Browse files
authored
Merge pull request rust-lang#223 from seanyoung/funcs
Move print_to_string() to Any{Value,Type}
2 parents 30e9f57 + a8ae800 commit 948d2e3

22 files changed

+26
-100
lines changed

src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ impl Context {
939939
///
940940
/// ```no_run
941941
/// use inkwell::context::Context;
942+
/// use inkwell::values::AnyValue;
942943
///
943944
/// let context = Context::create();
944945
/// let string = context.const_string(b"my_string", false);

src/types/array_type.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use llvm_sys::prelude::{LLVMTypeRef, LLVMValueRef};
33

44
use crate::AddressSpace;
55
use crate::context::ContextRef;
6-
use crate::support::LLVMString;
76
use crate::types::traits::AsTypeRef;
87
use crate::types::{Type, BasicTypeEnum, PointerType, FunctionType};
98
use crate::values::{AsValueRef, ArrayValue, IntValue};
@@ -187,11 +186,6 @@ impl<'ctx> ArrayType<'ctx> {
187186
}
188187
}
189188

190-
/// Prints the definition of a `ArrayType` to a `LLVMString`.
191-
pub fn print_to_string(self) -> LLVMString {
192-
self.array_type.print_to_string()
193-
}
194-
195189
// See Type::print_to_stderr note on 5.0+ status
196190
/// Prints the definition of an `ArrayType` to stderr. Not available in newer LLVM versions.
197191
#[llvm_versions(3.7..=4.0)]

src/types/float_type.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use llvm_sys::prelude::{LLVMTypeRef, LLVMValueRef};
44

55
use crate::AddressSpace;
66
use crate::context::ContextRef;
7-
use crate::support::LLVMString;
87
use crate::types::traits::AsTypeRef;
98
use crate::types::{Type, PointerType, FunctionType, BasicTypeEnum, ArrayType, VectorType};
109
use crate::values::{AsValueRef, ArrayValue, FloatValue, GenericValue, IntValue};
@@ -102,6 +101,7 @@ impl<'ctx> FloatType<'ctx> {
102101
///
103102
/// ```no_run
104103
/// use inkwell::context::Context;
104+
/// use inkwell::values::AnyValue;
105105
///
106106
/// let context = Context::create();
107107
/// let f64_type = context.f64_type();
@@ -139,6 +139,7 @@ impl<'ctx> FloatType<'ctx> {
139139
///
140140
/// ```no_run
141141
/// use inkwell::context::Context;
142+
/// use inkwell::values::AnyValue;
142143
///
143144
/// let context = Context::create();
144145
/// let f32_type = context.f32_type();
@@ -214,11 +215,6 @@ impl<'ctx> FloatType<'ctx> {
214215
self.float_type.ptr_type(address_space)
215216
}
216217

217-
/// Prints the definition of a `FloatType` to a `LLVMString`.
218-
pub fn print_to_string(self) -> LLVMString {
219-
self.float_type.print_to_string()
220-
}
221-
222218
// See Type::print_to_stderr note on 5.0+ status
223219
/// Prints the definition of an `IntType` to stderr. Not available in newer LLVM versions.
224220
#[llvm_versions(3.7..=4.0)]

src/types/fn_type.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ use std::mem::forget;
77

88
use crate::AddressSpace;
99
use crate::context::ContextRef;
10-
use crate::support::LLVMString;
1110
use crate::types::traits::AsTypeRef;
12-
use crate::types::{PointerType, Type, BasicTypeEnum};
11+
use crate::types::{AnyType, PointerType, Type, BasicTypeEnum};
1312

1413
/// A `FunctionType` is the type of a function variable.
1514
#[derive(PartialEq, Eq, Clone, Copy)]
@@ -155,11 +154,6 @@ impl<'ctx> FunctionType<'ctx> {
155154
self.fn_type.get_context()
156155
}
157156

158-
/// Prints the definition of a `FunctionType` to a `LLVMString`.
159-
pub fn print_to_string(self) -> LLVMString {
160-
self.fn_type.print_to_string()
161-
}
162-
163157
// See Type::print_to_stderr note on 5.0+ status
164158
/// Prints the definition of an `IntType` to stderr. Not available in newer LLVM versions.
165159
#[llvm_versions(3.7..=4.0)]

src/types/int_type.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use regex::Regex;
55

66
use crate::AddressSpace;
77
use crate::context::ContextRef;
8-
use crate::support::LLVMString;
98
use crate::types::traits::AsTypeRef;
109
use crate::types::{Type, ArrayType, BasicTypeEnum, VectorType, PointerType, FunctionType};
1110
use crate::values::{AsValueRef, ArrayValue, GenericValue, IntValue};
@@ -100,6 +99,7 @@ impl<'ctx> IntType<'ctx> {
10099
///
101100
/// use inkwell::context::Context;
102101
/// use inkwell::types::StringRadix;
102+
/// use inkwell::values::AnyValue;
103103
///
104104
/// let context = Context::create();
105105
/// let i8_type = context.i8_type();
@@ -171,6 +171,7 @@ impl<'ctx> IntType<'ctx> {
171171
///
172172
/// ```no_run
173173
/// use inkwell::context::Context;
174+
/// use inkwell::values::AnyValue;
174175
///
175176
/// let context = Context::create();
176177
/// let i8_type = context.i8_type();
@@ -314,11 +315,6 @@ impl<'ctx> IntType<'ctx> {
314315
}
315316
}
316317

317-
/// Prints the definition of an `IntType` to a `LLVMString`.
318-
pub fn print_to_string(self) -> LLVMString {
319-
self.int_type.print_to_string()
320-
}
321-
322318
// See Type::print_to_stderr note on 5.0+ status
323319
/// Prints the definition of an `IntType` to stderr. Not available in newer LLVM versions.
324320
#[llvm_versions(3.7..=4.0)]

src/types/ptr_type.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use llvm_sys::prelude::{LLVMTypeRef, LLVMValueRef};
33

44
use crate::AddressSpace;
55
use crate::context::ContextRef;
6-
use crate::support::LLVMString;
76
use crate::types::traits::AsTypeRef;
87
use crate::types::{AnyTypeEnum, BasicTypeEnum, ArrayType, FunctionType, Type, VectorType};
98
use crate::values::{AsValueRef, ArrayValue, PointerValue, IntValue};
@@ -156,11 +155,6 @@ impl<'ctx> PointerType<'ctx> {
156155
AddressSpace::try_from(addr_space).expect("Unexpectedly found invalid AddressSpace value")
157156
}
158157

159-
/// Prints the definition of a `PointerType` to a `LLVMString`.
160-
pub fn print_to_string(self) -> LLVMString {
161-
self.ptr_type.print_to_string()
162-
}
163-
164158
// See Type::print_to_stderr note on 5.0+ status
165159
/// Prints the definition of an `IntType` to stderr. Not available in newer LLVM versions.
166160
#[llvm_versions(3.7..=4.0)]

src/types/struct_type.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::mem::forget;
88

99
use crate::AddressSpace;
1010
use crate::context::ContextRef;
11-
use crate::support::LLVMString;
1211
use crate::types::traits::AsTypeRef;
1312
use crate::types::{ArrayType, BasicTypeEnum, PointerType, FunctionType, Type};
1413
use crate::values::{ArrayValue, BasicValueEnum, StructValue, IntValue, AsValueRef};
@@ -324,11 +323,6 @@ impl<'ctx> StructType<'ctx> {
324323
raw_vec.iter().map(|val| BasicTypeEnum::new(*val)).collect()
325324
}
326325

327-
/// Prints the definition of a `StructType` to a `LLVMString`.
328-
pub fn print_to_string(self) -> LLVMString {
329-
self.struct_type.print_to_string()
330-
}
331-
332326
// See Type::print_to_stderr note on 5.0+ status
333327
/// Prints the definition of an `StructType` to stderr. Not available in newer LLVM versions.
334328
#[llvm_versions(3.7..=4.0)]

src/types/traits.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::AddressSpace;
66
use crate::types::{IntType, FunctionType, FloatType, PointerType, StructType, ArrayType, VectorType, VoidType, Type};
77
use crate::types::enums::{AnyTypeEnum, BasicTypeEnum};
88
use crate::values::{IntMathValue, FloatMathValue, PointerMathValue, IntValue, FloatValue, PointerValue, VectorValue};
9+
use crate::support::LLVMString;
910

1011
// This is an ugly privacy hack so that Type can stay private to this module
1112
// and so that super traits using this trait will be not be implementable
@@ -22,13 +23,17 @@ macro_rules! trait_type_set {
2223
);
2324
}
2425

25-
// REVIEW: print_to_string might be a good candidate to live here?
2626
/// Represents any LLVM type.
2727
pub trait AnyType<'ctx>: AsTypeRef + Debug {
2828
/// Returns an `AnyTypeEnum` that represents the current type.
2929
fn as_any_type_enum(&self) -> AnyTypeEnum<'ctx> {
3030
AnyTypeEnum::new(self.as_type_ref())
3131
}
32+
33+
/// Prints the definition of a Type to a `LLVMString`.
34+
fn print_to_string(&self) -> LLVMString {
35+
Type::new(self.as_type_ref()).print_to_string()
36+
}
3237
}
3338

3439
/// Represents a basic LLVM type, that may be used in functions and struct definitions.

src/types/vec_type.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use llvm_sys::prelude::{LLVMTypeRef, LLVMValueRef};
33

44
use crate::AddressSpace;
55
use crate::context::ContextRef;
6-
use crate::support::LLVMString;
76
use crate::types::{ArrayType, BasicTypeEnum, Type, traits::AsTypeRef, FunctionType, PointerType};
87
use crate::values::{AsValueRef, ArrayValue, BasicValue, VectorValue, IntValue};
98

@@ -127,11 +126,6 @@ impl<'ctx> VectorType<'ctx> {
127126
VectorValue::new(self.vec_type.const_zero())
128127
}
129128

130-
/// Prints the definition of a `VectorType` to a `LLVMString`.
131-
pub fn print_to_string(self) -> LLVMString {
132-
self.vec_type.print_to_string()
133-
}
134-
135129
// See Type::print_to_stderr note on 5.0+ status
136130
/// Prints the definition of an `IntType` to stderr. Not available in newer LLVM versions.
137131
#[llvm_versions(3.7..=4.0)]

src/types/void_type.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use llvm_sys::prelude::LLVMTypeRef;
22

33
use crate::context::ContextRef;
4-
use crate::support::LLVMString;
54
use crate::types::traits::AsTypeRef;
65
use crate::types::{Type, BasicTypeEnum, FunctionType};
76

@@ -71,11 +70,6 @@ impl<'ctx> VoidType<'ctx> {
7170
self.void_type.fn_type(param_types, is_var_args)
7271
}
7372

74-
/// Prints the definition of a `VoidType` to a `LLVMString`.
75-
pub fn print_to_string(self) -> LLVMString {
76-
self.void_type.print_to_string()
77-
}
78-
7973
// See Type::print_to_stderr note on 5.0+ status
8074
/// Prints the definition of a `VoidType` to stderr. Not available in newer LLVM versions.
8175
#[llvm_versions(3.7..=4.0)]

src/values/array_value.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ use llvm_sys::prelude::LLVMValueRef;
44
use std::ffi::CStr;
55
use std::fmt;
66

7-
use crate::support::LLVMString;
87
use crate::types::ArrayType;
9-
use crate::values::traits::AsValueRef;
8+
use crate::values::traits::{AnyValue, AsValueRef};
109
use crate::values::{Value, InstructionValue};
1110

1211
/// An `ArrayValue` is a block of contiguous constants or variables.
@@ -45,11 +44,6 @@ impl<'ctx> ArrayValue<'ctx> {
4544
self.array_value.is_undef()
4645
}
4746

48-
/// Prints this `ArrayValue` to a string.
49-
pub fn print_to_string(self) -> LLVMString {
50-
self.array_value.print_to_string()
51-
}
52-
5347
/// Prints this `ArrayValue` to standard error.
5448
pub fn print_to_stderr(self) {
5549
self.array_value.print_to_stderr()

src/values/float_value.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use llvm_sys::prelude::LLVMValueRef;
44
use std::ffi::CStr;
55

66
use crate::FloatPredicate;
7-
use crate::support::LLVMString;
87
use crate::types::{AsTypeRef, FloatType, IntType};
98
use crate::values::traits::AsValueRef;
109
use crate::values::{InstructionValue, IntValue, Value};
@@ -41,10 +40,6 @@ impl<'ctx> FloatValue<'ctx> {
4140
self.float_value.is_undef()
4241
}
4342

44-
pub fn print_to_string(self) -> LLVMString {
45-
self.float_value.print_to_string()
46-
}
47-
4843
pub fn print_to_stderr(self) {
4944
self.float_value.print_to_stderr()
5045
}

src/values/fn_value.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use crate::basic_block::BasicBlock;
1919
#[llvm_versions(7.0..=latest)]
2020
use crate::debug_info::DISubprogram;
2121
use crate::module::Linkage;
22-
use crate::support::{to_c_str, LLVMString};
23-
use crate::types::{FunctionType, PointerType};
24-
use crate::values::traits::AsValueRef;
22+
use crate::support::to_c_str;
23+
use crate::types::{AnyType, FunctionType, PointerType};
24+
use crate::values::traits::{AnyValue, AsValueRef};
2525
use crate::values::{BasicValueEnum, GlobalValue, Value};
2626

2727
#[derive(PartialEq, Eq, Clone, Copy, Hash)]
@@ -62,10 +62,6 @@ impl<'ctx> FunctionValue<'ctx> {
6262
self.fn_value.is_undef()
6363
}
6464

65-
pub fn print_to_string(self) -> LLVMString {
66-
self.fn_value.print_to_string()
67-
}
68-
6965
pub fn print_to_stderr(self) {
7066
self.fn_value.print_to_stderr()
7167
}

src/values/int_value.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use llvm_sys::prelude::LLVMValueRef;
66
use std::ffi::CStr;
77

88
use crate::IntPredicate;
9-
use crate::support::LLVMString;
109
use crate::types::{AsTypeRef, FloatType, PointerType, IntType};
1110
use crate::values::traits::AsValueRef;
1211
use crate::values::{BasicValue, BasicValueEnum, FloatValue, InstructionValue, PointerValue, Value};
@@ -43,10 +42,6 @@ impl<'ctx> IntValue<'ctx> {
4342
self.int_value.is_undef()
4443
}
4544

46-
pub fn print_to_string(self) -> LLVMString {
47-
self.int_value.print_to_string()
48-
}
49-
5045
pub fn print_to_stderr(self) {
5146
self.int_value.print_to_stderr()
5247
}

src/values/phi_value.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use llvm_sys::prelude::{LLVMBasicBlockRef, LLVMValueRef};
44
use std::ffi::CStr;
55

66
use crate::basic_block::BasicBlock;
7-
use crate::support::LLVMString;
87
use crate::values::traits::AsValueRef;
98
use crate::values::{BasicValue, BasicValueEnum, InstructionValue, Value};
109

@@ -77,14 +76,6 @@ impl<'ctx> PhiValue<'ctx> {
7776
self.phi_value.is_undef()
7877
}
7978

80-
pub fn print_to_string(self) -> LLVMString {
81-
self.phi_value.print_to_string()
82-
}
83-
84-
pub fn print_to_stderr(self) {
85-
self.phi_value.print_to_stderr()
86-
}
87-
8879
// SubType: -> InstructionValue<Phi>
8980
pub fn as_instruction(self) -> InstructionValue<'ctx> {
9081
self.phi_value.as_instruction().expect("PhiValue should always be a Phi InstructionValue")

src/values/ptr_value.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use llvm_sys::prelude::LLVMValueRef;
33

44
use std::ffi::CStr;
55

6-
use crate::support::LLVMString;
76
use crate::types::{AsTypeRef, IntType, PointerType};
87
use crate::values::{AsValueRef, InstructionValue, IntValue, Value};
98

@@ -54,10 +53,6 @@ impl<'ctx> PointerValue<'ctx> {
5453
self.ptr_value.is_const()
5554
}
5655

57-
pub fn print_to_string(self) -> LLVMString {
58-
self.ptr_value.print_to_string()
59-
}
60-
6156
pub fn print_to_stderr(self) {
6257
self.ptr_value.print_to_stderr()
6358
}

src/values/struct_value.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use llvm_sys::prelude::LLVMValueRef;
22

33
use std::ffi::CStr;
44

5-
use crate::support::LLVMString;
65
use crate::types::StructType;
76
use crate::values::traits::AsValueRef;
87
use crate::values::{InstructionValue, Value};
@@ -39,10 +38,6 @@ impl<'ctx> StructValue<'ctx> {
3938
self.struct_value.is_undef()
4039
}
4140

42-
pub fn print_to_string(self) -> LLVMString {
43-
self.struct_value.print_to_string()
44-
}
45-
4641
pub fn print_to_stderr(self) {
4742
self.struct_value.print_to_stderr()
4843
}

src/values/traits.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::fmt::Debug;
55

66
use crate::values::{ArrayValue, AggregateValueEnum, BasicValueUse, CallSiteValue, GlobalValue, StructValue, BasicValueEnum, AnyValueEnum, IntValue, FloatValue, PointerValue, PhiValue, VectorValue, FunctionValue, InstructionValue, Value};
77
use crate::types::{IntMathType, FloatMathType, PointerMathType, IntType, FloatType, PointerType, VectorType};
8+
use crate::support::LLVMString;
89

910
// This is an ugly privacy hack so that Type can stay private to this module
1011
// and so that super traits using this trait will be not be implementable
@@ -121,6 +122,11 @@ pub trait AnyValue<'ctx>: AsValueRef + Debug {
121122
fn as_any_value_enum(&self) -> AnyValueEnum<'ctx> {
122123
AnyValueEnum::new(self.as_value_ref())
123124
}
125+
126+
/// Prints a value to a `LLVMString`
127+
fn print_to_string(&self) -> LLVMString {
128+
Value::new(self.as_value_ref()).print_to_string()
129+
}
124130
}
125131

126132
trait_value_set! {AggregateValue: ArrayValue, AggregateValueEnum, StructValue}

0 commit comments

Comments
 (0)