Skip to content

Commit 8be883e

Browse files
committed
First pass at (incomplete) LLVM 3.8 support
1 parent e3a6f54 commit 8be883e

File tree

8 files changed

+66
-23
lines changed

8 files changed

+66
-23
lines changed

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ matrix:
5555
packages:
5656
- *BASE_PACKAGES
5757
- llvm-3.7-dev
58+
- env:
59+
- LLVM_VERSION="3.8"
60+
<<: *BASE
61+
addons:
62+
apt:
63+
sources:
64+
- *BASE_SOURCES
65+
- llvm-toolchain-precise-3.8
66+
packages:
67+
- *BASE_PACKAGES
68+
- llvm-3.8-dev
5869
- deploy: # Documentation build; Only latest supported LLVM version for now
5970
provider: pages
6071
skip-cleanup: true

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ categories = ["development-tools::ffi"]
1414
default = []
1515
llvm3-6 = []
1616
llvm3-7 = []
17+
llvm3-8 = []
1718

1819
[dependencies]
1920
either = "1.4.0"
2021
enum-methods = "0.0.8"
2122
libc = "*"
22-
llvm-sys = "37"
23+
llvm-sys = "38"
2324

2425
[[example]]
2526
name = "kaleidoscope"

src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ pub mod types;
2020
pub mod values;
2121

2222
use llvm_sys::{LLVMIntPredicate, LLVMRealPredicate, LLVMVisibility, LLVMThreadLocalMode, LLVMDLLStorageClass};
23-
use llvm_sys::core::LLVMResetFatalErrorHandler;
2423
use llvm_sys::support::LLVMLoadLibraryPermanently;
2524

2625
use std::ffi::CString;
2726

28-
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
27+
28+
29+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7", feature = "llvm3-8")))]
2930
compile_error!("A LLVM feature flag must be provided. See the README for more details.");
3031

3132
// TODO: Probably move into error handling module
3233
pub fn enable_llvm_pretty_stack_trace() {
33-
// use llvm_sys::error_handling::LLVMEnablePrettyStackTrace; // v3.8
34+
#[cfg(any(feature = "llvm3-6", feature = "llvm3-7"))]
3435
use llvm_sys::core::LLVMEnablePrettyStackTrace;
36+
#[cfg(feature = "llvm3-8")]
37+
use llvm_sys::error_handling::LLVMEnablePrettyStackTrace;
3538

3639
unsafe {
3740
LLVMEnablePrettyStackTrace()
@@ -88,6 +91,11 @@ pub fn shutdown_llvm() {
8891

8992
/// Resets LLVM's fatal error handler back to the default
9093
pub fn reset_fatal_error_handler() {
94+
#[cfg(any(feature = "llvm3-6", feature = "llvm3-7"))]
95+
use llvm_sys::core::LLVMResetFatalErrorHandler;
96+
#[cfg(feature = "llvm3-8")]
97+
use llvm_sys::error_handling::LLVMResetFatalErrorHandler;
98+
9199
unsafe {
92100
LLVMResetFatalErrorHandler()
93101
}

src/types/enums.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ impl AnyTypeEnum {
6161
LLVMTypeKind::LLVMVectorTypeKind => AnyTypeEnum::VectorType(VectorType::new(type_)),
6262
LLVMTypeKind::LLVMMetadataTypeKind => panic!("FIXME: Unsupported type: Metadata"),
6363
LLVMTypeKind::LLVMX86_MMXTypeKind => panic!("FIXME: Unsupported type: MMX"),
64-
// LLVMTypeKind::LLVMTokenTypeKind => panic!("FIXME: Unsupported type: Token"), // Different version?
64+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
65+
LLVMTypeKind::LLVMTokenTypeKind => panic!("FIXME: Unsupported type: Token"),
6566
}
6667
}
6768
}
@@ -89,6 +90,8 @@ impl BasicTypeEnum {
8990
LLVMTypeKind::LLVMLabelTypeKind => unreachable!("Unsupported type: Label"),
9091
LLVMTypeKind::LLVMVoidTypeKind => unreachable!("Unsupported type: VoidType"),
9192
LLVMTypeKind::LLVMFunctionTypeKind => unreachable!("Unsupported type: FunctionType"),
93+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
94+
LLVMTypeKind::LLVMTokenTypeKind => panic!("FIXME: Unsupported type: Token"),
9295
}
9396
}
9497
}

