Skip to content

Commit 782f217

Browse files
authored
Merge pull request rust-lang#38 from TheDan64/three_eight
Support LLVM 3.8
2 parents e3a6f54 + cb6f413 commit 782f217

12 files changed

+102
-55
lines changed

.cargo/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
rustflags = ["-lffi"]

.travis.yml

Lines changed: 17 additions & 4 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
@@ -64,7 +75,7 @@ matrix:
6475
on:
6576
branch: master
6677
script:
67-
- cargo doc --no-default-features --features llvm3-7
78+
- cargo doc --no-default-features --features llvm3-8
6879
- echo '<meta http-equiv="refresh" content="1; url=inkwell/index.html">' > target/doc/index.html
6980
after_success:
7081
rust: nightly
@@ -73,15 +84,17 @@ matrix:
7384
sources:
7485
- *BASE_SOURCES
7586
# - llvm-toolchain-precise-3.6
76-
- llvm-toolchain-precise-3.7
87+
# - llvm-toolchain-precise-3.7
88+
- llvm-toolchain-precise-3.8
7789
packages:
7890
- *BASE_PACKAGES
7991
# - llvm-3.6-dev
80-
- llvm-3.7-dev
92+
# - llvm-3.7-dev
93+
- llvm-3.8-dev
8194

8295
env:
8396
global:
84-
- RUSTFLAGS="-C link-dead-code -C target-cpu=native"
97+
- RUSTFLAGS="-C link-dead-code -C target-cpu=native -l ffi"
8598

8699
after_success: |
87100
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&

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"

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Inkwell aims to help you pen your own programming languages by safely wrapping l
1414

