run rustfmt on librustc_llvm folder

This commit is contained in:
Srinivas Reddy Thatiparthy 2016-05-29 14:57:34 +05:30
parent 397cfaec0c
commit 593e1567ca
3 changed files with 83 additions and 56 deletions

View file

@ -18,7 +18,9 @@ use std::path::Path;
use std::slice; use std::slice;
use std::str; use std::str;
pub struct ArchiveRO { ptr: ArchiveRef } pub struct ArchiveRO {
ptr: ArchiveRef,
}
pub struct Iter<'a> { pub struct Iter<'a> {
archive: &'a ArchiveRO, archive: &'a ArchiveRO,
@ -61,11 +63,16 @@ impl ArchiveRO {
} }
} }
pub fn raw(&self) -> ArchiveRef { self.ptr } pub fn raw(&self) -> ArchiveRef {
self.ptr
}
pub fn iter(&self) -> Iter { pub fn iter(&self) -> Iter {
unsafe { unsafe {
Iter { ptr: ::LLVMRustArchiveIteratorNew(self.ptr), archive: self } Iter {
ptr: ::LLVMRustArchiveIteratorNew(self.ptr),
archive: self,
}
} }
} }
} }
@ -86,7 +93,10 @@ impl<'a> Iterator for Iter<'a> {
if ptr.is_null() { if ptr.is_null() {
::last_error().map(Err) ::last_error().map(Err)
} else { } else {
Some(Ok(Child { ptr: ptr, _data: marker::PhantomData })) Some(Ok(Child {
ptr: ptr,
_data: marker::PhantomData,
}))
} }
} }
} }
@ -107,8 +117,7 @@ impl<'a> Child<'a> {
if name_ptr.is_null() { if name_ptr.is_null() {
None None
} else { } else {
let name = slice::from_raw_parts(name_ptr as *const u8, let name = slice::from_raw_parts(name_ptr as *const u8, name_len as usize);
name_len as usize);
str::from_utf8(name).ok().map(|s| s.trim()) str::from_utf8(name).ok().map(|s| s.trim())
} }
} }
@ -125,11 +134,15 @@ impl<'a> Child<'a> {
} }
} }
pub fn raw(&self) -> ::ArchiveChildRef { self.ptr } pub fn raw(&self) -> ::ArchiveChildRef {
self.ptr
}
} }
impl<'a> Drop for Child<'a> { impl<'a> Drop for Child<'a> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ::LLVMRustArchiveChildFree(self.ptr); } unsafe {
::LLVMRustArchiveChildFree(self.ptr);
}
} }
} }

View file

