Skip to content

Commit 5539349

Browse files
committed
rustc: Move ArchiveRO to rustc_llvm
It is a wrapper around LLVM.
1 parent 7f6a66f commit 5539349

File tree

5 files changed

+74
-57
lines changed

5 files changed

+74
-57
lines changed

src/librustc/back/archive.rs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@
1010

1111
//! A helper class for dealing with static archives
1212
13-
use llvm::{ArchiveRef, llvm};
14-
15-
use libc;
1613
use std::io::process::{Command, ProcessOutput};
1714
use std::io::{fs, TempDir};
1815
use std::io;
19-
use std::mem;
2016
use std::os;
21-
use std::raw;
2217
use std::str;
2318
use syntax::abi;
2419
use ErrorHandler = syntax::diagnostic::Handler;
@@ -41,10 +36,6 @@ pub struct Archive<'a> {
4136
maybe_ar_prog: Option<String>
4237
}
4338

44-
pub struct ArchiveRO {
45-
ptr: ArchiveRef,
46-
}
47-
4839
fn run_ar(handler: &ErrorHandler, maybe_ar_prog: &Option<String>,
4940
args: &str, cwd: Option<&Path>,
5041
paths: &[&Path]) -> ProcessOutput {
@@ -238,49 +229,3 @@ impl<'a> Archive<'a> {
238229
}
239230
}
240231

241-
impl ArchiveRO {
242-
/// Opens a static archive for read-only purposes. This is more optimized
243-
/// than the `open` method because it uses LLVM's internal `Archive` class
244-
/// rather than shelling out to `ar` for everything.
245-
///
246-
/// If this archive is used with a mutable method, then an error will be
247-
/// raised.
248-
pub fn open(dst: &Path) -> Option<ArchiveRO> {
249-
unsafe {
250-
let ar = dst.with_c_str(|dst| {
251-
llvm::LLVMRustOpenArchive(dst)
252-
});
253-
if ar.is_null() {
254-
None
255-
} else {
256-
Some(ArchiveRO { ptr: ar })
257-
}
258-
}
259-
}
260-
261-
/// Reads a file in the archive
262-
pub fn read<'a>(&'a self, file: &str) -> Option<&'a [u8]> {
263-
unsafe {
264-
let mut size = 0 as libc::size_t;
265-
let ptr = file.with_c_str(|file| {
266-
llvm::LLVMRustArchiveReadSection(self.ptr, file, &mut size)
267-
});
268-
if ptr.is_null() {
269-
None
270-
} else {
271-
Some(mem::transmute(raw::Slice {
272-
data: ptr,
273-
len: size as uint,
274-
}))
275-
}
276-
}
277-
}
278-
}
279-
280-
impl Drop for ArchiveRO {
281-
fn drop(&mut self) {
282-
unsafe {
283-
llvm::LLVMRustDestroyArchive(self.ptr);
284-
}
285-
}
286-
}

src/librustc/back/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::archive::ArchiveRO;
1211
use super::link;
1312
use driver::session;
1413
use driver::config;
14+
use llvm::archive_ro::ArchiveRO;
1515
use llvm::{ModuleRef, TargetMachineRef, llvm, True, False};
1616
use metadata::cstore;
1717
use util::common::time;

src/librustc/metadata/loader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,11 @@
212212
//! no means all of the necessary details. Take a look at the rest of
213213
//! metadata::loader or metadata::creader for all the juicy details!
214214
215-
use back::archive::{ArchiveRO, METADATA_FILENAME};
215+
use back::archive::{METADATA_FILENAME};
216216
use back::svh::Svh;
217217
use driver::session::Session;
218218
use lib::llvm::{False, llvm, ObjectFile, mk_section_iter};
219+
use lib::llvm::archive_ro::ArchiveRO;
219220
use metadata::cstore::{MetadataBlob, MetadataVec, MetadataArchive};
220221
use metadata::decoder;
221222
use metadata::encoder;

src/librustc_llvm/archive_ro.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! A wrapper around LLVM's archive (.a) code
12+
13+
use libc;
14+
use ArchiveRef;
15+
use llvm;
16+
17+
use std::raw;
18+
use std::mem;
19+
20+
pub struct ArchiveRO {
21+
ptr: ArchiveRef,
22+
}
23+
24+
impl ArchiveRO {
25+
/// Opens a static archive for read-only purposes. This is more optimized
26+
/// than the `open` method because it uses LLVM's internal `Archive` class
27+
/// rather than shelling out to `ar` for everything.
28+
///
29+
/// If this archive is used with a mutable method, then an error will be
30+
/// raised.
31+
pub fn open(dst: &Path) -> Option<ArchiveRO> {
32+
unsafe {
33+
let ar = dst.with_c_str(|dst| {
34+
llvm::LLVMRustOpenArchive(dst)
35+
});
36+
if ar.is_null() {
37+
None
38+
} else {
39+
Some(ArchiveRO { ptr: ar })
40+
}
41+
}
42+
}
43+
44+
/// Reads a file in the archive
45+
pub fn read<'a>(&'a self, file: &str) -> Option<&'a [u8]> {
46+
unsafe {
47+
let mut size = 0 as libc::size_t;
48+
let ptr = file.with_c_str(|file| {
49+
llvm::LLVMRustArchiveReadSection(self.ptr, file, &mut size)
50+
});
51+
if ptr.is_null() {
52+
None
53+
} else {
54+
Some(mem::transmute(raw::Slice {
55+
data: ptr,
56+
len: size as uint,
57+
}))
58+
}
59+
}
60+
}
61+
}
62+
63+
impl Drop for ArchiveRO {
64+
fn drop(&mut self) {
65+
unsafe {
66+
llvm::LLVMRustDestroyArchive(self.ptr);
67+
}
68+
}
69+
}

src/librustc_llvm/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ extern crate libc;
3232
use std::c_str::ToCStr;
3333
use libc::{c_uint, c_ushort, uint64_t, c_int, size_t};
3434

35+
pub mod archive_ro;
36+
3537
pub type Opcode = u32;
3638
pub type Bool = c_uint;
3739

0 commit comments

Comments
 (0)