1515
* Any Rust version released in the last year or so
1616
* Rust Stable, Beta, or Nightly
17-
* LLVM 3.6 or 3.7 (3.8+ support is planned: [#1](https://github.com/TheDan64/inkwell/issues/1))
17+
* LLVM 3.6, 3.7, or 3.8 (3.9+ support is planned: [#1](https://github.com/TheDan64/inkwell/issues/1))
1818

1919
## Usage
2020

@@ -31,6 +31,7 @@ Supported versions:
3131
| :-----------: | :----------: |
3232
| llvm3-6 | llvm3-6 |
3333
| llvm3-7 | llvm3-7 |
34+
| llvm3-8 | llvm3-8 |
3435

3536
In the root of your source code you will have to add an extern crate to begin using Inkwell:
3637

src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@ 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+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7", feature = "llvm3-8")))]
2928
compile_error!("A LLVM feature flag must be provided. See the README for more details.");
3029

3130
// TODO: Probably move into error handling module
3231
pub fn enable_llvm_pretty_stack_trace() {
33-
// use llvm_sys::error_handling::LLVMEnablePrettyStackTrace; // v3.8
32+
#[cfg(any(feature = "llvm3-6", feature = "llvm3-7"))]
3433
use llvm_sys::core::LLVMEnablePrettyStackTrace;
34+
#[cfg(feature = "llvm3-8")]
35+
use llvm_sys::error_handling::LLVMEnablePrettyStackTrace;
3536

3637
unsafe {
3738
LLVMEnablePrettyStackTrace()
@@ -88,6 +89,11 @@ pub fn shutdown_llvm() {
8889

8990
/// Resets LLVM's fatal error handler back to the default
9091
pub fn reset_fatal_error_handler() {
92+
#[cfg(any(feature = "llvm3-6", feature = "llvm3-7"))]
93+
use llvm_sys::core::LLVMResetFatalErrorHandler;
94+
#[cfg(feature = "llvm3-8")]
95+
use llvm_sys::error_handling::LLVMResetFatalErrorHandler;
96+
9197
unsafe {
9298
LLVMResetFatalErrorHandler()
9399
}

src/passes.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use targets::TargetData;
1717
use values::{AsValueRef, FunctionValue};
1818

1919
// REVIEW: Opt Level might be identical to targets::Option<CodeGenOptLevel>
20-
// REVIEW: size_level 0-2 according to llvmlite
2120
#[derive(Debug)]
2221
pub struct PassManagerBuilder {
2322
pass_manager_builder: LLVMPassManagerBuilderRef,
@@ -28,7 +27,7 @@ impl PassManagerBuilder {
2827
assert!(!pass_manager_builder.is_null());
2928

3029
PassManagerBuilder {
31-
pass_manager_builder: pass_manager_builder,
30+
pass_manager_builder,
3231
}
3332
}
3433

@@ -118,7 +117,7 @@ impl PassManager {
118117
assert!(!pass_manager.is_null());
119118

120119
PassManager {
121-
pass_manager: pass_manager
120+
pass_manager,
122121
}
123122
}
124123

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 = 18;
1719

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

tests/test_builder.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,11 @@ 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", feature = "llvm3-8"))]
443444
assert_eq!(module.print_to_string(), &*CString::new("; ModuleID = \'my_mod\'\n\ndefine void @my_fn() {\nentry:\n unreachable\n}\n").unwrap());
445+
// llvm 6.0?:
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
446-
// Builds drops fine
449+
// Builder drops fine
447450
}

tests/test_passes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ fn test_pass_manager_builder() {
112112

113113
pass_manager_builder.populate_module_pass_manager(&module_pass_manager);
114114

115-
// REVIEW: Seems to return true in 3.7, even though no changes were made.
116-
// In 3.6 it returns false. LLVM bug?
117-
#[cfg(feature = "llvm3-6")]
115+
// TODOC: Seems to return true in 3.7, even though no changes were made.
116+
// In 3.6 and 3.8 it returns false. Seems like an LLVM bug
117+
#[cfg(not(feature = "llvm3-7"))]
118118
assert!(!module_pass_manager.run_on_module(&module));
119-
#[cfg(not(feature = "llvm3-6"))]
119+
#[cfg(feature = "llvm3-7")]
120120
assert!(module_pass_manager.run_on_module(&module));
121121

122122
// TODO: Populate LTO pass manager?

tests/test_values.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -400,25 +400,28 @@ fn test_metadata() {
400400
assert_eq!(MetadataValue::get_kind_id("dereferenceable_or_null"), 13);
401401
}
402402

403+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
404+
{
405+
assert_eq!(context.get_kind_id("make.implicit"), 14);
406+
assert_eq!(MetadataValue::get_kind_id("make.implicit"), 14);
407+
assert_eq!(context.get_kind_id("unpredictable"), 15);
408+
assert_eq!(MetadataValue::get_kind_id("unpredictable"), 15);
409+
assert_eq!(context.get_kind_id("invariant.group"), 16);
410+
assert_eq!(MetadataValue::get_kind_id("invariant.group"), 16);
411+
assert_eq!(context.get_kind_id("align"), 17);
412+
assert_eq!(MetadataValue::get_kind_id("align"), 17);
413+
}
403414
// TODO: Predefined, but only newer versions we don't support yet
404-
// assert_eq!(context.get_kind_id("make.implicit"), 14);
405-
// assert_eq!(MetadataValue::get_kind_id("make.implicit"), 14);
406-
// assert_eq!(context.get_kind_id("unpredictable"), 15);
407-
// assert_eq!(MetadataValue::get_kind_id("unpredictable"), 15);
408-
// assert_eq!(context.get_kind_id("invariant.group"), 16);
409-
// assert_eq!(MetadataValue::get_kind_id("invariant.group"), 16);
410-
// assert_eq!(context.get_kind_id("align"), 16);
411-
// assert_eq!(MetadataValue::get_kind_id("align"), 16);
412-
// assert_eq!(context.get_kind_id("llvm.loop"), 17);
413-
// assert_eq!(MetadataValue::get_kind_id("llvm.loop"), 17);
414-
// assert_eq!(context.get_kind_id("type"), 18);
415-
// assert_eq!(MetadataValue::get_kind_id("type"), 18);
416-
// assert_eq!(context.get_kind_id("section_prefix"), 19);
417-
// assert_eq!(MetadataValue::get_kind_id("section_prefix"), 19);
418-
// assert_eq!(context.get_kind_id("absolute_symbol"), 20);
419-
// assert_eq!(MetadataValue::get_kind_id("absolute_symbol"), 20);
420-
// assert_eq!(context.get_kind_id("associated"), 21);
421-
// assert_eq!(MetadataValue::get_kind_id("associated"), 21);
415+
// assert_eq!(context.get_kind_id("llvm.loop"), 18);
416+
// assert_eq!(MetadataValue::get_kind_id("llvm.loop"), 18);
417+
// assert_eq!(context.get_kind_id("type"), 19);
418+
// assert_eq!(MetadataValue::get_kind_id("type"), 19);
419+
// assert_eq!(context.get_kind_id("section_prefix"), 20);
420+
// assert_eq!(MetadataValue::get_kind_id("section_prefix"), 20);
421+
// assert_eq!(context.get_kind_id("absolute_symbol"), 21);
422+
// assert_eq!(MetadataValue::get_kind_id("absolute_symbol"), 21);
423+
// assert_eq!(context.get_kind_id("associated"), 22);
424+
// assert_eq!(MetadataValue::get_kind_id("associated"), 22);
422425

423426
assert_eq!(module.get_global_metadata_size("my_string_md"), 0);
424427
assert_eq!(module.get_global_metadata("my_string_md").len(), 0);
@@ -686,7 +689,9 @@ fn test_function_value_no_params() {
686689
assert!(fn_value.get_first_param().is_none());
687690
assert!(fn_value.get_last_param().is_none());
688691
assert!(fn_value.get_nth_param(0).is_none());
689-
#[cfg(not(feature = "llvm3-6"))]
692+
// REVIEW: get_personality_function causes segfault in 3.8 Probably LLVM bug
693+
// if so, should document
694+
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-8")))]
690695
assert!(fn_value.get_personality_function().is_none());
691696
assert!(!fn_value.is_null());
692697
assert!(!fn_value.is_undef());

0 commit comments

Comments
 (0)