@ -21,20 +21,25 @@ fn main() {
println!("cargo:rustc-cfg=cargobuild"); println!("cargo:rustc-cfg=cargobuild");
let target = env::var("TARGET").unwrap(); let target = env::var("TARGET").unwrap();
let llvm_config = env::var_os("LLVM_CONFIG").map(PathBuf::from) let llvm_config = env::var_os("LLVM_CONFIG")
.unwrap_or_else(|| { .map(PathBuf::from)
match env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) { .unwrap_or_else(|| {
Some(dir) => { match env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
let to_test = dir.parent().unwrap().parent().unwrap() Some(dir) => {
.join(&target).join("llvm/bin/llvm-config"); let to_test = dir.parent()
if Command::new(&to_test).output().is_ok() { .unwrap()
return to_test .parent()
} .unwrap()
} .join(&target)
None => {} .join("llvm/bin/llvm-config");
} if Command::new(&to_test).output().is_ok() {
PathBuf::from("llvm-config") return to_test;
}); }
}
None => {}
}
PathBuf::from("llvm-config")
});
println!("cargo:rerun-if-changed={}", llvm_config.display()); println!("cargo:rerun-if-changed={}", llvm_config.display());
@ -63,20 +68,22 @@ fn main() {
let host = env::var("HOST").unwrap(); let host = env::var("HOST").unwrap();
let is_crossed = target != host; let is_crossed = target != host;
let optional_components = ["x86", "arm", "aarch64", "mips", "powerpc", let optional_components = ["x86", "arm", "aarch64", "mips", "powerpc", "pnacl"];
"pnacl"];
// FIXME: surely we don't need all these components, right? Stuff like mcjit // FIXME: surely we don't need all these components, right? Stuff like mcjit
// or interpreter the compiler itself never uses. // or interpreter the compiler itself never uses.
let required_components = &["ipo", "bitreader", "bitwriter", "linker", let required_components = &["ipo",
"asmparser", "mcjit", "interpreter", "bitreader",
"bitwriter",
"linker",
"asmparser",
"mcjit",
"interpreter",
"instrumentation"]; "instrumentation"];
let components = output(Command::new(&llvm_config).arg("--components")); let components = output(Command::new(&llvm_config).arg("--components"));
let mut components = components.split_whitespace().collect::<Vec<_>>(); let mut components = components.split_whitespace().collect::<Vec<_>>();
components.retain(|c| { components.retain(|c| optional_components.contains(c) || required_components.contains(c));
optional_components.contains(c) || required_components.contains(c)
});
for component in required_components { for component in required_components {
if !components.contains(component) { if !components.contains(component) {
@ -96,7 +103,7 @@ fn main() {
for flag in cxxflags.split_whitespace() { for flag in cxxflags.split_whitespace() {
// Ignore flags like `-m64` when we're doing a cross build // Ignore flags like `-m64` when we're doing a cross build
if is_crossed && flag.starts_with("-m") { if is_crossed && flag.starts_with("-m") {
continue continue;
} }
cfg.flag(flag); cfg.flag(flag);
} }
@ -131,7 +138,7 @@ fn main() {
} else if lib.starts_with("-") { } else if lib.starts_with("-") {
&lib[1..] &lib[1..]
} else { } else {
continue continue;
}; };
// Don't need or want this library, but LLVM's CMake build system // Don't need or want this library, but LLVM's CMake build system
@ -140,10 +147,14 @@ fn main() {
// library and it otherwise may just pull in extra dependencies on // library and it otherwise may just pull in extra dependencies on
// libedit which we don't want // libedit which we don't want
if name == "LLVMLineEditor" { if name == "LLVMLineEditor" {
continue continue;
} }
let kind = if name.starts_with("LLVM") {"static"} else {"dylib"}; let kind = if name.starts_with("LLVM") {
"static"
} else {
"dylib"
};
println!("cargo:rustc-link-lib={}={}", kind, name); println!("cargo:rustc-link-lib={}={}", kind, name);
} }

View file

@ -16,7 +16,7 @@ pub use self::Diagnostic::*;
use libc::{c_char, c_uint}; use libc::{c_char, c_uint};
use std::ptr; use std::ptr;
use {ValueRef, TwineRef, DebugLocRef, DiagnosticInfoRef}; use {DebugLocRef, DiagnosticInfoRef, TwineRef, ValueRef};
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum OptimizationDiagnosticKind { pub enum OptimizationDiagnosticKind {
@ -46,8 +46,9 @@ pub struct OptimizationDiagnostic {
} }
impl OptimizationDiagnostic { impl OptimizationDiagnostic {
unsafe fn unpack(kind: OptimizationDiagnosticKind, di: DiagnosticInfoRef) unsafe fn unpack(kind: OptimizationDiagnosticKind,
-> OptimizationDiagnostic { di: DiagnosticInfoRef)
-> OptimizationDiagnostic {
let mut opt = OptimizationDiagnostic { let mut opt = OptimizationDiagnostic {
kind: kind, kind: kind,
@ -58,10 +59,10 @@ impl OptimizationDiagnostic {
}; };
super::LLVMUnpackOptimizationDiagnostic(di, super::LLVMUnpackOptimizationDiagnostic(di,
&mut opt.pass_name, &mut opt.pass_name,
&mut opt.function, &mut opt.function,
&mut opt.debug_loc, &mut opt.debug_loc,
&mut opt.message); &mut opt.message);
opt opt
} }
@ -75,8 +76,7 @@ pub struct InlineAsmDiagnostic {
} }
impl InlineAsmDiagnostic { impl InlineAsmDiagnostic {
unsafe fn unpack(di: DiagnosticInfoRef) unsafe fn unpack(di: DiagnosticInfoRef) -> InlineAsmDiagnostic {
-> InlineAsmDiagnostic {
let mut opt = InlineAsmDiagnostic { let mut opt = InlineAsmDiagnostic {
cookie: 0, cookie: 0,
@ -85,9 +85,9 @@ impl InlineAsmDiagnostic {
}; };
super::LLVMUnpackInlineAsmDiagnostic(di, super::LLVMUnpackInlineAsmDiagnostic(di,
&mut opt.cookie, &mut opt.cookie,
&mut opt.message, &mut opt.message,
&mut opt.instruction); &mut opt.instruction);
opt opt
} }
@ -106,22 +106,25 @@ impl Diagnostic {
let kind = super::LLVMGetDiagInfoKind(di); let kind = super::LLVMGetDiagInfoKind(di);
match kind { match kind {
super::DK_InlineAsm super::DK_InlineAsm => InlineAsm(InlineAsmDiagnostic::unpack(di)),
=> InlineAsm(InlineAsmDiagnostic::unpack(di)),
super::DK_OptimizationRemark super::DK_OptimizationRemark => {
=> Optimization(OptimizationDiagnostic::unpack(OptimizationRemark, di)), Optimization(OptimizationDiagnostic::unpack(OptimizationRemark, di))
}
super::DK_OptimizationRemarkMissed super::DK_OptimizationRemarkMissed => {
=> Optimization(OptimizationDiagnostic::unpack(OptimizationMissed, di)), Optimization(OptimizationDiagnostic::unpack(OptimizationMissed, di))
}
super::DK_OptimizationRemarkAnalysis super::DK_OptimizationRemarkAnalysis => {
=> Optimization(OptimizationDiagnostic::unpack(OptimizationAnalysis, di)), Optimization(OptimizationDiagnostic::unpack(OptimizationAnalysis, di))
}
super::DK_OptimizationFailure super::DK_OptimizationFailure => {
=> Optimization(OptimizationDiagnostic::unpack(OptimizationFailure, di)), Optimization(OptimizationDiagnostic::unpack(OptimizationFailure, di))
}
_ => UnknownDiagnostic(di) _ => UnknownDiagnostic(di),
} }
} }
} }