src/values/instruction_value.rs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ pub enum InstructionOpcode {
2222
BitCast,
2323
Br,
2424
Call,
25-
// Later versions:
26-
// CatchPad,
27-
// CatchRet,
28-
// CatchSwitch,
29-
// CleanupPad,
30-
// CleanupRet,
25+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
26+
CatchPad,
27+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
28+
CatchRet,
29+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
30+
CatchSwitch,
31+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
32+
CleanupPad,
33+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
34+
CleanupRet,
3135
ExtractElement,
3236
ExtractValue,
3337
FAdd,
@@ -92,12 +96,16 @@ impl InstructionOpcode {
9296
LLVMOpcode::LLVMBitCast => InstructionOpcode::BitCast,
9397
LLVMOpcode::LLVMBr => InstructionOpcode::Br,
9498
LLVMOpcode::LLVMCall => InstructionOpcode::Call,
95-
// Newer versions:
96-
// LLVMOpcode::LLVMCatchPad => InstructionOpcode::CatchPad,
97-
// LLVMOpcode::LLVMCatchRet => InstructionOpcode::CatchRet,
98-
// LLVMOpcode::LLVMCatchSwitch => InstructionOpcode::CatchSwitch,
99-
// LLVMOpcode::LLVMCleanupPad => InstructionOpcode::CleanupPad,
100-
// LLVMOpcode::LLVMCleanupRet => InstructionOpcode::CleanupRet,
99+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
100+
LLVMOpcode::LLVMCatchPad => InstructionOpcode::CatchPad,
101+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
102+
LLVMOpcode::LLVMCatchRet => InstructionOpcode::CatchRet,
103+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
104+
LLVMOpcode::LLVMCatchSwitch => InstructionOpcode::CatchSwitch,
105+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
106+
LLVMOpcode::LLVMCleanupPad => InstructionOpcode::CleanupPad,
107+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
108+
LLVMOpcode::LLVMCleanupRet => InstructionOpcode::CleanupRet,
101109
LLVMOpcode::LLVMExtractElement => InstructionOpcode::ExtractElement,
102110
LLVMOpcode::LLVMExtractValue => InstructionOpcode::ExtractValue,
103111
LLVMOpcode::LLVMFAdd => InstructionOpcode::FAdd,
@@ -162,12 +170,16 @@ impl InstructionOpcode {
162170
InstructionOpcode::BitCast => LLVMOpcode::LLVMBitCast,
163171
InstructionOpcode::Br => LLVMOpcode::LLVMBr,
164172
InstructionOpcode::Call => LLVMOpcode::LLVMCall,
165-
// Newer versions:
166-
// InstructionOpcode::CatchPad => LLVMOpcode::LLVMCatchPad,
167-
// InstructionOpcode::CatchRet => LLVMOpcode::LLVMCatchRet,
168-
// InstructionOpcode::CatchSwitch => LLVMOpcode::LLVMCatchSwitch,
169-
// InstructionOpcode::CleanupPad => LLVMOpcode::LLVMCleanupPad,
170-
// InstructionOpcode::CleanupRet => LLVMOpcode::LLVMCleanupRet,
173+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
174+
InstructionOpcode::CatchPad => LLVMOpcode::LLVMCatchPad,
175+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
176+
InstructionOpcode::CatchRet => LLVMOpcode::LLVMCatchRet,
177+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
178+
InstructionOpcode::CatchSwitch => LLVMOpcode::LLVMCatchSwitch,
179+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
180+
InstructionOpcode::CleanupPad => LLVMOpcode::LLVMCleanupPad,
181+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
182+
InstructionOpcode::CleanupRet => LLVMOpcode::LLVMCleanupRet,
171183
InstructionOpcode::ExtractElement => LLVMOpcode::LLVMExtractElement,
172184
InstructionOpcode::ExtractValue => LLVMOpcode::LLVMExtractValue,
173185
InstructionOpcode::FAdd => LLVMOpcode::LLVMFAdd,

src/values/metadata_value.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use std::slice::from_raw_parts;
1414
pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 12;
1515
#[cfg(feature = "llvm3-7")]
1616
pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 14;
17+
#[cfg(feature = "llvm3-8")]
18+
pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 20; // FIXME
1719

1820
#[derive(PartialEq, Eq, Clone, Copy)]
1921
pub struct MetadataValue {

tests/test_builder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,10 @@ fn test_no_builder_double_free2() {
440440
builder.position_at_end(&entry);
441441
builder.build_unreachable();
442442

443+
#[cfg(any(feature = "llvm3-6", feature = "llvm3-7"))]
443444
assert_eq!(module.print_to_string(), &*CString::new("; ModuleID = \'my_mod\'\n\ndefine void @my_fn() {\nentry:\n unreachable\n}\n").unwrap());
445+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
446+
assert_eq!(module.print_to_string(), &*CString::new("; ModuleID = \'my_mod\'\nsource_filename = \"my_mod\"\n\ndefine void @my_fn() {\nentry:\n unreachable\n}\n").unwrap());
444447

445448
// 2nd Context drops fine
446449
// Builds drops fine

tests/test_execution_engine.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ use self::inkwell::OptimizationLevel;
44
use self::inkwell::context::Context;
55
use self::inkwell::execution_engine::FunctionLookupError;
66
use self::inkwell::targets::{InitializationConfig, Target};
7+
use self::inkwell::enable_llvm_pretty_stack_trace;
78

89
#[test]
910
fn test_get_function_address() {
11+
enable_llvm_pretty_stack_trace();
12+
1013
let context = Context::create();
1114
// let module = context.create_module("errors_abound");
1215
let builder = context.create_builder();

0 commit comments

Comments
 (0)