diff options
| author | Brian Anderson <banderson@mozilla.com> | 2014-07-06 21:43:22 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2014-07-14 12:27:07 -0700 |
| commit | 55393493e1b61aaf1b91ab6bbce442d857d7b42d (patch) | |
| tree | 2b3462f7961645ff99a66513f549b4be227e20b5 | |
| parent | 7f6a66f77ef362059328524d54b6b987322d2c36 (diff) | |
| download | rust-55393493e1b61aaf1b91ab6bbce442d857d7b42d.tar.gz rust-55393493e1b61aaf1b91ab6bbce442d857d7b42d.zip | |
rustc: Move ArchiveRO to rustc_llvm
It is a wrapper around LLVM.
| -rw-r--r-- | src/librustc/back/archive.rs | 55 | ||||
| -rw-r--r-- | src/librustc/back/lto.rs | 2 | ||||
| -rw-r--r-- | src/librustc/metadata/loader.rs | 3 | ||||
| -rw-r--r-- | src/librustc_llvm/archive_ro.rs | 69 | ||||
| -rw-r--r-- | src/librustc_llvm/lib.rs | 2 |
5 files changed, 74 insertions, 57 deletions
diff --git a/src/librustc/back/archive.rs b/src/librustc/back/archive.rs index ac457f208dd..c4a9d9c80ef 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<String> } -pub struct ArchiveRO { - ptr: ArchiveRef, -} - fn run_ar(handler: &ErrorHandler, maybe_ar_prog: &Option<String>, 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<ArchiveRO> { - 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 cf163cdbb63..6fc60b657d3 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 1b2349a271e..1877bd1260e 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 00000000000..0b0577f7e8c --- /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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<ArchiveRO> { + 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 121e8882f1a..47e642345f8 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; |
