Skip to content

run rustfmt on librustc_llvm folder #33942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/librustc_llvm/archive_ro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
}
}
}
Expand All @@ -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,
}))
}
}
}
Expand All @@ -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())
}
}
Expand All @@ -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);
}
}
}
61 changes: 36 additions & 25 deletions src/librustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand All @@ -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);
}

Expand Down
49 changes: 26 additions & 23 deletions src/librustc_llvm/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand All @@ -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,
Expand All @@ -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
}
Expand All @@ -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),
}
}
}