diff --git a/src/Cargo.lock b/src/Cargo.lock index e5e9775a924b4..bc843c73f1fc0 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -106,6 +106,24 @@ dependencies = [ name = "bin_lib" version = "0.1.0" +[[package]] +name = "bindgen" +version = "0.31.3" +source = "git+https://github.com/rust-lang-nursery/rust-bindgen.git?rev=75f9e1c#75f9e1c233ab4c41a3e52afe7b349142d569dc0a" +dependencies = [ + "cexpr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "clang-sys 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.27.1 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "which 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bitflags" version = "0.7.0" @@ -248,11 +266,29 @@ name = "cc" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cexpr" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cfg-if" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "clang-sys" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "libloading 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "clap" version = "2.27.1" @@ -953,6 +989,16 @@ dependencies = [ "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "libloading" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "libssh2-sys" version = "0.2.6" @@ -1111,6 +1157,14 @@ dependencies = [ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "nom" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num" version = "0.1.40" @@ -1254,6 +1308,11 @@ dependencies = [ "unwind 0.0.0", ] +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "percent-encoding" version = "1.0.1" @@ -1758,10 +1817,9 @@ dependencies = [ name = "rustc_llvm" version = "0.0.0" dependencies = [ - "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bindgen 0.31.3 (git+https://github.com/rust-lang-nursery/rust-bindgen.git?rev=75f9e1c)", "build_helper 0.1.0", "cc 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_cratesio_shim 0.0.0", ] [[package]] @@ -2562,6 +2620,14 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "which" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "winapi" version = "0.2.8" @@ -2624,13 +2690,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum atty 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "21e50800ec991574876040fff8ee46b136a53e985286fbe6a3bdfe6421b78860" "checksum backtrace 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8709cc7ec06f6f0ae6c2c7e12f6ed41540781f72b488d83734978295ceae182e" "checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661" +"checksum bindgen 0.31.3 (git+https://github.com/rust-lang-nursery/rust-bindgen.git?rev=75f9e1c)" = "" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" "checksum bufstream 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f382711e76b9de6c744cc00d0497baba02fb00a787f088c879f01d09468e32" "checksum cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "be1057b8462184f634c3a208ee35b0f935cfd94b694b26deadccd98732088d7b" "checksum cc 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a9b13a57efd6b30ecd6598ebdb302cca617930b5470647570468a65d12ef9719" +"checksum cexpr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cdbb21df6ff3497a61df5059994297f746267020ba38ce237aad9c875f7b4313" "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" +"checksum clang-sys 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00048189ee171715296dfe3b2fcfd439563c7bfec0d98d3976ce3402d62c8f07" "checksum clap 2.27.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1b8c532887f1a292d17de05ae858a8fe50a301e196f9ef0ddb7ccd0d1d00f180" "checksum cmake 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "e14cd15a7cbc2c6a905677e54b831ee91af2ff43b352010f6133236463b65cac" "checksum commoncrypto 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d056a8586ba25a1e4d61cb090900e495952c7886786fc55f909ab2f819b69007" @@ -2692,6 +2761,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lazycell 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3b585b7a6811fb03aa10e74b278a0f00f8dd9b45dc681f148bb29fa5cb61859b" "checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2" "checksum libgit2-sys 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "6f74b4959cef96898f5123148724fc7dee043b9a6b99f219d948851bfbe53cb2" +"checksum libloading 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3f92926a9a4ba7aeeb01f5fba3f0d577147243b6e7fa8261c219cd1d6fbe3b1c" "checksum libssh2-sys 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0db4ec23611747ef772db1c4d650f8bd762f07b461727ec998f953c614024b75" "checksum libz-sys 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "87f737ad6cc6fd6eefe3d9dc5412f1573865bded441300904d2f42269e140f16" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" @@ -2707,6 +2777,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum net2 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "3a80f842784ef6c9a958b68b7516bc7e35883c614004dd94959a4dca1b716c09" "checksum nix 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "47e49f6982987135c5e9620ab317623e723bd06738fd85377e8d55f57c8b6487" +"checksum nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05aec50c70fd288702bcd93284a8444607f3292dbdf2a30de5ea5dcdbe72287b" "checksum num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "a311b77ebdc5dd4cf6449d81e4135d9f0e3b153839ac90e648a8ef538f923525" "checksum num-bigint 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "8fd0f8dbb4c0960998958a796281d88c16fbe68d87b1baa6f31e2979e81fd0bd" "checksum num-complex 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "503e668405c5492d67cf662a81e05be40efe2e6bcf10f7794a07bd9865e704e6" @@ -2721,6 +2792,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum openssl-sys 0.9.21 (registry+https://github.com/rust-lang/crates.io-index)" = "92867746af30eea7a89feade385f7f5366776f1c52ec6f0de81360373fa88363" "checksum os_pipe 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "998bfbb3042e715190fe2a41abfa047d7e8cb81374d2977d7f100eacd8619cb1" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" +"checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum pest 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0a6dda33d67c26f0aac90d324ab2eb7239c819fc7b2552fe9faa4fe88441edc8" "checksum phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "cb325642290f28ee14d8c6201159949a872f220c62af6e110a56ea914fbe42fc" @@ -2810,6 +2882,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "bb08f9e670fab86099470b97cd2b252d6527f0b3cc1401acdb595ffc9dd288ff" +"checksum which 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4be6cfa54dab45266e98b5d7be2f8ce959ddd49abd141a05d52dce4b07f803bb" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum wincolor 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a39ee4464208f6430992ff20154216ab2357772ac871d994c51628d60e58b8b0" diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index db013691bb1b8..169b19152faf9 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -153,6 +153,8 @@ pub fn std_cargo(build: &Build, features.push_str(" force_alloc_system"); } + features.push_str(" rustc_llvm/rebuild_bindings"); + if compiler.stage != 0 && build.config.sanitizers { // This variable is used by the sanitizer runtime crates, e.g. // rustc_lsan, to build the sanitizer runtime from C code diff --git a/src/librustc_llvm/Cargo.toml b/src/librustc_llvm/Cargo.toml index a9566c4bcacd7..e6da93d3133b3 100644 --- a/src/librustc_llvm/Cargo.toml +++ b/src/librustc_llvm/Cargo.toml @@ -10,12 +10,10 @@ path = "lib.rs" crate-type = ["dylib"] [features] -static-libstdcpp = [] - -[dependencies] -bitflags = "1.0" -rustc_cratesio_shim = { path = "../librustc_cratesio_shim" } +rebuild-bindings = ["bindgen"] [build-dependencies] -build_helper = { path = "../build_helper" } +# https://github.com/rust-lang-nursery/rust-bindgen/pull/1162. +bindgen = { git = "https://github.com/rust-lang-nursery/rust-bindgen.git", rev = "75f9e1c", optional = true } cc = "1.0.1" +build_helper = { path = "../build_helper" } diff --git a/src/librustc_llvm/archive_ro.rs b/src/librustc_llvm/archive_ro.rs index 6c3626cd880b2..ef4307fde5383 100644 --- a/src/librustc_llvm/archive_ro.rs +++ b/src/librustc_llvm/archive_ro.rs @@ -93,6 +93,7 @@ impl<'a> Iterator for Iter<'a> { if ptr.is_null() { ::last_error().map(Err) } else { + let ptr = ptr as *mut _; Some(Ok(Child { ptr, _data: marker::PhantomData, diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index 141a9a8d704d2..49bc8319fe4ef 100644 --- a/src/librustc_llvm/build.rs +++ b/src/librustc_llvm/build.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +extern crate bindgen; extern crate cc; extern crate build_helper; @@ -139,6 +140,382 @@ fn main() { let cxxflags = output(&mut cmd); let mut cfg = cc::Build::new(); cfg.warnings(false); + + #[cfg(feature = "rebuild-bindings")] + let mut builder = bindgen::builder() + .header("../rustllvm/PassWrapper.cpp") + .header("../rustllvm/RustWrapper.cpp") + .header("../rustllvm/ArchiveWrapper.cpp") + .clang_arg("-DBINDGEN_NO_TLS") + .clang_args(&["-x", "c++"]) + .enable_cxx_namespaces() + .rust_target(bindgen::RustTarget::Nightly) + .whitelist_recursively(false) + .whitelist_type("(LLVM)?Rust.*") + .whitelist_function("(LLVM)?Rust.*") + .rustfmt_bindings(true) + .layout_tests(false) + .with_codegen_config(bindgen::CodegenConfig{ + functions: true, + types: true, + vars: false, + methods: false, + constructors: false, + destructors: false, + }); + + #[cfg(feature = "rebuild-bindings")] + for visible_type in [ + // Rust wants to define constants of this type. + "LLVMBool", + // Rust wants to know these callback types. + "DemangleFn", + "LLVMDiagnosticHandler", + // Rust wants to know that these are pointers. + "LLVMBasicBlockRef", + "LLVMBuilderRef", + "LLVMMetadataRef", + "LLVMModuleRef", + "LLVMPassRef", + "LLVMRustArchiveRef", + "LLVMTargetMachineRef", + "LLVMTwineRef", + "LLVMTypeRef", + "LLVMValueRef", + ].into_iter() { + builder = builder + .whitelist_type(visible_type); + } + + #[cfg(feature = "rebuild-bindings")] + for opaque_type in [ + "LLVMContextRef", + "LLVMDebugLocRef", + "LLVMDiagnosticInfoRef", + "LLVMMemoryBufferRef", + "LLVMObjectFileRef", + "LLVMOpaqueBasicBlock", + "LLVMOpaqueBuilder", + "LLVMOpaqueMetadata", + "LLVMOpaqueModule", + "LLVMOpaquePass", + "LLVMOpaqueRef", + "LLVMOpaqueTargetMachine", + "LLVMOpaqueTwine", + "LLVMOpaqueType", + "LLVMOpaqueValue", + "LLVMPassManagerBuilderRef", + "LLVMPassManagerRef", + "LLVMRust.*Buffer", + "LLVMRustArchiveIteratorRef", + "LLVMRustJITMemoryManagerRef", + "LLVMRustThinLTOData", + "LLVMSectionIteratorRef", + "LLVMTargetDataRef", + "RustArchiveIterator", + "RustStringRef", + "llvm::DIBuilder", + "llvm::DiagnosticInfo", + "llvm::LLVMContext", + "llvm::OperandBundleDef", + "llvm::SMDiagnostic", + // https://github.com/rust-lang-nursery/rust-bindgen/issues/1164. + "llvm::object::Archive_Child", + // https://github.com/rust-lang-nursery/rust-bindgen/issues/1164. + "llvm::object::Archive_child_iterator", + "llvm::object::OwningBinary", + ].into_iter() { + builder = builder + .opaque_type(opaque_type) + .whitelist_type(opaque_type); + } + + #[cfg(feature = "rebuild-bindings")] + for bitfield_enum in [ + "LLVMRustDIFlags", + ].into_iter() { + builder = builder + .whitelist_type(bitfield_enum) + .bitfield_enum(bitfield_enum); + } + + #[cfg(feature = "rebuild-bindings")] + for rustified_enum in [ + "LLVMAtomicOrdering", + "LLVMAtomicRMWBinOp", + "LLVMDLLStorageClass", + "LLVMDiagnosticSeverity", + "LLVMIntPredicate", + "LLVMOpcode", + "LLVMRealPredicate", + "LLVMRustArchiveKind", + "LLVMRustAsmDialect", + "LLVMRustAttribute", + "LLVMRustCodeGenOptLevel", + "LLVMRustCodeModel", + "LLVMRustDiagnosticKind", + "LLVMRustFileType", + "LLVMRustLinkage", + "LLVMRustPassKind", + "LLVMRustRelocMode", + "LLVMRustResult", + "LLVMRustSynchronizationScope", + "LLVMRustVisibility", + "LLVMThreadLocalMode", + "LLVMTypeKind", + // https://github.com/rust-lang-nursery/rust-bindgen/issues/1161. + "llvm::CallingConv::.*", + // https://github.com/rust-lang-nursery/rust-bindgen/issues/1164. + // Opens the whole namespace, wtf? + "llvm::LLVMContext__bindgen_ty_1", +// llvm::LLVMContext_DiagnosticHandlerTy + ].into_iter() { + builder = builder + .whitelist_type(rustified_enum) + .rustified_enum(rustified_enum); + } + + + #[cfg(feature = "rebuild-bindings")] + for llvm_function in [ + "LLVMAddCase", + "LLVMAddClause", + "LLVMAddGlobal", + "LLVMAddIncoming", + "LLVMAddNamedMetadataOperand", + "LLVMAppendBasicBlockInContext", + "LLVMBuildAShr", + "LLVMBuildAdd", + "LLVMBuildAggregateRet", + "LLVMBuildAlloca", + "LLVMBuildAnd", + "LLVMBuildAtomicRMW", + "LLVMBuildBinOp", + "LLVMBuildBitCast", + "LLVMBuildBr", + "LLVMBuildCast", + "LLVMBuildCondBr", + "LLVMBuildExactSDiv", + "LLVMBuildExtractElement", + "LLVMBuildExtractValue", + "LLVMBuildFAdd", + "LLVMBuildFCmp", + "LLVMBuildFDiv", + "LLVMBuildFMul", + "LLVMBuildFNeg", + "LLVMBuildFPCast", + "LLVMBuildFPExt", + "LLVMBuildFPToSI", + "LLVMBuildFPToUI", + "LLVMBuildFPTrunc", + "LLVMBuildFRem", + "LLVMBuildFSub", + "LLVMBuildFree", + "LLVMBuildGEP", + "LLVMBuildGlobalString", + "LLVMBuildGlobalStringPtr", + "LLVMBuildICmp", + "LLVMBuildInBoundsGEP", + "LLVMBuildIndirectBr", + "LLVMBuildInsertElement", + "LLVMBuildInsertValue", + "LLVMBuildIntToPtr", + "LLVMBuildIsNotNull", + "LLVMBuildIsNull", + "LLVMBuildLShr", + "LLVMBuildLoad", + "LLVMBuildMul", + "LLVMBuildNSWAdd", + "LLVMBuildNSWMul", + "LLVMBuildNSWNeg", + "LLVMBuildNSWSub", + "LLVMBuildNUWAdd", + "LLVMBuildNUWMul", + "LLVMBuildNUWNeg", + "LLVMBuildNUWSub", + "LLVMBuildNeg", + "LLVMBuildNot", + "LLVMBuildOr", + "LLVMBuildPhi", + "LLVMBuildPointerCast", + "LLVMBuildPtrDiff", + "LLVMBuildPtrToInt", + "LLVMBuildResume", + "LLVMBuildRet", + "LLVMBuildRetVoid", + "LLVMBuildSDiv", + "LLVMBuildSExt", + "LLVMBuildSExtOrBitCast", + "LLVMBuildSIToFP", + "LLVMBuildSRem", + "LLVMBuildSelect", + "LLVMBuildShl", + "LLVMBuildShuffleVector", + "LLVMBuildStore", + "LLVMBuildStructGEP", + "LLVMBuildSub", + "LLVMBuildSwitch", + "LLVMBuildTrunc", + "LLVMBuildTruncOrBitCast", + "LLVMBuildUDiv", + "LLVMBuildUIToFP", + "LLVMBuildURem", + "LLVMBuildUnreachable", + "LLVMBuildVAArg", + "LLVMBuildXor", + "LLVMBuildZExt", + "LLVMBuildZExtOrBitCast", + "LLVMCloneModule", + "LLVMConstAShr", + "LLVMConstAdd", + "LLVMConstAnd", + "LLVMConstArray", + "LLVMConstBitCast", + "LLVMConstExtractValue", + "LLVMConstFAdd", + "LLVMConstFCmp", + "LLVMConstFDiv", + "LLVMConstFMul", + "LLVMConstFNeg", + "LLVMConstFPCast", + "LLVMConstFRem", + "LLVMConstFSub", + "LLVMConstICmp", + "LLVMConstInlineAsm", + "LLVMConstInt", + "LLVMConstIntCast", + "LLVMConstIntGetZExtValue", + "LLVMConstIntOfArbitraryPrecision", + "LLVMConstIntToPtr", + "LLVMConstLShr", + "LLVMConstMul", + "LLVMConstNeg", + "LLVMConstNot", + "LLVMConstNull", + "LLVMConstOr", + "LLVMConstPointerCast", + "LLVMConstPtrToInt", + "LLVMConstSDiv", + "LLVMConstSIToFP", + "LLVMConstSRem", + "LLVMConstShl", + "LLVMConstStringInContext", + "LLVMConstStructInContext", + "LLVMConstSub", + "LLVMConstTrunc", + "LLVMConstUDiv", + "LLVMConstUIToFP", + "LLVMConstURem", + "LLVMConstVector", + "LLVMConstXor", + "LLVMConstZExt", + "LLVMContextCreate", + "LLVMContextDispose", + "LLVMContextSetDiagnosticHandler", + "LLVMCountParamTypes", + "LLVMCountParams", + "LLVMCreateBuilderInContext", + "LLVMCreateFunctionPassManagerForModule", + "LLVMCreateObjectFile", + "LLVMCreatePassManager", + "LLVMCreateTargetData", + "LLVMDeleteBasicBlock", + "LLVMDeleteGlobal", + "LLVMDisposeBuilder", + "LLVMDisposeModule", + "LLVMDisposeObjectFile", + "LLVMDisposePassManager", + "LLVMDisposeSectionIterator", + "LLVMDisposeTargetData", + "LLVMDoubleTypeInContext", + "LLVMFloatTypeInContext", + "LLVMFunctionType", + "LLVMGetAlignment", + "LLVMGetBasicBlockParent", + "LLVMGetCurrentDebugLocation", + "LLVMGetDataLayout", + "LLVMGetElementType", + "LLVMGetFirstBasicBlock", + "LLVMGetFirstGlobal", + "LLVMGetGlobalParent", + "LLVMGetInitializer", + "LLVMGetInsertBlock", + "LLVMGetIntTypeWidth", + "LLVMGetMDKindIDInContext", + "LLVMGetModuleContext", + "LLVMGetNamedFunction", + "LLVMGetNamedGlobal", + "LLVMGetNextGlobal", + "LLVMGetParam", + "LLVMGetParamTypes", + "LLVMGetSectionContents", + "LLVMGetSectionSize", + "LLVMGetSections", + "LLVMGetUndef", + "LLVMGetValueName", + "LLVMGetVectorSize", + "LLVMInitializePasses", + "LLVMInt16TypeInContext", + "LLVMInt1TypeInContext", + "LLVMInt32TypeInContext", + "LLVMInt64TypeInContext", + "LLVMInt8TypeInContext", + "LLVMIntTypeInContext", + "LLVMIsAConstantInt", + "LLVMIsAGlobalVariable", + "LLVMIsDeclaration", + "LLVMIsGlobalConstant", + "LLVMIsSectionIteratorAtEnd", + "LLVMMDNodeInContext", + "LLVMMDStringInContext", + "LLVMModuleCreateWithNameInContext", + "LLVMMoveToNextSection", + "LLVMPassManagerBuilderCreate", + "LLVMPassManagerBuilderDispose", + "LLVMPassManagerBuilderPopulateFunctionPassManager", + "LLVMPassManagerBuilderPopulateLTOPassManager", + "LLVMPassManagerBuilderPopulateModulePassManager", + "LLVMPassManagerBuilderSetDisableUnrollLoops", + "LLVMPassManagerBuilderSetSizeLevel", + "LLVMPassManagerBuilderUseInlinerWithThreshold", + "LLVMPointerType", + "LLVMPositionBuilderAtEnd", + "LLVMPositionBuilderBefore", + "LLVMReplaceAllUsesWith", + "LLVMRunPassManager", + "LLVMSetAlignment", + "LLVMSetCleanup", + "LLVMSetCurrentDebugLocation", + "LLVMSetDLLStorageClass", + "LLVMSetDataLayout", + "LLVMSetFunctionCallConv", + "LLVMSetGlobalConstant", + "LLVMSetInitializer", + "LLVMSetInstDebugLocation", + "LLVMSetInstructionCallConv", + "LLVMSetMetadata", + "LLVMSetModuleInlineAsm", + "LLVMSetPersonalityFn", + "LLVMSetSection", + "LLVMSetTailCall", + "LLVMSetThreadLocal", + "LLVMSetThreadLocalMode", + "LLVMSetUnnamedAddr", + "LLVMSetValueName", + "LLVMSetVolatile", + "LLVMStartMultithreaded", + "LLVMStructCreateNamed", + "LLVMStructSetBody", + "LLVMStructTypeInContext", + "LLVMTypeOf", + "LLVMVectorType", + "LLVMVoidTypeInContext", + "LLVMWriteBitcodeToFile", + "LLVMX86MMXTypeInContext", + ].into_iter() { + builder = builder.whitelist_function(llvm_function); + } + for flag in cxxflags.split_whitespace() { // Ignore flags like `-m64` when we're doing a cross build if is_crossed && flag.starts_with("-m") { @@ -151,6 +528,32 @@ fn main() { } cfg.flag(flag); + #[cfg(feature = "rebuild-bindings")] + { + builder = builder.clang_arg(flag); + } + } + + #[cfg(feature = "rebuild-bindings")] + { + builder = builder.clang_arg( + "-I/home/tduberstein/local/clang/clang+llvm-5.0.0-linux-x86_64-sles11.3/lib/clang/5.0.0/include", + ); + } + let libclang_path_var = "LIBCLANG_PATH"; + let var = env::var(libclang_path_var); + env::set_var(libclang_path_var, "/home/tduberstein/local/clang/clang+llvm-5.0.0-linux-x86_64-sles11.3/lib"); + #[cfg(feature = "rebuild-bindings")] + builder.generate() + .expect("Failed to generate bindings") + .write_to_file("bindings.rs") + .expect("Failed to write bindings"); + match var { + Ok(var) => env::set_var(libclang_path_var, var), + Err(e) => match e { + env::VarError::NotPresent => (), + env::VarError::NotUnicode(var) => env::set_var(libclang_path_var, var), + }, } for component in &components { diff --git a/src/librustc_llvm/diagnostic.rs b/src/librustc_llvm/diagnostic.rs index c5cdf6566921c..695c848769654 100644 --- a/src/librustc_llvm/diagnostic.rs +++ b/src/librustc_llvm/diagnostic.rs @@ -93,7 +93,7 @@ impl OptimizationDiagnostic { } } -#[derive(Copy, Clone)] +#[derive(Clone)] pub struct InlineAsmDiagnostic { pub cookie: c_uint, pub message: TwineRef, diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index dd64d76bc0c51..e0012b0c0e968 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -8,455 +8,96 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// FIXME: Rename 'DIGlobalVariable' to 'DIGlobalVariableExpression' -// once support for LLVM 3.9 is dropped. -// -// This method was changed in this LLVM patch: -// https://reviews.llvm.org/D26769 - -use debuginfo::{DIBuilderRef, DIDescriptor, DIFile, DILexicalBlock, DISubprogram, DIType, - DIBasicType, DIDerivedType, DICompositeType, DIScope, DIVariable, - DIGlobalVariable, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator, - DINameSpace, DIFlags}; - -use libc::{c_uint, c_int, size_t, c_char}; -use libc::{c_longlong, c_ulonglong, c_void}; - -use RustStringRef; - -pub type Opcode = u32; -pub type Bool = c_uint; +pub use LLVMAtomicOrdering as AtomicOrdering; +pub use LLVMAtomicRMWBinOp as AtomicRmwBinOp; +pub use LLVMBasicBlockRef as BasicBlockRef; +pub use LLVMBool as Bool; +pub use LLVMBuilderRef as BuilderRef; +pub use LLVMContextRef as ContextRef; +pub use LLVMDLLStorageClass as DLLStorageClass; +pub use LLVMDebugLocRef as DebugLocRef; +pub use LLVMDiagnosticInfoRef as DiagnosticInfoRef; +pub use LLVMIntPredicate as IntPredicate; +pub use LLVMIntPredicate::LLVMIntEQ as IntEQ; +pub use LLVMIntPredicate::LLVMIntNE as IntNE; +pub use LLVMIntPredicate::LLVMIntSGE as IntSGE; +pub use LLVMIntPredicate::LLVMIntSGT as IntSGT; +pub use LLVMIntPredicate::LLVMIntSLE as IntSLE; +pub use LLVMIntPredicate::LLVMIntSLT as IntSLT; +pub use LLVMIntPredicate::LLVMIntUGE as IntUGE; +pub use LLVMIntPredicate::LLVMIntUGT as IntUGT; +pub use LLVMIntPredicate::LLVMIntULE as IntULE; +pub use LLVMIntPredicate::LLVMIntULT as IntULT; +pub use LLVMMemoryBufferRef as MemoryBufferRef; +pub use LLVMModuleRef as ModuleRef; +pub use LLVMObjectFileRef as ObjectFileRef; +pub use LLVMOpcode as Opcode; +pub use LLVMPassManagerBuilderRef as PassManagerBuilderRef; +pub use LLVMPassManagerRef as PassManagerRef; +pub use LLVMRealPredicate as RealPredicate; +pub use LLVMRealPredicate::LLVMRealOEQ as RealOEQ; +pub use LLVMRealPredicate::LLVMRealOGE as RealOGE; +pub use LLVMRealPredicate::LLVMRealOGT as RealOGT; +pub use LLVMRealPredicate::LLVMRealOLE as RealOLE; +pub use LLVMRealPredicate::LLVMRealOLT as RealOLT; +pub use LLVMRealPredicate::LLVMRealULT as RealULT; +pub use LLVMRealPredicate::LLVMRealUNE as RealUNE; +pub use LLVMRustArchiveChildRef as ArchiveChildRef; +pub use LLVMRustArchiveIteratorRef as ArchiveIteratorRef; +pub use LLVMRustArchiveKind as ArchiveKind; +pub use LLVMRustArchiveRef as ArchiveRef; +pub use LLVMRustAsmDialect as AsmDialect; +pub use LLVMRustAttribute as Attribute; +pub use LLVMRustCodeGenOptLevel as CodeGenOptLevel; +pub use LLVMRustCodeModel as CodeModel; +pub use LLVMRustDiagnosticKind as DiagnosticKind; +pub use LLVMRustFileType as FileType; +pub use LLVMRustLinkage as Linkage; +pub use LLVMRustModuleBuffer as ModuleBuffer; +pub use LLVMRustOperandBundleDefRef as OperandBundleDefRef; +pub use LLVMRustPassKind as PassKind; +pub use LLVMRustRelocMode as RelocMode; +pub use LLVMRustSynchronizationScope as SynchronizationScope; +pub use LLVMRustThinLTOBuffer as ThinLTOBuffer; +pub use LLVMRustThinLTOData as ThinLTOData; +pub use LLVMRustThinLTOModule as ThinLTOModule; +pub use LLVMRustVisibility as Visibility; +pub use LLVMSMDiagnosticRef as SMDiagnosticRef; +pub use LLVMSectionIteratorRef as SectionIteratorRef; +pub use LLVMTargetDataRef as TargetDataRef; +pub use LLVMTargetMachineRef as TargetMachineRef; +pub use LLVMThreadLocalMode as ThreadLocalMode; +pub use LLVMTwineRef as TwineRef; +pub use LLVMTypeKind as TypeKind; +pub use LLVMTypeKind::LLVMDoubleTypeKind as Double; +pub use LLVMTypeKind::LLVMFP128TypeKind as FP128; +pub use LLVMTypeKind::LLVMFloatTypeKind as Float; +pub use LLVMTypeKind::LLVMPPC_FP128TypeKind as PPC_FP128; +pub use LLVMTypeKind::LLVMVectorTypeKind as Vector; +pub use LLVMTypeKind::LLVMX86_FP80TypeKind as X86_FP80; +pub use LLVMTypeRef as TypeRef; +pub use LLVMValueRef as ValueRef; +pub use llvm::CallingConv::_bindgen_ty_1 as CallConv; +pub use llvm::LLVMContext__bindgen_ty_1 as MetadataType; + +pub type LLVMSMDiagnosticRef = *const llvm::SMDiagnostic; pub const True: Bool = 1 as Bool; pub const False: Bool = 0 as Bool; -#[derive(Copy, Clone, PartialEq)] -#[repr(C)] -pub enum LLVMRustResult { - Success, - Failure, -} -// Consts for the LLVM CallConv type, pre-cast to usize. - -/// LLVM CallingConv::ID. Should we wrap this? -#[derive(Copy, Clone, PartialEq, Debug)] -#[repr(C)] -pub enum CallConv { - CCallConv = 0, - FastCallConv = 8, - ColdCallConv = 9, - X86StdcallCallConv = 64, - X86FastcallCallConv = 65, - ArmAapcsCallConv = 67, - Msp430Intr = 69, - X86_ThisCall = 70, - PtxKernel = 71, - X86_64_SysV = 78, - X86_64_Win64 = 79, - X86_VectorCall = 80, - X86_Intr = 83, -} - -/// LLVMRustLinkage -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] -#[repr(C)] -pub enum Linkage { - ExternalLinkage = 0, - AvailableExternallyLinkage = 1, - LinkOnceAnyLinkage = 2, - LinkOnceODRLinkage = 3, - WeakAnyLinkage = 4, - WeakODRLinkage = 5, - AppendingLinkage = 6, - InternalLinkage = 7, - PrivateLinkage = 8, - ExternalWeakLinkage = 9, - CommonLinkage = 10, -} - -// LLVMRustVisibility -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] -#[repr(C)] -pub enum Visibility { - Default = 0, - Hidden = 1, - Protected = 2, -} - -/// LLVMDiagnosticSeverity -#[derive(Copy, Clone, Debug)] -#[repr(C)] -pub enum DiagnosticSeverity { - Error = 0, - Warning = 1, - Remark = 2, - Note = 3, -} - -/// LLVMDLLStorageClass -#[derive(Copy, Clone)] -#[repr(C)] -pub enum DLLStorageClass { - Default = 0, - DllImport = 1, // Function to be imported from DLL. - DllExport = 2, // Function to be accessible from DLL. -} - -/// Matches LLVMRustAttribute in rustllvm.h -/// Semantically a subset of the C++ enum llvm::Attribute::AttrKind, -/// though it is not ABI compatible (since it's a C++ enum) -#[repr(C)] -#[derive(Copy, Clone, Debug)] -pub enum Attribute { - AlwaysInline = 0, - ByVal = 1, - Cold = 2, - InlineHint = 3, - MinSize = 4, - Naked = 5, - NoAlias = 6, - NoCapture = 7, - NoInline = 8, - NonNull = 9, - NoRedZone = 10, - NoReturn = 11, - NoUnwind = 12, - OptimizeForSize = 13, - ReadOnly = 14, - SExt = 15, - StructRet = 16, - UWTable = 17, - ZExt = 18, - InReg = 19, - SanitizeThread = 20, - SanitizeAddress = 21, - SanitizeMemory = 22, -} - -/// LLVMIntPredicate -#[derive(Copy, Clone)] -#[repr(C)] -pub enum IntPredicate { - IntEQ = 32, - IntNE = 33, - IntUGT = 34, - IntUGE = 35, - IntULT = 36, - IntULE = 37, - IntSGT = 38, - IntSGE = 39, - IntSLT = 40, - IntSLE = 41, -} - -/// LLVMRealPredicate -#[derive(Copy, Clone)] -#[repr(C)] -pub enum RealPredicate { - RealPredicateFalse = 0, - RealOEQ = 1, - RealOGT = 2, - RealOGE = 3, - RealOLT = 4, - RealOLE = 5, - RealONE = 6, - RealORD = 7, - RealUNO = 8, - RealUEQ = 9, - RealUGT = 10, - RealUGE = 11, - RealULT = 12, - RealULE = 13, - RealUNE = 14, - RealPredicateTrue = 15, -} - -/// LLVMTypeKind -#[derive(Copy, Clone, PartialEq, Debug)] -#[repr(C)] -pub enum TypeKind { - Void = 0, - Half = 1, - Float = 2, - Double = 3, - X86_FP80 = 4, - FP128 = 5, - PPC_FP128 = 6, - Label = 7, - Integer = 8, - Function = 9, - Struct = 10, - Array = 11, - Pointer = 12, - Vector = 13, - Metadata = 14, - X86_MMX = 15, - Token = 16, -} - -/// LLVMAtomicRmwBinOp -#[derive(Copy, Clone)] -#[repr(C)] -pub enum AtomicRmwBinOp { - AtomicXchg = 0, - AtomicAdd = 1, - AtomicSub = 2, - AtomicAnd = 3, - AtomicNand = 4, - AtomicOr = 5, - AtomicXor = 6, - AtomicMax = 7, - AtomicMin = 8, - AtomicUMax = 9, - AtomicUMin = 10, -} - -/// LLVMAtomicOrdering -#[derive(Copy, Clone)] -#[repr(C)] -pub enum AtomicOrdering { - NotAtomic = 0, - Unordered = 1, - Monotonic = 2, - // Consume = 3, // Not specified yet. - Acquire = 4, - Release = 5, - AcquireRelease = 6, - SequentiallyConsistent = 7, -} - -/// LLVMRustSynchronizationScope -#[derive(Copy, Clone)] -#[repr(C)] -pub enum SynchronizationScope { - Other, - SingleThread, - CrossThread, -} - -/// LLVMRustFileType -#[derive(Copy, Clone)] -#[repr(C)] -pub enum FileType { - Other, - AssemblyFile, - ObjectFile, -} - -/// LLVMMetadataType -#[derive(Copy, Clone)] -#[repr(C)] -pub enum MetadataType { - MD_dbg = 0, - MD_tbaa = 1, - MD_prof = 2, - MD_fpmath = 3, - MD_range = 4, - MD_tbaa_struct = 5, - MD_invariant_load = 6, - MD_alias_scope = 7, - MD_noalias = 8, - MD_nontemporal = 9, - MD_mem_parallel_loop_access = 10, - MD_nonnull = 11, -} - -/// LLVMRustAsmDialect -#[derive(Copy, Clone)] -#[repr(C)] -pub enum AsmDialect { - Other, - Att, - Intel, -} - -/// LLVMRustCodeGenOptLevel -#[derive(Copy, Clone, PartialEq)] -#[repr(C)] -pub enum CodeGenOptLevel { - Other, - None, - Less, - Default, - Aggressive, -} - -/// LLVMRelocMode -#[derive(Copy, Clone, PartialEq)] -#[repr(C)] -pub enum RelocMode { - Default, - Static, - PIC, - DynamicNoPic, - ROPI, - RWPI, - ROPI_RWPI, -} - -/// LLVMRustCodeModel -#[derive(Copy, Clone)] -#[repr(C)] -pub enum CodeModel { - Other, - Default, - JITDefault, - Small, - Kernel, - Medium, - Large, -} - -/// LLVMRustDiagnosticKind -#[derive(Copy, Clone)] -#[repr(C)] -pub enum DiagnosticKind { - Other, - InlineAsm, - StackSize, - DebugMetadataVersion, - SampleProfile, - OptimizationRemark, - OptimizationRemarkMissed, - OptimizationRemarkAnalysis, - OptimizationRemarkAnalysisFPCommute, - OptimizationRemarkAnalysisAliasing, - OptimizationRemarkOther, - OptimizationFailure, -} - -/// LLVMRustArchiveKind -#[derive(Copy, Clone)] -#[repr(C)] -pub enum ArchiveKind { - Other, - K_GNU, - K_MIPS64, - K_BSD, - K_COFF, -} - -/// LLVMRustPassKind -#[derive(Copy, Clone, PartialEq, Debug)] -#[repr(C)] -pub enum PassKind { - Other, - Function, - Module, -} - -/// LLVMRustThinLTOData -pub enum ThinLTOData {} - -/// LLVMRustThinLTOBuffer -pub enum ThinLTOBuffer {} - -/// LLVMRustThinLTOModule -#[repr(C)] -pub struct ThinLTOModule { - pub identifier: *const c_char, - pub data: *const u8, - pub len: usize, -} - -/// LLVMThreadLocalMode -#[derive(Copy, Clone)] -#[repr(C)] -pub enum ThreadLocalMode { - NotThreadLocal, - GeneralDynamic, - LocalDynamic, - InitialExec, - LocalExec -} - -// Opaque pointer types -#[allow(missing_copy_implementations)] -pub enum Module_opaque {} -pub type ModuleRef = *mut Module_opaque; -#[allow(missing_copy_implementations)] -pub enum Context_opaque {} -pub type ContextRef = *mut Context_opaque; -#[allow(missing_copy_implementations)] -pub enum Type_opaque {} -pub type TypeRef = *mut Type_opaque; -#[allow(missing_copy_implementations)] -pub enum Value_opaque {} -pub type ValueRef = *mut Value_opaque; -#[allow(missing_copy_implementations)] -pub enum Metadata_opaque {} -pub type MetadataRef = *mut Metadata_opaque; -#[allow(missing_copy_implementations)] -pub enum BasicBlock_opaque {} -pub type BasicBlockRef = *mut BasicBlock_opaque; -#[allow(missing_copy_implementations)] -pub enum Builder_opaque {} -pub type BuilderRef = *mut Builder_opaque; -#[allow(missing_copy_implementations)] -pub enum ExecutionEngine_opaque {} -pub type ExecutionEngineRef = *mut ExecutionEngine_opaque; -#[allow(missing_copy_implementations)] -pub enum MemoryBuffer_opaque {} -pub type MemoryBufferRef = *mut MemoryBuffer_opaque; -#[allow(missing_copy_implementations)] -pub enum PassManager_opaque {} -pub type PassManagerRef = *mut PassManager_opaque; -#[allow(missing_copy_implementations)] -pub enum PassManagerBuilder_opaque {} -pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque; -#[allow(missing_copy_implementations)] -pub enum Use_opaque {} -pub type UseRef = *mut Use_opaque; -#[allow(missing_copy_implementations)] -pub enum TargetData_opaque {} -pub type TargetDataRef = *mut TargetData_opaque; -#[allow(missing_copy_implementations)] -pub enum ObjectFile_opaque {} -pub type ObjectFileRef = *mut ObjectFile_opaque; -#[allow(missing_copy_implementations)] -pub enum SectionIterator_opaque {} -pub type SectionIteratorRef = *mut SectionIterator_opaque; -#[allow(missing_copy_implementations)] -pub enum Pass_opaque {} -pub type PassRef = *mut Pass_opaque; -#[allow(missing_copy_implementations)] -pub enum TargetMachine_opaque {} -pub type TargetMachineRef = *mut TargetMachine_opaque; -pub enum Archive_opaque {} -pub type ArchiveRef = *mut Archive_opaque; -pub enum ArchiveIterator_opaque {} -pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque; -pub enum ArchiveChild_opaque {} -pub type ArchiveChildRef = *mut ArchiveChild_opaque; -#[allow(missing_copy_implementations)] -pub enum Twine_opaque {} -pub type TwineRef = *mut Twine_opaque; -#[allow(missing_copy_implementations)] -pub enum DiagnosticInfo_opaque {} -pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque; -#[allow(missing_copy_implementations)] -pub enum DebugLoc_opaque {} -pub type DebugLocRef = *mut DebugLoc_opaque; -#[allow(missing_copy_implementations)] -pub enum SMDiagnostic_opaque {} -pub type SMDiagnosticRef = *mut SMDiagnostic_opaque; -#[allow(missing_copy_implementations)] -pub enum RustArchiveMember_opaque {} -pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque; -#[allow(missing_copy_implementations)] -pub enum OperandBundleDef_opaque {} -pub type OperandBundleDefRef = *mut OperandBundleDef_opaque; - -pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void); -pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint); +pub use root::*; +pub use llvm::*; +#[allow(dead_code)] +#[allow(non_camel_case_types)] +#[allow(non_snake_case)] +#[allow(non_upper_case_globals)] +include!("bindings.rs"); pub mod debuginfo { - use super::MetadataRef; + use super::LLVMMetadataRef as MetadataRef; - #[allow(missing_copy_implementations)] - pub enum DIBuilder_opaque {} - pub type DIBuilderRef = *mut DIBuilder_opaque; + pub use super::LLVMRustDIBuilderRef as DIBuilderRef; pub type DIDescriptor = MetadataRef; pub type DIScope = DIDescriptor; @@ -470,1266 +111,14 @@ pub mod debuginfo { pub type DIDerivedType = DIType; pub type DICompositeType = DIDerivedType; pub type DIVariable = DIDescriptor; + // FIXME: Rename 'DIGlobalVariable' to 'DIGlobalVariableExpression' + // once support for LLVM 3.9 is dropped. + // + // This method was changed in this LLVM patch: + // https://reviews.llvm.org/D26769 pub type DIGlobalVariable = DIDescriptor; pub type DIArray = DIDescriptor; pub type DISubrange = DIDescriptor; pub type DIEnumerator = DIDescriptor; pub type DITemplateTypeParameter = DIDescriptor; - - // These values **must** match with LLVMRustDIFlags!! - bitflags! { - #[repr(C)] - #[derive(Default)] - pub struct DIFlags: ::libc::uint32_t { - const FlagZero = 0; - const FlagPrivate = 1; - const FlagProtected = 2; - const FlagPublic = 3; - const FlagFwdDecl = (1 << 2); - const FlagAppleBlock = (1 << 3); - const FlagBlockByrefStruct = (1 << 4); - const FlagVirtual = (1 << 5); - const FlagArtificial = (1 << 6); - const FlagExplicit = (1 << 7); - const FlagPrototyped = (1 << 8); - const FlagObjcClassComplete = (1 << 9); - const FlagObjectPointer = (1 << 10); - const FlagVector = (1 << 11); - const FlagStaticMember = (1 << 12); - const FlagLValueReference = (1 << 13); - const FlagRValueReference = (1 << 14); - const FlagMainSubprogram = (1 << 21); - } - } -} - -pub enum ModuleBuffer {} - -// Link to our native llvm bindings (things that we need to use the C++ api -// for) and because llvm is written in C++ we need to link against libstdc++ -// -// You'll probably notice that there is an omission of all LLVM libraries -// from this location. This is because the set of LLVM libraries that we -// link to is mostly defined by LLVM, and the `llvm-config` tool is used to -// figure out the exact set of libraries. To do this, the build system -// generates an llvmdeps.rs file next to this one which will be -// automatically updated whenever LLVM is updated to include an up-to-date -// set of the libraries we need to link to LLVM for. -#[link(name = "rustllvm", kind = "static")] // not quite true but good enough -extern "C" { - // Create and destroy contexts. - pub fn LLVMContextCreate() -> ContextRef; - pub fn LLVMContextDispose(C: ContextRef); - pub fn LLVMGetMDKindIDInContext(C: ContextRef, Name: *const c_char, SLen: c_uint) -> c_uint; - - // Create and destroy modules. - pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char, C: ContextRef) -> ModuleRef; - pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef; - pub fn LLVMCloneModule(M: ModuleRef) -> ModuleRef; - pub fn LLVMDisposeModule(M: ModuleRef); - - /// Data layout. See Module::getDataLayout. - pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char; - pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char); - - /// See Module::dump. - pub fn LLVMDumpModule(M: ModuleRef); - - /// See Module::setModuleInlineAsm. - pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char); - pub fn LLVMRustAppendModuleInlineAsm(M: ModuleRef, Asm: *const c_char); - - /// See llvm::LLVMTypeKind::getTypeID. - pub fn LLVMRustGetTypeKind(Ty: TypeRef) -> TypeKind; - - /// See llvm::Value::getContext - pub fn LLVMRustGetValueContext(V: ValueRef) -> ContextRef; - - // Operations on integer types - pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef; - pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef; - pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef; - pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef; - pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef; - pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint) -> TypeRef; - - pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint; - - // Operations on real types - pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef; - pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef; - - // Operations on function types - pub fn LLVMFunctionType(ReturnType: TypeRef, - ParamTypes: *const TypeRef, - ParamCount: c_uint, - IsVarArg: Bool) - -> TypeRef; - pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef; - pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint; - pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef); - - // Operations on struct types - pub fn LLVMStructTypeInContext(C: ContextRef, - ElementTypes: *const TypeRef, - ElementCount: c_uint, - Packed: Bool) - -> TypeRef; - pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool; - - // Operations on array, pointer, and vector types (sequence types) - pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef; - pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint) -> TypeRef; - pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint) -> TypeRef; - - pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef; - pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint; - - // Operations on other types - pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef; - pub fn LLVMX86MMXTypeInContext(C: ContextRef) -> TypeRef; - pub fn LLVMRustMetadataTypeInContext(C: ContextRef) -> TypeRef; - - // Operations on all values - pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef; - pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char; - pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char); - pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef); - pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef); - - // Operations on Uses - pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef; - pub fn LLVMGetNextUse(U: UseRef) -> UseRef; - pub fn LLVMGetUser(U: UseRef) -> ValueRef; - - // Operations on Users - pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef; - - // Operations on constants of any type - pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef; - pub fn LLVMConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef; - pub fn LLVMConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef; - pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef; - - // Operations on metadata - pub fn LLVMMDStringInContext(C: ContextRef, Str: *const c_char, SLen: c_uint) -> ValueRef; - pub fn LLVMMDNodeInContext(C: ContextRef, Vals: *const ValueRef, Count: c_uint) -> ValueRef; - pub fn LLVMAddNamedMetadataOperand(M: ModuleRef, Name: *const c_char, Val: ValueRef); - - // Operations on scalar constants - pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool) -> ValueRef; - pub fn LLVMConstIntOfArbitraryPrecision(IntTy: TypeRef, Wn: c_uint, Ws: *const u64) -> ValueRef; - pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong; - pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong; - pub fn LLVMRustConstInt128Get(ConstantVal: ValueRef, SExt: bool, - high: *mut u64, low: *mut u64) -> bool; - - - // Operations on composite constants - pub fn LLVMConstStringInContext(C: ContextRef, - Str: *const c_char, - Length: c_uint, - DontNullTerminate: Bool) - -> ValueRef; - pub fn LLVMConstStructInContext(C: ContextRef, - ConstantVals: *const ValueRef, - Count: c_uint, - Packed: Bool) - -> ValueRef; - - pub fn LLVMConstArray(ElementTy: TypeRef, - ConstantVals: *const ValueRef, - Length: c_uint) - -> ValueRef; - pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint) -> ValueRef; - - // Constant expressions - pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef; - pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef; - pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef; - pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef; - pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef; - pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstIntCast(ConstantVal: ValueRef, ToType: TypeRef, isSigned: Bool) -> ValueRef; - pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstExtractValue(AggConstant: ValueRef, - IdxList: *const c_uint, - NumIdx: c_uint) - -> ValueRef; - pub fn LLVMConstInlineAsm(Ty: TypeRef, - AsmString: *const c_char, - Constraints: *const c_char, - HasSideEffects: Bool, - IsAlignStack: Bool) - -> ValueRef; - - - // Operations on global variables, functions, and aliases (globals) - pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef; - pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool; - pub fn LLVMRustGetLinkage(Global: ValueRef) -> Linkage; - pub fn LLVMRustSetLinkage(Global: ValueRef, RustLinkage: Linkage); - pub fn LLVMGetSection(Global: ValueRef) -> *const c_char; - pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char); - pub fn LLVMRustGetVisibility(Global: ValueRef) -> Visibility; - pub fn LLVMRustSetVisibility(Global: ValueRef, Viz: Visibility); - pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint; - pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint); - pub fn LLVMSetDLLStorageClass(V: ValueRef, C: DLLStorageClass); - - - // Operations on global variables - pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef; - pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char) -> ValueRef; - pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef; - pub fn LLVMRustGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef; - pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef; - pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef; - pub fn LLVMDeleteGlobal(GlobalVar: ValueRef); - pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef; - pub fn LLVMSetInitializer(GlobalVar: ValueRef, ConstantVal: ValueRef); - pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool); - pub fn LLVMSetThreadLocalMode(GlobalVar: ValueRef, Mode: ThreadLocalMode); - pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool; - pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool); - pub fn LLVMRustGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef; - pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool); - - // Operations on functions - pub fn LLVMAddFunction(M: ModuleRef, Name: *const c_char, FunctionTy: TypeRef) -> ValueRef; - pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef; - pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef; - pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef; - pub fn LLVMRustGetOrInsertFunction(M: ModuleRef, - Name: *const c_char, - FunctionTy: TypeRef) - -> ValueRef; - pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint); - pub fn LLVMRustAddAlignmentAttr(Fn: ValueRef, index: c_uint, bytes: u32); - pub fn LLVMRustAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: u64); - pub fn LLVMRustAddDereferenceableOrNullAttr(Fn: ValueRef, index: c_uint, bytes: u64); - pub fn LLVMRustAddFunctionAttribute(Fn: ValueRef, index: c_uint, attr: Attribute); - pub fn LLVMRustAddFunctionAttrStringValue(Fn: ValueRef, - index: c_uint, - Name: *const c_char, - Value: *const c_char); - pub fn LLVMRustRemoveFunctionAttributes(Fn: ValueRef, index: c_uint, attr: Attribute); - - // Operations on parameters - pub fn LLVMCountParams(Fn: ValueRef) -> c_uint; - pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef; - - // Operations on basic blocks - pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef; - pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef; - pub fn LLVMAppendBasicBlockInContext(C: ContextRef, - Fn: ValueRef, - Name: *const c_char) - -> BasicBlockRef; - pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef); - - // Operations on instructions - pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef; - pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef; - pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef; - pub fn LLVMInstructionEraseFromParent(Inst: ValueRef); - - // Operations on call sites - pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint); - pub fn LLVMRustAddCallSiteAttribute(Instr: ValueRef, index: c_uint, attr: Attribute); - pub fn LLVMRustAddAlignmentCallSiteAttr(Instr: ValueRef, index: c_uint, bytes: u32); - pub fn LLVMRustAddDereferenceableCallSiteAttr(Instr: ValueRef, index: c_uint, bytes: u64); - pub fn LLVMRustAddDereferenceableOrNullCallSiteAttr(Instr: ValueRef, - index: c_uint, - bytes: u64); - - // Operations on load/store instructions (only) - pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool); - - // Operations on phi nodes - pub fn LLVMAddIncoming(PhiNode: ValueRef, - IncomingValues: *const ValueRef, - IncomingBlocks: *const BasicBlockRef, - Count: c_uint); - - // Instruction builders - pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef; - pub fn LLVMPositionBuilder(Builder: BuilderRef, Block: BasicBlockRef, Instr: ValueRef); - pub fn LLVMPositionBuilderBefore(Builder: BuilderRef, Instr: ValueRef); - pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef, Block: BasicBlockRef); - pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef; - pub fn LLVMDisposeBuilder(Builder: BuilderRef); - - // Metadata - pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef); - pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef; - pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef); - - // Terminators - pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef; - pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef; - pub fn LLVMBuildAggregateRet(B: BuilderRef, RetVals: *const ValueRef, N: c_uint) -> ValueRef; - pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef; - pub fn LLVMBuildCondBr(B: BuilderRef, - If: ValueRef, - Then: BasicBlockRef, - Else: BasicBlockRef) - -> ValueRef; - pub fn LLVMBuildSwitch(B: BuilderRef, - V: ValueRef, - Else: BasicBlockRef, - NumCases: c_uint) - -> ValueRef; - pub fn LLVMBuildIndirectBr(B: BuilderRef, Addr: ValueRef, NumDests: c_uint) -> ValueRef; - pub fn LLVMRustBuildInvoke(B: BuilderRef, - Fn: ValueRef, - Args: *const ValueRef, - NumArgs: c_uint, - Then: BasicBlockRef, - Catch: BasicBlockRef, - Bundle: OperandBundleDefRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMRustBuildLandingPad(B: BuilderRef, - Ty: TypeRef, - PersFn: ValueRef, - NumClauses: c_uint, - Name: *const c_char, - F: ValueRef) - -> ValueRef; - pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef; - pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef; - - pub fn LLVMRustBuildCleanupPad(B: BuilderRef, - ParentPad: ValueRef, - ArgCnt: c_uint, - Args: *const ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMRustBuildCleanupRet(B: BuilderRef, - CleanupPad: ValueRef, - UnwindBB: BasicBlockRef) - -> ValueRef; - pub fn LLVMRustBuildCatchPad(B: BuilderRef, - ParentPad: ValueRef, - ArgCnt: c_uint, - Args: *const ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMRustBuildCatchRet(B: BuilderRef, Pad: ValueRef, BB: BasicBlockRef) -> ValueRef; - pub fn LLVMRustBuildCatchSwitch(Builder: BuilderRef, - ParentPad: ValueRef, - BB: BasicBlockRef, - NumHandlers: c_uint, - Name: *const c_char) - -> ValueRef; - pub fn LLVMRustAddHandler(CatchSwitch: ValueRef, Handler: BasicBlockRef); - pub fn LLVMSetPersonalityFn(Func: ValueRef, Pers: ValueRef); - - // Add a case to the switch instruction - pub fn LLVMAddCase(Switch: ValueRef, OnVal: ValueRef, Dest: BasicBlockRef); - - // Add a clause to the landing pad instruction - pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef); - - // Set the cleanup on a landing pad instruction - pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool); - - // Arithmetic - pub fn LLVMBuildAdd(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildNSWAdd(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildNUWAdd(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildFAdd(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildSub(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildNSWSub(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildNUWSub(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildFSub(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildMul(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildNSWMul(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildNUWMul(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildFMul(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildUDiv(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildSDiv(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildExactSDiv(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildFDiv(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildURem(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildSRem(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildFRem(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildShl(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildLShr(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildAShr(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildAnd(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildOr(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildXor(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildBinOp(B: BuilderRef, - Op: Opcode, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char) -> ValueRef; - pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char) -> ValueRef; - pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char) -> ValueRef; - pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char) -> ValueRef; - pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char) -> ValueRef; - pub fn LLVMRustSetHasUnsafeAlgebra(Instr: ValueRef); - - // Memory - pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char) -> ValueRef; - pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef; - pub fn LLVMBuildLoad(B: BuilderRef, PointerVal: ValueRef, Name: *const c_char) -> ValueRef; - - pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef) -> ValueRef; - - pub fn LLVMBuildGEP(B: BuilderRef, - Pointer: ValueRef, - Indices: *const ValueRef, - NumIndices: c_uint, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildInBoundsGEP(B: BuilderRef, - Pointer: ValueRef, - Indices: *const ValueRef, - NumIndices: c_uint, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildStructGEP(B: BuilderRef, - Pointer: ValueRef, - Idx: c_uint, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildGlobalString(B: BuilderRef, - Str: *const c_char, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildGlobalStringPtr(B: BuilderRef, - Str: *const c_char, - Name: *const c_char) - -> ValueRef; - - // Casts - pub fn LLVMBuildTrunc(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildZExt(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildSExt(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildFPToUI(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildFPToSI(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildUIToFP(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildSIToFP(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildFPTrunc(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildFPExt(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildPtrToInt(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildIntToPtr(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildBitCast(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildZExtOrBitCast(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildSExtOrBitCast(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildTruncOrBitCast(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildCast(B: BuilderRef, - Op: Opcode, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildPointerCast(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMRustBuildIntCast(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - IsSized: bool) - -> ValueRef; - pub fn LLVMBuildFPCast(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> ValueRef; - - // Comparisons - pub fn LLVMBuildICmp(B: BuilderRef, - Op: c_uint, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildFCmp(B: BuilderRef, - Op: c_uint, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - - // Miscellaneous instructions - pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char) -> ValueRef; - pub fn LLVMRustBuildCall(B: BuilderRef, - Fn: ValueRef, - Args: *const ValueRef, - NumArgs: c_uint, - Bundle: OperandBundleDefRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildSelect(B: BuilderRef, - If: ValueRef, - Then: ValueRef, - Else: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildVAArg(B: BuilderRef, - list: ValueRef, - Ty: TypeRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildExtractElement(B: BuilderRef, - VecVal: ValueRef, - Index: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildInsertElement(B: BuilderRef, - VecVal: ValueRef, - EltVal: ValueRef, - Index: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildShuffleVector(B: BuilderRef, - V1: ValueRef, - V2: ValueRef, - Mask: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildExtractValue(B: BuilderRef, - AggVal: ValueRef, - Index: c_uint, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildInsertValue(B: BuilderRef, - AggVal: ValueRef, - EltVal: ValueRef, - Index: c_uint, - Name: *const c_char) - -> ValueRef; - - pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char) -> ValueRef; - pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char) -> ValueRef; - pub fn LLVMBuildPtrDiff(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - - // Atomic Operations - pub fn LLVMRustBuildAtomicLoad(B: BuilderRef, - PointerVal: ValueRef, - Name: *const c_char, - Order: AtomicOrdering) - -> ValueRef; - - pub fn LLVMRustBuildAtomicStore(B: BuilderRef, - Val: ValueRef, - Ptr: ValueRef, - Order: AtomicOrdering) - -> ValueRef; - - pub fn LLVMRustBuildAtomicCmpXchg(B: BuilderRef, - LHS: ValueRef, - CMP: ValueRef, - RHS: ValueRef, - Order: AtomicOrdering, - FailureOrder: AtomicOrdering, - Weak: Bool) - -> ValueRef; - - pub fn LLVMBuildAtomicRMW(B: BuilderRef, - Op: AtomicRmwBinOp, - LHS: ValueRef, - RHS: ValueRef, - Order: AtomicOrdering, - SingleThreaded: Bool) - -> ValueRef; - - pub fn LLVMRustBuildAtomicFence(B: BuilderRef, - Order: AtomicOrdering, - Scope: SynchronizationScope); - - - // Selected entries from the downcasts. - pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef; - pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef; - - /// Writes a module to the specified path. Returns 0 on success. - pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int; - - /// Creates target data from a target layout string. - pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef; - - /// Disposes target data. - pub fn LLVMDisposeTargetData(TD: TargetDataRef); - - /// Creates a pass manager. - pub fn LLVMCreatePassManager() -> PassManagerRef; - - /// Creates a function-by-function pass manager - pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef) -> PassManagerRef; - - /// Disposes a pass manager. - pub fn LLVMDisposePassManager(PM: PassManagerRef); - - /// Runs a pass manager on a module. - pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool; - - pub fn LLVMInitializePasses(); - - pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef; - pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef); - pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef, Value: Bool); - pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: PassManagerBuilderRef, Value: Bool); - pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(PMB: PassManagerBuilderRef, - threshold: c_uint); - pub fn LLVMPassManagerBuilderPopulateModulePassManager(PMB: PassManagerBuilderRef, - PM: PassManagerRef); - - pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(PMB: PassManagerBuilderRef, - PM: PassManagerRef); - pub fn LLVMPassManagerBuilderPopulateLTOPassManager(PMB: PassManagerBuilderRef, - PM: PassManagerRef, - Internalize: Bool, - RunInliner: Bool); - pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager( - PMB: PassManagerBuilderRef, - PM: PassManagerRef) -> bool; - - // Stuff that's in rustllvm/ because it's not upstream yet. - - /// Opens an object file. - pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef; - /// Closes an object file. - pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef); - - /// Enumerates the sections in an object file. - pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef; - /// Destroys a section iterator. - pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef); - /// Returns true if the section iterator is at the end of the section - /// list: - pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef, SI: SectionIteratorRef) -> Bool; - /// Moves the section iterator to point to the next section. - pub fn LLVMMoveToNextSection(SI: SectionIteratorRef); - /// Returns the current section size. - pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong; - /// Returns the current section contents as a string buffer. - pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char; - - /// Reads the given file and returns it as a memory buffer. Use - /// LLVMDisposeMemoryBuffer() to get rid of it. - pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char) -> MemoryBufferRef; - - pub fn LLVMStartMultithreaded() -> Bool; - - /// Returns a string describing the last error caused by an LLVMRust* call. - pub fn LLVMRustGetLastError() -> *const c_char; - - /// Print the pass timings since static dtors aren't picking them up. - pub fn LLVMRustPrintPassTimings(); - - pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef; - - pub fn LLVMStructSetBody(StructTy: TypeRef, - ElementTypes: *const TypeRef, - ElementCount: c_uint, - Packed: Bool); - - /// Enables LLVM debug output. - pub fn LLVMRustSetDebug(Enabled: c_int); - - /// Prepares inline assembly. - pub fn LLVMRustInlineAsm(Ty: TypeRef, - AsmString: *const c_char, - Constraints: *const c_char, - SideEffects: Bool, - AlignStack: Bool, - Dialect: AsmDialect) - -> ValueRef; - - pub fn LLVMRustDebugMetadataVersion() -> u32; - pub fn LLVMRustVersionMajor() -> u32; - pub fn LLVMRustVersionMinor() -> u32; - - pub fn LLVMRustAddModuleFlag(M: ModuleRef, name: *const c_char, value: u32); - - pub fn LLVMRustMetadataAsValue(C: ContextRef, MD: MetadataRef) -> ValueRef; - - pub fn LLVMRustDIBuilderCreate(M: ModuleRef) -> DIBuilderRef; - - pub fn LLVMRustDIBuilderDispose(Builder: DIBuilderRef); - - pub fn LLVMRustDIBuilderFinalize(Builder: DIBuilderRef); - - pub fn LLVMRustDIBuilderCreateCompileUnit(Builder: DIBuilderRef, - Lang: c_uint, - File: DIFile, - Producer: *const c_char, - isOptimized: bool, - Flags: *const c_char, - RuntimeVer: c_uint, - SplitName: *const c_char) - -> DIDescriptor; - - pub fn LLVMRustDIBuilderCreateFile(Builder: DIBuilderRef, - Filename: *const c_char, - Directory: *const c_char) - -> DIFile; - - pub fn LLVMRustDIBuilderCreateSubroutineType(Builder: DIBuilderRef, - File: DIFile, - ParameterTypes: DIArray) - -> DICompositeType; - - pub fn LLVMRustDIBuilderCreateFunction(Builder: DIBuilderRef, - Scope: DIDescriptor, - Name: *const c_char, - LinkageName: *const c_char, - File: DIFile, - LineNo: c_uint, - Ty: DIType, - isLocalToUnit: bool, - isDefinition: bool, - ScopeLine: c_uint, - Flags: DIFlags, - isOptimized: bool, - Fn: ValueRef, - TParam: DIArray, - Decl: DIDescriptor) - -> DISubprogram; - - pub fn LLVMRustDIBuilderCreateBasicType(Builder: DIBuilderRef, - Name: *const c_char, - SizeInBits: u64, - AlignInBits: u32, - Encoding: c_uint) - -> DIBasicType; - - pub fn LLVMRustDIBuilderCreatePointerType(Builder: DIBuilderRef, - PointeeTy: DIType, - SizeInBits: u64, - AlignInBits: u32, - Name: *const c_char) - -> DIDerivedType; - - pub fn LLVMRustDIBuilderCreateStructType(Builder: DIBuilderRef, - Scope: DIDescriptor, - Name: *const c_char, - File: DIFile, - LineNumber: c_uint, - SizeInBits: u64, - AlignInBits: u32, - Flags: DIFlags, - DerivedFrom: DIType, - Elements: DIArray, - RunTimeLang: c_uint, - VTableHolder: DIType, - UniqueId: *const c_char) - -> DICompositeType; - - pub fn LLVMRustDIBuilderCreateMemberType(Builder: DIBuilderRef, - Scope: DIDescriptor, - Name: *const c_char, - File: DIFile, - LineNo: c_uint, - SizeInBits: u64, - AlignInBits: u32, - OffsetInBits: u64, - Flags: DIFlags, - Ty: DIType) - -> DIDerivedType; - - pub fn LLVMRustDIBuilderCreateLexicalBlock(Builder: DIBuilderRef, - Scope: DIScope, - File: DIFile, - Line: c_uint, - Col: c_uint) - -> DILexicalBlock; - - pub fn LLVMRustDIBuilderCreateLexicalBlockFile(Builder: DIBuilderRef, - Scope: DIScope, - File: DIFile) - -> DILexicalBlock; - - pub fn LLVMRustDIBuilderCreateStaticVariable(Builder: DIBuilderRef, - Context: DIScope, - Name: *const c_char, - LinkageName: *const c_char, - File: DIFile, - LineNo: c_uint, - Ty: DIType, - isLocalToUnit: bool, - Val: ValueRef, - Decl: DIDescriptor, - AlignInBits: u32) - -> DIGlobalVariable; - - pub fn LLVMRustDIBuilderCreateVariable(Builder: DIBuilderRef, - Tag: c_uint, - Scope: DIDescriptor, - Name: *const c_char, - File: DIFile, - LineNo: c_uint, - Ty: DIType, - AlwaysPreserve: bool, - Flags: DIFlags, - ArgNo: c_uint, - AlignInBits: u32) - -> DIVariable; - - pub fn LLVMRustDIBuilderCreateArrayType(Builder: DIBuilderRef, - Size: u64, - AlignInBits: u32, - Ty: DIType, - Subscripts: DIArray) - -> DIType; - - pub fn LLVMRustDIBuilderCreateVectorType(Builder: DIBuilderRef, - Size: u64, - AlignInBits: u32, - Ty: DIType, - Subscripts: DIArray) - -> DIType; - - pub fn LLVMRustDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef, - Lo: i64, - Count: i64) - -> DISubrange; - - pub fn LLVMRustDIBuilderGetOrCreateArray(Builder: DIBuilderRef, - Ptr: *const DIDescriptor, - Count: c_uint) - -> DIArray; - - pub fn LLVMRustDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef, - Val: ValueRef, - VarInfo: DIVariable, - AddrOps: *const i64, - AddrOpsCount: c_uint, - DL: ValueRef, - InsertAtEnd: BasicBlockRef) - -> ValueRef; - - pub fn LLVMRustDIBuilderCreateEnumerator(Builder: DIBuilderRef, - Name: *const c_char, - Val: u64) - -> DIEnumerator; - - pub fn LLVMRustDIBuilderCreateEnumerationType(Builder: DIBuilderRef, - Scope: DIScope, - Name: *const c_char, - File: DIFile, - LineNumber: c_uint, - SizeInBits: u64, - AlignInBits: u32, - Elements: DIArray, - ClassType: DIType) - -> DIType; - - pub fn LLVMRustDIBuilderCreateUnionType(Builder: DIBuilderRef, - Scope: DIScope, - Name: *const c_char, - File: DIFile, - LineNumber: c_uint, - SizeInBits: u64, - AlignInBits: u32, - Flags: DIFlags, - Elements: DIArray, - RunTimeLang: c_uint, - UniqueId: *const c_char) - -> DIType; - - pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool); - - pub fn LLVMRustDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef, - Scope: DIScope, - Name: *const c_char, - Ty: DIType, - File: DIFile, - LineNo: c_uint, - ColumnNo: c_uint) - -> DITemplateTypeParameter; - - - pub fn LLVMRustDIBuilderCreateNameSpace(Builder: DIBuilderRef, - Scope: DIScope, - Name: *const c_char, - File: DIFile, - LineNo: c_uint) - -> DINameSpace; - pub fn LLVMRustDICompositeTypeSetTypeArray(Builder: DIBuilderRef, - CompositeType: DIType, - TypeArray: DIArray); - - - pub fn LLVMRustDIBuilderCreateDebugLocation(Context: ContextRef, - Line: c_uint, - Column: c_uint, - Scope: DIScope, - InlinedAt: MetadataRef) - -> ValueRef; - pub fn LLVMRustDIBuilderCreateOpDeref() -> i64; - pub fn LLVMRustDIBuilderCreateOpPlus() -> i64; - - pub fn LLVMRustWriteTypeToString(Type: TypeRef, s: RustStringRef); - pub fn LLVMRustWriteValueToString(value_ref: ValueRef, s: RustStringRef); - - pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef; - - pub fn LLVMRustPassKind(Pass: PassRef) -> PassKind; - pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> PassRef; - pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: PassRef); - - pub fn LLVMRustHasFeature(T: TargetMachineRef, s: *const c_char) -> bool; - - pub fn LLVMRustPrintTargetCPUs(T: TargetMachineRef); - pub fn LLVMRustPrintTargetFeatures(T: TargetMachineRef); - - pub fn LLVMRustCreateTargetMachine(Triple: *const c_char, - CPU: *const c_char, - Features: *const c_char, - Model: CodeModel, - Reloc: RelocMode, - Level: CodeGenOptLevel, - UseSoftFP: bool, - PositionIndependentExecutable: bool, - FunctionSections: bool, - DataSections: bool, - TrapUnreachable: bool, - Singlethread: bool) - -> TargetMachineRef; - pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef); - pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef, PM: PassManagerRef, M: ModuleRef); - pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef, - M: ModuleRef, - DisableSimplifyLibCalls: bool); - pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef, - OptLevel: CodeGenOptLevel, - MergeFunctions: bool, - SLPVectorize: bool, - LoopVectorize: bool); - pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, - M: ModuleRef, - DisableSimplifyLibCalls: bool); - pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef); - pub fn LLVMRustWriteOutputFile(T: TargetMachineRef, - PM: PassManagerRef, - M: ModuleRef, - Output: *const c_char, - FileType: FileType) - -> LLVMRustResult; - pub fn LLVMRustPrintModule(PM: PassManagerRef, - M: ModuleRef, - Output: *const c_char, - Demangle: extern fn(*const c_char, - size_t, - *mut c_char, - size_t) -> size_t); - pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char); - pub fn LLVMRustPrintPasses(); - pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char); - pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef, AddLifetimes: bool); - pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef, bc: *const c_char, len: size_t) -> bool; - pub fn LLVMRustLinkInParsedExternalBitcode(M: ModuleRef, M: ModuleRef) -> bool; - pub fn LLVMRustRunRestrictionPass(M: ModuleRef, syms: *const *const c_char, len: size_t); - pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef); - - pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef; - pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef; - pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef; - pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef, size: *mut size_t) -> *const c_char; - pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef, size: *mut size_t) -> *const c_char; - pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef); - pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef); - pub fn LLVMRustDestroyArchive(AR: ArchiveRef); - - pub fn LLVMRustGetSectionName(SI: SectionIteratorRef, data: *mut *const c_char) -> size_t; - - pub fn LLVMRustWriteTwineToString(T: TwineRef, s: RustStringRef); - - pub fn LLVMContextSetDiagnosticHandler(C: ContextRef, - Handler: DiagnosticHandler, - DiagnosticContext: *mut c_void); - - pub fn LLVMRustUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef, - pass_name_out: RustStringRef, - function_out: *mut ValueRef, - loc_line_out: *mut c_uint, - loc_column_out: *mut c_uint, - loc_filename_out: RustStringRef, - message_out: RustStringRef); - pub fn LLVMRustUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef, - cookie_out: *mut c_uint, - message_out: *mut TwineRef, - instruction_out: *mut ValueRef); - - pub fn LLVMRustWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef); - pub fn LLVMRustGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind; - - pub fn LLVMRustWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef); - - pub fn LLVMRustSetInlineAsmDiagnosticHandler(C: ContextRef, - H: InlineAsmDiagHandler, - CX: *mut c_void); - - pub fn LLVMRustWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef); - - pub fn LLVMRustWriteArchive(Dst: *const c_char, - NumMembers: size_t, - Members: *const RustArchiveMemberRef, - WriteSymbtab: bool, - Kind: ArchiveKind) - -> LLVMRustResult; - pub fn LLVMRustArchiveMemberNew(Filename: *const c_char, - Name: *const c_char, - Child: ArchiveChildRef) - -> RustArchiveMemberRef; - pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef); - - pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef, TM: TargetMachineRef); - pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef; - - pub fn LLVMRustBuildOperandBundleDef(Name: *const c_char, - Inputs: *const ValueRef, - NumInputs: c_uint) - -> OperandBundleDefRef; - pub fn LLVMRustFreeOperandBundleDef(Bundle: OperandBundleDefRef); - - pub fn LLVMRustPositionBuilderAtStart(B: BuilderRef, BB: BasicBlockRef); - - pub fn LLVMRustSetComdat(M: ModuleRef, V: ValueRef, Name: *const c_char); - pub fn LLVMRustUnsetComdat(V: ValueRef); - pub fn LLVMRustSetModulePIELevel(M: ModuleRef); - pub fn LLVMRustModuleBufferCreate(M: ModuleRef) -> *mut ModuleBuffer; - pub fn LLVMRustModuleBufferPtr(p: *const ModuleBuffer) -> *const u8; - pub fn LLVMRustModuleBufferLen(p: *const ModuleBuffer) -> usize; - pub fn LLVMRustModuleBufferFree(p: *mut ModuleBuffer); - pub fn LLVMRustModuleCost(M: ModuleRef) -> u64; - - pub fn LLVMRustThinLTOAvailable() -> bool; - pub fn LLVMRustWriteThinBitcodeToFile(PMR: PassManagerRef, - M: ModuleRef, - BC: *const c_char) -> bool; - pub fn LLVMRustThinLTOBufferCreate(M: ModuleRef) -> *mut ThinLTOBuffer; - pub fn LLVMRustThinLTOBufferFree(M: *mut ThinLTOBuffer); - pub fn LLVMRustThinLTOBufferPtr(M: *const ThinLTOBuffer) -> *const c_char; - pub fn LLVMRustThinLTOBufferLen(M: *const ThinLTOBuffer) -> size_t; - pub fn LLVMRustCreateThinLTOData( - Modules: *const ThinLTOModule, - NumModules: c_uint, - PreservedSymbols: *const *const c_char, - PreservedSymbolsLen: c_uint, - ) -> *mut ThinLTOData; - pub fn LLVMRustPrepareThinLTORename( - Data: *const ThinLTOData, - Module: ModuleRef, - ) -> bool; - pub fn LLVMRustPrepareThinLTOResolveWeak( - Data: *const ThinLTOData, - Module: ModuleRef, - ) -> bool; - pub fn LLVMRustPrepareThinLTOInternalize( - Data: *const ThinLTOData, - Module: ModuleRef, - ) -> bool; - pub fn LLVMRustPrepareThinLTOImport( - Data: *const ThinLTOData, - Module: ModuleRef, - ) -> bool; - pub fn LLVMRustFreeThinLTOData(Data: *mut ThinLTOData); - pub fn LLVMRustParseBitcodeForThinLTO( - Context: ContextRef, - Data: *const u8, - len: usize, - Identifier: *const c_char, - ) -> ModuleRef; - pub fn LLVMGetModuleIdentifier(M: ModuleRef, size: *mut usize) -> *const c_char; } diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 592bd62056455..34518699e4a24 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -20,22 +20,13 @@ #![feature(box_syntax)] #![feature(concat_idents)] +#![feature(const_fn)] #![feature(libc)] #![feature(link_args)] #![feature(static_nobundle)] -// See librustc_cratesio_shim/Cargo.toml for a comment explaining this. -#[allow(unused_extern_crates)] -extern crate rustc_cratesio_shim; - -#[macro_use] -extern crate bitflags; extern crate libc; -pub use self::IntPredicate::*; -pub use self::RealPredicate::*; -pub use self::TypeKind::*; -pub use self::AtomicRmwBinOp::*; pub use self::MetadataType::*; pub use self::CodeGenOptSize::*; pub use self::CallConv::*; @@ -104,18 +95,15 @@ impl FromStr for ArchiveKind { fn from_str(s: &str) -> Result { match s { - "gnu" => Ok(ArchiveKind::K_GNU), - "mips64" => Ok(ArchiveKind::K_MIPS64), - "bsd" => Ok(ArchiveKind::K_BSD), - "coff" => Ok(ArchiveKind::K_COFF), + "gnu" => Ok(ArchiveKind::GNU), + "mips64" => Ok(ArchiveKind::MIPS64), + "bsd" => Ok(ArchiveKind::BSD), + "coff" => Ok(ArchiveKind::COFF), _ => Err(()), } } } -#[allow(missing_copy_implementations)] -pub enum RustString_opaque {} -type RustStringRef = *mut RustString_opaque; type RustStringRepr = *mut RefCell>; /// Appending to a Rust string -- used by RawRustStringOstream. @@ -409,7 +397,11 @@ impl OperandBundleDef { pub fn new(name: &str, vals: &[ValueRef]) -> OperandBundleDef { let name = CString::new(name).unwrap(); let def = unsafe { - LLVMRustBuildOperandBundleDef(name.as_ptr(), vals.as_ptr(), vals.len() as c_uint) + LLVMRustBuildOperandBundleDef( + name.as_ptr(), + vals.as_ptr() as *mut _, + vals.len() as c_uint, + ) }; OperandBundleDef { inner: def } } diff --git a/src/librustc_trans/abi.rs b/src/librustc_trans/abi.rs index 1cd138d4ee6e9..46ece8c8a8907 100644 --- a/src/librustc_trans/abi.rs +++ b/src/librustc_trans/abi.rs @@ -695,26 +695,26 @@ impl<'a, 'tcx> FnType<'tcx> { use self::Abi::*; let cconv = match ccx.sess().target.target.adjust_abi(sig.abi) { RustIntrinsic | PlatformIntrinsic | - Rust | RustCall => llvm::CCallConv, + Rust | RustCall => llvm::CallConv::C, // It's the ABI's job to select this, not us. System => bug!("system abi should be selected elsewhere"), - Stdcall => llvm::X86StdcallCallConv, - Fastcall => llvm::X86FastcallCallConv, - Vectorcall => llvm::X86_VectorCall, - Thiscall => llvm::X86_ThisCall, - C => llvm::CCallConv, - Unadjusted => llvm::CCallConv, - Win64 => llvm::X86_64_Win64, - SysV64 => llvm::X86_64_SysV, - Aapcs => llvm::ArmAapcsCallConv, - PtxKernel => llvm::PtxKernel, - Msp430Interrupt => llvm::Msp430Intr, - X86Interrupt => llvm::X86_Intr, + Stdcall => llvm::X86_StdCall, + Fastcall => llvm::CallConv::X86_FastCall, + Vectorcall => llvm::CallConv::X86_VectorCall, + Thiscall => llvm::CallConv::X86_ThisCall, + C => llvm::CallConv::C, + Unadjusted => llvm::CallConv::C, + Win64 => llvm::CallConv::X86_64_Win64, + SysV64 => llvm::CallConv::X86_64_SysV, + Aapcs => llvm::CallConv::ARM_AAPCS, + PtxKernel => llvm::CallConv::PTX_Kernel, + Msp430Interrupt => llvm::CallConv::MSP430_INTR, + X86Interrupt => llvm::CallConv::X86_INTR, // These API constants ought to be more specific... - Cdecl => llvm::CCallConv, + Cdecl => llvm::CallConv::C, }; let mut inputs = sig.inputs(); @@ -1039,7 +1039,7 @@ impl<'a, 'tcx> FnType<'tcx> { } } - if self.cconv != llvm::CCallConv { + if self.cconv != llvm::CallConv::C { llvm::SetInstructionCallConv(callsite, self.cconv); } } diff --git a/src/librustc_trans/allocator.rs b/src/librustc_trans/allocator.rs index 9abb6d66f9c0f..d6b40b1a5208d 100644 --- a/src/librustc_trans/allocator.rs +++ b/src/librustc_trans/allocator.rs @@ -78,7 +78,7 @@ pub unsafe fn trans(tcx: TyCtxt, mods: &ModuleLlvm, kind: AllocatorKind) { AllocatorTy::Ptr => panic!("invalid allocator output"), }; let ty = llvm::LLVMFunctionType(output.unwrap_or(void), - args.as_ptr(), + args.as_mut_ptr(), args.len() as c_uint, False); let name = CString::new(format!("__rust_{}", method.name)).unwrap(); @@ -102,7 +102,7 @@ pub unsafe fn trans(tcx: TyCtxt, mods: &ModuleLlvm, kind: AllocatorKind) { }).collect::>(); let ret = llvm::LLVMRustBuildCall(llbuilder, callee, - args.as_ptr(), + args.as_ptr() as *mut _, args.len() as c_uint, ptr::null_mut(), "\0".as_ptr() as *const _); diff --git a/src/librustc_trans/asm.rs b/src/librustc_trans/asm.rs index 1959fd13ccb29..776c47d2020a9 100644 --- a/src/librustc_trans/asm.rs +++ b/src/librustc_trans/asm.rs @@ -115,7 +115,7 @@ pub fn trans_inline_asm<'a, 'tcx>( let val: llvm::ValueRef = C_i32(bcx.ccx, ia.ctxt.outer().as_u32() as i32); llvm::LLVMSetMetadata(r, kind, - llvm::LLVMMDNodeInContext(bcx.ccx.llcx(), &val, 1)); + llvm::LLVMMDNodeInContext(bcx.ccx.llcx(), &val as *const _ as *mut _, 1)); } } diff --git a/src/librustc_trans/back/lto.rs b/src/librustc_trans/back/lto.rs index 48c3fd638c36b..d47f5c2d34bef 100644 --- a/src/librustc_trans/back/lto.rs +++ b/src/librustc_trans/back/lto.rs @@ -346,7 +346,7 @@ fn thin_lto(diag_handler: &Handler, let buffer = ThinBuffer::new(llvm.llmod); thin_modules.push(llvm::ThinLTOModule { identifier: name.as_ptr(), - data: buffer.data().as_ptr(), + data: buffer.data().as_ptr() as *const _, len: buffer.data().len(), }); thin_buffers.push(buffer); @@ -375,7 +375,7 @@ fn thin_lto(diag_handler: &Handler, info!("foreign module {:?}", name); thin_modules.push(llvm::ThinLTOModule { identifier: name.as_ptr(), - data: module.data().as_ptr(), + data: module.data().as_ptr() as *const _, len: module.data().len(), }); serialized.push(module); @@ -508,7 +508,7 @@ impl ModuleBuffer { unsafe { let ptr = llvm::LLVMRustModuleBufferPtr(self.0); let len = llvm::LLVMRustModuleBufferLen(self.0); - slice::from_raw_parts(ptr, len) + slice::from_raw_parts(ptr as *const _, len) } } } @@ -609,7 +609,7 @@ impl ThinModule { let llcx = llvm::LLVMContextCreate(); let llmod = llvm::LLVMRustParseBitcodeForThinLTO( llcx, - self.data().as_ptr(), + self.data().as_ptr() as *const _, self.data().len(), self.shared.module_names[self.idx].as_ptr(), ); diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index da67940abcb77..ed1c59d91519f 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -50,14 +50,16 @@ use std::fs::{self, File}; use std::io; use std::io::{Read, Write}; use std::mem; +use std::os::raw::c_void; use std::path::{Path, PathBuf}; +use std::ptr; use std::str; use std::sync::Arc; use std::sync::mpsc::{channel, Sender, Receiver}; use std::slice; use std::time::Instant; use std::thread; -use libc::{c_uint, c_void, c_char, size_t}; +use libc::{c_uint, c_char, size_t}; pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 7] = [ ("pic", llvm::RelocMode::PIC), @@ -66,7 +68,7 @@ pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 7] = [ ("dynamic-no-pic", llvm::RelocMode::DynamicNoPic), ("ropi", llvm::RelocMode::ROPI), ("rwpi", llvm::RelocMode::RWPI), - ("ropi-rwpi", llvm::RelocMode::ROPI_RWPI), + ("ropi-rwpi", llvm::RelocMode::ROPIRWPI), ]; pub const CODE_GEN_MODEL_ARGS : [(&'static str, llvm::CodeModel); 5] = [ @@ -78,10 +80,10 @@ pub const CODE_GEN_MODEL_ARGS : [(&'static str, llvm::CodeModel); 5] = [ ]; pub const TLS_MODEL_ARGS : [(&'static str, llvm::ThreadLocalMode); 4] = [ - ("global-dynamic", llvm::ThreadLocalMode::GeneralDynamic), - ("local-dynamic", llvm::ThreadLocalMode::LocalDynamic), - ("initial-exec", llvm::ThreadLocalMode::InitialExec), - ("local-exec", llvm::ThreadLocalMode::LocalExec), + ("global-dynamic", llvm::ThreadLocalMode::LLVMGeneralDynamicTLSModel), + ("local-dynamic", llvm::ThreadLocalMode::LLVMLocalDynamicTLSModel), + ("initial-exec", llvm::ThreadLocalMode::LLVMInitialExecTLSModel), + ("local-exec", llvm::ThreadLocalMode::LLVMLocalExecTLSModel), ]; pub fn llvm_err(handler: &errors::Handler, msg: String) -> FatalError { @@ -398,8 +400,8 @@ impl<'a> DiagnosticHandlers<'a> { let data = Box::new((cgcx, handler)); unsafe { let arg = &*data as &(_, _) as *const _ as *mut _; - llvm::LLVMRustSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, arg); - llvm::LLVMContextSetDiagnosticHandler(llcx, diagnostic_handler, arg); + llvm::LLVMRustSetInlineAsmDiagnosticHandler(llcx, Some(inline_asm_handler), arg); + llvm::LLVMContextSetDiagnosticHandler(llcx, Some(diagnostic_handler), arg); } DiagnosticHandlers { inner: data, @@ -411,8 +413,16 @@ impl<'a> DiagnosticHandlers<'a> { impl<'a> Drop for DiagnosticHandlers<'a> { fn drop(&mut self) { unsafe { - llvm::LLVMRustSetInlineAsmDiagnosticHandler(self.llcx, inline_asm_handler, 0 as *mut _); - llvm::LLVMContextSetDiagnosticHandler(self.llcx, diagnostic_handler, 0 as *mut _); + llvm::LLVMRustSetInlineAsmDiagnosticHandler( + self.llcx, + Some(inline_asm_handler), + ptr::null_mut(), + ); + llvm::LLVMContextSetDiagnosticHandler( + self.llcx, + Some(diagnostic_handler), + ptr::null_mut(), + ); } } } @@ -424,7 +434,7 @@ unsafe extern "C" fn report_inline_asm<'a, 'b>(cgcx: &'a CodegenContext, } unsafe extern "C" fn inline_asm_handler(diag: SMDiagnosticRef, - user: *const c_void, + user: *mut c_void, cookie: c_uint) { if user.is_null() { return @@ -719,7 +729,7 @@ unsafe fn codegen(cgcx: &CodegenContext, } with_codegen(tm, llmod, config.no_builtins, |cpm| { - llvm::LLVMRustPrintModule(cpm, llmod, out.as_ptr(), demangle_callback); + llvm::LLVMRustPrintModule(cpm, llmod, out.as_ptr(), Some(demangle_callback)); llvm::LLVMDisposePassManager(cpm); }); timeline.record("ir"); diff --git a/src/librustc_trans/builder.rs b/src/librustc_trans/builder.rs index e40311af595cd..118a57f2aa0ec 100644 --- a/src/librustc_trans/builder.rs +++ b/src/librustc_trans/builder.rs @@ -155,7 +155,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { pub fn aggregate_ret(&self, ret_vals: &[ValueRef]) { unsafe { llvm::LLVMBuildAggregateRet(self.llbuilder, - ret_vals.as_ptr(), + ret_vals.as_ptr() as *mut _, ret_vals.len() as c_uint); } } @@ -208,7 +208,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { unsafe { llvm::LLVMRustBuildInvoke(self.llbuilder, llfn, - args.as_ptr(), + args.as_ptr() as *mut _, args.len() as c_uint, then, catch, @@ -561,7 +561,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { llvm::LLVMSetMetadata(load, llvm::MD_range as c_uint, llvm::LLVMMDNodeInContext(self.ccx.llcx(), - v.as_ptr(), + v.as_ptr() as *mut _, v.len() as c_uint)); } } @@ -569,7 +569,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { pub fn nonnull_metadata(&self, load: ValueRef) { unsafe { llvm::LLVMSetMetadata(load, llvm::MD_nonnull as c_uint, - llvm::LLVMMDNodeInContext(self.ccx.llcx(), ptr::null(), 0)); + llvm::LLVMMDNodeInContext(self.ccx.llcx(), ptr::null_mut(), 0)); } } @@ -626,7 +626,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // [1]: http://llvm.org/docs/LangRef.html#store-instruction let one = C_i32(self.ccx, 1); let node = llvm::LLVMMDNodeInContext(self.ccx.llcx(), - &one, + &one as *const _ as *mut _, 1); llvm::LLVMSetMetadata(insn, llvm::MD_nontemporal as c_uint, @@ -638,7 +638,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { pub fn gep(&self, ptr: ValueRef, indices: &[ValueRef]) -> ValueRef { self.count_insn("gep"); unsafe { - llvm::LLVMBuildGEP(self.llbuilder, ptr, indices.as_ptr(), + llvm::LLVMBuildGEP(self.llbuilder, ptr, indices.as_ptr() as *mut _, indices.len() as c_uint, noname()) } } @@ -647,7 +647,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.count_insn("inboundsgep"); unsafe { llvm::LLVMBuildInBoundsGEP( - self.llbuilder, ptr, indices.as_ptr(), indices.len() as c_uint, noname()) + self.llbuilder, ptr, indices.as_ptr() as *mut _, indices.len() as c_uint, noname()) } } @@ -812,14 +812,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { pub fn icmp(&self, op: IntPredicate, lhs: ValueRef, rhs: ValueRef) -> ValueRef { self.count_insn("icmp"); unsafe { - llvm::LLVMBuildICmp(self.llbuilder, op as c_uint, lhs, rhs, noname()) + llvm::LLVMBuildICmp(self.llbuilder, op, lhs, rhs, noname()) } } pub fn fcmp(&self, op: RealPredicate, lhs: ValueRef, rhs: ValueRef) -> ValueRef { self.count_insn("fcmp"); unsafe { - llvm::LLVMBuildFCmp(self.llbuilder, op as c_uint, lhs, rhs, noname()) + llvm::LLVMBuildFCmp(self.llbuilder, op, lhs, rhs, noname()) } } @@ -836,8 +836,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let phi = self.empty_phi(ty); self.count_insn("addincoming"); unsafe { - llvm::LLVMAddIncoming(phi, vals.as_ptr(), - bbs.as_ptr(), + llvm::LLVMAddIncoming(phi, vals.as_ptr() as *mut _, + bbs.as_ptr() as *mut _, vals.len() as c_uint); phi } @@ -889,7 +889,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let fty = Type::func(&argtys[..], &output); unsafe { let v = llvm::LLVMRustInlineAsm( - fty.to_ref(), asm, cons, volatile, alignstack, dia); + fty.to_ref(), asm as *mut _, cons as *mut _, volatile, alignstack, dia); self.call(v, inputs, None) } } @@ -909,7 +909,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut()); unsafe { - llvm::LLVMRustBuildCall(self.llbuilder, llfn, args.as_ptr(), + llvm::LLVMRustBuildCall(self.llbuilder, llfn, args.as_ptr() as *mut _, args.len() as c_uint, bundle, noname()) } } @@ -1009,7 +1009,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let args: &[ValueRef] = &[]; self.count_insn("trap"); llvm::LLVMRustBuildCall(self.llbuilder, t, - args.as_ptr(), args.len() as c_uint, + args.as_ptr() as *mut _, args.len() as c_uint, ptr::null_mut(), noname()); } @@ -1055,7 +1055,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { llvm::LLVMRustBuildCleanupPad(self.llbuilder, parent, args.len() as c_uint, - args.as_ptr(), + args.as_ptr() as *mut _, name.as_ptr()) }; assert!(!ret.is_null(), "LLVM does not have support for cleanuppad"); @@ -1080,7 +1080,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let name = CString::new("catchpad").unwrap(); let ret = unsafe { llvm::LLVMRustBuildCatchPad(self.llbuilder, parent, - args.len() as c_uint, args.as_ptr(), + args.len() as c_uint, args.as_ptr() as *mut _, name.as_ptr()) }; assert!(!ret.is_null(), "LLVM does not have support for catchpad"); @@ -1158,14 +1158,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { pub fn add_incoming_to_phi(&self, phi: ValueRef, val: ValueRef, bb: BasicBlockRef) { unsafe { - llvm::LLVMAddIncoming(phi, &val, &bb, 1 as c_uint); + llvm::LLVMAddIncoming( + phi, + &val as *const _ as *mut _, + &bb as *const _ as *mut _, + 1 as c_uint, + ); } } pub fn set_invariant_load(&self, load: ValueRef) { unsafe { llvm::LLVMSetMetadata(load, llvm::MD_invariant_load as c_uint, - llvm::LLVMMDNodeInContext(self.ccx.llcx(), ptr::null(), 0)); + llvm::LLVMMDNodeInContext(self.ccx.llcx(), ptr::null_mut(), 0)); } } @@ -1177,7 +1182,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let stored_ty = val_ty(val); let stored_ptr_ty = stored_ty.ptr_to(); - assert_eq!(dest_ptr_ty.kind(), llvm::TypeKind::Pointer); + assert_eq!(dest_ptr_ty.kind(), llvm::TypeKind::LLVMPointerTypeKind); if dest_ptr_ty == stored_ptr_ty { ptr @@ -1196,11 +1201,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { args: &'b [ValueRef]) -> Cow<'b, [ValueRef]> { let mut fn_ty = val_ty(llfn); // Strip off pointers - while fn_ty.kind() == llvm::TypeKind::Pointer { + while fn_ty.kind() == llvm::TypeKind::LLVMPointerTypeKind { fn_ty = fn_ty.element_type(); } - assert!(fn_ty.kind() == llvm::TypeKind::Function, + assert!(fn_ty.kind() == llvm::TypeKind::LLVMFunctionTypeKind, "builder::{} not passed a function, but {:?}", typ, fn_ty); let param_tys = fn_ty.func_params(); diff --git a/src/librustc_trans/cabi_arm.rs b/src/librustc_trans/cabi_arm.rs index 438053d63b51d..a2e7810192a9c 100644 --- a/src/librustc_trans/cabi_arm.rs +++ b/src/librustc_trans/cabi_arm.rs @@ -96,7 +96,7 @@ pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType // If this is a target with a hard-float ABI, and the function is not explicitly // `extern "aapcs"`, then we must use the VFP registers for homogeneous aggregates. let vfp = ccx.sess().target.target.llvm_target.ends_with("hf") - && fty.cconv != CallConv::ArmAapcsCallConv + && fty.cconv != CallConv::ARM_AAPCS && !fty.variadic; if !fty.ret.is_ignore() { diff --git a/src/librustc_trans/callee.rs b/src/librustc_trans/callee.rs index 4afeac2e8f589..c019716ae9d05 100644 --- a/src/librustc_trans/callee.rs +++ b/src/librustc_trans/callee.rs @@ -165,7 +165,10 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, tcx.is_dllimport_foreign_item(instance_def_id) { unsafe { - llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport); + llvm::LLVMSetDLLStorageClass( + llfn, + llvm::DLLStorageClass::LLVMDLLImportStorageClass, + ); } } diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs index 1f92c1067845e..e8556dd1ec3fe 100644 --- a/src/librustc_trans/common.rs +++ b/src/librustc_trans/common.rs @@ -231,20 +231,20 @@ pub fn C_struct(cx: &CrateContext, elts: &[ValueRef], packed: bool) -> ValueRef pub fn C_struct_in_context(llcx: ContextRef, elts: &[ValueRef], packed: bool) -> ValueRef { unsafe { llvm::LLVMConstStructInContext(llcx, - elts.as_ptr(), elts.len() as c_uint, + elts.as_ptr() as *mut _, elts.len() as c_uint, packed as Bool) } } pub fn C_array(ty: Type, elts: &[ValueRef]) -> ValueRef { unsafe { - return llvm::LLVMConstArray(ty.to_ref(), elts.as_ptr(), elts.len() as c_uint); + llvm::LLVMConstArray(ty.to_ref(), elts.as_ptr() as *mut _, elts.len() as c_uint) } } pub fn C_vector(elts: &[ValueRef]) -> ValueRef { unsafe { - return llvm::LLVMConstVector(elts.as_ptr(), elts.len() as c_uint); + llvm::LLVMConstVector(elts.as_ptr() as *mut _, elts.len() as c_uint) } } @@ -255,7 +255,7 @@ pub fn C_bytes(cx: &CrateContext, bytes: &[u8]) -> ValueRef { pub fn C_bytes_in_context(llcx: ContextRef, bytes: &[u8]) -> ValueRef { unsafe { let ptr = bytes.as_ptr() as *const c_char; - return llvm::LLVMConstStringInContext(llcx, ptr, bytes.len() as c_uint, True); + llvm::LLVMConstStringInContext(llcx, ptr, bytes.len() as c_uint, True) } } @@ -263,7 +263,7 @@ pub fn const_get_elt(v: ValueRef, idx: u64) -> ValueRef { unsafe { assert_eq!(idx as c_uint as u64, idx); let us = &[idx as c_uint]; - let r = llvm::LLVMConstExtractValue(v, us.as_ptr(), us.len() as c_uint); + let r = llvm::LLVMConstExtractValue(v, us.as_ptr() as *mut _, us.len() as c_uint); debug!("const_get_elt(v={:?}, idx={}, r={:?})", Value(v), idx, Value(r)); @@ -366,7 +366,7 @@ pub fn shift_mask_val<'a, 'tcx>( ) -> ValueRef { let kind = llty.kind(); match kind { - TypeKind::Integer => { + TypeKind::LLVMIntegerTypeKind => { // i8/u8 can shift by at most 7, i16/u16 by at most 15, etc. let val = llty.int_width() - 1; if invert { @@ -375,7 +375,7 @@ pub fn shift_mask_val<'a, 'tcx>( C_uint(mask_llty, val) } }, - TypeKind::Vector => { + TypeKind::LLVMVectorTypeKind => { let mask = shift_mask_val(bcx, llty.element_type(), mask_llty.element_type(), invert); bcx.vector_splat(mask_llty.vector_length(), mask) }, diff --git a/src/librustc_trans/consts.rs b/src/librustc_trans/consts.rs index cfca3b57cb9d7..4ddd73d392a34 100644 --- a/src/librustc_trans/consts.rs +++ b/src/librustc_trans/consts.rs @@ -226,7 +226,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef { // If final linkage happens to be static, we rely on compiler-emitted __imp_ stubs to // make things work. unsafe { - llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::DllImport); + llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::LLVMDLLImportStorageClass); } } g @@ -235,7 +235,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef { if ccx.use_dll_storage_attrs() && ccx.tcx().is_dllimport_foreign_item(def_id) { // For foreign (native) libs we know the exact storage type to use. unsafe { - llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::DllImport); + llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::LLVMDLLImportStorageClass); } } diff --git a/src/librustc_trans/debuginfo/metadata.rs b/src/librustc_trans/debuginfo/metadata.rs index b2ad538a8ab29..a582b14753338 100644 --- a/src/librustc_trans/debuginfo/metadata.rs +++ b/src/librustc_trans/debuginfo/metadata.rs @@ -21,8 +21,13 @@ use abi; use context::SharedCrateContext; use llvm::{self, ValueRef}; -use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, - DICompositeType, DILexicalBlock, DIFlags}; +use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType, DILexicalBlock}; +// https://github.com/rust-lang-nursery/rust-bindgen/issues/1165. +use llvm::{ + LLVMRustDIFlags, + LLVMRustDIFlags_FlagZero, + LLVMRustDIFlags_FlagArtificial, +}; use rustc::hir::def::CtorKind; use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE}; @@ -323,7 +328,7 @@ fn vec_slice_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, offset: Size::from_bytes(0), size: pointer_size, align: pointer_align, - flags: DIFlags::FlagZero, + flags: LLVMRustDIFlags_FlagZero, }, MemberDescription { name: "length".to_string(), @@ -331,7 +336,7 @@ fn vec_slice_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, offset: pointer_size, size: usize_size, align: usize_align, - flags: DIFlags::FlagZero, + flags: LLVMRustDIFlags_FlagZero, }, ]; @@ -432,7 +437,7 @@ fn trait_pointer_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, offset: layout.fields.offset(0), size: data_ptr_field.size, align: data_ptr_field.align, - flags: DIFlags::FlagArtificial, + flags: LLVMRustDIFlags_FlagArtificial, }, MemberDescription { name: "vtable".to_string(), @@ -440,7 +445,7 @@ fn trait_pointer_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, offset: layout.fields.offset(1), size: vtable_field.size, align: vtable_field.align, - flags: DIFlags::FlagArtificial, + flags: LLVMRustDIFlags_FlagArtificial, }, ]; @@ -841,7 +846,7 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext, cu_desc_metadata, ]; let gcov_metadata = llvm::LLVMMDNodeInContext(debug_context.llcontext, - gcov_cu_info.as_ptr(), + gcov_cu_info.as_ptr() as *mut _, gcov_cu_info.len() as c_uint); let llvm_gcov_ident = CString::new("llvm.gcov").unwrap(); @@ -886,7 +891,7 @@ struct MemberDescription { offset: Size, size: Size, align: Align, - flags: DIFlags, + flags: LLVMRustDIFlags, } // A factory for MemberDescriptions. It produces a list of member descriptions @@ -953,7 +958,7 @@ impl<'tcx> StructMemberDescriptionFactory<'tcx> { offset: layout.fields.offset(i), size, align, - flags: DIFlags::FlagZero, + flags: LLVMRustDIFlags_FlagZero, } }).collect() } @@ -1016,7 +1021,7 @@ impl<'tcx> TupleMemberDescriptionFactory<'tcx> { offset: layout.fields.offset(i), size, align, - flags: DIFlags::FlagZero, + flags: LLVMRustDIFlags_FlagZero, } }).collect() } @@ -1069,7 +1074,7 @@ impl<'tcx> UnionMemberDescriptionFactory<'tcx> { offset: Size::from_bytes(0), size, align, - flags: DIFlags::FlagZero, + flags: LLVMRustDIFlags_FlagZero, } }).collect() } @@ -1153,7 +1158,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> { offset: Size::from_bytes(0), size: self.layout.size, align: self.layout.align, - flags: DIFlags::FlagZero + flags: LLVMRustDIFlags_FlagZero } ] } @@ -1182,7 +1187,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> { offset: Size::from_bytes(0), size: variant.size, align: variant.align, - flags: DIFlags::FlagZero + flags: LLVMRustDIFlags_FlagZero } }).collect() } @@ -1243,7 +1248,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> { offset: Size::from_bytes(0), size: variant.size, align: variant.align, - flags: DIFlags::FlagZero + flags: LLVMRustDIFlags_FlagZero } ] } @@ -1274,7 +1279,7 @@ impl<'tcx> VariantMemberDescriptionFactory<'tcx> { offset: self.offsets[i], size, align, - flags: DIFlags::FlagZero + flags: LLVMRustDIFlags_FlagZero } }).collect() } @@ -1451,7 +1456,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, UNKNOWN_LINE_NUMBER, enum_type_size.bits(), enum_type_align.abi_bits() as u32, - DIFlags::FlagZero, + LLVMRustDIFlags_FlagZero, ptr::null_mut(), 0, // RuntimeLang unique_type_id_str.as_ptr()) @@ -1585,7 +1590,7 @@ fn create_struct_stub<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, UNKNOWN_LINE_NUMBER, struct_size.bits(), struct_align.abi_bits() as u32, - DIFlags::FlagZero, + LLVMRustDIFlags_FlagZero, ptr::null_mut(), empty_array, 0, @@ -1622,7 +1627,7 @@ fn create_union_stub<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, UNKNOWN_LINE_NUMBER, union_size.bits(), union_align.abi_bits() as u32, - DIFlags::FlagZero, + LLVMRustDIFlags_FlagZero, empty_array, 0, // RuntimeLang unique_type_id.as_ptr()) @@ -1728,7 +1733,7 @@ pub fn create_vtable_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, UNKNOWN_LINE_NUMBER, Size::from_bytes(0).bits(), cx.tcx().data_layout.pointer_align.abi_bits() as u32, - DIFlags::FlagArtificial, + LLVMRustDIFlags_FlagArtificial, ptr::null_mut(), empty_array, 0, diff --git a/src/librustc_trans/debuginfo/mod.rs b/src/librustc_trans/debuginfo/mod.rs index c0df25202d8a9..0719676fc3216 100644 --- a/src/librustc_trans/debuginfo/mod.rs +++ b/src/librustc_trans/debuginfo/mod.rs @@ -22,7 +22,14 @@ use self::source_loc::InternalDebugLocation::{self, UnknownLocation}; use llvm; use llvm::{ModuleRef, ContextRef, ValueRef}; -use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArray, DIFlags}; +use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArray}; +// https://github.com/rust-lang-nursery/rust-bindgen/issues/1165. +use llvm::{ + LLVMRustDIFlags_FlagZero, + LLVMRustDIFlags_FlagPrototyped, + LLVMRustDIFlags_FlagMainSubprogram, +}; + use rustc::hir::def_id::{DefId, CrateNum}; use rustc::ty::subst::Substs; @@ -262,11 +269,11 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, let function_name = CString::new(name).unwrap(); let linkage_name = CString::new(linkage_name).unwrap(); - let mut flags = DIFlags::FlagPrototyped; + let mut flags = LLVMRustDIFlags_FlagPrototyped; match *cx.sess().entry_fn.borrow() { Some((id, _)) => { if local_id == Some(id) { - flags = flags | DIFlags::FlagMainSubprogram; + flags = flags | LLVMRustDIFlags_FlagMainSubprogram; } } None => {} @@ -496,7 +503,7 @@ pub fn declare_local<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, loc.line as c_uint, type_metadata, cx.sess().opts.optimize != config::OptLevel::No, - DIFlags::FlagZero, + LLVMRustDIFlags_FlagZero, argument_index, align.abi() as u32, ) diff --git a/src/librustc_trans/debuginfo/utils.rs b/src/librustc_trans/debuginfo/utils.rs index 95427d9b3cd4e..fc61f8d4282cc 100644 --- a/src/librustc_trans/debuginfo/utils.rs +++ b/src/librustc_trans/debuginfo/utils.rs @@ -40,7 +40,7 @@ pub fn is_node_local_to_unit(cx: &CrateContext, node_id: ast::NodeId) -> bool #[allow(non_snake_case)] pub fn create_DIArray(builder: DIBuilderRef, arr: &[DIDescriptor]) -> DIArray { return unsafe { - llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32) + llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr() as *mut _, arr.len() as u32) }; } diff --git a/src/librustc_trans/declare.rs b/src/librustc_trans/declare.rs index f894bdf16e4de..35a77d79812a4 100644 --- a/src/librustc_trans/declare.rs +++ b/src/librustc_trans/declare.rs @@ -115,7 +115,7 @@ fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty: /// If there’s a value with the same name already declared, the function will /// update the declaration and return existing ValueRef instead. pub fn declare_cfn(ccx: &CrateContext, name: &str, fn_type: Type) -> ValueRef { - declare_raw_fn(ccx, name, llvm::CCallConv, fn_type) + declare_raw_fn(ccx, name, llvm::CallConv::C, fn_type) } diff --git a/src/librustc_trans/intrinsic.rs b/src/librustc_trans/intrinsic.rs index 997dd5573538a..a571a3814fd3c 100644 --- a/src/librustc_trans/intrinsic.rs +++ b/src/librustc_trans/intrinsic.rs @@ -405,7 +405,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, let offset = bcx.urem(ptr_val, align); let zero = C_null(bcx.ccx.isize_ty()); // `offset == 0` - let is_zero = bcx.icmp(llvm::IntPredicate::IntEQ, offset, zero); + let is_zero = bcx.icmp(llvm::IntPredicate::LLVMIntEQ, offset, zero); // `if offset == 0 { 0 } else { offset - align }` bcx.select(is_zero, zero, bcx.sub(offset, align)) } @@ -428,24 +428,27 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, let is_cxchg = split[1] == "cxchg" || split[1] == "cxchgweak"; let (order, failorder) = match split.len() { - 2 => (SequentiallyConsistent, SequentiallyConsistent), + 2 => ( + LLVMAtomicOrderingSequentiallyConsistent, + LLVMAtomicOrderingSequentiallyConsistent, + ), 3 => match split[2] { - "unordered" => (Unordered, Unordered), - "relaxed" => (Monotonic, Monotonic), - "acq" => (Acquire, Acquire), - "rel" => (Release, Monotonic), - "acqrel" => (AcquireRelease, Acquire), + "unordered" => (LLVMAtomicOrderingUnordered, LLVMAtomicOrderingUnordered), + "relaxed" => (LLVMAtomicOrderingMonotonic, LLVMAtomicOrderingMonotonic), + "acq" => (LLVMAtomicOrderingAcquire, LLVMAtomicOrderingAcquire), + "rel" => (LLVMAtomicOrderingRelease, LLVMAtomicOrderingMonotonic), + "acqrel" => (LLVMAtomicOrderingAcquireRelease, LLVMAtomicOrderingAcquire), "failrelaxed" if is_cxchg => - (SequentiallyConsistent, Monotonic), + (LLVMAtomicOrderingSequentiallyConsistent, LLVMAtomicOrderingMonotonic), "failacq" if is_cxchg => - (SequentiallyConsistent, Acquire), + (LLVMAtomicOrderingSequentiallyConsistent, LLVMAtomicOrderingAcquire), _ => ccx.sess().fatal("unknown ordering in atomic intrinsic") }, 4 => match (split[2], split[3]) { ("acq", "failrelaxed") if is_cxchg => - (Acquire, Monotonic), + (LLVMAtomicOrderingAcquire, LLVMAtomicOrderingMonotonic), ("acqrel", "failrelaxed") if is_cxchg => - (AcquireRelease, Monotonic), + (LLVMAtomicOrderingAcquireRelease, LLVMAtomicOrderingMonotonic), _ => ccx.sess().fatal("unknown ordering in atomic intrinsic") }, _ => ccx.sess().fatal("Atomic intrinsic not in correct format"), @@ -516,17 +519,17 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, // These are all AtomicRMW ops op => { let atom_op = match op { - "xchg" => llvm::AtomicXchg, - "xadd" => llvm::AtomicAdd, - "xsub" => llvm::AtomicSub, - "and" => llvm::AtomicAnd, - "nand" => llvm::AtomicNand, - "or" => llvm::AtomicOr, - "xor" => llvm::AtomicXor, - "max" => llvm::AtomicMax, - "min" => llvm::AtomicMin, - "umax" => llvm::AtomicUMax, - "umin" => llvm::AtomicUMin, + "xchg" => llvm::LLVMAtomicRMWBinOp::LLVMAtomicRMWBinOpXchg, + "xadd" => llvm::LLVMAtomicRMWBinOp::LLVMAtomicRMWBinOpAdd, + "xsub" => llvm::LLVMAtomicRMWBinOp::LLVMAtomicRMWBinOpSub, + "and" => llvm::LLVMAtomicRMWBinOp::LLVMAtomicRMWBinOpAnd, + "nand" => llvm::LLVMAtomicRMWBinOp::LLVMAtomicRMWBinOpNand, + "or" => llvm::LLVMAtomicRMWBinOp::LLVMAtomicRMWBinOpOr, + "xor" => llvm::LLVMAtomicRMWBinOp::LLVMAtomicRMWBinOpXor, + "max" => llvm::LLVMAtomicRMWBinOp::LLVMAtomicRMWBinOpMax, + "min" => llvm::LLVMAtomicRMWBinOp::LLVMAtomicRMWBinOpMin, + "umax" => llvm::LLVMAtomicRMWBinOp::LLVMAtomicRMWBinOpUMax, + "umin" => llvm::LLVMAtomicRMWBinOp::LLVMAtomicRMWBinOpUMin, _ => ccx.sess().fatal("unknown atomic operation") }; @@ -1052,7 +1055,7 @@ fn generic_simd_intrinsic<'a, 'tcx>( found `{}` with length {}", in_len, in_ty, ret_ty, out_len); - require!(llret_ty.element_type().kind() == llvm::Integer, + require!(llret_ty.element_type().kind() == llvm::LLVMTypeKind::LLVMIntegerTypeKind, "expected return type with integer elements, found `{}` with non-integer `{}`", ret_ty, ret_ty.simd_type(tcx)); diff --git a/src/librustc_trans/type_.rs b/src/librustc_trans/type_.rs index 1775e53284963..95f51b0a06d5e 100644 --- a/src/librustc_trans/type_.rs +++ b/src/librustc_trans/type_.rs @@ -176,19 +176,19 @@ impl Type { pub fn func(args: &[Type], ret: &Type) -> Type { let slice: &[TypeRef] = Type::to_ref_slice(args); - ty!(llvm::LLVMFunctionType(ret.to_ref(), slice.as_ptr(), + ty!(llvm::LLVMFunctionType(ret.to_ref(), slice.as_ptr() as *mut _, args.len() as c_uint, False)) } pub fn variadic_func(args: &[Type], ret: &Type) -> Type { let slice: &[TypeRef] = Type::to_ref_slice(args); - ty!(llvm::LLVMFunctionType(ret.to_ref(), slice.as_ptr(), + ty!(llvm::LLVMFunctionType(ret.to_ref(), slice.as_ptr() as *mut _, args.len() as c_uint, True)) } pub fn struct_(ccx: &CrateContext, els: &[Type], packed: bool) -> Type { let els: &[TypeRef] = Type::to_ref_slice(els); - ty!(llvm::LLVMStructTypeInContext(ccx.llcx(), els.as_ptr(), + ty!(llvm::LLVMStructTypeInContext(ccx.llcx(), els.as_ptr() as *mut _, els.len() as c_uint, packed as Bool)) } @@ -216,7 +216,7 @@ impl Type { pub fn set_struct_body(&mut self, els: &[Type], packed: bool) { let slice: &[TypeRef] = Type::to_ref_slice(els); unsafe { - llvm::LLVMStructSetBody(self.to_ref(), slice.as_ptr(), + llvm::LLVMStructSetBody(self.to_ref(), slice.as_ptr() as *mut _, els.len() as c_uint, packed as Bool) } } diff --git a/src/rustllvm/ArchiveWrapper.cpp b/src/rustllvm/ArchiveWrapper.cpp index 591ebdc9ddb25..66d05a98f82b3 100644 --- a/src/rustllvm/ArchiveWrapper.cpp +++ b/src/rustllvm/ArchiveWrapper.cpp @@ -76,7 +76,7 @@ typedef Archive::Child *LLVMRustArchiveChildRef; typedef Archive::Child const *LLVMRustArchiveChildConstRef; typedef RustArchiveIterator *LLVMRustArchiveIteratorRef; -extern "C" LLVMRustArchiveRef LLVMRustOpenArchive(char *Path) { +extern "C" LLVMRustArchiveRef LLVMRustOpenArchive(const char *Path) { ErrorOr> BufOr = MemoryBuffer::getFile(Path, -1, false); if (!BufOr) { @@ -220,7 +220,7 @@ extern "C" const char *LLVMRustArchiveChildData(LLVMRustArchiveChildRef Child, } extern "C" LLVMRustArchiveMemberRef -LLVMRustArchiveMemberNew(char *Filename, char *Name, +LLVMRustArchiveMemberNew(const char *Filename, const char *Name, LLVMRustArchiveChildRef Child) { RustArchiveMember *Member = new RustArchiveMember; Member->Filename = Filename; @@ -235,7 +235,7 @@ extern "C" void LLVMRustArchiveMemberFree(LLVMRustArchiveMemberRef Member) { } extern "C" LLVMRustResult -LLVMRustWriteArchive(char *Dst, size_t NumMembers, +LLVMRustWriteArchive(const char *Dst, size_t NumMembers, const LLVMRustArchiveMemberRef *NewMembers, bool WriteSymbtab, LLVMRustArchiveKind RustKind) { diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index 4a359fb3ad306..ef33dded692b1 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -486,7 +486,7 @@ extern "C" void LLVMRustRunFunctionPassManager(LLVMPassManagerRef PMR, P->doFinalization(); } -extern "C" void LLVMRustSetLLVMOptions(int Argc, char **Argv) { +extern "C" void LLVMRustSetLLVMOptions(int Argc, char * const *Argv) { // Initializing the command-line options more than once is not allowed. So, // check if they've already been initialized. (This could happen if we're // being called from rustpkg, for example). If the arguments change, then @@ -715,7 +715,7 @@ extern "C" void LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMBR, #endif } -extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols, +extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, const char * const *Symbols, size_t Len) { llvm::legacy::PassManager passes; @@ -969,14 +969,14 @@ addPreservedGUID(const ModuleSummaryIndex &Index, // here is basically the same as before threads are spawned in the `run` // function of `lib/LTO/ThinLTOCodeGenerator.cpp`. extern "C" LLVMRustThinLTOData* -LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules, - int num_modules, - const char **preserved_symbols, - int num_symbols) { +LLVMRustCreateThinLTOData(const LLVMRustThinLTOModule *modules, + unsigned num_modules, + const char * const *preserved_symbols, + unsigned num_symbols) { auto Ret = llvm::make_unique(); // Load each module's summary and merge it into one combined index - for (int i = 0; i < num_modules; i++) { + for (unsigned i = 0; i < num_modules; i++) { auto module = &modules[i]; StringRef buffer(module->data, module->len); MemoryBufferRef mem_buffer(buffer, module->identifier); @@ -1006,7 +1006,7 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules, // Convert the preserved symbols set from string to GUID, this is then needed // for internalization. We use `addPreservedGUID` to include any transitively // used symbol as well. - for (int i = 0; i < num_symbols; i++) { + for (unsigned i = 0; i < num_symbols; i++) { addPreservedGUID(Ret->Index, Ret->GUIDPreservedSymbols, GlobalValue::getGUID(preserved_symbols[i])); diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 424b226bcf778..8cee6b7eef849 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -57,7 +57,11 @@ static AtomicOrdering fromRust(LLVMAtomicOrdering Ordering) { report_fatal_error("Invalid LLVMAtomicOrdering value!"); } -static LLVM_THREAD_LOCAL char *LastError; +static +#ifndef BINDGEN_NO_TLS +LLVM_THREAD_LOCAL +#endif +char *LastError; extern "C" LLVMMemoryBufferRef LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) { @@ -566,8 +570,8 @@ extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M, const char *Name, unwrap(M)->addModuleFlag(Module::Warning, Name, Value); } -extern "C" void LLVMRustMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD) { - wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD))); +extern "C" LLVMValueRef LLVMRustMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD) { + return wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD))); } extern "C" LLVMRustDIBuilderRef LLVMRustDIBuilderCreate(LLVMModuleRef M) { @@ -797,7 +801,7 @@ LLVMRustDIBuilderGetOrCreateArray(LLVMRustDIBuilderRef Builder, extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd( LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMMetadataRef VarInfo, - int64_t *AddrOps, unsigned AddrOpsCount, LLVMValueRef DL, + const int64_t *AddrOps, unsigned AddrOpsCount, LLVMValueRef DL, LLVMBasicBlockRef InsertAtEnd) { return wrap(Builder->insertDeclare( unwrap(V), unwrap(VarInfo), @@ -904,7 +908,7 @@ extern "C" void LLVMRustWriteValueToString(LLVMValueRef V, } } -extern "C" bool LLVMRustLinkInExternalBitcode(LLVMModuleRef DstRef, char *BC, +extern "C" bool LLVMRustLinkInExternalBitcode(LLVMModuleRef DstRef, const char *BC, size_t Len) { Module *Dst = unwrap(DstRef); @@ -1256,6 +1260,8 @@ extern "C" void LLVMRustAddHandler(LLVMValueRef CatchSwitchRef, #endif } +typedef OperandBundleDef *LLVMRustOperandBundleDefRef; + #if LLVM_VERSION_GE(3, 8) extern "C" OperandBundleDef *LLVMRustBuildOperandBundleDef(const char *Name, LLVMValueRef *Inputs, diff --git a/src/rustllvm/rustllvm.h b/src/rustllvm/rustllvm.h index 20816af2f1c20..6255d13bf06f2 100644 --- a/src/rustllvm/rustllvm.h +++ b/src/rustllvm/rustllvm.h @@ -8,7 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#pragma once + #include "llvm-c/BitReader.h" +#include "llvm-c/BitWriter.h" #include "llvm-c/Core.h" #include "llvm-c/ExecutionEngine.h" #include "llvm-c/Object.h"