]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Move ArchiveRO to rustc_llvm
authorBrian Anderson <banderson@mozilla.com>
Mon, 7 Jul 2014 04:43:22 +0000 (21:43 -0700)
committerBrian Anderson <banderson@mozilla.com>
Mon, 14 Jul 2014 19:27:07 +0000 (12:27 -0700)
It is a wrapper around LLVM.

src/librustc/back/archive.rs
src/librustc/back/lto.rs
src/librustc/metadata/loader.rs
src/librustc_llvm/archive_ro.rs [new file with mode: 0644]
src/librustc_llvm/lib.rs

index ac457f208dd05b4720a37d42f4b40bdb1e057180..c4a9d9c80ef1284ccf197a8723cace79e52ba43b 100644 (file)
 
 //! 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 @@ fn find_library(&self, name: &str) -> Path {
     }
 }
 
-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);
-        }
-    }
-}
index cf163cdbb637cc70bda7321a6f3f52646e256c39..6fc60b657d31edbee728a7828258840722cecb77 100644 (file)
@@ -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;
index 1b2349a271ed1a6ed6b776b597d83af09388b08a..1877bd1260e517d611ce2930a41b11be52f62c5b 100644 (file)
 //! 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 (file)
index 0000000..0b0577f
--- /dev/null
@@ -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);
+        }
+    }
+}
index 121e8882f1ae18040324be652422439ec0125cbe..47e642345f8d40bb4080de54edb655671e3d2ea4 100644 (file)
@@ -32,6 +32,8 @@
 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;