From d3096c2348b463ccdbb1c066b688d487e72e6c73 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 5 Jul 2014 13:24:57 -0700 Subject: [PATCH 01/13] Move llvm bindings to their own crate --- .gitignore | 2 +- mk/crates.mk | 7 +- mk/llvm.mk | 2 +- mk/target.mk | 2 +- src/librustc/lib.rs | 4 +- src/librustc/lib/llvmdeps.rs | 64 +++++++++++++ src/librustc/middle/trans/context.rs | 4 +- src/librustc/middle/trans/type_.rs | 54 ++++++++++- .../lib/llvm.rs => librustc_llvm/lib.rs} | 89 +++++++++++++++++-- 9 files changed, 209 insertions(+), 19 deletions(-) create mode 100644 src/librustc/lib/llvmdeps.rs rename src/{librustc/lib/llvm.rs => librustc_llvm/lib.rs} (96%) diff --git a/.gitignore b/.gitignore index 896480ba25708..bc34fc2dcdfbb 100644 --- a/.gitignore +++ b/.gitignore @@ -86,5 +86,5 @@ src/etc/dl .settings/ /build i686-pc-mingw32/ -src/librustc/lib/llvmdeps.rs +src/librustc_llvm/llvmdeps.rs *.pot diff --git a/mk/crates.mk b/mk/crates.mk index 48a5bf6caf4cc..e565d3eb2b940 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -53,7 +53,7 @@ TARGET_CRATES := libc std green rustuv native flate arena glob term semver \ uuid serialize sync getopts collections num test time rand \ url log regex graphviz core rlibc alloc debug rustrt \ unicode -HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros +HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros rustc_llvm CRATES := $(TARGET_CRATES) $(HOST_CRATES) TOOLS := compiletest rustdoc rustc @@ -70,8 +70,9 @@ DEPS_green := std native:context_switch DEPS_rustuv := std native:uv native:uv_support DEPS_native := std DEPS_syntax := std term serialize log fmt_macros debug -DEPS_rustc := syntax native:rustllvm flate arena serialize getopts \ - time log graphviz debug +DEPS_rustc := syntax flate arena serialize getopts \ + time log graphviz debug rustc_llvm +DEPS_rustc_llvm := native:rustllvm libc std DEPS_rustdoc := rustc native:hoedown serialize getopts \ test time debug DEPS_flate := std native:miniz diff --git a/mk/llvm.mk b/mk/llvm.mk index 789ce2dabc25e..177e4de310324 100644 --- a/mk/llvm.mk +++ b/mk/llvm.mk @@ -57,7 +57,7 @@ $(foreach host,$(CFG_HOST), \ $(foreach host,$(CFG_HOST), \ $(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host)))) -$(S)src/librustc/lib/llvmdeps.rs: \ +$(S)src/librustc_llvm/llvmdeps.rs: \ $(LLVM_CONFIGS) \ $(S)src/etc/mklldeps.py \ $(MKFILE_DEPS) diff --git a/mk/target.mk b/mk/target.mk index e6fb22e8c42ad..7da11a21a7cb7 100644 --- a/mk/target.mk +++ b/mk/target.mk @@ -134,7 +134,7 @@ SNAPSHOT_RUSTC_POST_CLEANUP=$(HBIN0_H_$(CFG_BUILD))/rustc$(X_$(CFG_BUILD)) define TARGET_HOST_RULES -$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc: $(S)src/librustc/lib/llvmdeps.rs +$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $(S)src/librustc_llvm/llvmdeps.rs $$(TBIN$(1)_T_$(2)_H_$(3))/: mkdir -p $$@ diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 63fba0fd4b4e9..7da3ae0208714 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -41,6 +41,7 @@ extern crate flate; extern crate getopts; extern crate graphviz; extern crate libc; +extern crate llvm = "rustc_llvm"; extern crate serialize; extern crate time; #[phase(plugin, link)] extern crate log; @@ -128,8 +129,7 @@ pub mod util { } pub mod lib { - pub mod llvm; - pub mod llvmdeps; + pub use llvm; } __build_diagnostic_array!(DIAGNOSTICS) diff --git a/src/librustc/lib/llvmdeps.rs b/src/librustc/lib/llvmdeps.rs new file mode 100644 index 0000000000000..05e5e585a63ab --- /dev/null +++ b/src/librustc/lib/llvmdeps.rs @@ -0,0 +1,64 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// WARNING: THIS IS A GENERATED FILE, DO NOT MODIFY +// take a look at src/etc/mklldeps.py if you're interested + +#[cfg(target_arch = "x86_64", target_os = "linux")] +#[link(name = "LLVMInstrumentation", kind = "static")] +#[link(name = "LLVMInterpreter", kind = "static")] +#[link(name = "LLVMMCJIT", kind = "static")] +#[link(name = "LLVMRuntimeDyld", kind = "static")] +#[link(name = "LLVMJIT", kind = "static")] +#[link(name = "LLVMExecutionEngine", kind = "static")] +#[link(name = "LLVMAsmParser", kind = "static")] +#[link(name = "LLVMLinker", kind = "static")] +#[link(name = "LLVMBitWriter", kind = "static")] +#[link(name = "LLVMipo", kind = "static")] +#[link(name = "LLVMVectorize", kind = "static")] +#[link(name = "LLVMMipsDisassembler", kind = "static")] +#[link(name = "LLVMMipsCodeGen", kind = "static")] +#[link(name = "LLVMMipsAsmParser", kind = "static")] +#[link(name = "LLVMMipsDesc", kind = "static")] +#[link(name = "LLVMMipsInfo", kind = "static")] +#[link(name = "LLVMMipsAsmPrinter", kind = "static")] +#[link(name = "LLVMARMDisassembler", kind = "static")] +#[link(name = "LLVMARMCodeGen", kind = "static")] +#[link(name = "LLVMARMAsmParser", kind = "static")] +#[link(name = "LLVMARMDesc", kind = "static")] +#[link(name = "LLVMARMInfo", kind = "static")] +#[link(name = "LLVMARMAsmPrinter", kind = "static")] +#[link(name = "LLVMX86Disassembler", kind = "static")] +#[link(name = "LLVMX86AsmParser", kind = "static")] +#[link(name = "LLVMX86CodeGen", kind = "static")] +#[link(name = "LLVMSelectionDAG", kind = "static")] +#[link(name = "LLVMAsmPrinter", kind = "static")] +#[link(name = "LLVMMCParser", kind = "static")] +#[link(name = "LLVMCodeGen", kind = "static")] +#[link(name = "LLVMScalarOpts", kind = "static")] +#[link(name = "LLVMInstCombine", kind = "static")] +#[link(name = "LLVMTransformUtils", kind = "static")] +#[link(name = "LLVMipa", kind = "static")] +#[link(name = "LLVMAnalysis", kind = "static")] +#[link(name = "LLVMTarget", kind = "static")] +#[link(name = "LLVMX86Desc", kind = "static")] +#[link(name = "LLVMX86Info", kind = "static")] +#[link(name = "LLVMX86AsmPrinter", kind = "static")] +#[link(name = "LLVMMC", kind = "static")] +#[link(name = "LLVMObject", kind = "static")] +#[link(name = "LLVMBitReader", kind = "static")] +#[link(name = "LLVMCore", kind = "static")] +#[link(name = "LLVMX86Utils", kind = "static")] +#[link(name = "LLVMSupport", kind = "static")] +#[link(name = "pthread")] +#[link(name = "dl")] +#[link(name = "m")] +#[link(name = "stdc++")] +extern {} diff --git a/src/librustc/middle/trans/context.rs b/src/librustc/middle/trans/context.rs index 6387ec791bab9..5ee69e02af96a 100644 --- a/src/librustc/middle/trans/context.rs +++ b/src/librustc/middle/trans/context.rs @@ -11,7 +11,7 @@ use driver::config::NoDebugInfo; use driver::session::Session; use lib::llvm::{ContextRef, ModuleRef, ValueRef}; -use lib::llvm::{llvm, TargetData, TypeNames}; +use lib::llvm::{llvm, TargetData}; use lib::llvm::mk_target_data; use metadata::common::LinkMeta; use middle::resolve; @@ -21,7 +21,7 @@ use middle::trans::builder::Builder; use middle::trans::common::{ExternMap,tydesc_info,BuilderRef_res}; use middle::trans::debuginfo; use middle::trans::monomorphize::MonoId; -use middle::trans::type_::Type; +use middle::trans::type_::{Type, TypeNames}; use middle::ty; use util::sha2::Sha256; use util::nodemap::{NodeMap, NodeSet, DefIdMap}; diff --git a/src/librustc/middle/trans/type_.rs b/src/librustc/middle/trans/type_.rs index b10f6eda88053..54de399681163 100644 --- a/src/librustc/middle/trans/type_.rs +++ b/src/librustc/middle/trans/type_.rs @@ -10,7 +10,7 @@ #![allow(non_uppercase_pattern_statics)] -use lib::llvm::{llvm, TypeRef, Bool, False, True, TypeKind}; +use lib::llvm::{llvm, TypeRef, Bool, False, True, TypeKind, ValueRef}; use lib::llvm::{Float, Double, X86_FP80, PPC_FP128, FP128}; use middle::trans::context::CrateContext; @@ -20,8 +20,11 @@ use syntax::abi::{X86, X86_64, Arm, Mips, Mipsel}; use std::c_str::ToCStr; use std::mem; +use std::cell::RefCell; +use std::collections::HashMap; +use std::str::raw::from_c_str; -use libc::{c_uint}; +use libc::{c_uint, c_void, free}; #[deriving(Clone, PartialEq, Show)] pub struct Type { @@ -303,3 +306,50 @@ impl Type { } } } + +/* Memory-managed object interface to type handles. */ + +pub struct TypeNames { + named_types: RefCell>, +} + +impl TypeNames { + pub fn new() -> TypeNames { + TypeNames { + named_types: RefCell::new(HashMap::new()) + } + } + + pub fn associate_type(&self, s: &str, t: &Type) { + assert!(self.named_types.borrow_mut().insert(s.to_string(), + t.to_ref())); + } + + pub fn find_type(&self, s: &str) -> Option { + self.named_types.borrow().find_equiv(&s).map(|x| Type::from_ref(*x)) + } + + pub fn type_to_str(&self, ty: Type) -> String { + unsafe { + let s = llvm::LLVMTypeToString(ty.to_ref()); + let ret = from_c_str(s); + free(s as *mut c_void); + ret.to_string() + } + } + + pub fn types_to_str(&self, tys: &[Type]) -> String { + let strs: Vec = tys.iter().map(|t| self.type_to_str(*t)).collect(); + format!("[{}]", strs.connect(",")) + } + + pub fn val_to_str(&self, val: ValueRef) -> String { + unsafe { + let s = llvm::LLVMValueToString(val); + let ret = from_c_str(s); + free(s as *mut c_void); + ret.to_string() + } + } +} + diff --git a/src/librustc/lib/llvm.rs b/src/librustc_llvm/lib.rs similarity index 96% rename from src/librustc/lib/llvm.rs rename to src/librustc_llvm/lib.rs index a4425183cde64..121e8882f1ae1 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc_llvm/lib.rs @@ -13,13 +13,24 @@ #![allow(non_snake_case_functions)] #![allow(dead_code)] -use std::c_str::ToCStr; -use std::cell::RefCell; -use std::collections::HashMap; -use libc::{c_uint, c_ushort, c_void, free, uint64_t}; -use std::str::raw::from_c_str; +#![crate_id = "rustc_llvm#0.11.0"] +#![crate_name = "rustc_llvm"] +#![experimental] +#![license = "MIT/ASL2"] +#![crate_type = "dylib"] +#![crate_type = "rlib"] +#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", + html_favicon_url = "http://www.rust-lang.org/favicon.ico", + html_root_url = "http://doc.rust-lang.org/")] + +#![feature(globs)] +#![feature(link_args)] +#![allow(unused_attribute)] // NOTE: remove after stage0 + +extern crate libc; -use middle::trans::type_::Type; +use std::c_str::ToCStr; +use libc::{c_uint, c_ushort, uint64_t, c_int, size_t}; pub type Opcode = u32; pub type Bool = c_uint; @@ -338,6 +349,10 @@ pub mod llvm { use libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong, size_t, uint64_t}; + pub unsafe fn LLVMInitializeX86AsmPrinter() { + LLVMInitializeX86AsmPrinter_() + } + // 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++ // @@ -1747,7 +1762,8 @@ pub mod llvm { pub fn LLVMInitializeX86TargetInfo(); pub fn LLVMInitializeX86Target(); pub fn LLVMInitializeX86TargetMC(); - pub fn LLVMInitializeX86AsmPrinter(); + #[link_name = "LLVMInitializeX86AsmPrinter"] + pub fn LLVMInitializeX86AsmPrinter_(); pub fn LLVMInitializeX86AsmParser(); pub fn LLVMInitializeARMTargetInfo(); pub fn LLVMInitializeARMTarget(); @@ -1861,6 +1877,7 @@ pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) { llvm::LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr as uint64_t) } } + /* Memory-managed object interface to type handles. */ pub struct TypeNames { @@ -1981,3 +1998,61 @@ pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter { } } } + +// FIXME #15460 - create a public function that actually calls our +// static LLVM symbols. Otherwise the linker will just throw llvm +// away. We're just calling lots of stuff until we transitively get +// all of LLVM. This is worse than anything. +pub unsafe fn static_link_hack_this_sucks() { + llvm::LLVMInitializePasses(); + + llvm::LLVMInitializeX86TargetInfo(); + llvm::LLVMInitializeX86Target(); + llvm::LLVMInitializeX86TargetMC(); + llvm::LLVMInitializeX86AsmPrinter(); + llvm::LLVMInitializeX86AsmParser(); + + llvm::LLVMInitializeARMTargetInfo(); + llvm::LLVMInitializeARMTarget(); + llvm::LLVMInitializeARMTargetMC(); + llvm::LLVMInitializeARMAsmPrinter(); + llvm::LLVMInitializeARMAsmParser(); + + llvm::LLVMInitializeMipsTargetInfo(); + llvm::LLVMInitializeMipsTarget(); + llvm::LLVMInitializeMipsTargetMC(); + llvm::LLVMInitializeMipsAsmPrinter(); + llvm::LLVMInitializeMipsAsmParser(); + + llvm::LLVMRustSetLLVMOptions(0 as c_int, + 0 as *const _); + + llvm::LLVMPassManagerBuilderPopulateModulePassManager(0 as *mut _, 0 as *mut _); + llvm::LLVMPassManagerBuilderPopulateLTOPassManager(0 as *mut _, 0 as *mut _, False, False); + llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(0 as *mut _, 0 as *mut _); + llvm::LLVMPassManagerBuilderSetOptLevel(0 as *mut _, 0 as c_uint); + llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(0 as *mut _, 0 as c_uint); + llvm::LLVMWriteBitcodeToFile(0 as *mut _, 0 as *const _); + llvm::LLVMPassManagerBuilderCreate(); + llvm::LLVMPassManagerBuilderDispose(0 as *mut _); + + llvm::LLVMRustLinkInExternalBitcode(0 as *mut _, 0 as *const _, 0 as size_t); + + LLVMLinkInJIT(); + LLVMLinkInMCJIT(); + LLVMLinkInInterpreter(); + + extern { + fn LLVMLinkInJIT(); + fn LLVMLinkInMCJIT(); + fn LLVMLinkInInterpreter(); + } +} + +// The module containing the native LLVM dependencies, generated by the build system +// Note that this must come after the rustllvm extern declaration so that +// parts of LLVM that rustllvm depends on aren't thrown away by the linker. +// Works to the above fix for #15460 to ensure LLVM dependencies that +// are only used by rustllvm don't get stripped by the linker. +mod llvmdeps; + From cf360f328aad26bd19490270aa9716645aa4d4cf Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 4 Jul 2014 19:41:54 -0700 Subject: [PATCH 02/13] Extract librustc_back from librustc --- mk/crates.mk | 6 +- src/librustc/back/archive.rs | 4 +- src/librustc/back/link.rs | 186 +++++++++--------- src/librustc/back/lto.rs | 6 +- src/librustc/lib.rs | 34 ++-- src/{librustc/back => librustc_back}/abi.rs | 0 src/{librustc/back => librustc_back}/arm.rs | 2 +- src/librustc_back/lib.rs | 39 ++++ src/{librustc/back => librustc_back}/mips.rs | 2 +- .../back => librustc_back}/mipsel.rs | 2 +- src/{librustc/back => librustc_back}/svh.rs | 6 +- .../back => librustc_back}/target_strs.rs | 0 src/{librustc/back => librustc_back}/x86.rs | 2 +- .../back => librustc_back}/x86_64.rs | 2 +- 14 files changed, 166 insertions(+), 125 deletions(-) rename src/{librustc/back => librustc_back}/abi.rs (100%) rename src/{librustc/back => librustc_back}/arm.rs (99%) create mode 100644 src/librustc_back/lib.rs rename src/{librustc/back => librustc_back}/mips.rs (98%) rename src/{librustc/back => librustc_back}/mipsel.rs (98%) rename src/{librustc/back => librustc_back}/svh.rs (99%) rename src/{librustc/back => librustc_back}/target_strs.rs (100%) rename src/{librustc/back => librustc_back}/x86.rs (98%) rename src/{librustc/back => librustc_back}/x86_64.rs (99%) diff --git a/mk/crates.mk b/mk/crates.mk index e565d3eb2b940..c95576f6252aa 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -53,7 +53,8 @@ TARGET_CRATES := libc std green rustuv native flate arena glob term semver \ uuid serialize sync getopts collections num test time rand \ url log regex graphviz core rlibc alloc debug rustrt \ unicode -HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros rustc_llvm +HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros \ + rustc_llvm rustc_back CRATES := $(TARGET_CRATES) $(HOST_CRATES) TOOLS := compiletest rustdoc rustc @@ -71,8 +72,9 @@ DEPS_rustuv := std native:uv native:uv_support DEPS_native := std DEPS_syntax := std term serialize log fmt_macros debug DEPS_rustc := syntax flate arena serialize getopts \ - time log graphviz debug rustc_llvm + time log graphviz debug rustc_llvm rustc_back DEPS_rustc_llvm := native:rustllvm libc std +DEPS_rustc_back := std syntax rustc_llvm flate log libc DEPS_rustdoc := rustc native:hoedown serialize getopts \ test time debug DEPS_flate := std native:miniz diff --git a/src/librustc/back/archive.rs b/src/librustc/back/archive.rs index 4d921fb97dc50..8acb610db3f59 100644 --- a/src/librustc/back/archive.rs +++ b/src/librustc/back/archive.rs @@ -10,10 +10,10 @@ //! A helper class for dealing with static archives -use back::link::{get_ar_prog}; +use super::link::{get_ar_prog}; use driver::session::Session; use metadata::filesearch; -use lib::llvm::{ArchiveRef, llvm}; +use llvm::{ArchiveRef, llvm}; use libc; use std::io::process::{Command, ProcessOutput}; diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index a1df360a11b8e..2112e8d822d38 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -8,16 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use back::archive::{Archive, METADATA_FILENAME}; -use back::rpath; -use back::svh::Svh; +use super::archive::{Archive, METADATA_FILENAME}; +use super::rpath; +use super::svh::Svh; use driver::driver::{CrateTranslation, OutputFilenames, Input, FileInput}; use driver::config::NoDebugInfo; use driver::session::Session; use driver::config; -use lib::llvm::llvm; -use lib::llvm::ModuleRef; -use lib; +use llvm; +use llvm::ModuleRef; use metadata::common::LinkMeta; use metadata::{encoder, cstore, filesearch, csearch, loader, creader}; use middle::trans::context::CrateContext; @@ -55,7 +54,7 @@ pub enum OutputType { pub fn llvm_err(sess: &Session, msg: String) -> ! { unsafe { - let cstr = llvm::LLVMRustGetLastError(); + let cstr = llvm::llvm::LLVMRustGetLastError(); if cstr == ptr::null() { sess.fatal(msg.as_slice()); } else { @@ -70,14 +69,14 @@ pub fn llvm_err(sess: &Session, msg: String) -> ! { pub fn write_output_file( sess: &Session, - target: lib::llvm::TargetMachineRef, - pm: lib::llvm::PassManagerRef, + target: llvm::TargetMachineRef, + pm: llvm::PassManagerRef, m: ModuleRef, output: &Path, - file_type: lib::llvm::FileType) { + file_type: llvm::FileType) { unsafe { output.with_c_str(|output| { - let result = llvm::LLVMRustWriteOutputFile( + let result = llvm::llvm::LLVMRustWriteOutputFile( target, pm, m, output, file_type); if !result { llvm_err(sess, "could not write output".to_string()); @@ -88,18 +87,17 @@ pub fn write_output_file( pub mod write { - use back::lto; - use back::link::{write_output_file, OutputType}; - use back::link::{OutputTypeAssembly, OutputTypeBitcode}; - use back::link::{OutputTypeExe, OutputTypeLlvmAssembly}; - use back::link::{OutputTypeObject}; + use super::super::lto; + use super::{write_output_file, OutputType}; + use super::{OutputTypeAssembly, OutputTypeBitcode}; + use super::{OutputTypeExe, OutputTypeLlvmAssembly}; + use super::{OutputTypeObject}; use driver::driver::{CrateTranslation, OutputFilenames}; use driver::config::NoDebugInfo; use driver::session::Session; use driver::config; - use lib::llvm::llvm; - use lib::llvm::{ModuleRef, TargetMachineRef, PassManagerRef}; - use lib; + use llvm; + use llvm::{ModuleRef, TargetMachineRef, PassManagerRef}; use util::common::time; use syntax::abi; @@ -147,15 +145,15 @@ pub mod write { if sess.opts.cg.save_temps { output.with_extension("no-opt.bc").with_c_str(|buf| { - llvm::LLVMWriteBitcodeToFile(llmod, buf); + llvm::llvm::LLVMWriteBitcodeToFile(llmod, buf); }) } let opt_level = match sess.opts.optimize { - config::No => lib::llvm::CodeGenLevelNone, - config::Less => lib::llvm::CodeGenLevelLess, - config::Default => lib::llvm::CodeGenLevelDefault, - config::Aggressive => lib::llvm::CodeGenLevelAggressive, + config::No => llvm::CodeGenLevelNone, + config::Less => llvm::CodeGenLevelLess, + config::Default => llvm::CodeGenLevelDefault, + config::Aggressive => llvm::CodeGenLevelAggressive, }; let use_softfp = sess.opts.cg.soft_float; @@ -172,10 +170,10 @@ pub mod write { let fdata_sections = ffunction_sections; let reloc_model = match sess.opts.cg.relocation_model.as_slice() { - "pic" => lib::llvm::RelocPIC, - "static" => lib::llvm::RelocStatic, - "default" => lib::llvm::RelocDefault, - "dynamic-no-pic" => lib::llvm::RelocDynamicNoPic, + "pic" => llvm::RelocPIC, + "static" => llvm::RelocStatic, + "default" => llvm::RelocDefault, + "dynamic-no-pic" => llvm::RelocDynamicNoPic, _ => { sess.err(format!("{} is not a valid relocation mode", sess.opts @@ -193,9 +191,9 @@ pub mod write { .with_c_str(|t| { sess.opts.cg.target_cpu.as_slice().with_c_str(|cpu| { target_feature(sess).with_c_str(|features| { - llvm::LLVMRustCreateTargetMachine( + llvm::llvm::LLVMRustCreateTargetMachine( t, cpu, features, - lib::llvm::CodeModelDefault, + llvm::CodeModelDefault, reloc_model, opt_level, true /* EnableSegstk */, @@ -212,26 +210,26 @@ pub mod write { // does, and are by populated by LLVM's default PassManagerBuilder. // Each manager has a different set of passes, but they also share // some common passes. - let fpm = llvm::LLVMCreateFunctionPassManagerForModule(llmod); - let mpm = llvm::LLVMCreatePassManager(); + let fpm = llvm::llvm::LLVMCreateFunctionPassManagerForModule(llmod); + let mpm = llvm::llvm::LLVMCreatePassManager(); // If we're verifying or linting, add them to the function pass // manager. let addpass = |pass: &str| { - pass.as_slice().with_c_str(|s| llvm::LLVMRustAddPass(fpm, s)) + pass.as_slice().with_c_str(|s| llvm::llvm::LLVMRustAddPass(fpm, s)) }; if !sess.no_verify() { assert!(addpass("verify")); } if !sess.opts.cg.no_prepopulate_passes { - llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod); - llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod); + llvm::llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod); + llvm::llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod); populate_llvm_passes(fpm, mpm, llmod, opt_level, trans.no_builtins); } for pass in sess.opts.cg.passes.iter() { pass.as_slice().with_c_str(|s| { - if !llvm::LLVMRustAddPass(mpm, s) { + if !llvm::llvm::LLVMRustAddPass(mpm, s) { sess.warn(format!("unknown pass {}, ignoring", *pass).as_slice()); } @@ -240,13 +238,13 @@ pub mod write { // Finally, run the actual optimization passes time(sess.time_passes(), "llvm function passes", (), |()| - llvm::LLVMRustRunFunctionPassManager(fpm, llmod)); + llvm::llvm::LLVMRustRunFunctionPassManager(fpm, llmod)); time(sess.time_passes(), "llvm module passes", (), |()| - llvm::LLVMRunPassManager(mpm, llmod)); + llvm::llvm::LLVMRunPassManager(mpm, llmod)); // Deallocate managers that we're now done with - llvm::LLVMDisposePassManager(fpm); - llvm::LLVMDisposePassManager(mpm); + llvm::llvm::LLVMDisposePassManager(fpm); + llvm::llvm::LLVMDisposePassManager(mpm); // Emit the bytecode if we're either saving our temporaries or // emitting an rlib. Whenever an rlib is created, the bytecode is @@ -255,7 +253,7 @@ pub mod write { (sess.crate_types.borrow().contains(&config::CrateTypeRlib) && sess.opts.output_types.contains(&OutputTypeExe)) { output.temp_path(OutputTypeBitcode).with_c_str(|buf| { - llvm::LLVMWriteBitcodeToFile(llmod, buf); + llvm::llvm::LLVMWriteBitcodeToFile(llmod, buf); }) } @@ -265,7 +263,7 @@ pub mod write { if sess.opts.cg.save_temps { output.with_extension("lto.bc").with_c_str(|buf| { - llvm::LLVMWriteBitcodeToFile(llmod, buf); + llvm::llvm::LLVMWriteBitcodeToFile(llmod, buf); }) } } @@ -281,11 +279,11 @@ pub mod write { fn with_codegen(tm: TargetMachineRef, llmod: ModuleRef, no_builtins: bool, f: |PassManagerRef|) { unsafe { - let cpm = llvm::LLVMCreatePassManager(); - llvm::LLVMRustAddAnalysisPasses(tm, cpm, llmod); - llvm::LLVMRustAddLibraryInfo(cpm, llmod, no_builtins); + let cpm = llvm::llvm::LLVMCreatePassManager(); + llvm::llvm::LLVMRustAddAnalysisPasses(tm, cpm, llmod); + llvm::llvm::LLVMRustAddLibraryInfo(cpm, llmod, no_builtins); f(cpm); - llvm::LLVMDisposePassManager(cpm); + llvm::llvm::LLVMDisposePassManager(cpm); } } @@ -296,13 +294,13 @@ pub mod write { match *output_type { OutputTypeBitcode => { path.with_c_str(|buf| { - llvm::LLVMWriteBitcodeToFile(llmod, buf); + llvm::llvm::LLVMWriteBitcodeToFile(llmod, buf); }) } OutputTypeLlvmAssembly => { path.with_c_str(|output| { with_codegen(tm, llmod, trans.no_builtins, |cpm| { - llvm::LLVMRustPrintModule(cpm, llmod, output); + llvm::llvm::LLVMRustPrintModule(cpm, llmod, output); }) }) } @@ -320,7 +318,7 @@ pub mod write { }; with_codegen(tm, llmod, trans.no_builtins, |cpm| { write_output_file(sess, tm, cpm, llmod, &path, - lib::llvm::AssemblyFile); + llvm::AssemblyFile); }); } OutputTypeObject => { @@ -338,7 +336,7 @@ pub mod write { Some(ref path) => { with_codegen(tm, llmod, trans.no_builtins, |cpm| { write_output_file(sess, tm, cpm, llmod, path, - lib::llvm::ObjectFile); + llvm::ObjectFile); }); } None => {} @@ -350,16 +348,16 @@ pub mod write { .with_extension("metadata.o"); write_output_file(sess, tm, cpm, trans.metadata_module, &out, - lib::llvm::ObjectFile); + llvm::ObjectFile); }) } }); - llvm::LLVMRustDisposeTargetMachine(tm); - llvm::LLVMDisposeModule(trans.metadata_module); - llvm::LLVMDisposeModule(llmod); - llvm::LLVMContextDispose(llcx); - if sess.time_llvm_passes() { llvm::LLVMRustPrintPassTimings(); } + llvm::llvm::LLVMRustDisposeTargetMachine(tm); + llvm::llvm::LLVMDisposeModule(trans.metadata_module); + llvm::llvm::LLVMDisposeModule(llmod); + llvm::llvm::LLVMContextDispose(llcx); + if sess.time_llvm_passes() { llvm::llvm::LLVMRustPrintPassTimings(); } } } @@ -426,69 +424,69 @@ pub mod write { } INIT.doit(|| { - llvm::LLVMInitializePasses(); + llvm::llvm::LLVMInitializePasses(); // Only initialize the platforms supported by Rust here, because // using --llvm-root will have multiple platforms that rustllvm // doesn't actually link to and it's pointless to put target info // into the registry that Rust cannot generate machine code for. - llvm::LLVMInitializeX86TargetInfo(); - llvm::LLVMInitializeX86Target(); - llvm::LLVMInitializeX86TargetMC(); - llvm::LLVMInitializeX86AsmPrinter(); - llvm::LLVMInitializeX86AsmParser(); - - llvm::LLVMInitializeARMTargetInfo(); - llvm::LLVMInitializeARMTarget(); - llvm::LLVMInitializeARMTargetMC(); - llvm::LLVMInitializeARMAsmPrinter(); - llvm::LLVMInitializeARMAsmParser(); - - llvm::LLVMInitializeMipsTargetInfo(); - llvm::LLVMInitializeMipsTarget(); - llvm::LLVMInitializeMipsTargetMC(); - llvm::LLVMInitializeMipsAsmPrinter(); - llvm::LLVMInitializeMipsAsmParser(); - - llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int, + llvm::llvm::LLVMInitializeX86TargetInfo(); + llvm::llvm::LLVMInitializeX86Target(); + llvm::llvm::LLVMInitializeX86TargetMC(); + llvm::llvm::LLVMInitializeX86AsmPrinter(); + llvm::llvm::LLVMInitializeX86AsmParser(); + + llvm::llvm::LLVMInitializeARMTargetInfo(); + llvm::llvm::LLVMInitializeARMTarget(); + llvm::llvm::LLVMInitializeARMTargetMC(); + llvm::llvm::LLVMInitializeARMAsmPrinter(); + llvm::llvm::LLVMInitializeARMAsmParser(); + + llvm::llvm::LLVMInitializeMipsTargetInfo(); + llvm::llvm::LLVMInitializeMipsTarget(); + llvm::llvm::LLVMInitializeMipsTargetMC(); + llvm::llvm::LLVMInitializeMipsAsmPrinter(); + llvm::llvm::LLVMInitializeMipsAsmParser(); + + llvm::llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int, llvm_args.as_ptr()); }); } - unsafe fn populate_llvm_passes(fpm: lib::llvm::PassManagerRef, - mpm: lib::llvm::PassManagerRef, + unsafe fn populate_llvm_passes(fpm: llvm::PassManagerRef, + mpm: llvm::PassManagerRef, llmod: ModuleRef, - opt: lib::llvm::CodeGenOptLevel, + opt: llvm::CodeGenOptLevel, no_builtins: bool) { // Create the PassManagerBuilder for LLVM. We configure it with // reasonable defaults and prepare it to actually populate the pass // manager. - let builder = llvm::LLVMPassManagerBuilderCreate(); + let builder = llvm::llvm::LLVMPassManagerBuilderCreate(); match opt { - lib::llvm::CodeGenLevelNone => { + llvm::CodeGenLevelNone => { // Don't add lifetime intrinsics at O0 - llvm::LLVMRustAddAlwaysInlinePass(builder, false); + llvm::llvm::LLVMRustAddAlwaysInlinePass(builder, false); } - lib::llvm::CodeGenLevelLess => { - llvm::LLVMRustAddAlwaysInlinePass(builder, true); + llvm::CodeGenLevelLess => { + llvm::llvm::LLVMRustAddAlwaysInlinePass(builder, true); } // numeric values copied from clang - lib::llvm::CodeGenLevelDefault => { - llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, + llvm::CodeGenLevelDefault => { + llvm::llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 225); } - lib::llvm::CodeGenLevelAggressive => { - llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, + llvm::CodeGenLevelAggressive => { + llvm::llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 275); } } - llvm::LLVMPassManagerBuilderSetOptLevel(builder, opt as c_uint); - llvm::LLVMRustAddBuilderLibraryInfo(builder, llmod, no_builtins); + llvm::llvm::LLVMPassManagerBuilderSetOptLevel(builder, opt as c_uint); + llvm::llvm::LLVMRustAddBuilderLibraryInfo(builder, llmod, no_builtins); // Use the builder to populate the function/module pass managers. - llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(builder, fpm); - llvm::LLVMPassManagerBuilderPopulateModulePassManager(builder, mpm); - llvm::LLVMPassManagerBuilderDispose(builder); + llvm::llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(builder, fpm); + llvm::llvm::LLVMPassManagerBuilderPopulateModulePassManager(builder, mpm); + llvm::llvm::LLVMPassManagerBuilderDispose(builder); } } @@ -611,7 +609,7 @@ pub fn build_link_meta(sess: &Session, krate: &ast::Crate, name: String) -> LinkMeta { let r = LinkMeta { crate_name: name, - crate_hash: Svh::calculate(sess, krate), + crate_hash: Svh::calculate(&sess.opts.cg.metadata, krate), }; info!("{}", r); return r; diff --git a/src/librustc/back/lto.rs b/src/librustc/back/lto.rs index b9ae9530f8e1c..cf163cdbb637c 100644 --- a/src/librustc/back/lto.rs +++ b/src/librustc/back/lto.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use back::archive::ArchiveRO; -use back::link; +use super::archive::ArchiveRO; +use super::link; use driver::session; use driver::config; -use lib::llvm::{ModuleRef, TargetMachineRef, llvm, True, False}; +use llvm::{ModuleRef, TargetMachineRef, llvm, True, False}; use metadata::cstore; use util::common::time; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 7da3ae0208714..65124ceff1dbb 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -42,6 +42,7 @@ extern crate getopts; extern crate graphviz; extern crate libc; extern crate llvm = "rustc_llvm"; +extern crate rustc_back = "rustc_back"; extern crate serialize; extern crate time; #[phase(plugin, link)] extern crate log; @@ -49,6 +50,24 @@ extern crate time; mod diagnostics; +pub mod back { + pub use rustc_back::abi; + pub use rustc_back::arm; + pub use rustc_back::mips; + pub use rustc_back::mipsel; + pub use rustc_back::svh; + pub use rustc_back::target_strs; + pub use rustc_back::x86; + pub use rustc_back::x86_64; + + pub mod archive; + pub mod link; + pub mod lto; + pub mod rpath; + +} +>>>>>>> Extract librustc_back from librustc + pub mod middle { pub mod def; pub mod trans; @@ -97,21 +116,6 @@ pub mod front { pub mod show_span; } -pub mod back { - pub mod abi; - pub mod archive; - pub mod arm; - pub mod link; - pub mod lto; - pub mod mips; - pub mod mipsel; - pub mod rpath; - pub mod svh; - pub mod target_strs; - pub mod x86; - pub mod x86_64; -} - pub mod metadata; pub mod driver; diff --git a/src/librustc/back/abi.rs b/src/librustc_back/abi.rs similarity index 100% rename from src/librustc/back/abi.rs rename to src/librustc_back/abi.rs diff --git a/src/librustc/back/arm.rs b/src/librustc_back/arm.rs similarity index 99% rename from src/librustc/back/arm.rs rename to src/librustc_back/arm.rs index 7a7d248a4cbf5..a0730360ec729 100644 --- a/src/librustc/back/arm.rs +++ b/src/librustc_back/arm.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use back::target_strs; +use target_strs; use syntax::abi; pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t { diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs new file mode 100644 index 0000000000000..5334c49930005 --- /dev/null +++ b/src/librustc_back/lib.rs @@ -0,0 +1,39 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_id = "rustc_back#0.11.0-pre"] +#![crate_name = "rustc_back"] +#![experimental] +#![comment = "The Rust compiler backend"] +#![license = "MIT/ASL2"] +#![crate_type = "dylib"] +#![crate_type = "rlib"] +#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", + html_favicon_url = "http://www.rust-lang.org/favicon.ico", + html_root_url = "http://doc.rust-lang.org/")] + +#![feature(globs)] +#![feature(phase)] +#![allow(unused_attribute)] // NOTE: remove after stage0 + +#[phase(plugin, link)] +extern crate log; +extern crate syntax; +extern crate libc; +extern crate flate; + +pub mod abi; +pub mod arm; +pub mod mips; +pub mod mipsel; +pub mod svh; +pub mod target_strs; +pub mod x86; +pub mod x86_64; diff --git a/src/librustc/back/mips.rs b/src/librustc_back/mips.rs similarity index 98% rename from src/librustc/back/mips.rs rename to src/librustc_back/mips.rs index 8f3da03e825ea..4176d0e9a6f57 100644 --- a/src/librustc/back/mips.rs +++ b/src/librustc_back/mips.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use back::target_strs; +use target_strs; use syntax::abi; pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t { diff --git a/src/librustc/back/mipsel.rs b/src/librustc_back/mipsel.rs similarity index 98% rename from src/librustc/back/mipsel.rs rename to src/librustc_back/mipsel.rs index c2c48a41e8fe0..d3ea9d3aa7237 100644 --- a/src/librustc/back/mipsel.rs +++ b/src/librustc_back/mipsel.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use back::target_strs; +use target_strs; use syntax::abi; pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t { diff --git a/src/librustc/back/svh.rs b/src/librustc_back/svh.rs similarity index 99% rename from src/librustc/back/svh.rs rename to src/librustc_back/svh.rs index 324ed3b567ec4..66bc8c740c47f 100644 --- a/src/librustc/back/svh.rs +++ b/src/librustc_back/svh.rs @@ -53,8 +53,6 @@ use std::iter::range_step; use syntax::ast; use syntax::visit; -use driver::session::Session; - #[deriving(Clone, PartialEq)] pub struct Svh { hash: String, @@ -70,7 +68,7 @@ impl Svh { self.hash.as_slice() } - pub fn calculate(sess: &Session, krate: &ast::Crate) -> Svh { + pub fn calculate(metadata: &Vec, krate: &ast::Crate) -> Svh { // FIXME (#14132): This is better than it used to be, but it still not // ideal. We now attempt to hash only the relevant portions of the // Crate AST as well as the top-level crate attributes. (However, @@ -82,7 +80,7 @@ impl Svh { // avoid collisions. let mut state = SipState::new(); - for data in sess.opts.cg.metadata.iter() { + for data in metadata.iter() { data.hash(&mut state); } diff --git a/src/librustc/back/target_strs.rs b/src/librustc_back/target_strs.rs similarity index 100% rename from src/librustc/back/target_strs.rs rename to src/librustc_back/target_strs.rs diff --git a/src/librustc/back/x86.rs b/src/librustc_back/x86.rs similarity index 98% rename from src/librustc/back/x86.rs rename to src/librustc_back/x86.rs index d2dac03267d5f..b4d67bc98d2e3 100644 --- a/src/librustc/back/x86.rs +++ b/src/librustc_back/x86.rs @@ -9,7 +9,7 @@ // except according to those terms. -use back::target_strs; +use target_strs; use syntax::abi; pub fn get_target_strs(target_triple: String, target_os: abi::Os) diff --git a/src/librustc/back/x86_64.rs b/src/librustc_back/x86_64.rs similarity index 99% rename from src/librustc/back/x86_64.rs rename to src/librustc_back/x86_64.rs index c2eae18737bfa..70807edc9960e 100644 --- a/src/librustc/back/x86_64.rs +++ b/src/librustc_back/x86_64.rs @@ -9,7 +9,7 @@ // except according to those terms. -use back::target_strs; +use target_strs; use syntax::abi; pub fn get_target_strs(target_triple: String, target_os: abi::Os) -> target_strs::t { From c5a2ac10972092c9610f4f0727e53c1a6782961e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Jul 2014 14:08:09 -0700 Subject: [PATCH 03/13] rustc: Invert some rpath dependencies --- src/librustc/back/link.rs | 20 +++++- src/librustc/back/rpath.rs | 142 +++++++++++++++---------------------- 2 files changed, 77 insertions(+), 85 deletions(-) diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 2112e8d822d38..e08c071ff4e62 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -10,6 +10,7 @@ use super::archive::{Archive, METADATA_FILENAME}; use super::rpath; +use super::rpath::RPathConfig; use super::svh::Svh; use driver::driver::{CrateTranslation, OutputFilenames, Input, FileInput}; use driver::config::NoDebugInfo; @@ -1385,7 +1386,24 @@ fn link_args(cmd: &mut Command, // where extern libraries might live, based on the // addl_lib_search_paths if sess.opts.cg.rpath { - cmd.args(rpath::get_rpath_flags(sess, out_filename).as_slice()); + let sysroot = sess.sysroot(); + let target_triple = sess.opts.target_triple.as_slice(); + let get_install_prefix_lib_path = || { + let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX"); + let tlib = filesearch::relative_target_lib_path(sysroot, target_triple); + let mut path = Path::new(install_prefix); + path.push(&tlib); + + path + }; + let rpath_config = RPathConfig { + os: sess.targ_cfg.os, + used_crates: sess.cstore.get_used_crates(cstore::RequireDynamic), + out_filename: out_filename.clone(), + get_install_prefix_lib_path: get_install_prefix_lib_path, + realpath: ::util::fs::realpath + }; + cmd.args(rpath::get_rpath_flags(rpath_config).as_slice()); } // compiler-rt contains implementations of low-level LLVM helpers. This is diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index a458cf22a5bdc..6a133d8619abc 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -9,30 +9,30 @@ // except according to those terms. -use driver::session::Session; -use metadata::cstore; -use metadata::filesearch; -use util::fs; - use std::collections::HashSet; use std::os; +use std::io::IoError; use syntax::abi; - -fn not_win32(os: abi::Os) -> bool { - os != abi::OsWin32 +use syntax::ast; + +pub struct RPathConfig<'a> { + pub os: abi::Os, + pub used_crates: Vec<(ast::CrateNum, Option)>, + pub out_filename: Path, + pub get_install_prefix_lib_path: ||:'a -> Path, + pub realpath: |&Path|:'a -> Result } -pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec { - let os = sess.targ_cfg.os; +pub fn get_rpath_flags(config: RPathConfig) -> Vec { // No rpath on windows - if os == abi::OsWin32 { + if config.os == abi::OsWin32 { return Vec::new(); } let mut flags = Vec::new(); - if sess.targ_cfg.os == abi::OsFreebsd { + if config.os == abi::OsFreebsd { flags.push_all(["-Wl,-rpath,/usr/local/lib/gcc46".to_string(), "-Wl,-rpath,/usr/local/lib/gcc44".to_string(), "-Wl,-z,origin".to_string()]); @@ -40,23 +40,17 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec { debug!("preparing the RPATH!"); - let sysroot = sess.sysroot(); - let output = out_filename; - let libs = sess.cstore.get_used_crates(cstore::RequireDynamic); + let libs = config.used_crates.clone(); let libs = libs.move_iter().filter_map(|(_, l)| { l.map(|p| p.clone()) }).collect::>(); - let rpaths = get_rpaths(os, - sysroot, - output, - libs.as_slice(), - sess.opts.target_triple.as_slice()); + let rpaths = get_rpaths(config, libs.as_slice()); flags.push_all(rpaths_to_flags(rpaths.as_slice()).as_slice()); flags } -pub fn rpaths_to_flags(rpaths: &[String]) -> Vec { +fn rpaths_to_flags(rpaths: &[String]) -> Vec { let mut ret = Vec::new(); for rpath in rpaths.iter() { ret.push(format!("-Wl,-rpath,{}", (*rpath).as_slice())); @@ -64,26 +58,21 @@ pub fn rpaths_to_flags(rpaths: &[String]) -> Vec { return ret; } -fn get_rpaths(os: abi::Os, - sysroot: &Path, - output: &Path, - libs: &[Path], - target_triple: &str) -> Vec { - debug!("sysroot: {}", sysroot.display()); - debug!("output: {}", output.display()); +fn get_rpaths(mut config: RPathConfig, + libs: &[Path]) -> Vec { + debug!("output: {}", config.out_filename.display()); debug!("libs:"); for libpath in libs.iter() { debug!(" {}", libpath.display()); } - debug!("target_triple: {}", target_triple); // Use relative paths to the libraries. Binaries can be moved // as long as they maintain the relative relationship to the // crates they depend on. - let rel_rpaths = get_rpaths_relative_to_output(os, output, libs); + let rel_rpaths = get_rpaths_relative_to_output(&mut config, libs); // And a final backup rpath to the global library location. - let fallback_rpaths = vec!(get_install_prefix_rpath(sysroot, target_triple)); + let fallback_rpaths = vec!(get_install_prefix_rpath(config)); fn log_rpaths(desc: &str, rpaths: &[String]) { debug!("{} rpaths:", desc); @@ -103,31 +92,28 @@ fn get_rpaths(os: abi::Os, return rpaths; } -fn get_rpaths_relative_to_output(os: abi::Os, - output: &Path, +fn get_rpaths_relative_to_output(config: &mut RPathConfig, libs: &[Path]) -> Vec { - libs.iter().map(|a| get_rpath_relative_to_output(os, output, a)).collect() + libs.iter().map(|a| get_rpath_relative_to_output(config, a)).collect() } -pub fn get_rpath_relative_to_output(os: abi::Os, - output: &Path, - lib: &Path) - -> String { +fn get_rpath_relative_to_output(config: &mut RPathConfig, + lib: &Path) -> String { use std::os; - assert!(not_win32(os)); + assert!(config.os != abi::OsWin32); // Mac doesn't appear to support $ORIGIN - let prefix = match os { + let prefix = match config.os { abi::OsAndroid | abi::OsLinux | abi::OsFreebsd => "$ORIGIN", abi::OsMacos => "@loader_path", abi::OsWin32 | abi::OsiOS => unreachable!() }; - let mut lib = fs::realpath(&os::make_absolute(lib)).unwrap(); + let mut lib = (config.realpath)(&os::make_absolute(lib)).unwrap(); lib.pop(); - let mut output = fs::realpath(&os::make_absolute(output)).unwrap(); + let mut output = (config.realpath)(&os::make_absolute(&config.out_filename)).unwrap(); output.pop(); let relative = lib.path_relative_from(&output); let relative = relative.expect("could not create rpath relative to output"); @@ -137,18 +123,14 @@ pub fn get_rpath_relative_to_output(os: abi::Os, relative.as_str().expect("non-utf8 component in path")) } -pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &str) -> String { - let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX"); - - let tlib = filesearch::relative_target_lib_path(sysroot, target_triple); - let mut path = Path::new(install_prefix); - path.push(&tlib); +fn get_install_prefix_rpath(config: RPathConfig) -> String { + let path = (config.get_install_prefix_lib_path)(); let path = os::make_absolute(&path); // FIXME (#9639): This needs to handle non-utf8 paths path.as_str().expect("non-utf8 component in rpath").to_string() } -pub fn minimize_rpaths(rpaths: &[String]) -> Vec { +fn minimize_rpaths(rpaths: &[String]) -> Vec { let mut set = HashSet::new(); let mut minimized = Vec::new(); for rpath in rpaths.iter() { @@ -161,10 +143,9 @@ pub fn minimize_rpaths(rpaths: &[String]) -> Vec { #[cfg(unix, test)] mod test { - use back::rpath::get_install_prefix_rpath; - use back::rpath::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output}; + use super::{RPathConfig}; + use super::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output}; use syntax::abi; - use metadata::filesearch; #[test] fn test_rpaths_to_flags() { @@ -177,27 +158,6 @@ mod test { "-Wl,-rpath,path2".to_string())); } - #[test] - fn test_prefix_rpath() { - let sysroot = filesearch::get_or_default_sysroot(); - let res = get_install_prefix_rpath(&sysroot, "triple"); - let mut d = Path::new((option_env!("CFG_PREFIX")).expect("CFG_PREFIX")); - d.push("lib"); - d.push(filesearch::rustlibdir()); - d.push("triple/lib"); - debug!("test_prefix_path: {} vs. {}", - res, - d.display()); - assert!(res.as_bytes().ends_with(d.as_vec())); - } - - #[test] - fn test_prefix_rpath_abs() { - let sysroot = filesearch::get_or_default_sysroot(); - let res = get_install_prefix_rpath(&sysroot, "triple"); - assert!(Path::new(res).is_absolute()); - } - #[test] fn test_minimize1() { let res = minimize_rpaths([ @@ -237,28 +197,42 @@ mod test { #[cfg(target_os = "linux")] #[cfg(target_os = "android")] fn test_rpath_relative() { - let o = abi::OsLinux; - let res = get_rpath_relative_to_output(o, - &Path::new("bin/rustc"), &Path::new("lib/libstd.so")); - assert_eq!(res.as_slice(), "$ORIGIN/../lib"); + let config = &mut RPathConfig { + os: abi::OsLinux, + used_crates: Vec::new(), + out_filename: Path::new("bin/rustc"), + get_install_prefix_lib_path: || fail!(), + realpath: |p| Ok(p.clone()) + }; + let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so")); + assert_eq!(res.as_slice(), "$ORIGIN/../lib"); } #[test] #[cfg(target_os = "freebsd")] fn test_rpath_relative() { - let o = abi::OsFreebsd; - let res = get_rpath_relative_to_output(o, - &Path::new("bin/rustc"), &Path::new("lib/libstd.so")); + let config = &mut RPathConfig { + os: abi::OsFreebsd, + used_crates: Vec::new(), + out_filename: Path::new("bin/rustc"), + get_install_prefix_lib_path: || fail!(), + realpath: |p| Ok(p.clone()) + }; + let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so")); assert_eq!(res.as_slice(), "$ORIGIN/../lib"); } #[test] #[cfg(target_os = "macos")] fn test_rpath_relative() { - let o = abi::OsMacos; - let res = get_rpath_relative_to_output(o, - &Path::new("bin/rustc"), - &Path::new("lib/libstd.so")); + let config = &mut RPathConfig { + os: abi::OsMacos, + used_crates: Vec::new(), + out_filename: Path::new("bin/rustc"), + get_install_prefix_lib_path: || fail!(), + realpath: |p| p.clone() + }; + let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so")); assert_eq!(res.as_slice(), "@loader_path/../lib"); } } From 930abc156789db6ee897a68f02fac6af682cca5b Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Jul 2014 18:01:16 -0700 Subject: [PATCH 04/13] Extract rpath to rustc_back::rpath --- src/librustc/lib.rs | 2 +- src/librustc_back/lib.rs | 1 + src/{librustc/back => librustc_back}/rpath.rs | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename src/{librustc/back => librustc_back}/rpath.rs (100%) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 65124ceff1dbb..d5d754748f11a 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -55,6 +55,7 @@ pub mod back { pub use rustc_back::arm; pub use rustc_back::mips; pub use rustc_back::mipsel; + pub use rustc_back::rpath; pub use rustc_back::svh; pub use rustc_back::target_strs; pub use rustc_back::x86; @@ -63,7 +64,6 @@ pub mod back { pub mod archive; pub mod link; pub mod lto; - pub mod rpath; } >>>>>>> Extract librustc_back from librustc diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 5334c49930005..156a419bb2d85 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -33,6 +33,7 @@ pub mod abi; pub mod arm; pub mod mips; pub mod mipsel; +pub mod rpath; pub mod svh; pub mod target_strs; pub mod x86; diff --git a/src/librustc/back/rpath.rs b/src/librustc_back/rpath.rs similarity index 100% rename from src/librustc/back/rpath.rs rename to src/librustc_back/rpath.rs From 7f6a66f77ef362059328524d54b6b987322d2c36 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Jul 2014 20:46:00 -0700 Subject: [PATCH 05/13] rustc: Invert some archive deps --- src/librustc/back/archive.rs | 85 +++++++++++++++++++++++------------- src/librustc/back/link.rs | 34 +++++++++++++-- 2 files changed, 85 insertions(+), 34 deletions(-) diff --git a/src/librustc/back/archive.rs b/src/librustc/back/archive.rs index 8acb610db3f59..ac457f208dd05 100644 --- a/src/librustc/back/archive.rs +++ b/src/librustc/back/archive.rs @@ -10,9 +10,6 @@ //! A helper class for dealing with static archives -use super::link::{get_ar_prog}; -use driver::session::Session; -use metadata::filesearch; use llvm::{ArchiveRef, llvm}; use libc; @@ -24,22 +21,38 @@ use std::os; use std::raw; use std::str; use syntax::abi; +use ErrorHandler = syntax::diagnostic::Handler; pub static METADATA_FILENAME: &'static str = "rust.metadata.bin"; +pub struct ArchiveConfig<'a> { + pub handler: &'a ErrorHandler, + pub dst: Path, + pub lib_search_paths: Vec, + pub os: abi::Os, + pub maybe_ar_prog: Option +} + pub struct Archive<'a> { - sess: &'a Session, + handler: &'a ErrorHandler, dst: Path, + lib_search_paths: Vec, + os: abi::Os, + maybe_ar_prog: Option } pub struct ArchiveRO { ptr: ArchiveRef, } -fn run_ar(sess: &Session, args: &str, cwd: Option<&Path>, +fn run_ar(handler: &ErrorHandler, maybe_ar_prog: &Option, + args: &str, cwd: Option<&Path>, paths: &[&Path]) -> ProcessOutput { - let ar = get_ar_prog(sess); - let mut cmd = Command::new(ar.as_slice()); + let ar = match *maybe_ar_prog { + Some(ref ar) => ar.as_slice(), + None => "ar" + }; + let mut cmd = Command::new(ar); cmd.arg(args).args(paths); debug!("{}", cmd); @@ -56,25 +69,25 @@ fn run_ar(sess: &Session, args: &str, cwd: Option<&Path>, Ok(prog) => { let o = prog.wait_with_output().unwrap(); if !o.status.success() { - sess.err(format!("{} failed with: {}", + handler.err(format!("{} failed with: {}", cmd, o.status).as_slice()); - sess.note(format!("stdout ---\n{}", + handler.note(format!("stdout ---\n{}", str::from_utf8(o.output .as_slice()).unwrap()) .as_slice()); - sess.note(format!("stderr ---\n{}", + handler.note(format!("stderr ---\n{}", str::from_utf8(o.error .as_slice()).unwrap()) .as_slice()); - sess.abort_if_errors(); + handler.abort_if_errors(); } o }, Err(e) => { - sess.err(format!("could not exec `{}`: {}", ar.as_slice(), + handler.err(format!("could not exec `{}`: {}", ar.as_slice(), e).as_slice()); - sess.abort_if_errors(); + handler.abort_if_errors(); fail!("rustc::back::archive::run_ar() should not reach this point"); } } @@ -82,16 +95,29 @@ fn run_ar(sess: &Session, args: &str, cwd: Option<&Path>, impl<'a> Archive<'a> { /// Initializes a new static archive with the given object file - pub fn create<'b>(sess: &'a Session, dst: &'b Path, - initial_object: &'b Path) -> Archive<'a> { - run_ar(sess, "crus", None, [dst, initial_object]); - Archive { sess: sess, dst: dst.clone() } + pub fn create<'b>(config: ArchiveConfig<'a>, initial_object: &'b Path) -> Archive<'a> { + let ArchiveConfig { handler, dst, lib_search_paths, os, maybe_ar_prog } = config; + run_ar(handler, &maybe_ar_prog, "crus", None, [&dst, initial_object]); + Archive { + handler: handler, + dst: dst, + lib_search_paths: lib_search_paths, + os: os, + maybe_ar_prog: maybe_ar_prog + } } /// Opens an existing static archive - pub fn open(sess: &'a Session, dst: Path) -> Archive<'a> { + pub fn open(config: ArchiveConfig<'a>) -> Archive<'a> { + let ArchiveConfig { handler, dst, lib_search_paths, os, maybe_ar_prog } = config; assert!(dst.exists()); - Archive { sess: sess, dst: dst } + Archive { + handler: handler, + dst: dst, + lib_search_paths: lib_search_paths, + os: os, + maybe_ar_prog: maybe_ar_prog + } } /// Adds all of the contents of a native library to this archive. This will @@ -120,22 +146,22 @@ impl<'a> Archive<'a> { /// Adds an arbitrary file to this archive pub fn add_file(&mut self, file: &Path, has_symbols: bool) { let cmd = if has_symbols {"r"} else {"rS"}; - run_ar(self.sess, cmd, None, [&self.dst, file]); + run_ar(self.handler, &self.maybe_ar_prog, cmd, None, [&self.dst, file]); } /// Removes a file from this archive pub fn remove_file(&mut self, file: &str) { - run_ar(self.sess, "d", None, [&self.dst, &Path::new(file)]); + run_ar(self.handler, &self.maybe_ar_prog, "d", None, [&self.dst, &Path::new(file)]); } /// Updates all symbols in the archive (runs 'ar s' over it) pub fn update_symbols(&mut self) { - run_ar(self.sess, "s", None, [&self.dst]); + run_ar(self.handler, &self.maybe_ar_prog, "s", None, [&self.dst]); } /// Lists all files in an archive pub fn files(&self) -> Vec { - let output = run_ar(self.sess, "t", None, [&self.dst]); + let output = run_ar(self.handler, &self.maybe_ar_prog, "t", None, [&self.dst]); let output = str::from_utf8(output.output.as_slice()).unwrap(); // use lines_any because windows delimits output with `\r\n` instead of // just `\n` @@ -148,7 +174,7 @@ impl<'a> Archive<'a> { // First, extract the contents of the archive to a temporary directory let archive = os::make_absolute(archive); - run_ar(self.sess, "x", Some(loc.path()), [&archive]); + run_ar(self.handler, &self.maybe_ar_prog, "x", Some(loc.path()), [&archive]); // Next, we must rename all of the inputs to "guaranteed unique names". // The reason for this is that archives are keyed off the name of the @@ -184,12 +210,12 @@ impl<'a> Archive<'a> { // Finally, add all the renamed files to this archive let mut args = vec!(&self.dst); args.extend(inputs.iter()); - run_ar(self.sess, "r", None, args.as_slice()); + run_ar(self.handler, &self.maybe_ar_prog, "r", None, args.as_slice()); Ok(()) } fn find_library(&self, name: &str) -> Path { - let (osprefix, osext) = match self.sess.targ_cfg.os { + let (osprefix, osext) = match self.os { abi::OsWin32 => ("", "lib"), _ => ("lib", "a"), }; // On Windows, static libraries sometimes show up as libfoo.a and other @@ -197,10 +223,7 @@ impl<'a> Archive<'a> { let oslibname = format!("{}{}.{}", osprefix, name, osext); let unixlibname = format!("lib{}.a", name); - let mut rustpath = filesearch::rust_path(); - rustpath.push(self.sess.target_filesearch().get_lib_path()); - let search = self.sess.opts.addl_lib_search_paths.borrow(); - for path in search.iter().chain(rustpath.iter()) { + for path in self.lib_search_paths.iter() { debug!("looking for {} inside {}", name, path.display()); let test = path.join(oslibname.as_slice()); if test.exists() { return test } @@ -209,7 +232,7 @@ impl<'a> Archive<'a> { if test.exists() { return test } } } - self.sess.fatal(format!("could not find native static library `{}`, \ + self.handler.fatal(format!("could not find native static library `{}`, \ perhaps an -L flag is missing?", name).as_slice()); } diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index e08c071ff4e62..a552f54215055 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use super::archive::{Archive, METADATA_FILENAME}; +use super::archive::{Archive, ArchiveConfig, METADATA_FILENAME}; use super::rpath; use super::rpath::RPathConfig; use super::svh::Svh; @@ -29,6 +29,7 @@ use util::sha2::{Digest, Sha256}; use std::c_str::{ToCStr, CString}; use std::char; +use std::collections::HashSet; use std::io::{fs, TempDir, Command}; use std::io; use std::ptr; @@ -962,6 +963,17 @@ fn link_binary_output(sess: &Session, out_filename } +fn archive_search_paths(sess: &Session) -> Vec { + let mut rustpath = filesearch::rust_path(); + rustpath.push(sess.target_filesearch().get_lib_path()); + // FIXME: Addl lib search paths are an unordered HashSet? + // Shouldn't this search be done in some order? + let addl_lib_paths: HashSet = sess.opts.addl_lib_search_paths.borrow().clone(); + let mut search: Vec = addl_lib_paths.move_iter().collect(); + search.push_all(rustpath.as_slice()); + return search; +} + // Create an 'rlib' // // An rlib in its current incarnation is essentially a renamed .a file. The @@ -972,7 +984,15 @@ fn link_rlib<'a>(sess: &'a Session, trans: Option<&CrateTranslation>, // None == no metadata/bytecode obj_filename: &Path, out_filename: &Path) -> Archive<'a> { - let mut a = Archive::create(sess, out_filename, obj_filename); + let handler = &sess.diagnostic().handler; + let config = ArchiveConfig { + handler: handler, + dst: out_filename.clone(), + lib_search_paths: archive_search_paths(sess), + os: sess.targ_cfg.os, + maybe_ar_prog: sess.opts.cg.ar.clone() + }; + let mut a = Archive::create(config, obj_filename); for &(ref l, kind) in sess.cstore.get_used_libraries().borrow().iter() { match kind { @@ -1561,7 +1581,15 @@ fn add_upstream_rust_crates(cmd: &mut Command, sess: &Session, sess.abort_if_errors(); } } - let mut archive = Archive::open(sess, dst.clone()); + let handler = &sess.diagnostic().handler; + let config = ArchiveConfig { + handler: handler, + dst: dst.clone(), + lib_search_paths: archive_search_paths(sess), + os: sess.targ_cfg.os, + maybe_ar_prog: sess.opts.cg.ar.clone() + }; + let mut archive = Archive::open(config); archive.remove_file(format!("{}.o", name).as_slice()); let files = archive.files(); if files.iter().any(|s| s.as_slice().ends_with(".o")) { From 55393493e1b61aaf1b91ab6bbce442d857d7b42d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Jul 2014 21:43:22 -0700 Subject: [PATCH 06/13] rustc: Move ArchiveRO to rustc_llvm It is a wrapper around LLVM. --- src/librustc/back/archive.rs | 55 -------------------------- src/librustc/back/lto.rs | 2 +- src/librustc/metadata/loader.rs | 3 +- src/librustc_llvm/archive_ro.rs | 69 +++++++++++++++++++++++++++++++++ src/librustc_llvm/lib.rs | 2 + 5 files changed, 74 insertions(+), 57 deletions(-) create mode 100644 src/librustc_llvm/archive_ro.rs diff --git a/src/librustc/back/archive.rs b/src/librustc/back/archive.rs index ac457f208dd05..c4a9d9c80ef12 100644 --- a/src/librustc/back/archive.rs +++ b/src/librustc/back/archive.rs @@ -10,15 +10,10 @@ //! A helper class for dealing with static archives -use llvm::{ArchiveRef, llvm}; - -use libc; use std::io::process::{Command, ProcessOutput}; use std::io::{fs, TempDir}; use std::io; -use std::mem; use std::os; -use std::raw; use std::str; use syntax::abi; use ErrorHandler = syntax::diagnostic::Handler; @@ -41,10 +36,6 @@ pub struct Archive<'a> { maybe_ar_prog: Option } -pub struct ArchiveRO { - ptr: ArchiveRef, -} - fn run_ar(handler: &ErrorHandler, maybe_ar_prog: &Option, args: &str, cwd: Option<&Path>, paths: &[&Path]) -> ProcessOutput { @@ -238,49 +229,3 @@ impl<'a> Archive<'a> { } } -impl ArchiveRO { - /// Opens a static archive for read-only purposes. This is more optimized - /// than the `open` method because it uses LLVM's internal `Archive` class - /// rather than shelling out to `ar` for everything. - /// - /// If this archive is used with a mutable method, then an error will be - /// raised. - pub fn open(dst: &Path) -> Option { - unsafe { - let ar = dst.with_c_str(|dst| { - llvm::LLVMRustOpenArchive(dst) - }); - if ar.is_null() { - None - } else { - Some(ArchiveRO { ptr: ar }) - } - } - } - - /// Reads a file in the archive - pub fn read<'a>(&'a self, file: &str) -> Option<&'a [u8]> { - unsafe { - let mut size = 0 as libc::size_t; - let ptr = file.with_c_str(|file| { - llvm::LLVMRustArchiveReadSection(self.ptr, file, &mut size) - }); - if ptr.is_null() { - None - } else { - Some(mem::transmute(raw::Slice { - data: ptr, - len: size as uint, - })) - } - } - } -} - -impl Drop for ArchiveRO { - fn drop(&mut self) { - unsafe { - llvm::LLVMRustDestroyArchive(self.ptr); - } - } -} diff --git a/src/librustc/back/lto.rs b/src/librustc/back/lto.rs index cf163cdbb637c..6fc60b657d31e 100644 --- a/src/librustc/back/lto.rs +++ b/src/librustc/back/lto.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use super::archive::ArchiveRO; use super::link; use driver::session; use driver::config; +use llvm::archive_ro::ArchiveRO; use llvm::{ModuleRef, TargetMachineRef, llvm, True, False}; use metadata::cstore; use util::common::time; diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 1b2349a271ed1..1877bd1260e51 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -212,10 +212,11 @@ //! no means all of the necessary details. Take a look at the rest of //! metadata::loader or metadata::creader for all the juicy details! -use back::archive::{ArchiveRO, METADATA_FILENAME}; +use back::archive::{METADATA_FILENAME}; use back::svh::Svh; use driver::session::Session; use lib::llvm::{False, llvm, ObjectFile, mk_section_iter}; +use lib::llvm::archive_ro::ArchiveRO; use metadata::cstore::{MetadataBlob, MetadataVec, MetadataArchive}; use metadata::decoder; use metadata::encoder; diff --git a/src/librustc_llvm/archive_ro.rs b/src/librustc_llvm/archive_ro.rs new file mode 100644 index 0000000000000..0b0577f7e8c5e --- /dev/null +++ b/src/librustc_llvm/archive_ro.rs @@ -0,0 +1,69 @@ +// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! A wrapper around LLVM's archive (.a) code + +use libc; +use ArchiveRef; +use llvm; + +use std::raw; +use std::mem; + +pub struct ArchiveRO { + ptr: ArchiveRef, +} + +impl ArchiveRO { + /// Opens a static archive for read-only purposes. This is more optimized + /// than the `open` method because it uses LLVM's internal `Archive` class + /// rather than shelling out to `ar` for everything. + /// + /// If this archive is used with a mutable method, then an error will be + /// raised. + pub fn open(dst: &Path) -> Option { + unsafe { + let ar = dst.with_c_str(|dst| { + llvm::LLVMRustOpenArchive(dst) + }); + if ar.is_null() { + None + } else { + Some(ArchiveRO { ptr: ar }) + } + } + } + + /// Reads a file in the archive + pub fn read<'a>(&'a self, file: &str) -> Option<&'a [u8]> { + unsafe { + let mut size = 0 as libc::size_t; + let ptr = file.with_c_str(|file| { + llvm::LLVMRustArchiveReadSection(self.ptr, file, &mut size) + }); + if ptr.is_null() { + None + } else { + Some(mem::transmute(raw::Slice { + data: ptr, + len: size as uint, + })) + } + } + } +} + +impl Drop for ArchiveRO { + fn drop(&mut self) { + unsafe { + llvm::LLVMRustDestroyArchive(self.ptr); + } + } +} diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 121e8882f1ae1..47e642345f8d4 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -32,6 +32,8 @@ extern crate libc; use std::c_str::ToCStr; use libc::{c_uint, c_ushort, uint64_t, c_int, size_t}; +pub mod archive_ro; + pub type Opcode = u32; pub type Bool = c_uint; From 504d4599e248ae3cf00fac09849e23412c4881f4 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Jul 2014 21:50:37 -0700 Subject: [PATCH 07/13] rustc: Move archive to rustc_back --- src/librustc/lib.rs | 2 +- src/{librustc/back => librustc_back}/archive.rs | 0 src/librustc_back/lib.rs | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) rename src/{librustc/back => librustc_back}/archive.rs (100%) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index d5d754748f11a..cf6852438a72a 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -52,6 +52,7 @@ mod diagnostics; pub mod back { pub use rustc_back::abi; + pub use rustc_back::archive; pub use rustc_back::arm; pub use rustc_back::mips; pub use rustc_back::mipsel; @@ -61,7 +62,6 @@ pub mod back { pub use rustc_back::x86; pub use rustc_back::x86_64; - pub mod archive; pub mod link; pub mod lto; diff --git a/src/librustc/back/archive.rs b/src/librustc_back/archive.rs similarity index 100% rename from src/librustc/back/archive.rs rename to src/librustc_back/archive.rs diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 156a419bb2d85..f646102802bd9 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -30,6 +30,7 @@ extern crate libc; extern crate flate; pub mod abi; +pub mod archive; pub mod arm; pub mod mips; pub mod mipsel; From be018645d8e19e04ef8bf2db22f2190cb5f04f0a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Jul 2014 21:58:30 -0700 Subject: [PATCH 08/13] rustc_back: Update crate docs Indicate that anything that can be extracted here should and that things with syntax deps should be split out someday. --- src/librustc_back/lib.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index f646102802bd9..b4c4118c76d56 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -8,10 +8,23 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +//! Some stuff used by rustc that doesn't have many dependencies +//! +//! Originally extracted from rustc::back, which was nominally the +//! compiler 'backend', though LLVM is rustc's backend, so rustc_back +//! is really just odds-and-ends relating to code gen and linking. +//! This crate mostly exists to make rustc smaller, so we might put +//! more 'stuff' here in the future. It does not have a dependency on +//! rustc_llvm. +//! +//! FIXME: Split this into two crates: one that has deps on syntax, and +//! one that doesn't; the one that doesn't might get decent parallel +//! build speedups. + #![crate_id = "rustc_back#0.11.0-pre"] #![crate_name = "rustc_back"] #![experimental] -#![comment = "The Rust compiler backend"] +#![comment = "The Rust compiler minimal-dependency dumping-ground"] #![license = "MIT/ASL2"] #![crate_type = "dylib"] #![crate_type = "rlib"] From 46266bd60651b75e476115ec97a4ab0c4f9f462a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Jul 2014 22:13:55 -0700 Subject: [PATCH 09/13] rustc: Move util::fs to rustc_back --- src/librustc/lib.rs | 3 ++- src/{librustc/util => librustc_back}/fs.rs | 0 src/librustc_back/lib.rs | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) rename src/{librustc/util => librustc_back}/fs.rs (100%) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index cf6852438a72a..016af688c50fb 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -125,11 +125,12 @@ pub mod plugin; pub mod lint; pub mod util { + pub use rustc_back::fs; + pub mod common; pub mod ppaux; pub mod sha2; pub mod nodemap; - pub mod fs; } pub mod lib { diff --git a/src/librustc/util/fs.rs b/src/librustc_back/fs.rs similarity index 100% rename from src/librustc/util/fs.rs rename to src/librustc_back/fs.rs diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index b4c4118c76d56..00791b39bcaac 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -45,6 +45,7 @@ extern crate flate; pub mod abi; pub mod archive; pub mod arm; +pub mod fs; pub mod mips; pub mod mipsel; pub mod rpath; From c199790077587e88445b0244c34e0a4a526d6498 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Jul 2014 22:21:04 -0700 Subject: [PATCH 10/13] rustc: Move util::sha2 to rustc_back --- src/librustc/lib.rs | 2 +- src/librustc_back/lib.rs | 5 +++-- src/{librustc/util => librustc_back}/sha2.rs | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) rename src/{librustc/util => librustc_back}/sha2.rs (99%) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 016af688c50fb..99eed04b55898 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -126,10 +126,10 @@ pub mod lint; pub mod util { pub use rustc_back::fs; + pub use rustc_back::sha2; pub mod common; pub mod ppaux; - pub mod sha2; pub mod nodemap; } diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 00791b39bcaac..8ec74f4d6efcc 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -32,8 +32,7 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/")] -#![feature(globs)] -#![feature(phase)] +#![feature(globs, phase, macro_rules)] #![allow(unused_attribute)] // NOTE: remove after stage0 #[phase(plugin, link)] @@ -41,6 +40,7 @@ extern crate log; extern crate syntax; extern crate libc; extern crate flate; +extern crate serialize; pub mod abi; pub mod archive; @@ -49,6 +49,7 @@ pub mod fs; pub mod mips; pub mod mipsel; pub mod rpath; +pub mod sha2; pub mod svh; pub mod target_strs; pub mod x86; diff --git a/src/librustc/util/sha2.rs b/src/librustc_back/sha2.rs similarity index 99% rename from src/librustc/util/sha2.rs rename to src/librustc_back/sha2.rs index bfd3deb0f2dcd..681de6a6626be 100644 --- a/src/librustc/util/sha2.rs +++ b/src/librustc_back/sha2.rs @@ -12,6 +12,8 @@ //! use. This implementation is not intended for external use or for any use where security is //! important. +#![allow(deprecated)] // to_be32 + use std::iter::range_step; use std::num::Zero; use std::slice::bytes::{MutableByteVector, copy_memory}; From 8e2e15f163fa696aaeae658c84bdcb95bd67432a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 7 Jul 2014 16:54:02 -0700 Subject: [PATCH 11/13] rustc_llvm: Remove an unnecessary workaround Just some leftover junk from extracting llvm. --- src/librustc_llvm/lib.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 47e642345f8d4..f46a41835f637 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -351,10 +351,6 @@ pub mod llvm { use libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong, size_t, uint64_t}; - pub unsafe fn LLVMInitializeX86AsmPrinter() { - LLVMInitializeX86AsmPrinter_() - } - // 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++ // @@ -1764,8 +1760,7 @@ pub mod llvm { pub fn LLVMInitializeX86TargetInfo(); pub fn LLVMInitializeX86Target(); pub fn LLVMInitializeX86TargetMC(); - #[link_name = "LLVMInitializeX86AsmPrinter"] - pub fn LLVMInitializeX86AsmPrinter_(); + pub fn LLVMInitializeX86AsmPrinter(); pub fn LLVMInitializeX86AsmParser(); pub fn LLVMInitializeARMTargetInfo(); pub fn LLVMInitializeARMTarget(); From 3096d9bf946d2e3e74b24dbb4a5d116a5d9ac7c7 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 7 Jul 2014 17:58:01 -0700 Subject: [PATCH 12/13] rustc_llvm: Remove the inner llvm module This makes it much saner for clients to use the library since they don't have to worry about shadowing one llvm with another. --- src/librustc/back/link.rs | 114 +- src/librustc/back/lto.rs | 3 +- src/librustc/driver/config.rs | 2 +- src/librustc/driver/driver.rs | 2 +- src/librustc/driver/mod.rs | 2 +- src/librustc/metadata/loader.rs | 5 +- src/librustc/middle/trans/_match.rs | 3 +- src/librustc/middle/trans/adt.rs | 2 +- src/librustc/middle/trans/asm.rs | 6 +- src/librustc/middle/trans/base.rs | 160 +- src/librustc/middle/trans/basic_block.rs | 3 +- src/librustc/middle/trans/build.rs | 21 +- src/librustc/middle/trans/builder.rs | 29 +- src/librustc/middle/trans/cabi.rs | 2 +- src/librustc/middle/trans/cabi_arm.rs | 5 +- src/librustc/middle/trans/cabi_mips.rs | 5 +- src/librustc/middle/trans/cabi_x86.rs | 2 +- src/librustc/middle/trans/cabi_x86_64.rs | 7 +- src/librustc/middle/trans/callee.rs | 4 +- src/librustc/middle/trans/cleanup.rs | 2 +- src/librustc/middle/trans/closure.rs | 2 +- src/librustc/middle/trans/common.rs | 11 +- src/librustc/middle/trans/consts.rs | 5 +- src/librustc/middle/trans/context.rs | 7 +- src/librustc/middle/trans/controlflow.rs | 2 +- src/librustc/middle/trans/datum.rs | 2 +- src/librustc/middle/trans/debuginfo.rs | 6 +- src/librustc/middle/trans/expr.rs | 6 +- src/librustc/middle/trans/foreign.rs | 57 +- src/librustc/middle/trans/glue.rs | 8 +- src/librustc/middle/trans/inline.rs | 2 +- src/librustc/middle/trans/intrinsic.rs | 4 +- src/librustc/middle/trans/llrepr.rs | 2 +- src/librustc/middle/trans/machine.rs | 6 +- src/librustc/middle/trans/meth.rs | 9 +- src/librustc/middle/trans/monomorphize.rs | 2 +- src/librustc/middle/trans/reflect.rs | 3 +- src/librustc/middle/trans/tvec.rs | 8 +- src/librustc/middle/trans/type_.rs | 5 +- src/librustc/middle/trans/value.rs | 3 +- src/librustc_llvm/archive_ro.rs | 7 +- src/librustc_llvm/lib.rs | 2860 ++++++++++----------- 42 files changed, 1698 insertions(+), 1698 deletions(-) diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index a552f54215055..cad164c9e2019 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -56,7 +56,7 @@ pub enum OutputType { pub fn llvm_err(sess: &Session, msg: String) -> ! { unsafe { - let cstr = llvm::llvm::LLVMRustGetLastError(); + let cstr = llvm::LLVMRustGetLastError(); if cstr == ptr::null() { sess.fatal(msg.as_slice()); } else { @@ -78,7 +78,7 @@ pub fn write_output_file( file_type: llvm::FileType) { unsafe { output.with_c_str(|output| { - let result = llvm::llvm::LLVMRustWriteOutputFile( + let result = llvm::LLVMRustWriteOutputFile( target, pm, m, output, file_type); if !result { llvm_err(sess, "could not write output".to_string()); @@ -147,7 +147,7 @@ pub mod write { if sess.opts.cg.save_temps { output.with_extension("no-opt.bc").with_c_str(|buf| { - llvm::llvm::LLVMWriteBitcodeToFile(llmod, buf); + llvm::LLVMWriteBitcodeToFile(llmod, buf); }) } @@ -193,7 +193,7 @@ pub mod write { .with_c_str(|t| { sess.opts.cg.target_cpu.as_slice().with_c_str(|cpu| { target_feature(sess).with_c_str(|features| { - llvm::llvm::LLVMRustCreateTargetMachine( + llvm::LLVMRustCreateTargetMachine( t, cpu, features, llvm::CodeModelDefault, reloc_model, @@ -212,26 +212,26 @@ pub mod write { // does, and are by populated by LLVM's default PassManagerBuilder. // Each manager has a different set of passes, but they also share // some common passes. - let fpm = llvm::llvm::LLVMCreateFunctionPassManagerForModule(llmod); - let mpm = llvm::llvm::LLVMCreatePassManager(); + let fpm = llvm::LLVMCreateFunctionPassManagerForModule(llmod); + let mpm = llvm::LLVMCreatePassManager(); // If we're verifying or linting, add them to the function pass // manager. let addpass = |pass: &str| { - pass.as_slice().with_c_str(|s| llvm::llvm::LLVMRustAddPass(fpm, s)) + pass.as_slice().with_c_str(|s| llvm::LLVMRustAddPass(fpm, s)) }; if !sess.no_verify() { assert!(addpass("verify")); } if !sess.opts.cg.no_prepopulate_passes { - llvm::llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod); - llvm::llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod); + llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod); + llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod); populate_llvm_passes(fpm, mpm, llmod, opt_level, trans.no_builtins); } for pass in sess.opts.cg.passes.iter() { pass.as_slice().with_c_str(|s| { - if !llvm::llvm::LLVMRustAddPass(mpm, s) { + if !llvm::LLVMRustAddPass(mpm, s) { sess.warn(format!("unknown pass {}, ignoring", *pass).as_slice()); } @@ -240,13 +240,13 @@ pub mod write { // Finally, run the actual optimization passes time(sess.time_passes(), "llvm function passes", (), |()| - llvm::llvm::LLVMRustRunFunctionPassManager(fpm, llmod)); + llvm::LLVMRustRunFunctionPassManager(fpm, llmod)); time(sess.time_passes(), "llvm module passes", (), |()| - llvm::llvm::LLVMRunPassManager(mpm, llmod)); + llvm::LLVMRunPassManager(mpm, llmod)); // Deallocate managers that we're now done with - llvm::llvm::LLVMDisposePassManager(fpm); - llvm::llvm::LLVMDisposePassManager(mpm); + llvm::LLVMDisposePassManager(fpm); + llvm::LLVMDisposePassManager(mpm); // Emit the bytecode if we're either saving our temporaries or // emitting an rlib. Whenever an rlib is created, the bytecode is @@ -255,7 +255,7 @@ pub mod write { (sess.crate_types.borrow().contains(&config::CrateTypeRlib) && sess.opts.output_types.contains(&OutputTypeExe)) { output.temp_path(OutputTypeBitcode).with_c_str(|buf| { - llvm::llvm::LLVMWriteBitcodeToFile(llmod, buf); + llvm::LLVMWriteBitcodeToFile(llmod, buf); }) } @@ -265,7 +265,7 @@ pub mod write { if sess.opts.cg.save_temps { output.with_extension("lto.bc").with_c_str(|buf| { - llvm::llvm::LLVMWriteBitcodeToFile(llmod, buf); + llvm::LLVMWriteBitcodeToFile(llmod, buf); }) } } @@ -281,11 +281,11 @@ pub mod write { fn with_codegen(tm: TargetMachineRef, llmod: ModuleRef, no_builtins: bool, f: |PassManagerRef|) { unsafe { - let cpm = llvm::llvm::LLVMCreatePassManager(); - llvm::llvm::LLVMRustAddAnalysisPasses(tm, cpm, llmod); - llvm::llvm::LLVMRustAddLibraryInfo(cpm, llmod, no_builtins); + let cpm = llvm::LLVMCreatePassManager(); + llvm::LLVMRustAddAnalysisPasses(tm, cpm, llmod); + llvm::LLVMRustAddLibraryInfo(cpm, llmod, no_builtins); f(cpm); - llvm::llvm::LLVMDisposePassManager(cpm); + llvm::LLVMDisposePassManager(cpm); } } @@ -296,13 +296,13 @@ pub mod write { match *output_type { OutputTypeBitcode => { path.with_c_str(|buf| { - llvm::llvm::LLVMWriteBitcodeToFile(llmod, buf); + llvm::LLVMWriteBitcodeToFile(llmod, buf); }) } OutputTypeLlvmAssembly => { path.with_c_str(|output| { with_codegen(tm, llmod, trans.no_builtins, |cpm| { - llvm::llvm::LLVMRustPrintModule(cpm, llmod, output); + llvm::LLVMRustPrintModule(cpm, llmod, output); }) }) } @@ -355,11 +355,11 @@ pub mod write { } }); - llvm::llvm::LLVMRustDisposeTargetMachine(tm); - llvm::llvm::LLVMDisposeModule(trans.metadata_module); - llvm::llvm::LLVMDisposeModule(llmod); - llvm::llvm::LLVMContextDispose(llcx); - if sess.time_llvm_passes() { llvm::llvm::LLVMRustPrintPassTimings(); } + llvm::LLVMRustDisposeTargetMachine(tm); + llvm::LLVMDisposeModule(trans.metadata_module); + llvm::LLVMDisposeModule(llmod); + llvm::LLVMContextDispose(llcx); + if sess.time_llvm_passes() { llvm::LLVMRustPrintPassTimings(); } } } @@ -426,31 +426,31 @@ pub mod write { } INIT.doit(|| { - llvm::llvm::LLVMInitializePasses(); + llvm::LLVMInitializePasses(); // Only initialize the platforms supported by Rust here, because // using --llvm-root will have multiple platforms that rustllvm // doesn't actually link to and it's pointless to put target info // into the registry that Rust cannot generate machine code for. - llvm::llvm::LLVMInitializeX86TargetInfo(); - llvm::llvm::LLVMInitializeX86Target(); - llvm::llvm::LLVMInitializeX86TargetMC(); - llvm::llvm::LLVMInitializeX86AsmPrinter(); - llvm::llvm::LLVMInitializeX86AsmParser(); - - llvm::llvm::LLVMInitializeARMTargetInfo(); - llvm::llvm::LLVMInitializeARMTarget(); - llvm::llvm::LLVMInitializeARMTargetMC(); - llvm::llvm::LLVMInitializeARMAsmPrinter(); - llvm::llvm::LLVMInitializeARMAsmParser(); - - llvm::llvm::LLVMInitializeMipsTargetInfo(); - llvm::llvm::LLVMInitializeMipsTarget(); - llvm::llvm::LLVMInitializeMipsTargetMC(); - llvm::llvm::LLVMInitializeMipsAsmPrinter(); - llvm::llvm::LLVMInitializeMipsAsmParser(); - - llvm::llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int, + llvm::LLVMInitializeX86TargetInfo(); + llvm::LLVMInitializeX86Target(); + llvm::LLVMInitializeX86TargetMC(); + llvm::LLVMInitializeX86AsmPrinter(); + llvm::LLVMInitializeX86AsmParser(); + + llvm::LLVMInitializeARMTargetInfo(); + llvm::LLVMInitializeARMTarget(); + llvm::LLVMInitializeARMTargetMC(); + llvm::LLVMInitializeARMAsmPrinter(); + llvm::LLVMInitializeARMAsmParser(); + + llvm::LLVMInitializeMipsTargetInfo(); + llvm::LLVMInitializeMipsTarget(); + llvm::LLVMInitializeMipsTargetMC(); + llvm::LLVMInitializeMipsAsmPrinter(); + llvm::LLVMInitializeMipsAsmParser(); + + llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int, llvm_args.as_ptr()); }); } @@ -463,32 +463,32 @@ pub mod write { // Create the PassManagerBuilder for LLVM. We configure it with // reasonable defaults and prepare it to actually populate the pass // manager. - let builder = llvm::llvm::LLVMPassManagerBuilderCreate(); + let builder = llvm::LLVMPassManagerBuilderCreate(); match opt { llvm::CodeGenLevelNone => { // Don't add lifetime intrinsics at O0 - llvm::llvm::LLVMRustAddAlwaysInlinePass(builder, false); + llvm::LLVMRustAddAlwaysInlinePass(builder, false); } llvm::CodeGenLevelLess => { - llvm::llvm::LLVMRustAddAlwaysInlinePass(builder, true); + llvm::LLVMRustAddAlwaysInlinePass(builder, true); } // numeric values copied from clang llvm::CodeGenLevelDefault => { - llvm::llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, + llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 225); } llvm::CodeGenLevelAggressive => { - llvm::llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, + llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(builder, 275); } } - llvm::llvm::LLVMPassManagerBuilderSetOptLevel(builder, opt as c_uint); - llvm::llvm::LLVMRustAddBuilderLibraryInfo(builder, llmod, no_builtins); + llvm::LLVMPassManagerBuilderSetOptLevel(builder, opt as c_uint); + llvm::LLVMRustAddBuilderLibraryInfo(builder, llmod, no_builtins); // Use the builder to populate the function/module pass managers. - llvm::llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(builder, fpm); - llvm::llvm::LLVMPassManagerBuilderPopulateModulePassManager(builder, mpm); - llvm::llvm::LLVMPassManagerBuilderDispose(builder); + llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(builder, fpm); + llvm::LLVMPassManagerBuilderPopulateModulePassManager(builder, mpm); + llvm::LLVMPassManagerBuilderDispose(builder); } } diff --git a/src/librustc/back/lto.rs b/src/librustc/back/lto.rs index 6fc60b657d31e..6184ea4591f08 100644 --- a/src/librustc/back/lto.rs +++ b/src/librustc/back/lto.rs @@ -11,8 +11,9 @@ use super::link; use driver::session; use driver::config; +use llvm; use llvm::archive_ro::ArchiveRO; -use llvm::{ModuleRef, TargetMachineRef, llvm, True, False}; +use llvm::{ModuleRef, TargetMachineRef, True, False}; use metadata::cstore; use util::common::time; diff --git a/src/librustc/driver/config.rs b/src/librustc/driver/config.rs index b726c50afe9d1..232a1252f596c 100644 --- a/src/librustc/driver/config.rs +++ b/src/librustc/driver/config.rs @@ -33,10 +33,10 @@ use syntax::parse::token::InternedString; use std::collections::{HashSet, HashMap}; use getopts::{optopt, optmulti, optflag, optflagopt}; use getopts; -use lib::llvm::llvm; use std::cell::{RefCell}; use std::fmt; +use llvm; pub struct Config { pub os: abi::Os, diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index d03bf3593fa41..2149504a67ae7 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -15,8 +15,8 @@ use driver::{config, PpMode}; use driver::{PpmFlowGraph, PpmExpanded, PpmExpandedIdentified, PpmTyped}; use driver::{PpmIdentified}; use front; -use lib::llvm::{ContextRef, ModuleRef}; use lint; +use llvm::{ContextRef, ModuleRef}; use metadata::common::LinkMeta; use metadata::creader; use middle::cfg; diff --git a/src/librustc/driver/mod.rs b/src/librustc/driver/mod.rs index 2614c9ebf98b0..e850b71dda8cc 100644 --- a/src/librustc/driver/mod.rs +++ b/src/librustc/driver/mod.rs @@ -292,7 +292,7 @@ pub fn handle_options(mut args: Vec) -> Option { } if cg_flags.contains(&"passes=list".to_string()) { - unsafe { ::lib::llvm::llvm::LLVMRustPrintPasses(); } + unsafe { ::llvm::LLVMRustPrintPasses(); } return None; } diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 1877bd1260e51..e7d52ef3b3d6c 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -215,8 +215,9 @@ use back::archive::{METADATA_FILENAME}; use back::svh::Svh; use driver::session::Session; -use lib::llvm::{False, llvm, ObjectFile, mk_section_iter}; -use lib::llvm::archive_ro::ArchiveRO; +use llvm; +use llvm::{False, ObjectFile, mk_section_iter}; +use llvm::archive_ro::ArchiveRO; use metadata::cstore::{MetadataBlob, MetadataVec, MetadataArchive}; use metadata::decoder; use metadata::encoder; diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 3cfd1aaee8ff3..958d2cd377431 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -190,7 +190,8 @@ use back::abi; use driver::config::FullDebugInfo; -use lib::llvm::{llvm, ValueRef, BasicBlockRef}; +use llvm; +use llvm::{ValueRef, BasicBlockRef}; use middle::const_eval; use middle::def; use middle::check_match; diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index 898cb036ea537..3ee61b1d67596 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -48,7 +48,7 @@ use libc::c_ulonglong; use std::rc::Rc; -use lib::llvm::{ValueRef, True, IntEQ, IntNE}; +use llvm::{ValueRef, True, IntEQ, IntNE}; use middle::subst; use middle::subst::Subst; use middle::trans::_match; diff --git a/src/librustc/middle/trans/asm.rs b/src/librustc/middle/trans/asm.rs index 81bb50a83afdf..9760ef07a40e4 100644 --- a/src/librustc/middle/trans/asm.rs +++ b/src/librustc/middle/trans/asm.rs @@ -12,7 +12,7 @@ # Translation of inline assembly. */ -use lib; +use llvm; use middle::trans::build::*; use middle::trans::callee; use middle::trans::common::*; @@ -99,8 +99,8 @@ pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::InlineAsm) }; let dialect = match ia.dialect { - ast::AsmAtt => lib::llvm::AD_ATT, - ast::AsmIntel => lib::llvm::AD_Intel + ast::AsmAtt => llvm::AD_ATT, + ast::AsmIntel => llvm::AD_Intel }; let r = ia.asm.get().with_c_str(|a| { diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 4d329ebd2a00c..6bcc9b9b745b7 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -31,9 +31,9 @@ use driver::config; use driver::config::{NoDebugInfo, FullDebugInfo}; use driver::session::Session; use driver::driver::{CrateAnalysis, CrateTranslation}; -use lib::llvm::{ModuleRef, ValueRef, BasicBlockRef}; -use lib::llvm::{llvm, Vector}; -use lib; +use llvm; +use llvm::{ModuleRef, ValueRef, BasicBlockRef}; +use llvm::{Vector}; use metadata::{csearch, encoder, loader}; use lint; use middle::astencode; @@ -172,7 +172,7 @@ impl<'a> Drop for StatRecorder<'a> { } // only use this for foreign function ABIs and glue, use `decl_rust_fn` for Rust functions -fn decl_fn(ccx: &CrateContext, name: &str, cc: lib::llvm::CallConv, +fn decl_fn(ccx: &CrateContext, name: &str, cc: llvm::CallConv, ty: Type, output: ty::t) -> ValueRef { let llfn: ValueRef = name.with_c_str(|buf| { @@ -186,16 +186,16 @@ fn decl_fn(ccx: &CrateContext, name: &str, cc: lib::llvm::CallConv, ty::ty_bot => { unsafe { llvm::LLVMAddFunctionAttribute(llfn, - lib::llvm::FunctionIndex as c_uint, - lib::llvm::NoReturnAttribute as uint64_t) + llvm::FunctionIndex as c_uint, + llvm::NoReturnAttribute as uint64_t) } } _ => {} } - lib::llvm::SetFunctionCallConv(llfn, cc); + llvm::SetFunctionCallConv(llfn, cc); // Function addresses in Rust are never significant, allowing functions to be merged. - lib::llvm::SetUnnamedAddr(llfn, true); + llvm::SetUnnamedAddr(llfn, true); if ccx.is_split_stack_supported() { set_split_stack(llfn); @@ -209,14 +209,14 @@ pub fn decl_cdecl_fn(ccx: &CrateContext, name: &str, ty: Type, output: ty::t) -> ValueRef { - decl_fn(ccx, name, lib::llvm::CCallConv, ty, output) + decl_fn(ccx, name, llvm::CCallConv, ty, output) } // only use this for foreign function ABIs and glue, use `get_extern_rust_fn` for Rust functions pub fn get_extern_fn(ccx: &CrateContext, externs: &mut ExternMap, name: &str, - cc: lib::llvm::CallConv, + cc: llvm::CallConv, ty: Type, output: ty::t) -> ValueRef { @@ -253,7 +253,7 @@ pub fn decl_rust_fn(ccx: &CrateContext, fn_ty: ty::t, name: &str) -> ValueRef { }; let llfty = type_of_rust_fn(ccx, has_env, inputs.as_slice(), output); - let llfn = decl_fn(ccx, name, lib::llvm::CCallConv, llfty, output); + let llfn = decl_fn(ccx, name, llvm::CCallConv, llfty, output); let attrs = get_fn_llvm_attributes(ccx, fn_ty); for &(idx, attr) in attrs.iter() { unsafe { @@ -266,7 +266,7 @@ pub fn decl_rust_fn(ccx: &CrateContext, fn_ty: ty::t, name: &str) -> ValueRef { pub fn decl_internal_rust_fn(ccx: &CrateContext, fn_ty: ty::t, name: &str) -> ValueRef { let llfn = decl_rust_fn(ccx, fn_ty, name); - lib::llvm::SetLinkage(llfn, lib::llvm::InternalLinkage); + llvm::SetLinkage(llfn, llvm::InternalLinkage); llfn } @@ -375,26 +375,26 @@ pub fn get_tydesc(ccx: &CrateContext, t: ty::t) -> Rc { #[allow(dead_code)] // useful pub fn set_optimize_for_size(f: ValueRef) { - lib::llvm::SetFunctionAttribute(f, lib::llvm::OptimizeForSizeAttribute) + llvm::SetFunctionAttribute(f, llvm::OptimizeForSizeAttribute) } pub fn set_no_inline(f: ValueRef) { - lib::llvm::SetFunctionAttribute(f, lib::llvm::NoInlineAttribute) + llvm::SetFunctionAttribute(f, llvm::NoInlineAttribute) } #[allow(dead_code)] // useful pub fn set_no_unwind(f: ValueRef) { - lib::llvm::SetFunctionAttribute(f, lib::llvm::NoUnwindAttribute) + llvm::SetFunctionAttribute(f, llvm::NoUnwindAttribute) } // Tell LLVM to emit the information necessary to unwind the stack for the // function f. pub fn set_uwtable(f: ValueRef) { - lib::llvm::SetFunctionAttribute(f, lib::llvm::UWTableAttribute) + llvm::SetFunctionAttribute(f, llvm::UWTableAttribute) } pub fn set_inline_hint(f: ValueRef) { - lib::llvm::SetFunctionAttribute(f, lib::llvm::InlineHintAttribute) + llvm::SetFunctionAttribute(f, llvm::InlineHintAttribute) } pub fn set_llvm_fn_attrs(attrs: &[ast::Attribute], llfn: ValueRef) { @@ -415,25 +415,25 @@ pub fn set_llvm_fn_attrs(attrs: &[ast::Attribute], llfn: ValueRef) { if contains_name(attrs, "cold") { unsafe { llvm::LLVMAddFunctionAttribute(llfn, - lib::llvm::FunctionIndex as c_uint, - lib::llvm::ColdAttribute as uint64_t) + llvm::FunctionIndex as c_uint, + llvm::ColdAttribute as uint64_t) } } } pub fn set_always_inline(f: ValueRef) { - lib::llvm::SetFunctionAttribute(f, lib::llvm::AlwaysInlineAttribute) + llvm::SetFunctionAttribute(f, llvm::AlwaysInlineAttribute) } pub fn set_split_stack(f: ValueRef) { "split-stack".with_c_str(|buf| { - unsafe { llvm::LLVMAddFunctionAttrString(f, lib::llvm::FunctionIndex as c_uint, buf); } + unsafe { llvm::LLVMAddFunctionAttrString(f, llvm::FunctionIndex as c_uint, buf); } }) } pub fn unset_split_stack(f: ValueRef) { "split-stack".with_c_str(|buf| { - unsafe { llvm::LLVMRemoveFunctionAttrString(f, lib::llvm::FunctionIndex as c_uint, buf); } + unsafe { llvm::LLVMRemoveFunctionAttrString(f, llvm::FunctionIndex as c_uint, buf); } }) } @@ -479,7 +479,7 @@ pub fn get_res_dtor(ccx: &CrateContext, get_extern_fn(ccx, &mut *ccx.externs.borrow_mut(), name.as_slice(), - lib::llvm::CCallConv, + llvm::CCallConv, llty, dtor_ty) } @@ -546,36 +546,36 @@ pub fn compare_scalar_values<'a>( } floating_point => { let cmp = match op { - ast::BiEq => lib::llvm::RealOEQ, - ast::BiNe => lib::llvm::RealUNE, - ast::BiLt => lib::llvm::RealOLT, - ast::BiLe => lib::llvm::RealOLE, - ast::BiGt => lib::llvm::RealOGT, - ast::BiGe => lib::llvm::RealOGE, + ast::BiEq => llvm::RealOEQ, + ast::BiNe => llvm::RealUNE, + ast::BiLt => llvm::RealOLT, + ast::BiLe => llvm::RealOLE, + ast::BiGt => llvm::RealOGT, + ast::BiGe => llvm::RealOGE, _ => die(cx) }; return FCmp(cx, cmp, lhs, rhs); } signed_int => { let cmp = match op { - ast::BiEq => lib::llvm::IntEQ, - ast::BiNe => lib::llvm::IntNE, - ast::BiLt => lib::llvm::IntSLT, - ast::BiLe => lib::llvm::IntSLE, - ast::BiGt => lib::llvm::IntSGT, - ast::BiGe => lib::llvm::IntSGE, + ast::BiEq => llvm::IntEQ, + ast::BiNe => llvm::IntNE, + ast::BiLt => llvm::IntSLT, + ast::BiLe => llvm::IntSLE, + ast::BiGt => llvm::IntSGT, + ast::BiGe => llvm::IntSGE, _ => die(cx) }; return ICmp(cx, cmp, lhs, rhs); } unsigned_int => { let cmp = match op { - ast::BiEq => lib::llvm::IntEQ, - ast::BiNe => lib::llvm::IntNE, - ast::BiLt => lib::llvm::IntULT, - ast::BiLe => lib::llvm::IntULE, - ast::BiGt => lib::llvm::IntUGT, - ast::BiGe => lib::llvm::IntUGE, + ast::BiEq => llvm::IntEQ, + ast::BiNe => llvm::IntNE, + ast::BiLt => llvm::IntULT, + ast::BiLe => llvm::IntULE, + ast::BiGt => llvm::IntUGT, + ast::BiGe => llvm::IntUGE, _ => die(cx) }; return ICmp(cx, cmp, lhs, rhs); @@ -602,12 +602,12 @@ pub fn compare_simd_types( }, ty::ty_uint(_) | ty::ty_int(_) => { let cmp = match op { - ast::BiEq => lib::llvm::IntEQ, - ast::BiNe => lib::llvm::IntNE, - ast::BiLt => lib::llvm::IntSLT, - ast::BiLe => lib::llvm::IntSLE, - ast::BiGt => lib::llvm::IntSGT, - ast::BiGe => lib::llvm::IntSGE, + ast::BiEq => llvm::IntEQ, + ast::BiNe => llvm::IntNE, + ast::BiLt => llvm::IntSLT, + ast::BiLe => llvm::IntSLE, + ast::BiGt => llvm::IntSGT, + ast::BiGe => llvm::IntSGE, _ => cx.sess().bug("compare_simd_types: must be a comparison operator"), }; let return_ty = Type::vector(&type_of(cx.ccx(), t), size as u64); @@ -801,11 +801,11 @@ pub fn fail_if_zero_or_overflows<'a>( let (is_zero, is_signed) = match ty::get(rhs_t).sty { ty::ty_int(t) => { let zero = C_integral(Type::int_from_ty(cx.ccx(), t), 0u64, false); - (ICmp(cx, lib::llvm::IntEQ, rhs, zero), true) + (ICmp(cx, llvm::IntEQ, rhs, zero), true) } ty::ty_uint(t) => { let zero = C_integral(Type::uint_from_ty(cx.ccx(), t), 0u64, false); - (ICmp(cx, lib::llvm::IntEQ, rhs, zero), false) + (ICmp(cx, llvm::IntEQ, rhs, zero), false) } _ => { cx.sess().bug(format!("fail-if-zero on unexpected type: {}", @@ -841,10 +841,10 @@ pub fn fail_if_zero_or_overflows<'a>( } _ => unreachable!(), }; - let minus_one = ICmp(bcx, lib::llvm::IntEQ, rhs, + let minus_one = ICmp(bcx, llvm::IntEQ, rhs, C_integral(llty, -1, false)); with_cond(bcx, minus_one, |bcx| { - let is_min = ICmp(bcx, lib::llvm::IntEQ, lhs, + let is_min = ICmp(bcx, llvm::IntEQ, lhs, C_integral(llty, min, true)); with_cond(bcx, is_min, |bcx| { controlflow::trans_fail(bcx, span, @@ -975,11 +975,11 @@ pub fn load_ty(cx: &Block, ptr: ValueRef, t: ty::t) -> ValueRef { if type_is_zero_size(cx.ccx(), t) { C_undef(type_of::type_of(cx.ccx(), t)) } else if ty::type_is_bool(t) { - Trunc(cx, LoadRangeAssert(cx, ptr, 0, 2, lib::llvm::False), Type::i1(cx.ccx())) + Trunc(cx, LoadRangeAssert(cx, ptr, 0, 2, llvm::False), Type::i1(cx.ccx())) } else if ty::type_is_char(t) { // a char is a unicode codepoint, and so takes values from 0 // to 0x10FFFF inclusive only. - LoadRangeAssert(cx, ptr, 0, 0x10FFFF + 1, lib::llvm::False) + LoadRangeAssert(cx, ptr, 0, 0x10FFFF + 1, llvm::False) } else { Load(cx, ptr) } @@ -1755,7 +1755,7 @@ fn finish_register_fn(ccx: &CrateContext, sp: Span, sym: String, node_id: ast::N ccx.item_symbols.borrow_mut().insert(node_id, sym); if !ccx.reachable.contains(&node_id) { - lib::llvm::SetLinkage(llfn, lib::llvm::InternalLinkage); + llvm::SetLinkage(llfn, llvm::InternalLinkage); } // The stack exhaustion lang item shouldn't have a split stack because @@ -1764,10 +1764,10 @@ fn finish_register_fn(ccx: &CrateContext, sp: Span, sym: String, node_id: ast::N let def = ast_util::local_def(node_id); if ccx.tcx.lang_items.stack_exhausted() == Some(def) { unset_split_stack(llfn); - lib::llvm::SetLinkage(llfn, lib::llvm::ExternalLinkage); + llvm::SetLinkage(llfn, llvm::ExternalLinkage); } if ccx.tcx.lang_items.eh_personality() == Some(def) { - lib::llvm::SetLinkage(llfn, lib::llvm::ExternalLinkage); + llvm::SetLinkage(llfn, llvm::ExternalLinkage); } @@ -1814,13 +1814,13 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6 // implications directly to the call instruction. Right now, // the only attribute we need to worry about is `sret`. if type_of::return_uses_outptr(ccx, ret_ty) { - attrs.push((1, lib::llvm::StructRetAttribute as u64)); + attrs.push((1, llvm::StructRetAttribute as u64)); // The outptr can be noalias and nocapture because it's entirely // invisible to the program. We can also mark it as nonnull - attrs.push((1, lib::llvm::NoAliasAttribute as u64)); - attrs.push((1, lib::llvm::NoCaptureAttribute as u64)); - attrs.push((1, lib::llvm::NonNullAttribute as u64)); + attrs.push((1, llvm::NoAliasAttribute as u64)); + attrs.push((1, llvm::NoCaptureAttribute as u64)); + attrs.push((1, llvm::NonNullAttribute as u64)); // Add one more since there's an outptr first_arg_offset += 1; @@ -1834,7 +1834,7 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6 ty::ty_str | ty::ty_vec(..) | ty::ty_trait(..) => true, _ => false } => {} ty::ty_uniq(_) => { - attrs.push((lib::llvm::ReturnIndex as uint, lib::llvm::NoAliasAttribute as u64)); + attrs.push((llvm::ReturnIndex as uint, llvm::NoAliasAttribute as u64)); } _ => {} } @@ -1847,14 +1847,14 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6 ty::ty_str | ty::ty_vec(..) | ty::ty_trait(..) => true, _ => false } => {} ty::ty_uniq(_) | ty::ty_rptr(_, _) => { - attrs.push((lib::llvm::ReturnIndex as uint, lib::llvm::NonNullAttribute as u64)); + attrs.push((llvm::ReturnIndex as uint, llvm::NonNullAttribute as u64)); } _ => {} } match ty::get(ret_ty).sty { ty::ty_bool => { - attrs.push((lib::llvm::ReturnIndex as uint, lib::llvm::ZExtAttribute as u64)); + attrs.push((llvm::ReturnIndex as uint, llvm::ZExtAttribute as u64)); } _ => {} } @@ -1867,25 +1867,25 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6 // For non-immediate arguments the callee gets its own copy of // the value on the stack, so there are no aliases. It's also // program-invisible so can't possibly capture - attrs.push((idx, lib::llvm::NoAliasAttribute as u64)); - attrs.push((idx, lib::llvm::NoCaptureAttribute as u64)); - attrs.push((idx, lib::llvm::NonNullAttribute as u64)); + attrs.push((idx, llvm::NoAliasAttribute as u64)); + attrs.push((idx, llvm::NoCaptureAttribute as u64)); + attrs.push((idx, llvm::NonNullAttribute as u64)); } ty::ty_bool => { - attrs.push((idx, lib::llvm::ZExtAttribute as u64)); + attrs.push((idx, llvm::ZExtAttribute as u64)); } // `~` pointer parameters never alias because ownership is transferred ty::ty_uniq(_) => { - attrs.push((idx, lib::llvm::NoAliasAttribute as u64)); - attrs.push((idx, lib::llvm::NonNullAttribute as u64)); + attrs.push((idx, llvm::NoAliasAttribute as u64)); + attrs.push((idx, llvm::NonNullAttribute as u64)); } // `&mut` pointer parameters never alias other parameters, or mutable global data ty::ty_rptr(b, mt) if mt.mutbl == ast::MutMutable => { - attrs.push((idx, lib::llvm::NoAliasAttribute as u64)); - attrs.push((idx, lib::llvm::NonNullAttribute as u64)); + attrs.push((idx, llvm::NoAliasAttribute as u64)); + attrs.push((idx, llvm::NonNullAttribute as u64)); match b { ReLateBound(_, BrAnon(_)) => { - attrs.push((idx, lib::llvm::NoCaptureAttribute as u64)); + attrs.push((idx, llvm::NoCaptureAttribute as u64)); } _ => {} } @@ -1893,12 +1893,12 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6 // When a reference in an argument has no named lifetime, it's impossible for that // reference to escape this function (returned or stored beyond the call by a closure). ty::ty_rptr(ReLateBound(_, BrAnon(_)), _) => { - attrs.push((idx, lib::llvm::NoCaptureAttribute as u64)); - attrs.push((idx, lib::llvm::NonNullAttribute as u64)); + attrs.push((idx, llvm::NoCaptureAttribute as u64)); + attrs.push((idx, llvm::NonNullAttribute as u64)); } // & pointer parameters are never null ty::ty_rptr(_, _) => { - attrs.push((idx, lib::llvm::NonNullAttribute as u64)); + attrs.push((idx, llvm::NonNullAttribute as u64)); } _ => () } @@ -1912,7 +1912,7 @@ pub fn register_fn_llvmty(ccx: &CrateContext, sp: Span, sym: String, node_id: ast::NodeId, - cc: lib::llvm::CallConv, + cc: llvm::CallConv, llfty: Type) -> ValueRef { debug!("register_fn_llvmty id={} sym={}", node_id, sym); @@ -2073,7 +2073,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef { }); if !ccx.reachable.contains(&id) { - lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage); + llvm::SetLinkage(g, llvm::InternalLinkage); } // Apply the `unnamed_addr` attribute if @@ -2081,7 +2081,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef { if !ast_util::static_has_significant_address( mutbl, i.attrs.as_slice()) { - lib::llvm::SetUnnamedAddr(g, true); + llvm::SetUnnamedAddr(g, true); // This is a curious case where we must make // all of these statics inlineable. If a @@ -2103,7 +2103,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef { if attr::contains_name(i.attrs.as_slice(), "thread_local") { - lib::llvm::set_thread_local(g, true); + llvm::set_thread_local(g, true); } if !inlineable { @@ -2241,7 +2241,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef { // linkage b/c that doesn't quite make sense. Otherwise items can // have internal linkage if they're not reachable. if !foreign && !ccx.reachable.contains(&id) { - lib::llvm::SetLinkage(val, lib::llvm::InternalLinkage); + llvm::SetLinkage(val, llvm::InternalLinkage); } ccx.item_vals.borrow_mut().insert(id, val); diff --git a/src/librustc/middle/trans/basic_block.rs b/src/librustc/middle/trans/basic_block.rs index 303ad5fbce2ce..13b8ed4df6b82 100644 --- a/src/librustc/middle/trans/basic_block.rs +++ b/src/librustc/middle/trans/basic_block.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use lib::llvm::{llvm, BasicBlockRef}; +use llvm; +use llvm::{BasicBlockRef}; use middle::trans::value::{Users, Value}; use std::iter::{Filter, Map}; diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index ce11cd24f7b04..995ad16b59f5b 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -11,11 +11,10 @@ #![allow(dead_code)] // FFI wrappers #![allow(non_snake_case_functions)] -use lib::llvm::llvm; -use lib::llvm::{CallConv, AtomicBinOp, AtomicOrdering, AsmDialect}; -use lib::llvm::{Opcode, IntPredicate, RealPredicate}; -use lib::llvm::{ValueRef, BasicBlockRef}; -use lib; +use llvm; +use llvm::{CallConv, AtomicBinOp, AtomicOrdering, AsmDialect}; +use llvm::{Opcode, IntPredicate, RealPredicate}; +use llvm::{ValueRef, BasicBlockRef}; use middle::trans::common::*; use syntax::codemap::Span; @@ -97,7 +96,7 @@ pub fn Switch(cx: &Block, v: ValueRef, else_: BasicBlockRef, num_cases: uint) pub fn AddCase(s: ValueRef, on_val: ValueRef, dest: BasicBlockRef) { unsafe { - if llvm::LLVMIsUndef(s) == lib::llvm::True { return; } + if llvm::LLVMIsUndef(s) == llvm::True { return; } llvm::LLVMAddCase(s, on_val, dest); } } @@ -350,7 +349,7 @@ pub fn Load(cx: &Block, pointer_val: ValueRef) -> ValueRef { let ccx = cx.fcx.ccx; if cx.unreachable.get() { let ty = val_ty(pointer_val); - let eltty = if ty.kind() == lib::llvm::Array { + let eltty = if ty.kind() == llvm::Array { ty.element_type() } else { ccx.int_type @@ -382,11 +381,11 @@ pub fn AtomicLoad(cx: &Block, pointer_val: ValueRef, order: AtomicOrdering) -> V pub fn LoadRangeAssert(cx: &Block, pointer_val: ValueRef, lo: c_ulonglong, - hi: c_ulonglong, signed: lib::llvm::Bool) -> ValueRef { + hi: c_ulonglong, signed: llvm::Bool) -> ValueRef { if cx.unreachable.get() { let ccx = cx.fcx.ccx; let ty = val_ty(pointer_val); - let eltty = if ty.kind() == lib::llvm::Array { + let eltty = if ty.kind() == llvm::Array { ty.element_type() } else { ccx.int_type @@ -647,7 +646,7 @@ pub fn Phi(cx: &Block, ty: Type, vals: &[ValueRef], pub fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) { unsafe { - if llvm::LLVMIsUndef(phi) == lib::llvm::True { return; } + if llvm::LLVMIsUndef(phi) == llvm::True { return; } llvm::LLVMAddIncoming(phi, &val, &bb, 1 as c_uint); } } @@ -656,7 +655,7 @@ pub fn _UndefReturn(cx: &Block, fn_: ValueRef) -> ValueRef { unsafe { let ccx = cx.fcx.ccx; let ty = val_ty(fn_); - let retty = if ty.kind() == lib::llvm::Integer { + let retty = if ty.kind() == llvm::Integer { ty.return_type() } else { ccx.int_type diff --git a/src/librustc/middle/trans/builder.rs b/src/librustc/middle/trans/builder.rs index 3a9e3e4cf9b07..32e91c337f086 100644 --- a/src/librustc/middle/trans/builder.rs +++ b/src/librustc/middle/trans/builder.rs @@ -10,11 +10,10 @@ #![allow(dead_code)] // FFI wrappers -use lib; -use lib::llvm::llvm; -use lib::llvm::{CallConv, AtomicBinOp, AtomicOrdering, AsmDialect}; -use lib::llvm::{Opcode, IntPredicate, RealPredicate, False}; -use lib::llvm::{ValueRef, BasicBlockRef, BuilderRef, ModuleRef}; +use llvm; +use llvm::{CallConv, AtomicBinOp, AtomicOrdering, AsmDialect}; +use llvm::{Opcode, IntPredicate, RealPredicate, False}; +use llvm::{ValueRef, BasicBlockRef, BuilderRef, ModuleRef}; use middle::trans::base; use middle::trans::common::*; use middle::trans::machine::llalign_of_pref; @@ -460,7 +459,7 @@ impl<'a> Builder<'a> { self.count_insn("load.volatile"); unsafe { let insn = llvm::LLVMBuildLoad(self.llbuilder, ptr, noname()); - llvm::LLVMSetVolatile(insn, lib::llvm::True); + llvm::LLVMSetVolatile(insn, llvm::True); insn } } @@ -477,7 +476,7 @@ impl<'a> Builder<'a> { pub fn load_range_assert(&self, ptr: ValueRef, lo: c_ulonglong, - hi: c_ulonglong, signed: lib::llvm::Bool) -> ValueRef { + hi: c_ulonglong, signed: llvm::Bool) -> ValueRef { let value = self.load(ptr); unsafe { @@ -487,7 +486,7 @@ impl<'a> Builder<'a> { let v = [min, max]; - llvm::LLVMSetMetadata(value, lib::llvm::MD_range as c_uint, + llvm::LLVMSetMetadata(value, llvm::MD_range as c_uint, llvm::LLVMMDNodeInContext(self.ccx.llcx, v.as_ptr(), v.len() as c_uint)); } @@ -514,7 +513,7 @@ impl<'a> Builder<'a> { self.count_insn("store.volatile"); unsafe { let insn = llvm::LLVMBuildStore(self.llbuilder, val, ptr); - llvm::LLVMSetVolatile(insn, lib::llvm::True); + llvm::LLVMSetVolatile(insn, llvm::True); } } @@ -788,10 +787,10 @@ impl<'a> Builder<'a> { dia: AsmDialect) -> ValueRef { self.count_insn("inlineasm"); - let volatile = if volatile { lib::llvm::True } - else { lib::llvm::False }; - let alignstack = if alignstack { lib::llvm::True } - else { lib::llvm::False }; + let volatile = if volatile { llvm::True } + else { llvm::False }; + let alignstack = if alignstack { llvm::True } + else { llvm::False }; let argtys = inputs.iter().map(|v| { debug!("Asm Input Type: {:?}", self.ccx.tn.val_to_string(*v)); @@ -832,7 +831,7 @@ impl<'a> Builder<'a> { conv: CallConv, attributes: &[(uint, u64)]) -> ValueRef { self.count_insn("callwithconv"); let v = self.call(llfn, args, attributes); - lib::llvm::SetInstructionCallConv(v, conv); + llvm::SetInstructionCallConv(v, conv); v } @@ -945,7 +944,7 @@ impl<'a> Builder<'a> { pub fn set_cleanup(&self, landing_pad: ValueRef) { self.count_insn("setcleanup"); unsafe { - llvm::LLVMSetCleanup(landing_pad, lib::llvm::True); + llvm::LLVMSetCleanup(landing_pad, llvm::True); } } diff --git a/src/librustc/middle/trans/cabi.rs b/src/librustc/middle/trans/cabi.rs index df1347f6d8f10..0a10fb8b17208 100644 --- a/src/librustc/middle/trans/cabi.rs +++ b/src/librustc/middle/trans/cabi.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use lib::llvm::Attribute; +use llvm::Attribute; use std::option; use middle::trans::context::CrateContext; use middle::trans::cabi_x86; diff --git a/src/librustc/middle/trans/cabi_arm.rs b/src/librustc/middle/trans/cabi_arm.rs index c44a4e02ad462..0e2bf2104fd55 100644 --- a/src/librustc/middle/trans/cabi_arm.rs +++ b/src/librustc/middle/trans/cabi_arm.rs @@ -10,8 +10,9 @@ #![allow(non_uppercase_pattern_statics)] -use lib::llvm::{llvm, Integer, Pointer, Float, Double, Struct, Array}; -use lib::llvm::{StructRetAttribute, ZExtAttribute}; +use llvm; +use llvm::{Integer, Pointer, Float, Double, Struct, Array}; +use llvm::{StructRetAttribute, ZExtAttribute}; use middle::trans::cabi::{FnType, ArgType}; use middle::trans::context::CrateContext; use middle::trans::type_::Type; diff --git a/src/librustc/middle/trans/cabi_mips.rs b/src/librustc/middle/trans/cabi_mips.rs index 9e5b38d2f7ddb..d07090686874f 100644 --- a/src/librustc/middle/trans/cabi_mips.rs +++ b/src/librustc/middle/trans/cabi_mips.rs @@ -12,8 +12,9 @@ use libc::c_uint; use std::cmp; -use lib::llvm::{llvm, Integer, Pointer, Float, Double, Struct, Array}; -use lib::llvm::{StructRetAttribute, ZExtAttribute}; +use llvm; +use llvm::{Integer, Pointer, Float, Double, Struct, Array}; +use llvm::{StructRetAttribute, ZExtAttribute}; use middle::trans::context::CrateContext; use middle::trans::cabi::*; use middle::trans::type_::Type; diff --git a/src/librustc/middle/trans/cabi_x86.rs b/src/librustc/middle/trans/cabi_x86.rs index 0d88c611cbaed..6bb3d992f50c6 100644 --- a/src/librustc/middle/trans/cabi_x86.rs +++ b/src/librustc/middle/trans/cabi_x86.rs @@ -10,7 +10,7 @@ use syntax::abi::{OsWin32, OsMacos, OsiOS}; -use lib::llvm::*; +use llvm::*; use super::cabi::*; use super::common::*; use super::machine::*; diff --git a/src/librustc/middle/trans/cabi_x86_64.rs b/src/librustc/middle/trans/cabi_x86_64.rs index 5b8ddfe1be7bf..493aca0ddf0c4 100644 --- a/src/librustc/middle/trans/cabi_x86_64.rs +++ b/src/librustc/middle/trans/cabi_x86_64.rs @@ -13,9 +13,10 @@ #![allow(non_uppercase_pattern_statics)] -use lib::llvm::{llvm, Integer, Pointer, Float, Double}; -use lib::llvm::{Struct, Array, Attribute}; -use lib::llvm::{StructRetAttribute, ByValAttribute, ZExtAttribute}; +use llvm; +use llvm::{Integer, Pointer, Float, Double}; +use llvm::{Struct, Array, Attribute}; +use llvm::{StructRetAttribute, ByValAttribute, ZExtAttribute}; use middle::trans::cabi::*; use middle::trans::context::CrateContext; use middle::trans::type_::Type; diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 15415620c5bba..db2d17c85db5f 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -19,8 +19,8 @@ use arena::TypedArena; use back::abi; use back::link; -use lib::llvm::ValueRef; -use lib::llvm::llvm; +use llvm; +use llvm::ValueRef; use metadata::csearch; use middle::def; use middle::subst; diff --git a/src/librustc/middle/trans/cleanup.rs b/src/librustc/middle/trans/cleanup.rs index 0485b10044657..6e40445d8f903 100644 --- a/src/librustc/middle/trans/cleanup.rs +++ b/src/librustc/middle/trans/cleanup.rs @@ -13,7 +13,7 @@ * drop glue. See discussion in `doc.rs` for a high-level summary. */ -use lib::llvm::{BasicBlockRef, ValueRef}; +use llvm::{BasicBlockRef, ValueRef}; use middle::trans::base; use middle::trans::build; use middle::trans::callee; diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index ef147eb22b506..f2400f6bfefe3 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -12,7 +12,7 @@ use back::abi; use back::link::mangle_internal_name_by_path_and_seq; use driver::config::FullDebugInfo; -use lib::llvm::ValueRef; +use llvm::ValueRef; use middle::def; use middle::freevars; use middle::lang_items::ClosureExchangeMallocFnLangItem; diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 23a391cb86dfe..945185f595342 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -13,10 +13,9 @@ //! Code that is useful in various trans modules. use driver::session::Session; -use lib::llvm::{ValueRef, BasicBlockRef, BuilderRef}; -use lib::llvm::{True, False, Bool}; -use lib::llvm::llvm; -use lib; +use llvm; +use llvm::{ValueRef, BasicBlockRef, BuilderRef}; +use llvm::{True, False, Bool}; use middle::def; use middle::lang_items::LangItem; use middle::subst; @@ -570,7 +569,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> Va }); llvm::LLVMSetInitializer(g, sc); llvm::LLVMSetGlobalConstant(g, True); - lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage); + llvm::SetLinkage(g, llvm::InternalLinkage); cx.const_cstr_cache.borrow_mut().insert(s, g); g @@ -599,7 +598,7 @@ pub fn C_binary_slice(cx: &CrateContext, data: &[u8]) -> ValueRef { }); llvm::LLVMSetInitializer(g, lldata); llvm::LLVMSetGlobalConstant(g, True); - lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage); + llvm::SetLinkage(g, llvm::InternalLinkage); let cs = llvm::LLVMConstPointerCast(g, Type::i8p(cx).to_ref()); C_struct(cx, [cs, C_uint(cx, len)], false) diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 11a8207f8c43e..2fd468d8fda8f 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -10,9 +10,10 @@ use back::abi; -use lib::llvm::{llvm, ConstFCmp, ConstICmp, SetLinkage, PrivateLinkage, ValueRef, Bool, True, +use llvm; +use llvm::{ConstFCmp, ConstICmp, SetLinkage, PrivateLinkage, ValueRef, Bool, True, False}; -use lib::llvm::{IntEQ, IntNE, IntUGT, IntUGE, IntULT, IntULE, IntSGT, IntSGE, IntSLT, IntSLE, +use llvm::{IntEQ, IntNE, IntUGT, IntUGE, IntULT, IntULE, IntSGT, IntSGE, IntSLT, IntSLE, RealOEQ, RealOGT, RealOGE, RealOLT, RealOLE, RealONE}; use metadata::csearch; diff --git a/src/librustc/middle/trans/context.rs b/src/librustc/middle/trans/context.rs index 5ee69e02af96a..8c55f33a0d46d 100644 --- a/src/librustc/middle/trans/context.rs +++ b/src/librustc/middle/trans/context.rs @@ -10,9 +10,10 @@ use driver::config::NoDebugInfo; use driver::session::Session; -use lib::llvm::{ContextRef, ModuleRef, ValueRef}; -use lib::llvm::{llvm, TargetData}; -use lib::llvm::mk_target_data; +use llvm; +use llvm::{ContextRef, ModuleRef, ValueRef}; +use llvm::{TargetData}; +use llvm::mk_target_data; use metadata::common::LinkMeta; use middle::resolve; use middle::trans::adt; diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index acc44d08d3cb0..845684bb037a9 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use lib::llvm::*; +use llvm::*; use driver::config::FullDebugInfo; use middle::def; use middle::lang_items::{FailFnLangItem, FailBoundsCheckFnLangItem}; diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index b65f5a5c7d6b6..d4b2b04745b58 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -13,7 +13,7 @@ * Datums are and how they are intended to be used. */ -use lib::llvm::ValueRef; +use llvm::ValueRef; use middle::trans::base::*; use middle::trans::common::*; use middle::trans::cleanup; diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index e3af8f93eadb3..6e81c10c4a0a9 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -180,9 +180,9 @@ seen before (which is most of the time). */ use driver::config; use driver::config::{FullDebugInfo, LimitedDebugInfo, NoDebugInfo}; -use lib::llvm::llvm; -use lib::llvm::{ModuleRef, ContextRef, ValueRef}; -use lib::llvm::debuginfo::*; +use llvm; +use llvm::{ModuleRef, ContextRef, ValueRef}; +use llvm::debuginfo::*; use metadata::csearch; use middle::subst; use middle::trans::adt; diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 516c46564cd9f..60bf80191cb10 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -34,8 +34,8 @@ #![allow(non_camel_case_types)] use back::abi; -use lib::llvm::{ValueRef, llvm}; -use lib; +use llvm; +use llvm::{ValueRef}; use metadata::csearch; use middle::def; use middle::lang_items::MallocFnLangItem; @@ -548,7 +548,7 @@ fn trans_index<'a>(bcx: &'a Block<'a>, debug!("trans_index: base {}", bcx.val_to_string(base)); debug!("trans_index: len {}", bcx.val_to_string(len)); - let bounds_check = ICmp(bcx, lib::llvm::IntUGE, ix_val, len); + let bounds_check = ICmp(bcx, llvm::IntUGE, ix_val, len); let expect = ccx.get_intrinsic(&("llvm.expect.i1")); let expected = Call(bcx, expect, diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index f73984d3b36fa..56fbccefede5e 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -10,9 +10,8 @@ use back::{link}; -use lib::llvm::llvm; -use lib::llvm::{ValueRef, CallConv, Linkage}; -use lib; +use llvm; +use llvm::{ValueRef, CallConv, Linkage}; use middle::weak_lang_items; use middle::trans::base::push_ctxt; use middle::trans::base; @@ -88,14 +87,14 @@ pub fn llvm_calling_convention(ccx: &CrateContext, // It's the ABI's job to select this, not us. System => ccx.sess().bug("system abi should be selected elsewhere"), - Stdcall => lib::llvm::X86StdcallCallConv, - Fastcall => lib::llvm::X86FastcallCallConv, - C => lib::llvm::CCallConv, - Win64 => lib::llvm::X86_64_Win64, + Stdcall => llvm::X86StdcallCallConv, + Fastcall => llvm::X86FastcallCallConv, + C => llvm::CCallConv, + Win64 => llvm::X86_64_Win64, // These API constants ought to be more specific... - Cdecl => lib::llvm::CCallConv, - Aapcs => lib::llvm::CCallConv, + Cdecl => llvm::CCallConv, + Aapcs => llvm::CCallConv, } }) } @@ -110,17 +109,17 @@ pub fn llvm_linkage_by_name(name: &str) -> Option { // ghost, dllimport, dllexport and linkonce_odr_autohide are not supported // and don't have to be, LLVM treats them as no-ops. match name { - "appending" => Some(lib::llvm::AppendingLinkage), - "available_externally" => Some(lib::llvm::AvailableExternallyLinkage), - "common" => Some(lib::llvm::CommonLinkage), - "extern_weak" => Some(lib::llvm::ExternalWeakLinkage), - "external" => Some(lib::llvm::ExternalLinkage), - "internal" => Some(lib::llvm::InternalLinkage), - "linkonce" => Some(lib::llvm::LinkOnceAnyLinkage), - "linkonce_odr" => Some(lib::llvm::LinkOnceODRLinkage), - "private" => Some(lib::llvm::PrivateLinkage), - "weak" => Some(lib::llvm::WeakAnyLinkage), - "weak_odr" => Some(lib::llvm::WeakODRLinkage), + "appending" => Some(llvm::AppendingLinkage), + "available_externally" => Some(llvm::AvailableExternallyLinkage), + "common" => Some(llvm::CommonLinkage), + "extern_weak" => Some(llvm::ExternalWeakLinkage), + "external" => Some(llvm::ExternalLinkage), + "internal" => Some(llvm::InternalLinkage), + "linkonce" => Some(llvm::LinkOnceAnyLinkage), + "linkonce_odr" => Some(llvm::LinkOnceODRLinkage), + "private" => Some(llvm::PrivateLinkage), + "weak" => Some(llvm::WeakAnyLinkage), + "weak_odr" => Some(llvm::WeakODRLinkage), _ => None, } } @@ -157,14 +156,14 @@ pub fn register_static(ccx: &CrateContext, let g1 = ident.get().with_c_str(|buf| { llvm::LLVMAddGlobal(ccx.llmod, llty2.to_ref(), buf) }); - lib::llvm::SetLinkage(g1, linkage); + llvm::SetLinkage(g1, linkage); let mut real_name = "_rust_extern_with_linkage_".to_string(); real_name.push_str(ident.get()); let g2 = real_name.with_c_str(|buf| { llvm::LLVMAddGlobal(ccx.llmod, llty.to_ref(), buf) }); - lib::llvm::SetLinkage(g2, lib::llvm::InternalLinkage); + llvm::SetLinkage(g2, llvm::InternalLinkage); llvm::LLVMSetInitializer(g2, g1); g2 } @@ -217,7 +216,7 @@ pub fn register_foreign_item_fn(ccx: &CrateContext, abi: Abi, fty: ty::t, // Make sure the calling convention is right for variadic functions // (should've been caught if not in typeck) if tys.fn_sig.variadic { - assert!(cc == lib::llvm::CCallConv); + assert!(cc == llvm::CCallConv); } // Create the LLVM value for the C extern fn @@ -347,7 +346,7 @@ pub fn trans_native_call<'a>( llarg_rust } else { if ty::type_is_bool(*passed_arg_tys.get(i)) { - let val = LoadRangeAssert(bcx, llarg_rust, 0, 2, lib::llvm::False); + let val = LoadRangeAssert(bcx, llarg_rust, 0, 2, llvm::False); Trunc(bcx, val, Type::i1(bcx.ccx())) } else { Load(bcx, llarg_rust) @@ -384,9 +383,9 @@ pub fn trans_native_call<'a>( if fn_type.ret_ty.is_indirect() { // The outptr can be noalias and nocapture because it's entirely // invisible to the program. We can also mark it as nonnull - attrs.push((1, lib::llvm::NoAliasAttribute as u64)); - attrs.push((1, lib::llvm::NoCaptureAttribute as u64)); - attrs.push((1, lib::llvm::NonNullAttribute as u64)); + attrs.push((1, llvm::NoAliasAttribute as u64)); + attrs.push((1, llvm::NoCaptureAttribute as u64)); + attrs.push((1, llvm::NonNullAttribute as u64)); }; // Add attributes that depend on the concrete foreign ABI @@ -531,7 +530,7 @@ pub fn register_rust_fn_with_foreign_abi(ccx: &CrateContext, let cconv = match ty::get(t).sty { ty::ty_bare_fn(ref fn_ty) => { let c = llvm_calling_convention(ccx, fn_ty.abi); - c.unwrap_or(lib::llvm::CCallConv) + c.unwrap_or(llvm::CCallConv) } _ => fail!("expected bare fn in register_rust_fn_with_foreign_abi") }; @@ -743,7 +742,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext, llforeign_arg } else { if ty::type_is_bool(rust_ty) { - let tmp = builder.load_range_assert(llforeign_arg, 0, 2, lib::llvm::False); + let tmp = builder.load_range_assert(llforeign_arg, 0, 2, llvm::False); builder.trunc(tmp, Type::i1(ccx)) } else { builder.load(llforeign_arg) diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 4d9f004e3dcd1..40065d0bc5053 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -15,8 +15,8 @@ use back::abi; use back::link::*; -use lib::llvm::{llvm, ValueRef, True}; -use lib; +use llvm; +use llvm::{ValueRef, True}; use middle::lang_items::{FreeFnLangItem, ExchangeFreeFnLangItem}; use middle::subst; use middle::trans::adt; @@ -492,7 +492,7 @@ fn make_generic_glue(ccx: &CrateContext, let bcx = init_function(&fcx, false, ty::mk_nil()); - lib::llvm::SetLinkage(llfn, lib::llvm::InternalLinkage); + llvm::SetLinkage(llfn, llvm::InternalLinkage); ccx.stats.n_glues_created.set(ccx.stats.n_glues_created.get() + 1u); // All glue functions take values passed *by alias*; this is a // requirement since in many contexts glue is invoked indirectly and @@ -550,7 +550,7 @@ pub fn emit_tydescs(ccx: &CrateContext) { let gvar = ti.tydesc; llvm::LLVMSetInitializer(gvar, tydesc); llvm::LLVMSetGlobalConstant(gvar, True); - lib::llvm::SetLinkage(gvar, lib::llvm::InternalLinkage); + llvm::SetLinkage(gvar, llvm::InternalLinkage); } }; } diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs index f11577482b6dc..d64eeb727e733 100644 --- a/src/librustc/middle/trans/inline.rs +++ b/src/librustc/middle/trans/inline.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use lib::llvm::{AvailableExternallyLinkage, SetLinkage}; +use llvm::{AvailableExternallyLinkage, SetLinkage}; use metadata::csearch; use middle::astencode; use middle::trans::base::{push_ctxt, trans_item, get_item_val, trans_fn}; diff --git a/src/librustc/middle/trans/intrinsic.rs b/src/librustc/middle/trans/intrinsic.rs index 309c700bfe899..af5cdf7a1be73 100644 --- a/src/librustc/middle/trans/intrinsic.rs +++ b/src/librustc/middle/trans/intrinsic.rs @@ -10,8 +10,8 @@ #![allow(non_uppercase_pattern_statics)] -use lib::llvm::{SequentiallyConsistent, Acquire, Release, Xchg, ValueRef}; -use lib; +use llvm; +use llvm::{SequentiallyConsistent, Acquire, Release, Xchg, ValueRef}; use middle::subst; use middle::subst::FnSpace; use middle::trans::base::*; diff --git a/src/librustc/middle/trans/llrepr.rs b/src/librustc/middle/trans/llrepr.rs index f7884ca5643f7..2740e5695be10 100644 --- a/src/librustc/middle/trans/llrepr.rs +++ b/src/librustc/middle/trans/llrepr.rs @@ -10,7 +10,7 @@ use middle::trans::context::CrateContext; use middle::trans::type_::Type; -use lib::llvm::ValueRef; +use llvm::ValueRef; pub trait LlvmRepr { fn llrepr(&self, ccx: &CrateContext) -> String; diff --git a/src/librustc/middle/trans/machine.rs b/src/librustc/middle/trans/machine.rs index 7a7e3a9b75913..15bbc5ae84589 100644 --- a/src/librustc/middle/trans/machine.rs +++ b/src/librustc/middle/trans/machine.rs @@ -10,9 +10,9 @@ // Information concerning the machine representation of various types. -use lib::llvm::{ValueRef}; -use lib::llvm::False; -use lib::llvm::llvm; +use llvm; +use llvm::{ValueRef}; +use llvm::False; use middle::trans::common::*; use middle::trans::type_::Type; diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 6b54556bbe0ac..092a524e48a18 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -10,9 +10,8 @@ use back::abi; -use lib::llvm::llvm; -use lib::llvm::ValueRef; -use lib; +use llvm; +use llvm::ValueRef; use metadata::csearch; use middle::subst; use middle::trans::base::*; @@ -460,8 +459,8 @@ pub fn make_vtable>(ccx: &CrateContext, llvm::LLVMAddGlobal(ccx.llmod, val_ty(tbl).to_ref(), buf) }); llvm::LLVMSetInitializer(vt_gvar, tbl); - llvm::LLVMSetGlobalConstant(vt_gvar, lib::llvm::True); - lib::llvm::SetLinkage(vt_gvar, lib::llvm::InternalLinkage); + llvm::LLVMSetGlobalConstant(vt_gvar, llvm::True); + llvm::SetLinkage(vt_gvar, llvm::InternalLinkage); vt_gvar } } diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 01544214ccf7f..7687e82654a92 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -10,7 +10,7 @@ use back::link::exported_name; use driver::session; -use lib::llvm::ValueRef; +use llvm::ValueRef; use middle::subst; use middle::subst::Subst; use middle::trans::base::{set_llvm_fn_attrs, set_inline_hint}; diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index e50eb8f0be993..bc156fc37917c 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -9,7 +9,8 @@ // except according to those terms. use back::link::mangle_internal_name_by_path_and_seq; -use lib::llvm::{ValueRef, llvm}; +use llvm; +use llvm::{ValueRef}; use middle::trans::adt; use middle::trans::base::*; use middle::trans::build::*; diff --git a/src/librustc/middle/trans/tvec.rs b/src/librustc/middle/trans/tvec.rs index a6e554039e77e..07571b2f4c4a5 100644 --- a/src/librustc/middle/trans/tvec.rs +++ b/src/librustc/middle/trans/tvec.rs @@ -11,8 +11,8 @@ #![allow(non_camel_case_types)] use back::abi; -use lib; -use lib::llvm::{llvm, ValueRef}; +use llvm; +use llvm::{ValueRef}; use middle::lang_items::StrDupUniqFnLangItem; use middle::trans::base::*; use middle::trans::base; @@ -543,7 +543,7 @@ pub fn iter_vec_loop<'r, { // i < count let lhs = Load(cond_bcx, loop_counter); let rhs = count; - let cond_val = ICmp(cond_bcx, lib::llvm::IntULT, lhs, rhs); + let cond_val = ICmp(cond_bcx, llvm::IntULT, lhs, rhs); CondBr(cond_bcx, cond_val, body_bcx.llbb, next_bcx.llbb); } @@ -599,7 +599,7 @@ pub fn iter_vec_raw<'r, let data_ptr = Phi(header_bcx, val_ty(data_ptr), [data_ptr], [bcx.llbb]); let not_yet_at_end = - ICmp(header_bcx, lib::llvm::IntULT, data_ptr, data_end_ptr); + ICmp(header_bcx, llvm::IntULT, data_ptr, data_end_ptr); let body_bcx = fcx.new_temp_block("iter_vec_loop_body"); let next_bcx = fcx.new_temp_block("iter_vec_next"); CondBr(header_bcx, not_yet_at_end, body_bcx.llbb, next_bcx.llbb); diff --git a/src/librustc/middle/trans/type_.rs b/src/librustc/middle/trans/type_.rs index 54de399681163..10ee8f9ffc7ee 100644 --- a/src/librustc/middle/trans/type_.rs +++ b/src/librustc/middle/trans/type_.rs @@ -10,8 +10,9 @@ #![allow(non_uppercase_pattern_statics)] -use lib::llvm::{llvm, TypeRef, Bool, False, True, TypeKind, ValueRef}; -use lib::llvm::{Float, Double, X86_FP80, PPC_FP128, FP128}; +use llvm; +use llvm::{TypeRef, Bool, False, True, TypeKind, ValueRef}; +use llvm::{Float, Double, X86_FP80, PPC_FP128, FP128}; use middle::trans::context::CrateContext; diff --git a/src/librustc/middle/trans/value.rs b/src/librustc/middle/trans/value.rs index e627b859f4295..2db6a87a9dc53 100644 --- a/src/librustc/middle/trans/value.rs +++ b/src/librustc/middle/trans/value.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use lib::llvm::{llvm, UseRef, ValueRef}; +use llvm; +use llvm::{UseRef, ValueRef}; use middle::trans::basic_block::BasicBlock; use middle::trans::common::Block; use libc::c_uint; diff --git a/src/librustc_llvm/archive_ro.rs b/src/librustc_llvm/archive_ro.rs index 0b0577f7e8c5e..6c3778787e2e2 100644 --- a/src/librustc_llvm/archive_ro.rs +++ b/src/librustc_llvm/archive_ro.rs @@ -12,7 +12,6 @@ use libc; use ArchiveRef; -use llvm; use std::raw; use std::mem; @@ -31,7 +30,7 @@ impl ArchiveRO { pub fn open(dst: &Path) -> Option { unsafe { let ar = dst.with_c_str(|dst| { - llvm::LLVMRustOpenArchive(dst) + ::LLVMRustOpenArchive(dst) }); if ar.is_null() { None @@ -46,7 +45,7 @@ impl ArchiveRO { unsafe { let mut size = 0 as libc::size_t; let ptr = file.with_c_str(|file| { - llvm::LLVMRustArchiveReadSection(self.ptr, file, &mut size) + ::LLVMRustArchiveReadSection(self.ptr, file, &mut size) }); if ptr.is_null() { None @@ -63,7 +62,7 @@ impl ArchiveRO { impl Drop for ArchiveRO { fn drop(&mut self) { unsafe { - llvm::LLVMRustDestroyArchive(self.ptr); + ::LLVMRustDestroyArchive(self.ptr); } } } diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index f46a41835f637..3d0c5a821709f 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -30,7 +30,12 @@ extern crate libc; use std::c_str::ToCStr; -use libc::{c_uint, c_ushort, uint64_t, c_int, size_t}; +use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char}; +use libc::{c_longlong, c_ulonglong}; +use debuginfo::{DIBuilderRef, DIDescriptor, + DIFile, DILexicalBlock, DISubprogram, DIType, + DIBasicType, DIDerivedType, DICompositeType, + DIVariable, DIGlobalVariable, DIArray, DISubrange}; pub mod archive_ro; @@ -340,1538 +345,1527 @@ pub mod debuginfo { } } -pub mod llvm { - use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, ExecutionEngineRef}; - use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef}; - use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef}; - use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef}; - use super::{ValueRef, TargetMachineRef, FileType, ArchiveRef}; - use super::{CodeGenModel, RelocMode, CodeGenOptLevel}; - use super::debuginfo::*; - use libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong, - size_t, uint64_t}; - - // 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")] - extern { - /* 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 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); - - /** Target triple. See Module::getTargetTriple. */ - pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char; - pub fn LLVMSetTarget(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); - - /** See llvm::LLVMTypeKind::getTypeID. */ - pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind; - - /** See llvm::LLVMType::getContext. */ - pub fn LLVMGetTypeContext(Ty: TypeRef) -> 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; - pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef; - pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef; - pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef; - - /* Operations on function types */ - pub fn LLVMFunctionType(ReturnType: TypeRef, - ParamTypes: *const TypeRef, - ParamCount: c_uint, - IsVarArg: Bool) +// 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")] +extern { + /* 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 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); + + /** Target triple. See Module::getTargetTriple. */ + pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char; + pub fn LLVMSetTarget(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); + + /** See llvm::LLVMTypeKind::getTypeID. */ + pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind; + + /** See llvm::LLVMType::getContext. */ + pub fn LLVMGetTypeContext(Ty: TypeRef) -> 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 LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool; - pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef; - pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint; - pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *const TypeRef); - - /* Operations on struct types */ - pub fn LLVMStructTypeInContext(C: ContextRef, - ElementTypes: *const TypeRef, - ElementCount: c_uint, - Packed: Bool) - -> TypeRef; - pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint; - pub fn LLVMGetStructElementTypes(StructTy: TypeRef, - Dest: *mut 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 LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint; - pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint; - pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef) - -> *const (); - pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint; - - /* Operations on other types */ - pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef; - pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef; - pub fn LLVMMetadataTypeInContext(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 LLVMDumpValue(Val: ValueRef); - pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef); - pub fn LLVMHasMetadata(Val: ValueRef) -> c_int; - pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> 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; - pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef; - - /* Operations on Users */ - pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int; - pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef; - pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef); - - /* Operations on constants of any type */ - pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef; - /* all zeroes */ - pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef; - pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef) - -> ValueRef; - pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef) - -> ValueRef; - /* only for int/vector */ - pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef; - pub fn LLVMIsConstant(Val: ValueRef) -> Bool; - pub fn LLVMIsNull(Val: ValueRef) -> Bool; - pub fn LLVMIsUndef(Val: ValueRef) -> Bool; - pub fn LLVMConstPointerNull(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, - Str: *const c_char, - Val: ValueRef); - /* Operations on scalar constants */ - pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool) - -> ValueRef; - pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8) - -> ValueRef; - pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef, - Text: *const c_char, - SLen: c_uint, - Radix: u8) - -> ValueRef; - pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef; - pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char) - -> ValueRef; - pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef, - Text: *const c_char, - SLen: c_uint) - -> ValueRef; - pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong; - pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong; + pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint; + + /* Operations on real types */ + pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef; + pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef; + pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef; + pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef; + pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef; + + /* Operations on function types */ + pub fn LLVMFunctionType(ReturnType: TypeRef, + ParamTypes: *const TypeRef, + ParamCount: c_uint, + IsVarArg: Bool) + -> TypeRef; + pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool; + pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef; + pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint; + pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *const TypeRef); + + /* Operations on struct types */ + pub fn LLVMStructTypeInContext(C: ContextRef, + ElementTypes: *const TypeRef, + ElementCount: c_uint, + Packed: Bool) + -> TypeRef; + pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint; + pub fn LLVMGetStructElementTypes(StructTy: TypeRef, + Dest: *mut 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 LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint; + pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint; + pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef) + -> *const (); + pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint; + + /* Operations on other types */ + pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef; + pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef; + pub fn LLVMMetadataTypeInContext(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 LLVMDumpValue(Val: ValueRef); + pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef); + pub fn LLVMHasMetadata(Val: ValueRef) -> c_int; + pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> 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; + pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef; + + /* Operations on Users */ + pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int; + pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef; + pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef); + + /* Operations on constants of any type */ + pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef; + /* all zeroes */ + pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef; + pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef) + -> ValueRef; + pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef) + -> ValueRef; + /* only for int/vector */ + pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef; + pub fn LLVMIsConstant(Val: ValueRef) -> Bool; + pub fn LLVMIsNull(Val: ValueRef) -> Bool; + pub fn LLVMIsUndef(Val: ValueRef) -> Bool; + pub fn LLVMConstPointerNull(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, + Str: *const c_char, + Val: ValueRef); + + /* Operations on scalar constants */ + pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool) + -> ValueRef; + pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8) + -> ValueRef; + pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef, + Text: *const c_char, + SLen: c_uint, + Radix: u8) + -> ValueRef; + pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef; + pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char) + -> ValueRef; + pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef, + Text: *const c_char, + SLen: c_uint) + -> ValueRef; + pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong; + pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong; - /* 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; + /* 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; + 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 LLVMAlignOf(Ty: TypeRef) -> ValueRef; - pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef; - pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef; - pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef; - pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef; - pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef; - pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef; - pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) + /* Constant expressions */ + pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef; + pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef; + pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef; + pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef; + pub fn LLVMConstNUWNeg(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 LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) + -> ValueRef; + pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) + -> ValueRef; + pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) + -> ValueRef; + pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef) + -> ValueRef; + pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef) + -> ValueRef; + pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef) + -> ValueRef; + pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef) + -> ValueRef; + pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef) + -> ValueRef; + pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef) + -> ValueRef; + pub fn LLVMConstNUWMul(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 LLVMConstExactSDiv(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 LLVMConstGEP(ConstantVal: ValueRef, + ConstantIndices: *const ValueRef, + NumIndices: c_uint) + -> ValueRef; + pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef, + ConstantIndices: *const ValueRef, + NumIndices: c_uint) + -> ValueRef; + pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef) + -> ValueRef; + pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef) + -> ValueRef; + pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef) + -> ValueRef; + pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) - -> ValueRef; - pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) - -> ValueRef; - pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) + pub fn LLVMConstFPExt(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 LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef) - -> ValueRef; - pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef) - -> ValueRef; - pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef) - -> ValueRef; - pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef) + pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef) + pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef; - pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef) - -> ValueRef; - pub fn LLVMConstNUWMul(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 LLVMConstExactSDiv(LHSConstant: ValueRef, - RHSConstant: ValueRef) + pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) -> 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) + pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) + -> ValueRef; + pub fn LLVMConstTruncOrBitCast(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 LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef) + pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef) -> 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 LLVMConstGEP(ConstantVal: ValueRef, - ConstantIndices: *const ValueRef, - NumIndices: c_uint) - -> ValueRef; - pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef, - ConstantIndices: *const ValueRef, - NumIndices: c_uint) - -> ValueRef; - pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef) - -> ValueRef; - pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef) - -> ValueRef; - pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef) - -> ValueRef; - pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef) - -> ValueRef; - pub fn LLVMConstFPExt(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) + pub fn LLVMConstSelect(ConstantCondition: ValueRef, + ConstantIfTrue: ValueRef, + ConstantIfFalse: ValueRef) + -> ValueRef; + pub fn LLVMConstExtractElement(VectorConstant: ValueRef, + IndexConstant: ValueRef) + -> ValueRef; + pub fn LLVMConstInsertElement(VectorConstant: ValueRef, + ElementValueConstant: ValueRef, + IndexConstant: ValueRef) + -> ValueRef; + pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef, + VectorBConstant: ValueRef, + MaskConstant: ValueRef) + -> ValueRef; + pub fn LLVMConstExtractValue(AggConstant: ValueRef, + IdxList: *const c_uint, + NumIdx: c_uint) -> ValueRef; - pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef) - -> ValueRef; - pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) - -> ValueRef; - pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) - -> ValueRef; - pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) - -> ValueRef; - pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef) - -> ValueRef; - pub fn LLVMConstIntCast(ConstantVal: ValueRef, - ToType: TypeRef, - isSigned: Bool) + pub fn LLVMConstInsertValue(AggConstant: ValueRef, + ElementValueConstant: ValueRef, + IdxList: *const c_uint, + NumIdx: c_uint) -> ValueRef; - pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef) - -> ValueRef; - pub fn LLVMConstSelect(ConstantCondition: ValueRef, - ConstantIfTrue: ValueRef, - ConstantIfFalse: ValueRef) - -> ValueRef; - pub fn LLVMConstExtractElement(VectorConstant: ValueRef, - IndexConstant: ValueRef) - -> ValueRef; - pub fn LLVMConstInsertElement(VectorConstant: ValueRef, - ElementValueConstant: ValueRef, - IndexConstant: ValueRef) - -> ValueRef; - pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef, - VectorBConstant: ValueRef, - MaskConstant: ValueRef) - -> ValueRef; - pub fn LLVMConstExtractValue(AggConstant: ValueRef, - IdxList: *const c_uint, - NumIdx: c_uint) - -> ValueRef; - pub fn LLVMConstInsertValue(AggConstant: ValueRef, - ElementValueConstant: 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; - pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef; - + pub fn LLVMConstInlineAsm(Ty: TypeRef, + AsmString: *const c_char, + Constraints: *const c_char, + HasSideEffects: Bool, + IsAlignStack: Bool) + -> ValueRef; + pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef; - /* Operations on global variables, functions, and aliases (globals) */ - pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef; - pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool; - pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint; - pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint); - pub fn LLVMGetSection(Global: ValueRef) -> *const c_char; - pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char); - pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint; - pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint); - pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint; - pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint); + /* Operations on global variables, functions, and aliases (globals) */ + pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef; + pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool; + pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint; + pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint); + pub fn LLVMGetSection(Global: ValueRef) -> *const c_char; + pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char); + pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint; + pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint); + pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint; + pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint); - /* Operations on global variables */ - pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char) - -> ValueRef; - pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef, - Ty: TypeRef, - Name: *const c_char, - AddressSpace: c_uint) - -> ValueRef; - pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef; - pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef; - pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef; - pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef; - pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef; - pub fn LLVMDeleteGlobal(GlobalVar: ValueRef); - pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef; - pub fn LLVMSetInitializer(GlobalVar: ValueRef, - ConstantVal: ValueRef); - pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool; - pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool); - pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool; - pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool); - - /* Operations on aliases */ - pub fn LLVMAddAlias(M: ModuleRef, - Ty: TypeRef, - Aliasee: ValueRef, - Name: *const c_char) - -> ValueRef; - /* 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 LLVMGetLastFunction(M: ModuleRef) -> ValueRef; - pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef; - pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef; - pub fn LLVMDeleteFunction(Fn: ValueRef); - pub fn LLVMGetOrInsertFunction(M: ModuleRef, + /* Operations on global variables */ + pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char) + -> ValueRef; + pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef, + Ty: TypeRef, Name: *const c_char, - FunctionTy: TypeRef) + AddressSpace: c_uint) -> ValueRef; - pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint; - pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint; - pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint); - pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char; - pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char); - pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t); - pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char); - pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char); - pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong; - - /* Operations on parameters */ - pub fn LLVMCountParams(Fn: ValueRef) -> c_uint; - pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef); - pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef; - pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef; - pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef; - pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef; - pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef; - pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef; - pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint); - pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint); - pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint; - pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint); - - /* Operations on basic blocks */ - pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef; - pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool; - pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef; - pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef; - pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint; - pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef); - pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef; - pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef; - pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef; - pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef; - pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef; - - pub fn LLVMAppendBasicBlockInContext(C: ContextRef, - Fn: ValueRef, - Name: *const c_char) - -> BasicBlockRef; - pub fn LLVMInsertBasicBlockInContext(C: ContextRef, - BB: BasicBlockRef, - Name: *const c_char) - -> BasicBlockRef; - pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef); - - pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef, - MoveAfter: BasicBlockRef); - - pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef, - MoveBefore: BasicBlockRef); - - /* Operations on instructions */ - pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef; - pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef; - pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef; - pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef; - pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef; - pub fn LLVMInstructionEraseFromParent(Inst: ValueRef); - - /* Operations on call sites */ - pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint); - pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint; - pub fn LLVMAddInstrAttribute(Instr: ValueRef, - index: c_uint, - IA: c_uint); - pub fn LLVMRemoveInstrAttribute(Instr: ValueRef, - index: c_uint, - IA: c_uint); - pub fn LLVMSetInstrParamAlignment(Instr: ValueRef, - index: c_uint, - align: c_uint); - pub fn LLVMAddCallSiteAttribute(Instr: ValueRef, - index: c_uint, - Val: uint64_t); - - /* Operations on call instructions (only) */ - pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool; - pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool); - - /* Operations on load/store instructions (only) */ - pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool; - 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); - pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint; - pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint) - -> ValueRef; - pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint) - -> BasicBlockRef; - - /* 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 LLVMClearInsertionPosition(Builder: BuilderRef); - pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef); - pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef, - Instr: ValueRef, - Name: *const c_char); - pub fn LLVMDisposeBuilder(Builder: BuilderRef); - pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef); - - /* 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 LLVMBuildInvoke(B: BuilderRef, - Fn: ValueRef, - Args: *const ValueRef, - NumArgs: c_uint, - Then: BasicBlockRef, - Catch: BasicBlockRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildLandingPad(B: BuilderRef, - Ty: TypeRef, - PersFn: ValueRef, - NumClauses: c_uint, - Name: *const c_char) + pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef; + pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef; + pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef; + pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef; + pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef; + pub fn LLVMDeleteGlobal(GlobalVar: ValueRef); + pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef; + pub fn LLVMSetInitializer(GlobalVar: ValueRef, + ConstantVal: ValueRef); + pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool; + pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool); + pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool; + pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool); + + /* Operations on aliases */ + pub fn LLVMAddAlias(M: ModuleRef, + Ty: TypeRef, + Aliasee: ValueRef, + Name: *const c_char) + -> ValueRef; + + /* 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 LLVMGetLastFunction(M: ModuleRef) -> ValueRef; + pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef; + pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef; + pub fn LLVMDeleteFunction(Fn: ValueRef); + pub fn LLVMGetOrInsertFunction(M: ModuleRef, + Name: *const c_char, + FunctionTy: TypeRef) -> ValueRef; - pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef; - pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef; - - /* Add a case to the switch instruction */ - pub fn LLVMAddCase(Switch: ValueRef, - OnVal: ValueRef, - Dest: BasicBlockRef); - - /* Add a destination to the indirectbr instruction */ - pub fn LLVMAddDestination(IndirectBr: 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) + pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint; + pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint; + pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint); + pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char; + pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char); + pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t); + pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char); + pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char); + pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong; + + /* Operations on parameters */ + pub fn LLVMCountParams(Fn: ValueRef) -> c_uint; + pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef); + pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef; + pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef; + pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef; + pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef; + pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef; + pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef; + pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint); + pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint); + pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint; + pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint); + + /* Operations on basic blocks */ + pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef; + pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool; + pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef; + pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef; + pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint; + pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef); + pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef; + pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef; + pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef; + pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef; + pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef; + + pub fn LLVMAppendBasicBlockInContext(C: ContextRef, + Fn: ValueRef, + Name: *const c_char) + -> BasicBlockRef; + pub fn LLVMInsertBasicBlockInContext(C: ContextRef, + BB: BasicBlockRef, + Name: *const c_char) + -> BasicBlockRef; + pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef); + + pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef, + MoveAfter: BasicBlockRef); + + pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef, + MoveBefore: BasicBlockRef); + + /* Operations on instructions */ + pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef; + pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef; + pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef; + pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef; + pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef; + pub fn LLVMInstructionEraseFromParent(Inst: ValueRef); + + /* Operations on call sites */ + pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint); + pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint; + pub fn LLVMAddInstrAttribute(Instr: ValueRef, + index: c_uint, + IA: c_uint); + pub fn LLVMRemoveInstrAttribute(Instr: ValueRef, + index: c_uint, + IA: c_uint); + pub fn LLVMSetInstrParamAlignment(Instr: ValueRef, + index: c_uint, + align: c_uint); + pub fn LLVMAddCallSiteAttribute(Instr: ValueRef, + index: c_uint, + Val: uint64_t); + + /* Operations on call instructions (only) */ + pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool; + pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool); + + /* Operations on load/store instructions (only) */ + pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool; + 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); + pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint; + pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint) + -> ValueRef; + pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint) + -> BasicBlockRef; + + /* 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 LLVMClearInsertionPosition(Builder: BuilderRef); + pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef); + pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef, + Instr: ValueRef, + Name: *const c_char); + pub fn LLVMDisposeBuilder(Builder: BuilderRef); + pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef); + + /* 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 LLVMBuildNUWMul(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, + pub fn LLVMBuildInvoke(B: BuilderRef, + Fn: ValueRef, + Args: *const ValueRef, + NumArgs: c_uint, + Then: BasicBlockRef, + Catch: BasicBlockRef, + Name: *const c_char) + -> ValueRef; + pub fn LLVMBuildLandingPad(B: BuilderRef, + Ty: TypeRef, + PersFn: ValueRef, + NumClauses: c_uint, 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, + pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef; + pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef; + + /* Add a case to the switch instruction */ + pub fn LLVMAddCase(Switch: ValueRef, + OnVal: ValueRef, + Dest: BasicBlockRef); + + /* Add a destination to the indirectbr instruction */ + pub fn LLVMAddDestination(IndirectBr: 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 LLVMBuildXor(B: BuilderRef, - LHS: ValueRef, - RHS: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildBinOp(B: BuilderRef, - Op: Opcode, + 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 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 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; - /* Memory */ - pub fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildArrayMalloc(B: BuilderRef, - Ty: TypeRef, - Val: ValueRef, - Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char) - -> ValueRef; - pub fn LLVMBuildArrayAlloca(B: BuilderRef, - Ty: TypeRef, - Val: ValueRef, + /* Memory */ + pub fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *const c_char) + -> ValueRef; + pub fn LLVMBuildArrayMalloc(B: BuilderRef, + Ty: TypeRef, + Val: ValueRef, + Name: *const c_char) + -> ValueRef; + pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char) + -> ValueRef; + pub fn LLVMBuildArrayAlloca(B: BuilderRef, + Ty: TypeRef, + Val: ValueRef, + 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; - 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, + /* 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 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, + 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 LLVMBuildSExt(B: BuilderRef, + pub fn LLVMBuildIntToPtr(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, + 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 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, + pub fn LLVMBuildIntCast(B: BuilderRef, + Val: ValueRef, + DestTy: TypeRef, + Name: *const c_char) + -> 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 LLVMBuildCall(B: BuilderRef, + Fn: ValueRef, + Args: *const ValueRef, + NumArgs: c_uint, + 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 LLVMBuildBitCast(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, + pub fn LLVMBuildInsertValue(B: BuilderRef, + AggVal: ValueRef, + EltVal: ValueRef, + Index: c_uint, 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 LLVMBuildIntCast(B: BuilderRef, - Val: ValueRef, - DestTy: TypeRef, - Name: *const c_char) - -> 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 LLVMBuildCall(B: BuilderRef, - Fn: ValueRef, - Args: *const ValueRef, - NumArgs: c_uint, - 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) + 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 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 LLVMBuildPtrDiff(B: BuilderRef, + LHS: ValueRef, + RHS: ValueRef, + Name: *const c_char) + -> ValueRef; - pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char) + /* Atomic Operations */ + pub fn LLVMBuildAtomicLoad(B: BuilderRef, + PointerVal: ValueRef, + Name: *const c_char, + Order: AtomicOrdering, + Alignment: c_uint) -> 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 LLVMBuildAtomicLoad(B: BuilderRef, - PointerVal: ValueRef, - Name: *const c_char, - Order: AtomicOrdering, - Alignment: c_uint) - -> ValueRef; - - pub fn LLVMBuildAtomicStore(B: BuilderRef, - Val: ValueRef, - Ptr: ValueRef, - Order: AtomicOrdering, - Alignment: c_uint) - -> ValueRef; + pub fn LLVMBuildAtomicStore(B: BuilderRef, + Val: ValueRef, + Ptr: ValueRef, + Order: AtomicOrdering, + Alignment: c_uint) + -> ValueRef; - pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef, - LHS: ValueRef, - CMP: ValueRef, - RHS: ValueRef, - Order: AtomicOrdering, - FailureOrder: AtomicOrdering) - -> ValueRef; - pub fn LLVMBuildAtomicRMW(B: BuilderRef, - Op: AtomicBinOp, + pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef, LHS: ValueRef, + CMP: ValueRef, RHS: ValueRef, Order: AtomicOrdering, - SingleThreaded: Bool) + FailureOrder: AtomicOrdering) -> ValueRef; + pub fn LLVMBuildAtomicRMW(B: BuilderRef, + Op: AtomicBinOp, + LHS: ValueRef, + RHS: ValueRef, + Order: AtomicOrdering, + SingleThreaded: Bool) + -> ValueRef; - pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering); - - - /* 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; - /// Adds the target data to the given pass manager. The pass manager - /// references the target data only weakly. - pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef); - /** Number of bytes clobbered when doing a Store to *T. */ - pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef) - -> c_ulonglong; - - /** Number of bytes clobbered when doing a Store to *T. */ - pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef) - -> c_ulonglong; - - /** Distance between successive elements in an array of T. - Includes ABI padding. */ - pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint; - - /** Returns the preferred alignment of a type. */ - pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef) - -> c_uint; - /** Returns the minimum alignment of a type. */ - pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef) - -> c_uint; - - /// Computes the byte offset of the indexed struct element for a - /// target. - pub fn LLVMOffsetOfElement(TD: TargetDataRef, - StructTy: TypeRef, - Element: c_uint) - -> c_ulonglong; - - /** - * Returns the minimum alignment of a type when part of a call frame. - */ - pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef) - -> c_uint; - - /** 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; - - /** Runs the function passes on the provided function. */ - pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef) - -> Bool; - - /** Initializes all the function passes scheduled in the manager */ - pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool; - - /** Finalizes all the function passes scheduled in the manager */ - pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool; - - pub fn LLVMInitializePasses(); - - /** Adds a verification pass. */ - pub fn LLVMAddVerifierPass(PM: PassManagerRef); - - pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef); - pub fn LLVMAddIPSCCPPass(PM: PassManagerRef); - pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef); - pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef); - pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef); - pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef); - pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef); - pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef); - pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef); - pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef); - pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef); - pub fn LLVMAddReassociatePass(PM: PassManagerRef); - pub fn LLVMAddLoopRotatePass(PM: PassManagerRef); - pub fn LLVMAddLICMPass(PM: PassManagerRef); - pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef); - pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef); - pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef); - pub fn LLVMAddGVNPass(PM: PassManagerRef); - pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef); - pub fn LLVMAddSCCPPass(PM: PassManagerRef); - pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef); - pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef); - pub fn LLVMAddConstantMergePass(PM: PassManagerRef); - pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef); - pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef); - pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef); - pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef); - pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef); - pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef); - pub fn LLVMAddPruneEHPass(PM: PassManagerRef); - pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef); - pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef); - pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef); - pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef); - pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef); - - pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef; - pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef); - pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef, - OptimizationLevel: c_uint); - pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef, - Value: Bool); - pub fn LLVMPassManagerBuilderSetDisableUnitAtATime( - PMB: PassManagerBuilderRef, - Value: Bool); - pub fn LLVMPassManagerBuilderSetDisableUnrollLoops( - PMB: PassManagerBuilderRef, - Value: Bool); - pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls( - 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); - - /** Destroys a memory buffer. */ - pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef); - - - /* 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; - /** Borrows the contents of the memory buffer (doesn't copy it) */ - pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char, - InputDataLength: size_t, - BufferName: *const c_char, - RequiresNull: Bool) - -> MemoryBufferRef; - pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char, - InputDataLength: size_t, - BufferName: *const c_char) - -> MemoryBufferRef; + pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering); - pub fn LLVMIsMultithreaded() -> Bool; - pub fn LLVMStartMultithreaded() -> Bool; - /** Returns a string describing the last error caused by an LLVMRust* - call. */ - pub fn LLVMRustGetLastError() -> *const c_char; + /* Selected entries from the downcasts. */ + pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef; + pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef; - /// Print the pass timings since static dtors aren't picking them up. - pub fn LLVMRustPrintPassTimings(); + /** Writes a module to the specified path. Returns 0 on success. */ + pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int; - pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef; + /** Creates target data from a target layout string. */ + pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef; + /// Adds the target data to the given pass manager. The pass manager + /// references the target data only weakly. + pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef); + /** Number of bytes clobbered when doing a Store to *T. */ + pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef) + -> c_ulonglong; - pub fn LLVMStructSetBody(StructTy: TypeRef, - ElementTypes: *const TypeRef, - ElementCount: c_uint, - Packed: Bool); + /** Number of bytes clobbered when doing a Store to *T. */ + pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef) + -> c_ulonglong; - pub fn LLVMConstNamedStruct(S: TypeRef, - ConstantVals: *const ValueRef, - Count: c_uint) - -> ValueRef; + /** Distance between successive elements in an array of T. + Includes ABI padding. */ + pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint; - /** Enables LLVM debug output. */ - pub fn LLVMSetDebug(Enabled: c_int); + /** Returns the preferred alignment of a type. */ + pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef) + -> c_uint; + /** Returns the minimum alignment of a type. */ + pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef) + -> c_uint; + + /// Computes the byte offset of the indexed struct element for a + /// target. + pub fn LLVMOffsetOfElement(TD: TargetDataRef, + StructTy: TypeRef, + Element: c_uint) + -> c_ulonglong; + + /** + * Returns the minimum alignment of a type when part of a call frame. + */ + pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef) + -> c_uint; - /** Prepares inline assembly. */ - pub fn LLVMInlineAsm(Ty: TypeRef, - AsmString: *const c_char, - Constraints: *const c_char, - SideEffects: Bool, - AlignStack: Bool, - Dialect: c_uint) - -> ValueRef; + /** 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; + + /** Runs the function passes on the provided function. */ + pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef) + -> Bool; + + /** Initializes all the function passes scheduled in the manager */ + pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool; + + /** Finalizes all the function passes scheduled in the manager */ + pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool; + + pub fn LLVMInitializePasses(); + + /** Adds a verification pass. */ + pub fn LLVMAddVerifierPass(PM: PassManagerRef); + + pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef); + pub fn LLVMAddIPSCCPPass(PM: PassManagerRef); + pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef); + pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef); + pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef); + pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef); + pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef); + pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef); + pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef); + pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef); + pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef); + pub fn LLVMAddReassociatePass(PM: PassManagerRef); + pub fn LLVMAddLoopRotatePass(PM: PassManagerRef); + pub fn LLVMAddLICMPass(PM: PassManagerRef); + pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef); + pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef); + pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef); + pub fn LLVMAddGVNPass(PM: PassManagerRef); + pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef); + pub fn LLVMAddSCCPPass(PM: PassManagerRef); + pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef); + pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef); + pub fn LLVMAddConstantMergePass(PM: PassManagerRef); + pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef); + pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef); + pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef); + pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef); + pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef); + pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef); + pub fn LLVMAddPruneEHPass(PM: PassManagerRef); + pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef); + pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef); + pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef); + pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef); + pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef); + + pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef; + pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef); + pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef, + OptimizationLevel: c_uint); + pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef, + Value: Bool); + pub fn LLVMPassManagerBuilderSetDisableUnitAtATime( + PMB: PassManagerBuilderRef, + Value: Bool); + pub fn LLVMPassManagerBuilderSetDisableUnrollLoops( + PMB: PassManagerBuilderRef, + Value: Bool); + pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls( + 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); + + /** Destroys a memory buffer. */ + pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef); + + + /* 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; + /** Borrows the contents of the memory buffer (doesn't copy it) */ + pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char, + InputDataLength: size_t, + BufferName: *const c_char, + RequiresNull: Bool) + -> MemoryBufferRef; + pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char, + InputDataLength: size_t, + BufferName: *const c_char) + -> MemoryBufferRef; - pub static LLVMRustDebugMetadataVersion: u32; + pub fn LLVMIsMultithreaded() -> Bool; + pub fn LLVMStartMultithreaded() -> Bool; - pub fn LLVMRustAddModuleFlag(M: ModuleRef, - name: *const c_char, - value: u32); + /** Returns a string describing the last error caused by an LLVMRust* + call. */ + pub fn LLVMRustGetLastError() -> *const c_char; - pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef; + /// Print the pass timings since static dtors aren't picking them up. + pub fn LLVMRustPrintPassTimings(); - pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef); + pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef; - pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef); + pub fn LLVMStructSetBody(StructTy: TypeRef, + ElementTypes: *const TypeRef, + ElementCount: c_uint, + Packed: Bool); - pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef, - Lang: c_uint, - File: *const c_char, - Dir: *const c_char, - Producer: *const c_char, - isOptimized: bool, - Flags: *const c_char, - RuntimeVer: c_uint, - SplitName: *const c_char); + pub fn LLVMConstNamedStruct(S: TypeRef, + ConstantVals: *const ValueRef, + Count: c_uint) + -> ValueRef; - pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef, - Filename: *const c_char, - Directory: *const c_char) - -> DIFile; + /** Enables LLVM debug output. */ + pub fn LLVMSetDebug(Enabled: c_int); - pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef, - File: DIFile, - ParameterTypes: DIArray) - -> DICompositeType; + /** Prepares inline assembly. */ + pub fn LLVMInlineAsm(Ty: TypeRef, + AsmString: *const c_char, + Constraints: *const c_char, + SideEffects: Bool, + AlignStack: Bool, + Dialect: c_uint) + -> ValueRef; - pub fn LLVMDIBuilderCreateFunction(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: c_uint, - isOptimized: bool, - Fn: ValueRef, - TParam: ValueRef, - Decl: ValueRef) - -> DISubprogram; - - pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef, - Name: *const c_char, - SizeInBits: c_ulonglong, - AlignInBits: c_ulonglong, - Encoding: c_uint) - -> DIBasicType; + pub static LLVMRustDebugMetadataVersion: u32; - pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef, - PointeeTy: DIType, - SizeInBits: c_ulonglong, - AlignInBits: c_ulonglong, - Name: *const c_char) - -> DIDerivedType; + pub fn LLVMRustAddModuleFlag(M: ModuleRef, + name: *const c_char, + value: u32); - pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef, - Scope: DIDescriptor, - Name: *const c_char, + pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef; + + pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef); + + pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef); + + pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef, + Lang: c_uint, + File: *const c_char, + Dir: *const c_char, + Producer: *const c_char, + isOptimized: bool, + Flags: *const c_char, + RuntimeVer: c_uint, + SplitName: *const c_char); + + pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef, + Filename: *const c_char, + Directory: *const c_char) + -> DIFile; + + pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef, File: DIFile, - LineNumber: c_uint, - SizeInBits: c_ulonglong, - AlignInBits: c_ulonglong, - Flags: c_uint, - DerivedFrom: DIType, - Elements: DIArray, - RunTimeLang: c_uint, - VTableHolder: ValueRef, - UniqueId: *const c_char) + ParameterTypes: DIArray) -> DICompositeType; - pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef, - Scope: DIDescriptor, + pub fn LLVMDIBuilderCreateFunction(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: c_uint, + isOptimized: bool, + Fn: ValueRef, + TParam: ValueRef, + Decl: ValueRef) + -> DISubprogram; + + pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef, + Name: *const c_char, + SizeInBits: c_ulonglong, + AlignInBits: c_ulonglong, + Encoding: c_uint) + -> DIBasicType; + + pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef, + PointeeTy: DIType, + SizeInBits: c_ulonglong, + AlignInBits: c_ulonglong, + Name: *const c_char) + -> DIDerivedType; + + pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef, + Scope: DIDescriptor, + Name: *const c_char, + File: DIFile, + LineNumber: c_uint, + SizeInBits: c_ulonglong, + AlignInBits: c_ulonglong, + Flags: c_uint, + DerivedFrom: DIType, + Elements: DIArray, + RunTimeLang: c_uint, + VTableHolder: ValueRef, + UniqueId: *const c_char) + -> DICompositeType; + + pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef, + Scope: DIDescriptor, + Name: *const c_char, + File: DIFile, + LineNo: c_uint, + SizeInBits: c_ulonglong, + AlignInBits: c_ulonglong, + OffsetInBits: c_ulonglong, + Flags: c_uint, + Ty: DIType) + -> DIDerivedType; + + pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef, + Scope: DIDescriptor, + File: DIFile, + Line: c_uint, + Col: c_uint, + Discriminator: c_uint) + -> DILexicalBlock; + + pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef, + Context: DIDescriptor, Name: *const c_char, + LinkageName: *const c_char, File: DIFile, LineNo: c_uint, - SizeInBits: c_ulonglong, - AlignInBits: c_ulonglong, - OffsetInBits: c_ulonglong, - Flags: c_uint, - Ty: DIType) - -> DIDerivedType; - - pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef, - Scope: DIDescriptor, - File: DIFile, - Line: c_uint, - Col: c_uint, - Discriminator: c_uint) - -> DILexicalBlock; - - pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef, - Context: DIDescriptor, - Name: *const c_char, - LinkageName: *const c_char, - File: DIFile, - LineNo: c_uint, - Ty: DIType, - isLocalToUnit: bool, - Val: ValueRef, - Decl: ValueRef) - -> DIGlobalVariable; - - pub fn LLVMDIBuilderCreateLocalVariable(Builder: DIBuilderRef, - Tag: c_uint, - Scope: DIDescriptor, - Name: *const c_char, - File: DIFile, - LineNo: c_uint, - Ty: DIType, - AlwaysPreserve: bool, - Flags: c_uint, - ArgNo: c_uint) - -> DIVariable; - - pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef, - Size: c_ulonglong, - AlignInBits: c_ulonglong, - Ty: DIType, - Subscripts: DIArray) - -> DIType; - - pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef, - Size: c_ulonglong, - AlignInBits: c_ulonglong, Ty: DIType, - Subscripts: DIArray) - -> DIType; - - pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef, - Lo: c_longlong, - Count: c_longlong) - -> DISubrange; - - pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef, - Ptr: *const DIDescriptor, - Count: c_uint) - -> DIArray; - - pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef, - Val: ValueRef, - VarInfo: DIVariable, - InsertAtEnd: BasicBlockRef) - -> ValueRef; - - pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef, - Val: ValueRef, - VarInfo: DIVariable, - InsertBefore: ValueRef) - -> ValueRef; - - pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef, - Name: *const c_char, - Val: c_ulonglong) - -> ValueRef; - - pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef, - Scope: ValueRef, - Name: *const c_char, - File: ValueRef, - LineNumber: c_uint, - SizeInBits: c_ulonglong, - AlignInBits: c_ulonglong, - Elements: ValueRef, - ClassType: ValueRef) - -> ValueRef; - - pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef, - Scope: ValueRef, + isLocalToUnit: bool, + Val: ValueRef, + Decl: ValueRef) + -> DIGlobalVariable; + + pub fn LLVMDIBuilderCreateLocalVariable(Builder: DIBuilderRef, + Tag: c_uint, + Scope: DIDescriptor, Name: *const c_char, - File: ValueRef, - LineNumber: c_uint, - SizeInBits: c_ulonglong, - AlignInBits: c_ulonglong, + File: DIFile, + LineNo: c_uint, + Ty: DIType, + AlwaysPreserve: bool, Flags: c_uint, - Elements: ValueRef, - RunTimeLang: c_uint, - UniqueId: *const c_char) - -> ValueRef; + ArgNo: c_uint) + -> DIVariable; + + pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef, + Size: c_ulonglong, + AlignInBits: c_ulonglong, + Ty: DIType, + Subscripts: DIArray) + -> DIType; + + pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef, + Size: c_ulonglong, + AlignInBits: c_ulonglong, + Ty: DIType, + Subscripts: DIArray) + -> DIType; + + pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef, + Lo: c_longlong, + Count: c_longlong) + -> DISubrange; + + pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef, + Ptr: *const DIDescriptor, + Count: c_uint) + -> DIArray; + + pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef, + Val: ValueRef, + VarInfo: DIVariable, + InsertAtEnd: BasicBlockRef) + -> ValueRef; - pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool); - - pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef, - Scope: ValueRef, - Name: *const c_char, - Ty: ValueRef, - File: ValueRef, - LineNo: c_uint, - ColumnNo: c_uint) - -> ValueRef; - - pub fn LLVMDIBuilderCreateOpDeref(IntType: TypeRef) -> ValueRef; - - pub fn LLVMDIBuilderCreateOpPlus(IntType: TypeRef) -> ValueRef; - - pub fn LLVMDIBuilderCreateComplexVariable(Builder: DIBuilderRef, - Tag: c_uint, - Scope: ValueRef, - Name: *const c_char, - File: ValueRef, - LineNo: c_uint, - Ty: ValueRef, - AddrOps: *const ValueRef, - AddrOpsCount: c_uint, - ArgNo: c_uint) - -> ValueRef; - - pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef, - Scope: ValueRef, - Name: *const c_char, - File: ValueRef, - LineNo: c_uint) + pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef, + Val: ValueRef, + VarInfo: DIVariable, + InsertBefore: ValueRef) -> ValueRef; - pub fn LLVMDICompositeTypeSetTypeArray(CompositeType: ValueRef, TypeArray: ValueRef); - pub fn LLVMTypeToString(Type: TypeRef) -> *const c_char; - pub fn LLVMValueToString(value_ref: ValueRef) -> *const c_char; - - pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef; - - pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef; - - pub fn LLVMInitializeX86TargetInfo(); - pub fn LLVMInitializeX86Target(); - pub fn LLVMInitializeX86TargetMC(); - pub fn LLVMInitializeX86AsmPrinter(); - pub fn LLVMInitializeX86AsmParser(); - pub fn LLVMInitializeARMTargetInfo(); - pub fn LLVMInitializeARMTarget(); - pub fn LLVMInitializeARMTargetMC(); - pub fn LLVMInitializeARMAsmPrinter(); - pub fn LLVMInitializeARMAsmParser(); - pub fn LLVMInitializeMipsTargetInfo(); - pub fn LLVMInitializeMipsTarget(); - pub fn LLVMInitializeMipsTargetMC(); - pub fn LLVMInitializeMipsAsmPrinter(); - pub fn LLVMInitializeMipsAsmParser(); - - pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *const c_char) -> bool; - pub fn LLVMRustCreateTargetMachine(Triple: *const c_char, - CPU: *const c_char, - Features: *const c_char, - Model: CodeGenModel, - Reloc: RelocMode, - Level: CodeGenOptLevel, - EnableSegstk: bool, - UseSoftFP: bool, - NoFramePointerElim: bool, - FunctionSections: bool, - DataSections: 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 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) -> bool; - pub fn LLVMRustPrintModule(PM: PassManagerRef, + pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef, + Name: *const c_char, + Val: c_ulonglong) + -> ValueRef; + + pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef, + Scope: ValueRef, + Name: *const c_char, + File: ValueRef, + LineNumber: c_uint, + SizeInBits: c_ulonglong, + AlignInBits: c_ulonglong, + Elements: ValueRef, + ClassType: ValueRef) + -> ValueRef; + + pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef, + Scope: ValueRef, + Name: *const c_char, + File: ValueRef, + LineNumber: c_uint, + SizeInBits: c_ulonglong, + AlignInBits: c_ulonglong, + Flags: c_uint, + Elements: ValueRef, + RunTimeLang: c_uint, + UniqueId: *const c_char) + -> ValueRef; + + pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool); + + pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef, + Scope: ValueRef, + Name: *const c_char, + Ty: ValueRef, + File: ValueRef, + LineNo: c_uint, + ColumnNo: c_uint) + -> ValueRef; + + pub fn LLVMDIBuilderCreateOpDeref(IntType: TypeRef) -> ValueRef; + + pub fn LLVMDIBuilderCreateOpPlus(IntType: TypeRef) -> ValueRef; + + pub fn LLVMDIBuilderCreateComplexVariable(Builder: DIBuilderRef, + Tag: c_uint, + Scope: ValueRef, + Name: *const c_char, + File: ValueRef, + LineNo: c_uint, + Ty: ValueRef, + AddrOps: *const ValueRef, + AddrOpsCount: c_uint, + ArgNo: c_uint) + -> ValueRef; + + pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef, + Scope: ValueRef, + Name: *const c_char, + File: ValueRef, + LineNo: c_uint) + -> ValueRef; + + pub fn LLVMDICompositeTypeSetTypeArray(CompositeType: ValueRef, TypeArray: ValueRef); + pub fn LLVMTypeToString(Type: TypeRef) -> *const c_char; + pub fn LLVMValueToString(value_ref: ValueRef) -> *const c_char; + + pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef; + + pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef; + + pub fn LLVMInitializeX86TargetInfo(); + pub fn LLVMInitializeX86Target(); + pub fn LLVMInitializeX86TargetMC(); + pub fn LLVMInitializeX86AsmPrinter(); + pub fn LLVMInitializeX86AsmParser(); + pub fn LLVMInitializeARMTargetInfo(); + pub fn LLVMInitializeARMTarget(); + pub fn LLVMInitializeARMTargetMC(); + pub fn LLVMInitializeARMAsmPrinter(); + pub fn LLVMInitializeARMAsmParser(); + pub fn LLVMInitializeMipsTargetInfo(); + pub fn LLVMInitializeMipsTarget(); + pub fn LLVMInitializeMipsTargetMC(); + pub fn LLVMInitializeMipsAsmPrinter(); + pub fn LLVMInitializeMipsAsmParser(); + + pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *const c_char) -> bool; + pub fn LLVMRustCreateTargetMachine(Triple: *const c_char, + CPU: *const c_char, + Features: *const c_char, + Model: CodeGenModel, + Reloc: RelocMode, + Level: CodeGenOptLevel, + EnableSegstk: bool, + UseSoftFP: bool, + NoFramePointerElim: bool, + FunctionSections: bool, + DataSections: 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 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); - 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 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 LLVMRustArchiveReadSection(AR: ArchiveRef, name: *const c_char, - out_len: *mut size_t) -> *const c_char; - pub fn LLVMRustDestroyArchive(AR: ArchiveRef); - - pub fn LLVMRustSetDLLExportStorageClass(V: ValueRef); - pub fn LLVMVersionMajor() -> c_int; - pub fn LLVMVersionMinor() -> c_int; - - pub fn LLVMRustGetSectionName(SI: SectionIteratorRef, - data: *mut *const c_char) -> c_int; - } + Output: *const c_char, + FileType: FileType) -> bool; + pub fn LLVMRustPrintModule(PM: PassManagerRef, + M: ModuleRef, + Output: *const c_char); + 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 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 LLVMRustArchiveReadSection(AR: ArchiveRef, name: *const c_char, + out_len: *mut size_t) -> *const c_char; + pub fn LLVMRustDestroyArchive(AR: ArchiveRef); + + pub fn LLVMRustSetDLLExportStorageClass(V: ValueRef); + pub fn LLVMVersionMajor() -> c_int; + pub fn LLVMVersionMinor() -> c_int; + + pub fn LLVMRustGetSectionName(SI: SectionIteratorRef, + data: *mut *const c_char) -> c_int; } pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) { unsafe { - llvm::LLVMSetInstructionCallConv(instr, cc as c_uint); + LLVMSetInstructionCallConv(instr, cc as c_uint); } } pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) { unsafe { - llvm::LLVMSetFunctionCallConv(fn_, cc as c_uint); + LLVMSetFunctionCallConv(fn_, cc as c_uint); } } pub fn SetLinkage(global: ValueRef, link: Linkage) { unsafe { - llvm::LLVMSetLinkage(global, link as c_uint); + LLVMSetLinkage(global, link as c_uint); } } pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) { unsafe { - llvm::LLVMSetUnnamedAddr(global, unnamed as Bool); + LLVMSetUnnamedAddr(global, unnamed as Bool); } } pub fn set_thread_local(global: ValueRef, is_thread_local: bool) { unsafe { - llvm::LLVMSetThreadLocal(global, is_thread_local as Bool); + LLVMSetThreadLocal(global, is_thread_local as Bool); } } pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef { unsafe { - llvm::LLVMConstICmp(pred as c_ushort, v1, v2) + LLVMConstICmp(pred as c_ushort, v1, v2) } } pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef { unsafe { - llvm::LLVMConstFCmp(pred as c_ushort, v1, v2) + LLVMConstFCmp(pred as c_ushort, v1, v2) } } pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) { unsafe { - llvm::LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr as uint64_t) + LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr as uint64_t) } } @@ -1930,7 +1924,7 @@ pub struct TargetData { impl Drop for TargetData { fn drop(&mut self) { unsafe { - llvm::LLVMDisposeTargetData(self.lltd); + LLVMDisposeTargetData(self.lltd); } } } @@ -1938,7 +1932,7 @@ impl Drop for TargetData { pub fn mk_target_data(string_rep: &str) -> TargetData { TargetData { lltd: string_rep.with_c_str(|buf| { - unsafe { llvm::LLVMCreateTargetData(buf) } + unsafe { LLVMCreateTargetData(buf) } }) } } @@ -1953,7 +1947,7 @@ impl ObjectFile { // This will take ownership of llmb pub fn new(llmb: MemoryBufferRef) -> Option { unsafe { - let llof = llvm::LLVMCreateObjectFile(llmb); + let llof = LLVMCreateObjectFile(llmb); if llof as int == 0 { // LLVMCreateObjectFile took ownership of llmb return None @@ -1969,7 +1963,7 @@ impl ObjectFile { impl Drop for ObjectFile { fn drop(&mut self) { unsafe { - llvm::LLVMDisposeObjectFile(self.llof); + LLVMDisposeObjectFile(self.llof); } } } @@ -1983,7 +1977,7 @@ pub struct SectionIter { impl Drop for SectionIter { fn drop(&mut self) { unsafe { - llvm::LLVMDisposeSectionIterator(self.llsi); + LLVMDisposeSectionIterator(self.llsi); } } } @@ -1991,7 +1985,7 @@ impl Drop for SectionIter { pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter { unsafe { SectionIter { - llsi: llvm::LLVMGetSections(llof) + llsi: LLVMGetSections(llof) } } } @@ -2001,39 +1995,39 @@ pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter { // away. We're just calling lots of stuff until we transitively get // all of LLVM. This is worse than anything. pub unsafe fn static_link_hack_this_sucks() { - llvm::LLVMInitializePasses(); - - llvm::LLVMInitializeX86TargetInfo(); - llvm::LLVMInitializeX86Target(); - llvm::LLVMInitializeX86TargetMC(); - llvm::LLVMInitializeX86AsmPrinter(); - llvm::LLVMInitializeX86AsmParser(); - - llvm::LLVMInitializeARMTargetInfo(); - llvm::LLVMInitializeARMTarget(); - llvm::LLVMInitializeARMTargetMC(); - llvm::LLVMInitializeARMAsmPrinter(); - llvm::LLVMInitializeARMAsmParser(); - - llvm::LLVMInitializeMipsTargetInfo(); - llvm::LLVMInitializeMipsTarget(); - llvm::LLVMInitializeMipsTargetMC(); - llvm::LLVMInitializeMipsAsmPrinter(); - llvm::LLVMInitializeMipsAsmParser(); - - llvm::LLVMRustSetLLVMOptions(0 as c_int, + LLVMInitializePasses(); + + LLVMInitializeX86TargetInfo(); + LLVMInitializeX86Target(); + LLVMInitializeX86TargetMC(); + LLVMInitializeX86AsmPrinter(); + LLVMInitializeX86AsmParser(); + + LLVMInitializeARMTargetInfo(); + LLVMInitializeARMTarget(); + LLVMInitializeARMTargetMC(); + LLVMInitializeARMAsmPrinter(); + LLVMInitializeARMAsmParser(); + + LLVMInitializeMipsTargetInfo(); + LLVMInitializeMipsTarget(); + LLVMInitializeMipsTargetMC(); + LLVMInitializeMipsAsmPrinter(); + LLVMInitializeMipsAsmParser(); + + LLVMRustSetLLVMOptions(0 as c_int, 0 as *const _); - llvm::LLVMPassManagerBuilderPopulateModulePassManager(0 as *mut _, 0 as *mut _); - llvm::LLVMPassManagerBuilderPopulateLTOPassManager(0 as *mut _, 0 as *mut _, False, False); - llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(0 as *mut _, 0 as *mut _); - llvm::LLVMPassManagerBuilderSetOptLevel(0 as *mut _, 0 as c_uint); - llvm::LLVMPassManagerBuilderUseInlinerWithThreshold(0 as *mut _, 0 as c_uint); - llvm::LLVMWriteBitcodeToFile(0 as *mut _, 0 as *const _); - llvm::LLVMPassManagerBuilderCreate(); - llvm::LLVMPassManagerBuilderDispose(0 as *mut _); + LLVMPassManagerBuilderPopulateModulePassManager(0 as *mut _, 0 as *mut _); + LLVMPassManagerBuilderPopulateLTOPassManager(0 as *mut _, 0 as *mut _, False, False); + LLVMPassManagerBuilderPopulateFunctionPassManager(0 as *mut _, 0 as *mut _); + LLVMPassManagerBuilderSetOptLevel(0 as *mut _, 0 as c_uint); + LLVMPassManagerBuilderUseInlinerWithThreshold(0 as *mut _, 0 as c_uint); + LLVMWriteBitcodeToFile(0 as *mut _, 0 as *const _); + LLVMPassManagerBuilderCreate(); + LLVMPassManagerBuilderDispose(0 as *mut _); - llvm::LLVMRustLinkInExternalBitcode(0 as *mut _, 0 as *const _, 0 as size_t); + LLVMRustLinkInExternalBitcode(0 as *mut _, 0 as *const _, 0 as size_t); LLVMLinkInJIT(); LLVMLinkInMCJIT(); From a008fc84aaf429a1966c422297302cf809df796d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 11 Jul 2014 17:57:45 -0700 Subject: [PATCH 13/13] Fix rebase fallout. Sorry. --- src/librustc/lib.rs | 1 - src/librustc/middle/trans/intrinsic.rs | 48 +++++++++++++------------- src/librustc/middle/trans/type_.rs | 8 ++--- src/librustc_back/rpath.rs | 2 +- src/librustc_llvm/lib.rs | 46 ------------------------ 5 files changed, 29 insertions(+), 76 deletions(-) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 99eed04b55898..92d1c176a1b92 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -66,7 +66,6 @@ pub mod back { pub mod lto; } ->>>>>>> Extract librustc_back from librustc pub mod middle { pub mod def; diff --git a/src/librustc/middle/trans/intrinsic.rs b/src/librustc/middle/trans/intrinsic.rs index af5cdf7a1be73..bb33a5e4f8d2f 100644 --- a/src/librustc/middle/trans/intrinsic.rs +++ b/src/librustc/middle/trans/intrinsic.rs @@ -426,13 +426,13 @@ pub fn trans_intrinsic_call<'a>(mut bcx: &'a Block<'a>, node: ast::NodeId, assert!(split.len() >= 2, "Atomic intrinsic not correct format"); let order = if split.len() == 2 { - lib::llvm::SequentiallyConsistent + llvm::SequentiallyConsistent } else { match *split.get(2) { - "relaxed" => lib::llvm::Monotonic, - "acq" => lib::llvm::Acquire, - "rel" => lib::llvm::Release, - "acqrel" => lib::llvm::AcquireRelease, + "relaxed" => llvm::Monotonic, + "acq" => llvm::Acquire, + "rel" => llvm::Release, + "acqrel" => llvm::AcquireRelease, _ => ccx.sess().fatal("unknown ordering in atomic intrinsic") } }; @@ -443,23 +443,23 @@ pub fn trans_intrinsic_call<'a>(mut bcx: &'a Block<'a>, node: ast::NodeId, // of this, I assume that it's good enough for us to use for // now. let strongest_failure_ordering = match order { - lib::llvm::NotAtomic | lib::llvm::Unordered => + llvm::NotAtomic | llvm::Unordered => ccx.sess().fatal("cmpxchg must be atomic"), - lib::llvm::Monotonic | lib::llvm::Release => - lib::llvm::Monotonic, + llvm::Monotonic | llvm::Release => + llvm::Monotonic, - lib::llvm::Acquire | lib::llvm::AcquireRelease => - lib::llvm::Acquire, + llvm::Acquire | llvm::AcquireRelease => + llvm::Acquire, - lib::llvm::SequentiallyConsistent => - lib::llvm::SequentiallyConsistent + llvm::SequentiallyConsistent => + llvm::SequentiallyConsistent }; let res = AtomicCmpXchg(bcx, *llargs.get(0), *llargs.get(1), *llargs.get(2), order, strongest_failure_ordering); - if unsafe { lib::llvm::llvm::LLVMVersionMinor() >= 5 } { + if unsafe { llvm::LLVMVersionMinor() >= 5 } { ExtractValue(bcx, res, 0) } else { res @@ -482,17 +482,17 @@ pub fn trans_intrinsic_call<'a>(mut bcx: &'a Block<'a>, node: ast::NodeId, // These are all AtomicRMW ops op => { let atom_op = match op { - "xchg" => lib::llvm::Xchg, - "xadd" => lib::llvm::Add, - "xsub" => lib::llvm::Sub, - "and" => lib::llvm::And, - "nand" => lib::llvm::Nand, - "or" => lib::llvm::Or, - "xor" => lib::llvm::Xor, - "max" => lib::llvm::Max, - "min" => lib::llvm::Min, - "umax" => lib::llvm::UMax, - "umin" => lib::llvm::UMin, + "xchg" => llvm::Xchg, + "xadd" => llvm::Add, + "xsub" => llvm::Sub, + "and" => llvm::And, + "nand" => llvm::Nand, + "or" => llvm::Or, + "xor" => llvm::Xor, + "max" => llvm::Max, + "min" => llvm::Min, + "umax" => llvm::UMax, + "umin" => llvm::UMin, _ => ccx.sess().fatal("unknown atomic operation") }; diff --git a/src/librustc/middle/trans/type_.rs b/src/librustc/middle/trans/type_.rs index 10ee8f9ffc7ee..573965108ad94 100644 --- a/src/librustc/middle/trans/type_.rs +++ b/src/librustc/middle/trans/type_.rs @@ -308,6 +308,7 @@ impl Type { } } + /* Memory-managed object interface to type handles. */ pub struct TypeNames { @@ -330,7 +331,7 @@ impl TypeNames { self.named_types.borrow().find_equiv(&s).map(|x| Type::from_ref(*x)) } - pub fn type_to_str(&self, ty: Type) -> String { + pub fn type_to_string(&self, ty: Type) -> String { unsafe { let s = llvm::LLVMTypeToString(ty.to_ref()); let ret = from_c_str(s); @@ -340,11 +341,11 @@ impl TypeNames { } pub fn types_to_str(&self, tys: &[Type]) -> String { - let strs: Vec = tys.iter().map(|t| self.type_to_str(*t)).collect(); + let strs: Vec = tys.iter().map(|t| self.type_to_string(*t)).collect(); format!("[{}]", strs.connect(",")) } - pub fn val_to_str(&self, val: ValueRef) -> String { + pub fn val_to_string(&self, val: ValueRef) -> String { unsafe { let s = llvm::LLVMValueToString(val); let ret = from_c_str(s); @@ -353,4 +354,3 @@ impl TypeNames { } } } - diff --git a/src/librustc_back/rpath.rs b/src/librustc_back/rpath.rs index 6a133d8619abc..e298e1dbfe94a 100644 --- a/src/librustc_back/rpath.rs +++ b/src/librustc_back/rpath.rs @@ -230,7 +230,7 @@ mod test { used_crates: Vec::new(), out_filename: Path::new("bin/rustc"), get_install_prefix_lib_path: || fail!(), - realpath: |p| p.clone() + realpath: |p| Ok(p.clone()) }; let res = get_rpath_relative_to_output(config, &Path::new("lib/libstd.so")); assert_eq!(res.as_slice(), "@loader_path/../lib"); diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 3d0c5a821709f..9ee8fa98c7499 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -1869,52 +1869,6 @@ pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) { } } -/* Memory-managed object interface to type handles. */ - -pub struct TypeNames { - named_types: RefCell>, -} - -impl TypeNames { - pub fn new() -> TypeNames { - TypeNames { - named_types: RefCell::new(HashMap::new()) - } - } - - pub fn associate_type(&self, s: &str, t: &Type) { - assert!(self.named_types.borrow_mut().insert(s.to_string(), - t.to_ref())); - } - - pub fn find_type(&self, s: &str) -> Option { - self.named_types.borrow().find_equiv(&s).map(|x| Type::from_ref(*x)) - } - - pub fn type_to_string(&self, ty: Type) -> String { - unsafe { - let s = llvm::LLVMTypeToString(ty.to_ref()); - let ret = from_c_str(s); - free(s as *mut c_void); - ret.to_string() - } - } - - pub fn types_to_str(&self, tys: &[Type]) -> String { - let strs: Vec = tys.iter().map(|t| self.type_to_string(*t)).collect(); - format!("[{}]", strs.connect(",")) - } - - pub fn val_to_string(&self, val: ValueRef) -> String { - unsafe { - let s = llvm::LLVMValueToString(val); - let ret = from_c_str(s); - free(s as *mut c_void); - ret.to_string() - } - } -} - /* Memory-managed interface to target data. */ pub struct TargetData {