Skip to content

Commit e54be0d

Browse files
committed
Added LLVM 7 COMDAT & additional pass support
Also cleaned up common pattern of redefining a llvm_sys enum to rustify names
1 parent 8e0ddaf commit e54be0d

File tree

14 files changed

+307
-289
lines changed

14 files changed

+307
-289
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ llvm7-0 = []
2424
[dependencies]
2525
either = "1.5"
2626
enum-methods = "0.0.8"
27+
inkwell_internal_macros = { path = "./internal_macros", version = "0.1.0" }
2728
libc = "0.2"
2829
llvm-sys = "70.0"
29-
inkwell_internal_macros = { path = "./internal_macros", version = "0.1.0" }
3030

3131
[badges]
3232
travis-ci = { repository = "TheDan64/inkwell" }

src/builder.rs

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

814814
let value = unsafe {
815-
LLVMBuildICmp(self.builder, op.as_llvm_predicate(), lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr())
815+
LLVMBuildICmp(self.builder, op.as_llvm_enum(), lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr())
816816
};
817817

818818
T::new(value)
@@ -824,7 +824,7 @@ impl Builder {
824824
let c_string = CString::new(name).expect("Conversion to CString failed unexpectedly");
825825

826826
let value = unsafe {
827-
LLVMBuildFCmp(self.builder, op.as_llvm_predicate(), lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr())
827+
LLVMBuildFCmp(self.builder, op.as_llvm_enum(), lhs.as_value_ref(), rhs.as_value_ref(), c_string.as_ptr())
828828
};
829829

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

src/lib.rs

Lines changed: 76 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ extern crate llvm_sys;
1717
#[macro_use]
1818
extern crate inkwell_internal_macros;
1919

20+
#[macro_use]
21+
pub mod support;
2022
#[deny(missing_docs)]
2123
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7", feature = "llvm3-8")))]
2224
pub mod attributes;
2325
#[deny(missing_docs)]
26+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7", feature = "llvm3-8", feature = "llvm3-9",
27+
feature = "llvm4-0", feature = "llvm5-0", feature = "llvm6-0")))]
28+
pub mod comdat;
29+
#[deny(missing_docs)]
2430
pub mod basic_block;
2531
pub mod builder;
2632
#[deny(missing_docs)]
@@ -32,7 +38,6 @@ pub mod memory_buffer;
3238
pub mod module;
3339
pub mod object_file;
3440
pub mod passes;
35-
pub mod support;
3641
pub mod targets;
3742
pub mod types;
3843
pub mod values;
@@ -98,110 +103,71 @@ impl From<u32> for AddressSpace {
98103
}
99104

