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::str;
pub struct ArchiveRO { ptr: ArchiveRef }
pub struct ArchiveRO {
ptr: ArchiveRef,
}
pub struct Iter<'a> {
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 {
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() {
::last_error().map(Err)
} 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() {
None
} else {
let name = slice::from_raw_parts(name_ptr as *const u8,
name_len as usize);
let name = slice::from_raw_parts(name_ptr as *const u8, name_len as usize);
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> {
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");
let target = env::var("TARGET").unwrap();
let llvm_config = env::var_os("LLVM_CONFIG").map(PathBuf::from)
.unwrap_or_else(|| {
match env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
Some(dir) => {
let to_test = dir.parent().unwrap().parent().unwrap()
.join(&target).join("llvm/bin/llvm-config");
if Command::new(&to_test).output().is_ok() {
return to_test
}
}
None => {}
}
PathBuf::from("llvm-config")
});
let llvm_config = env::var_os("LLVM_CONFIG")
.map(PathBuf::from)
.unwrap_or_else(|| {
match env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
Some(dir) => {
let to_test = dir.parent()
.unwrap()
.parent()
.unwrap()
.join(&target)
.join("llvm/bin/llvm-config");
if Command::new(&to_test).output().is_ok() {
return to_test;
}
}
None => {}
}
PathBuf::from("llvm-config")
});
println!("cargo:rerun-if-changed={}", llvm_config.display());
@ -63,20 +68,22 @@ fn main() {
let host = env::var("HOST").unwrap();
let is_crossed = target != host;
let optional_components = ["x86", "arm", "aarch64", "mips", "powerpc",
"pnacl"];
let optional_components = ["x86", "arm", "aarch64", "mips", "powerpc", "pnacl"];
// FIXME: surely we don't need all these components, right? Stuff like mcjit
// or interpreter the compiler itself never uses.
let required_components = &["ipo", "bitreader", "bitwriter", "linker",
"asmparser", "mcjit", "interpreter",
let required_components = &["ipo",
"bitreader",
"bitwriter",
"linker",
"asmparser",
"mcjit",
"interpreter",
"instrumentation"];
let components = output(Command::new(&llvm_config).arg("--components"));
let mut components = components.split_whitespace().collect::<Vec<_>>();
components.retain(|c| {
optional_components.contains(c) || required_components.contains(c)
});
components.retain(|c| optional_components.contains(c) || required_components.contains(c));
for component in required_components {
if !components.contains(component) {
@ -96,7 +103,7 @@ fn main() {
for flag in cxxflags.split_whitespace() {
// Ignore flags like `-m64` when we're doing a cross build
if is_crossed && flag.starts_with("-m") {
continue
continue;
}
cfg.flag(flag);
}
@ -131,7 +138,7 @@ fn main() {
} else if lib.starts_with("-") {
&lib[1..]
} else {
continue
continue;
};
// 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
// libedit which we don't want
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);
}

View file

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