Skip to content

Commit 8cd0b29

Browse files
committed
Continued replacing enum_rename with llvm_enum
1 parent 3ee0c22 commit 8cd0b29

File tree

6 files changed

+136
-80
lines changed

6 files changed

+136
-80
lines changed

src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ impl Builder {
10201020
let c_string = CString::new(name).expect("Conversion to CString failed unexpectedly");
10211021

10221022
let value = unsafe {
1023-
LLVMBuildICmp(self.builder, op.as_llvm_enum(), lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr())
1023+
LLVMBuildICmp(self.builder, op.into(), lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr())
10241024
};
10251025

10261026
T::new(value)
@@ -1032,7 +1032,7 @@ impl Builder {
10321032
let c_string = CString::new(name).expect("Conversion to CString failed unexpectedly");
10331033

10341034
let value = unsafe {
1035-
LLVMBuildFCmp(self.builder, op.as_llvm_enum(), lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr())
1035+
LLVMBuildFCmp(self.builder, op.into(), lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr())
10361036
};
10371037

10381038
<<T::BaseType as FloatMathType>::MathConvType as IntMathType>::ValueType::new(value)

src/lib.rs

Lines changed: 113 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -98,78 +98,128 @@ impl TryFrom<u32> for AddressSpace {
9898
match val {
9999
0 => Ok(AddressSpace::Generic),
100100
1 => Ok(AddressSpace::Global),
101-
2 => Ok(AddressSpace::Shared),
102-
3 => Ok(AddressSpace::Const),
103-
4 => Ok(AddressSpace::Local),
101+
3 => Ok(AddressSpace::Shared),
102+
4 => Ok(AddressSpace::Const),
103+
5 => Ok(AddressSpace::Local),
104104
_ => Err(()),
105105
}
106106
}
107107
}
108108

109109
// REVIEW: Maybe this belongs in some sort of prelude?
110-
enum_rename!{
111-
/// This enum defines how to compare a `left` and `right` `IntValue`.
112-
IntPredicate <=> LLVMIntPredicate {
113-
/// Equal
114-
EQ <=> LLVMIntEQ,
115-
/// Not Equal
116-
NE <=> LLVMIntNE,
117-
/// Unsigned Greater Than
118-
UGT <=> LLVMIntUGT,
119-
/// Unsigned Greater Than or Equal
120-
UGE <=> LLVMIntUGE,
121-
/// Unsigned Less Than
122-
ULT <=> LLVMIntULT,
123-
/// Unsigned Less Than or Equal
124-
ULE <=> LLVMIntULE,
125-
/// Signed Greater Than
126-
SGT <=> LLVMIntSGT,
127-
/// Signed Greater Than or Equal
128-
SGE <=> LLVMIntSGE,
129-
/// Signed Less Than
130-
SLT <=> LLVMIntSLT,
131-
/// Signed Less Than or Equal
132-
SLE <=> LLVMIntSLE,
133-
}
110+
/// This enum defines how to compare a `left` and `right` `IntValue`.
111+
#[llvm_enum(LLVMIntPredicate)]
112+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
113+
pub enum IntPredicate {
114+
/// Equal
115+
#[llvm_variant(LLVMIntEQ)]
116+
EQ,
117+
118+
/// Not Equal
119+
#[llvm_variant(LLVMIntNE)]
120+
NE,
121+
122+
/// Unsigned Greater Than
123+
#[llvm_variant(LLVMIntUGT)]
124+
UGT,
125+
126+
/// Unsigned Greater Than or Equal
127+
#[llvm_variant(LLVMIntUGE)]
128+
UGE,
129+
130+
/// Unsigned Less Than
131+
#[llvm_variant(LLVMIntULT)]
132+
ULT,
133+
134+
/// Unsigned Less Than or Equal
135+
#[llvm_variant(LLVMIntULE)]
136+
ULE,
137+
138+
/// Signed Greater Than
139+
#[llvm_variant(LLVMIntSGT)]
140+
SGT,
141+
142+
/// Signed Greater Than or Equal
143+
#[llvm_variant(LLVMIntSGE)]
144+
SGE,
145+
146+
/// Signed Less Than
147+
#[llvm_variant(LLVMIntSLT)]
148+
SLT,
149+
150+
/// Signed Less Than or Equal
151+
#[llvm_variant(LLVMIntSLE)]
152+
SLE,
134153
}
135154

136155
// REVIEW: Maybe this belongs in some sort of prelude?
137-
enum_rename!{
138-
/// Defines how to compare a `left` and `right` `FloatValue`.
139-
FloatPredicate <=> LLVMRealPredicate {
140-
/// Returns true if `left` == `right` and neither are NaN
141-
OEQ <=> LLVMRealOEQ,
142-
/// Returns true if `left` >= `right` and neither are NaN
143-
OGE <=> LLVMRealOGE,
144-
/// Returns true if `left` > `right` and neither are NaN
145-
OGT <=> LLVMRealOGT,
146-
/// Returns true if `left` <= `right` and neither are NaN
147-
OLE <=> LLVMRealOLE,
148-
/// Returns true if `left` < `right` and neither are NaN
149-
OLT <=> LLVMRealOLT,
150-
/// Returns true if `left` != `right` and neither are NaN
151-
ONE <=> LLVMRealONE,
152-
/// Returns true if neither value is NaN
153-
ORD <=> LLVMRealORD,
154-
/// Always returns false
155-
PredicateFalse <=> LLVMRealPredicateFalse,
156-
/// Always returns true
157-
PredicateTrue <=> LLVMRealPredicateTrue,
158-
/// Returns true if `left` == `right` or either is NaN
159-
UEQ <=> LLVMRealUEQ,
160-
/// Returns true if `left` >= `right` or either is NaN
161-
UGE <=> LLVMRealUGE,
162-
/// Returns true if `left` > `right` or either is NaN
163-
UGT <=> LLVMRealUGT,
164-
/// Returns true if `left` <= `right` or either is NaN
165-
ULE <=> LLVMRealULE,
166-
/// Returns true if `left` < `right` or either is NaN
167-
ULT <=> LLVMRealULT,
168-
/// Returns true if `left` != `right` or either is NaN
169-
UNE <=> LLVMRealUNE,
170-
/// Returns true if either value is NaN
171-
UNO <=> LLVMRealUNO,
172-
}
156+
/// Defines how to compare a `left` and `right` `FloatValue`.
157+
#[llvm_enum(LLVMRealPredicate)]
158+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
159+
pub enum FloatPredicate {
160+
/// Returns true if `left` == `right` and neither are NaN
161+
#[llvm_variant(LLVMRealOEQ)]
162+
OEQ,
163+
164+
/// Returns true if `left` >= `right` and neither are NaN
165+
#[llvm_variant(LLVMRealOGE)]
166+
OGE,
167+
168+
/// Returns true if `left` > `right` and neither are NaN
169+
#[llvm_variant(LLVMRealOGT)]
170+
OGT,
171+
172+
/// Returns true if `left` <= `right` and neither are NaN
173+
#[llvm_variant(LLVMRealOLE)]
174+
OLE,
175+
176+
/// Returns true if `left` < `right` and neither are NaN
177+
#[llvm_variant(LLVMRealOLT)]
178+
OLT,
179+
180+
/// Returns true if `left` != `right` and neither are NaN
181+
#[llvm_variant(LLVMRealONE)]
182+
ONE,
183+
184+
/// Returns true if neither value is NaN
185+
#[llvm_variant(LLVMRealORD)]
186+
ORD,
187+
188+
/// Always returns false
189+
#[llvm_variant(LLVMRealPredicateFalse)]
190+
PredicateFalse,
191+
192+
/// Always returns true
193+
#[llvm_variant(LLVMRealPredicateTrue)]
194+
PredicateTrue,
195+
196+
/// Returns true if `left` == `right` or either is NaN
197+
#[llvm_variant(LLVMRealUEQ)]
198+
UEQ,
199+
200+
/// Returns true if `left` >= `right` or either is NaN
201+
#[llvm_variant(LLVMRealUGE)]
202+
UGE,
203+
204+
/// Returns true if `left` > `right` or either is NaN
205+
#[llvm_variant(LLVMRealUGT)]
206+
UGT,
207+
208+
/// Returns true if `left` <= `right` or either is NaN
209+
#[llvm_variant(LLVMRealULE)]
210+
ULE,
211+
212+
/// Returns true if `left` < `right` or either is NaN
213+
#[llvm_variant(LLVMRealULT)]
214+
ULT,
215+
216+
/// Returns true if `left` != `right` or either is NaN
217+
#[llvm_variant(LLVMRealUNE)]
218+
UNE,
219+
220+
/// Returns true if either value is NaN
221+
#[llvm_variant(LLVMRealUNO)]
222+
UNO,
173223
}
174224

175225
// REVIEW: Maybe this belongs in some sort of prelude?

src/support/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ pub fn enable_llvm_pretty_stack_trace() {
154154
}
155155
}
156156

157+
// DEPRECATED: Use llvm_enum attr instead
157158
macro_rules! enum_rename {
158159
($(#[$enum_attrs:meta])* $enum_name:ident <=> $llvm_enum_name:ident {
159160
$($(#[$variant_attrs:meta])* $args:ident <=> $llvm_args:ident,)+

src/values/float_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl FloatValue {
158158
// SubType: rhs same as lhs; return IntValue<bool>
159159
pub fn const_compare(&self, op: FloatPredicate, rhs: FloatValue) -> IntValue {
160160
let value = unsafe {
161-
LLVMConstFCmp(op.as_llvm_enum(), self.as_value_ref(), rhs.as_value_ref())
161+
LLVMConstFCmp(op.into(), self.as_value_ref(), rhs.as_value_ref())
162162
};
163163

164164
IntValue::new(value)

src/values/global_value.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ impl GlobalValue {
181181
pub fn set_unnamed_addr(&self, has_unnamed_addr: bool) {
182182
unsafe {
183183
if has_unnamed_addr {
184-
LLVMSetUnnamedAddress(self.as_value_ref(), UnnamedAddress::Global.as_llvm_enum())
184+
LLVMSetUnnamedAddress(self.as_value_ref(), UnnamedAddress::Global.into())
185185
} else {
186-
LLVMSetUnnamedAddress(self.as_value_ref(), UnnamedAddress::None.as_llvm_enum())
186+
LLVMSetUnnamedAddress(self.as_value_ref(), UnnamedAddress::None.into())
187187
}
188188
}
189189
}
@@ -302,7 +302,7 @@ impl GlobalValue {
302302
use llvm_sys::core::LLVMSetUnnamedAddress;
303303

304304
unsafe {
305-
LLVMSetUnnamedAddress(self.as_value_ref(), address.as_llvm_enum())
305+
LLVMSetUnnamedAddress(self.as_value_ref(), address.into())
306306
}
307307
}
308308

@@ -331,15 +331,20 @@ impl AsValueRef for GlobalValue {
331331
}
332332
}
333333

334+
/// This enum determines the significance of a `GlobalValue`'s address.
334335
#[llvm_versions(7.0..=latest)]
335-
enum_rename! {
336-
/// This enum determines the significance of a `GlobalValue`'s address.
337-
UnnamedAddress <=> LLVMUnnamedAddr {
338-
/// Address of the `GlobalValue` is significant.
339-
None <=> LLVMNoUnnamedAddr,
340-
/// Address of the `GlobalValue` is locally insignificant.
341-
Local <=> LLVMLocalUnnamedAddr,
342-
/// Address of the `GlobalValue` is globally insignificant.
343-
Global <=> LLVMGlobalUnnamedAddr,
344-
}
336+
#[llvm_enum(LLVMUnnamedAddr)]
337+
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
338+
pub enum UnnamedAddress {
339+
/// Address of the `GlobalValue` is significant.
340+
#[llvm_variant(LLVMNoUnnamedAddr)]
341+
None,
342+
343+
/// Address of the `GlobalValue` is locally insignificant.
344+
#[llvm_variant(LLVMLocalUnnamedAddr)]
345+
Local,
346+
347+
/// Address of the `GlobalValue` is globally insignificant.
348+
#[llvm_variant(LLVMGlobalUnnamedAddr)]
349+
Global,
345350
}

src/values/int_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl IntValue {
370370
// SubType: rhs same as lhs; return IntValue<bool>
371371
pub fn const_int_compare(&self, op: IntPredicate, rhs: IntValue) -> IntValue {
372372
let value = unsafe {
373-
LLVMConstICmp(op.as_llvm_enum(), self.as_value_ref(), rhs.as_value_ref())
373+
LLVMConstICmp(op.into(), self.as_value_ref(), rhs.as_value_ref())
374374
};
375375

376376
IntValue::new(value)

0 commit comments

Comments
 (0)