100105
// REVIEW: Maybe this belongs in some sort of prelude?
101-
/// This enum defines how to compare a `left` and `right` `IntValue`.
102-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
103-
pub enum IntPredicate {
104-
/// Equal
105-
EQ,
106-
/// Not Equal
107-
NE,
108-
/// Unsigned Greater Than
109-
UGT,
110-
/// Unsigned Greater Than or Equal
111-
UGE,
112-
/// Unsigned Less Than
113-
ULT,
114-
/// Unsigned Less Than or Equal
115-
ULE,
116-
/// Signed Greater Than
117-
SGT,
118-
/// Signed Greater Than or Equal
119-
SGE,
120-
/// Signed Less Than
121-
SLT,
122-
/// Signed Less Than or Equal
123-
SLE,
124-
}
125-
126-
impl IntPredicate {
127-
pub(crate) fn as_llvm_predicate(&self) -> LLVMIntPredicate {
128-
match *self {
129-
IntPredicate::EQ => LLVMIntPredicate::LLVMIntEQ,
130-
IntPredicate::NE => LLVMIntPredicate::LLVMIntNE,
131-
IntPredicate::UGT => LLVMIntPredicate::LLVMIntUGT,
132-
IntPredicate::UGE => LLVMIntPredicate::LLVMIntUGE,
133-
IntPredicate::ULT => LLVMIntPredicate::LLVMIntULT,
134-
IntPredicate::ULE => LLVMIntPredicate::LLVMIntULE,
135-
IntPredicate::SGT => LLVMIntPredicate::LLVMIntSGT,
136-
IntPredicate::SGE => LLVMIntPredicate::LLVMIntSGE,
137-
IntPredicate::SLT => LLVMIntPredicate::LLVMIntSLT,
138-
IntPredicate::SLE => LLVMIntPredicate::LLVMIntSLE,
139-
}
106+
enum_rename!{
107+
/// This enum defines how to compare a `left` and `right` `IntValue`.
108+
IntPredicate <=> LLVMIntPredicate {
109+
/// Equal
110+
EQ <=> LLVMIntEQ,
111+
/// Not Equal
112+
NE <=> LLVMIntNE,
113+
/// Unsigned Greater Than
114+
UGT <=> LLVMIntUGT,
115+
/// Unsigned Greater Than or Equal
116+
UGE <=> LLVMIntUGE,
117+
/// Unsigned Less Than
118+
ULT <=> LLVMIntULT,
119+
/// Unsigned Less Than or Equal
120+
ULE <=> LLVMIntULE,
121+
/// Signed Greater Than
122+
SGT <=> LLVMIntSGT,
123+
/// Signed Greater Than or Equal
124+
SGE <=> LLVMIntSGE,
125+
/// Signed Less Than
126+
SLT <=> LLVMIntSLT,
127+
/// Signed Less Than or Equal
128+
SLE <=> LLVMIntSLE,
140129
}
141130
}
142131

143132
// REVIEW: Maybe this belongs in some sort of prelude?
144-
/// Defines how to compare a `left` and `right` `FloatValue`.
145-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
146-
pub enum FloatPredicate {
147-
/// Returns true if `left` == `right` and neither are NaN
148-
OEQ,
149-
/// Returns true if `left` >= `right` and neither are NaN
150-
OGE,
151-
/// Returns true if `left` > `right` and neither are NaN
152-
OGT,
153-
/// Returns true if `left` <= `right` and neither are NaN
154-
OLE,
155-
/// Returns true if `left` < `right` and neither are NaN
156-
OLT,
157-
/// Returns true if `left` != `right` and neither are NaN
158-
ONE,
159-
/// Returns true if neither value is NaN
160-
ORD,
161-
/// Always returns false
162-
PredicateFalse,
163-
/// Always returns true
164-
PredicateTrue,
165-
/// Returns true if `left` == `right` or either is NaN
166-
UEQ,
167-
/// Returns true if `left` >= `right` or either is NaN
168-
UGE,
169-
/// Returns true if `left` > `right` or either is NaN
170-
UGT,
171-
/// Returns true if `left` <= `right` or either is NaN
172-
ULE,
173-
/// Returns true if `left` < `right` or either is NaN
174-
ULT,
175-
/// Returns true if `left` != `right` or either is NaN
176-
UNE,
177-
/// Returns true if either value is NaN
178-
UNO,
179-
}
180-
181-
impl FloatPredicate {
182-
pub(crate) fn as_llvm_predicate(&self) -> LLVMRealPredicate {
183-
match *self {
184-
FloatPredicate::PredicateFalse => LLVMRealPredicate::LLVMRealPredicateFalse,
185-
FloatPredicate::OEQ => LLVMRealPredicate::LLVMRealOEQ,
186-
FloatPredicate::OGT => LLVMRealPredicate::LLVMRealOGT,
187-
FloatPredicate::OGE => LLVMRealPredicate::LLVMRealOGE,
188-
FloatPredicate::OLT => LLVMRealPredicate::LLVMRealOLT,
189-
FloatPredicate::OLE => LLVMRealPredicate::LLVMRealOLE,
190-
FloatPredicate::ONE => LLVMRealPredicate::LLVMRealONE,
191-
FloatPredicate::ORD => LLVMRealPredicate::LLVMRealORD,
192-
FloatPredicate::UNO => LLVMRealPredicate::LLVMRealUNO,
193-
FloatPredicate::UEQ => LLVMRealPredicate::LLVMRealUEQ,
194-
FloatPredicate::UGT => LLVMRealPredicate::LLVMRealUGT,
195-
FloatPredicate::UGE => LLVMRealPredicate::LLVMRealUGE,
196-
FloatPredicate::ULT => LLVMRealPredicate::LLVMRealULT,
197-
FloatPredicate::ULE => LLVMRealPredicate::LLVMRealULE,
198-
FloatPredicate::UNE => LLVMRealPredicate::LLVMRealUNE,
199-
FloatPredicate::PredicateTrue => LLVMRealPredicate::LLVMRealPredicateTrue,
200-
}
133+
enum_rename!{
134+
/// Defines how to compare a `left` and `right` `FloatValue`.
135+
FloatPredicate <=> LLVMRealPredicate {
136+
/// Returns true if `left` == `right` and neither are NaN
137+
OEQ <=> LLVMRealOEQ,
138+
/// Returns true if `left` >= `right` and neither are NaN
139+
OGE <=> LLVMRealOGE,
140+
/// Returns true if `left` > `right` and neither are NaN
141+
OGT <=> LLVMRealOGT,
142+
/// Returns true if `left` <= `right` and neither are NaN
143+
OLE <=> LLVMRealOLE,
144+
/// Returns true if `left` < `right` and neither are NaN
145+
OLT <=> LLVMRealOLT,
146+
/// Returns true if `left` != `right` and neither are NaN
147+
ONE <=> LLVMRealONE,
148+
/// Returns true if neither value is NaN
149+
ORD <=> LLVMRealORD,
150+
/// Always returns false
151+
PredicateFalse <=> LLVMRealPredicateFalse,
152+
/// Always returns true
153+
PredicateTrue <=> LLVMRealPredicateTrue,
154+
/// Returns true if `left` == `right` or either is NaN
155+
UEQ <=> LLVMRealUEQ,
156+
/// Returns true if `left` >= `right` or either is NaN
157+
UGE <=> LLVMRealUGE,
158+
/// Returns true if `left` > `right` or either is NaN
159+
UGT <=> LLVMRealUGT,
160+
/// Returns true if `left` <= `right` or either is NaN
161+
ULE <=> LLVMRealULE,
162+
/// Returns true if `left` < `right` or either is NaN
163+
ULT <=> LLVMRealULT,
164+
/// Returns true if `left` != `right` or either is NaN
165+
UNE <=> LLVMRealUNE,
166+
/// Returns true if either value is NaN
167+
UNO <=> LLVMRealUNO,
201168
}
202169
}
203170

204-
205171
/// Defines the optimization level used to compile a `Module`.
206172
///
207173
/// # Remarks
@@ -222,12 +188,12 @@ impl Default for OptimizationLevel {
222188
}
223189
}
224190

225-
// REVIEW: Maybe this belongs in some sort of prelude?
226-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
227-
pub enum GlobalVisibility {
228-
Default,
229-
Hidden,
230-
Protected,
191+
enum_rename!{
192+
GlobalVisibility <=> LLVMVisibility {
193+
Default <=> LLVMDefaultVisibility,
194+
Hidden <=> LLVMHiddenVisibility,
195+
Protected <=> LLVMProtectedVisibility,
196+
}
231197
}
232198

233199
impl Default for GlobalVisibility {
@@ -237,24 +203,6 @@ impl Default for GlobalVisibility {
237203
}
238204
}
239205

240-
impl GlobalVisibility {
241-
pub(crate) fn new(visibility: LLVMVisibility) -> Self {
242-
match visibility {
243-
LLVMVisibility::LLVMDefaultVisibility => GlobalVisibility::Default,
244-
LLVMVisibility::LLVMHiddenVisibility => GlobalVisibility::Hidden,
245-
LLVMVisibility::LLVMProtectedVisibility => GlobalVisibility::Protected,
246-
}
247-
}
248-
249-
pub(crate) fn as_llvm_visibility(&self) -> LLVMVisibility {
250-
match *self {
251-
GlobalVisibility::Default => LLVMVisibility::LLVMDefaultVisibility,
252-
GlobalVisibility::Hidden => LLVMVisibility::LLVMHiddenVisibility,
253-
GlobalVisibility::Protected => LLVMVisibility::LLVMProtectedVisibility,
254-
}
255-
}
256-
}
257-
258206
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
259207
pub enum ThreadLocalMode {
260208
GeneralDynamicTLSModel,
@@ -285,11 +233,12 @@ impl ThreadLocalMode {
285233
}
286234
}
287235

288-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
289-
pub enum DLLStorageClass {
290-
Default,
291-
Import,
292-
Export,
236+
enum_rename! {
237+
DLLStorageClass <=> LLVMDLLStorageClass {
238+
Default <=> LLVMDefaultStorageClass,
239+
Import <=> LLVMDLLImportStorageClass,
240+
Export <=> LLVMDLLExportStorageClass,
241+
}
293242
}
294243

295244
impl Default for DLLStorageClass {
@@ -298,21 +247,3 @@ impl Default for DLLStorageClass {
298247
DLLStorageClass::Default
299248
}
300249
}
301-
302-
impl DLLStorageClass {
303-
pub(crate) fn new(dll_storage_class: LLVMDLLStorageClass) -> Self {
304-
match dll_storage_class {
305-
LLVMDLLStorageClass::LLVMDefaultStorageClass => DLLStorageClass::Default,
306-
LLVMDLLStorageClass::LLVMDLLImportStorageClass => DLLStorageClass::Import,
307-
LLVMDLLStorageClass::LLVMDLLExportStorageClass => DLLStorageClass::Export,
308-
}
309-
}
310-
311-
pub(crate) fn as_llvm_class(&self) -> LLVMDLLStorageClass {
312-
match *self {
313-
DLLStorageClass::Default => LLVMDLLStorageClass::LLVMDefaultStorageClass,
314-
DLLStorageClass::Import => LLVMDLLStorageClass::LLVMDLLImportStorageClass,
315-
DLLStorageClass::Export => LLVMDLLStorageClass::LLVMDLLExportStorageClass,
316-
}
317-
}
318-
}

0 commit comments

Comments
 (0)