Skip to content

Commit ae1ca1f

Browse files
committed
---
yaml --- r: 24216 b: refs/heads/master c: 64de6d6 h: refs/heads/master v: v3
1 parent ed2a6d6 commit ae1ca1f

File tree

7 files changed

+40
-119
lines changed

7 files changed

+40
-119
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: ebe6b2d15c3d007df93601fde99bb06f96c480c1
2+
refs/heads/master: 64de6d638da71f7b3a55d663b194b95f7f06d6c8
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/str.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,10 +1827,10 @@ const tag_six_b: uint = 252u;
18271827
* let i = str::as_bytes("Hello World") { |bytes| vec::len(bytes) };
18281828
* ~~~
18291829
*/
1830-
pure fn as_bytes<T>(s: &const ~str, f: fn(~[u8]) -> T) -> T {
1830+
pure fn as_bytes<T>(s: &const ~str, f: fn((&~[u8])) -> T) -> T {
18311831
unsafe {
18321832
let v: *~[u8] = cast::transmute(copy s);
1833-
f(*v)
1833+
f(&*v)
18341834
}
18351835
}
18361836

@@ -1945,7 +1945,7 @@ fn reserve_at_least(s: &const ~str, n: uint) {
19451945
*/
19461946
pure fn capacity(s: &const ~str) -> uint {
19471947
do as_bytes(s) |buf| {
1948-
let vcap = vec::capacity(buf);
1948+
let vcap = vec::capacity(*buf);
19491949
assert vcap > 0u;
19501950
vcap - 1u
19511951
}
@@ -2037,7 +2037,7 @@ mod raw {
20372037

20382038
/// Form a slice from a *u8 buffer of the given length without copying.
20392039
unsafe fn buf_as_slice<T>(buf: *u8, len: uint,
2040-
f: fn(&&v: &str) -> T) -> T {
2040+
f: fn(v: &str) -> T) -> T {
20412041
let v = (buf, len + 1);
20422042
assert is_utf8(::cast::reinterpret_cast(&v));
20432043
f(::cast::transmute(move v))

trunk/src/rustc/back/link.rs

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -74,44 +74,14 @@ mod jit {
7474
m: ModuleRef,
7575
opt: c_int,
7676
stacks: bool) unsafe {
77-
let manager = llvm::LLVMRustPrepareJIT(rusti::morestack_addr());
78-
79-
// We need to tell JIT where to resolve all linked
80-
// symbols from. The equivalent of -lstd, -lcore, etc.
81-
// By default the JIT will resolve symbols from the std and
82-
// core linked into rustc. We don't want that,
83-
// incase the user wants to use an older std library.
84-
85-
let cstore = sess.cstore;
86-
for cstore::get_used_crate_files(cstore).each |cratepath| {
87-
let path = cratepath.to_str();
88-
89-
debug!("linking: %s", path);
90-
91-
let _: () = str::as_c_str(
92-
path,
93-
|buf_t| {
94-
if !llvm::LLVMRustLoadCrate(manager, buf_t) {
95-
llvm_err(sess, ~"Could not link");
96-
}
97-
debug!("linked: %s", path);
98-
});
99-
}
100-
101-
// The execute function will return a void pointer
102-
// to the _rust_main function. We can do closure
103-
// magic here to turn it straight into a callable rust
104-
// closure. It will also cleanup the memory manager
105-
// for us.
106-
107-
let entry = llvm::LLVMRustExecuteJIT(manager,
108-
pm, m, opt, stacks);
77+
let ptr = llvm::LLVMRustJIT(rusti::morestack_addr(),
78+
pm, m, opt, stacks);
10979

110-
if ptr::is_null(entry) {
80+
if ptr::is_null(ptr) {
11181
llvm_err(sess, ~"Could not JIT");
11282
} else {
11383
let closure = Closure {
114-
code: entry,
84+
code: ptr,
11585
env: ptr::null()
11686
};
11787
let func: fn(~[~str]) = cast::transmute(move closure);

trunk/src/rustc/lib/llvm.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -990,19 +990,15 @@ extern mod llvm {
990990
call. */
991991
fn LLVMRustGetLastError() -> *c_char;
992992

993-
/** Prepare the JIT. Returns a memory manager that can load crates. */
994-
fn LLVMRustPrepareJIT(__morestack: *()) -> *();
995-
996-
/** Load a crate into the memory manager. */
997-
fn LLVMRustLoadCrate(MM: *(),
998-
Filename: *c_char) -> bool;
999-
1000-
/** Execute the JIT engine. */
1001-
fn LLVMRustExecuteJIT(MM: *(),
1002-
PM: PassManagerRef,
1003-
M: ModuleRef,
1004-
OptLevel: c_int,
1005-
EnableSegmentedStacks: bool) -> *();
993+
/** Load a shared library to resolve symbols against. */
994+
fn LLVMRustLoadLibrary(Filename: *c_char) -> bool;
995+
996+
/** Create and execute the JIT engine. */
997+
fn LLVMRustJIT(__morestack: *(),
998+
PM: PassManagerRef,
999+
M: ModuleRef,
1000+
OptLevel: c_int,
1001+
EnableSegmentedStacks: bool) -> *();
10061002

10071003
/** Parses the bitcode in the given memory buffer. */
10081004
fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef;

trunk/src/rustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
11751175
// vec::from_slice(metadata_encoding_version) +
11761176

11771177
(do str::as_bytes(&~"rust\x00\x00\x00\x01") |bytes| {
1178-
vec::slice(bytes, 0, 8)
1178+
vec::slice(*bytes, 0, 8)
11791179
}) + flate::deflate_bytes(wr.buf.check_out(|buf| buf))
11801180
}
11811181

trunk/src/rustllvm/RustWrapper.cpp

Lines changed: 19 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "llvm/Transforms/Scalar.h"
2121
#include "llvm/Transforms/IPO.h"
2222
#include "llvm/ADT/Triple.h"
23-
#include "llvm/ADT/DenseSet.h"
2423
#include "llvm/Assembly/Parser.h"
2524
#include "llvm/Assembly/PrintModulePass.h"
2625
#include "llvm/Support/FormattedStream.h"
@@ -43,6 +42,7 @@
4342
#include "llvm-c/Core.h"
4443
#include "llvm-c/BitReader.h"
4544
#include "llvm-c/Object.h"
45+
#include <cstdlib>
4646

4747
// Used by RustMCJITMemoryManager::getPointerToNamedFunction()
4848
// to get around glibc issues. See the function for more information.
@@ -53,7 +53,6 @@
5353
#endif
5454

5555
using namespace llvm;
56-
using namespace llvm::sys;
5756

5857
static const char *LLVMRustError;
5958

@@ -101,6 +100,18 @@ void LLVMRustInitializeTargets() {
101100
LLVMInitializeX86AsmParser();
102101
}
103102

103+
extern "C" bool
104+
LLVMRustLoadLibrary(const char* file) {
105+
std::string err;
106+
107+
if(llvm::sys::DynamicLibrary::LoadLibraryPermanently(file, &err)) {
108+
LLVMRustError = err.c_str();
109+
return false;
110+
}
111+
112+
return true;
113+
}
114+
104115
// Custom memory manager for MCJITting. It needs special features
105116
// that the generic JIT memory manager doesn't entail. Based on
106117
// code from LLI, change where needed for Rust.
@@ -110,13 +121,10 @@ class RustMCJITMemoryManager : public JITMemoryManager {
110121
SmallVector<sys::MemoryBlock, 16> AllocatedCodeMem;
111122
SmallVector<sys::MemoryBlock, 16> FreeCodeMem;
112123
void* __morestack;
113-
DenseSet<DynamicLibrary*> crates;
114124

115125
RustMCJITMemoryManager(void* sym) : __morestack(sym) { }
116126
~RustMCJITMemoryManager();
117127

118-
bool loadCrate(const char*, std::string*);
119-
120128
virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
121129
unsigned SectionID);
122130

@@ -189,19 +197,6 @@ class RustMCJITMemoryManager : public JITMemoryManager {
189197
}
190198
};
191199

192-
bool RustMCJITMemoryManager::loadCrate(const char* file, std::string* err) {
193-
DynamicLibrary crate = DynamicLibrary::getPermanentLibrary(file,
194-
err);
195-
196-
if(crate.isValid()) {
197-
crates.insert(&crate);
198-
199-
return true;
200-
}
201-
202-
return false;
203-
}
204-
205200
uint8_t *RustMCJITMemoryManager::allocateDataSection(uintptr_t Size,
206201
unsigned Alignment,
207202
unsigned SectionID) {
@@ -281,19 +276,6 @@ void *RustMCJITMemoryManager::getPointerToNamedFunction(const std::string &Name,
281276
if (Name == "__morestack") return &__morestack;
282277

283278
const char *NameStr = Name.c_str();
284-
285-
// Look through loaded crates for symbols.
286-
287-
for (DenseSet<DynamicLibrary*>::iterator I = crates.begin(),
288-
E = crates.end(); I != E; ++I) {
289-
void *Ptr = (*I)->getAddressOfSymbol(NameStr);
290-
291-
if (Ptr) return Ptr;
292-
}
293-
294-
// Fallback to using any symbols LLVM has loaded (generally
295-
// from the main program).
296-
297279
void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr);
298280
if (Ptr) return Ptr;
299281

@@ -311,48 +293,21 @@ RustMCJITMemoryManager::~RustMCJITMemoryManager() {
311293
}
312294

313295
extern "C" void*
314-
LLVMRustPrepareJIT(void* __morestack) {
315-
// An execution engine will take ownership of this later
316-
// and clean it up for us.
317-
318-
return (void*) new RustMCJITMemoryManager(__morestack);
319-
}
320-
321-
extern "C" bool
322-
LLVMRustLoadCrate(void* mem, const char* crate) {
323-
RustMCJITMemoryManager* manager = (RustMCJITMemoryManager*) mem;
324-
std::string Err;
325-
326-
assert(manager);
327-
328-
if(!manager->loadCrate(crate, &Err)) {
329-
LLVMRustError = Err.c_str();
330-
return false;
331-
}
332-
333-
return true;
334-
}
335-
336-
extern "C" void*
337-
LLVMRustExecuteJIT(void* mem,
338-
LLVMPassManagerRef PMR,
339-
LLVMModuleRef M,
340-
CodeGenOpt::Level OptLevel,
341-
bool EnableSegmentedStacks) {
296+
LLVMRustJIT(void* __morestack,
297+
LLVMPassManagerRef PMR,
298+
LLVMModuleRef M,
299+
CodeGenOpt::Level OptLevel,
300+
bool EnableSegmentedStacks) {
342301

343302
InitializeNativeTarget();
344303
InitializeNativeTargetAsmPrinter();
345304

346305
std::string Err;
347306
TargetOptions Options;
348-
Options.JITExceptionHandling = true;
349307
Options.JITEmitDebugInfo = true;
350308
Options.NoFramePointerElim = true;
351309
Options.EnableSegmentedStacks = EnableSegmentedStacks;
352310
PassManager *PM = unwrap<PassManager>(PMR);
353-
RustMCJITMemoryManager* MM = (RustMCJITMemoryManager*) mem;
354-
355-
assert(MM);
356311

357312
PM->add(createBasicAliasAnalysisPass());
358313
PM->add(createInstructionCombiningPass());
@@ -363,6 +318,7 @@ LLVMRustExecuteJIT(void* mem,
363318
PM->add(createPromoteMemoryToRegisterPass());
364319
PM->run(*unwrap(M));
365320

321+
RustMCJITMemoryManager* MM = new RustMCJITMemoryManager(__morestack);
366322
ExecutionEngine* EE = EngineBuilder(unwrap(M))
367323
.setTargetOptions(Options)
368324
.setJITMemoryManager(MM)

trunk/src/rustllvm/rustllvm.def.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ LLVMRustWriteOutputFile
44
LLVMRustGetLastError
55
LLVMRustConstSmallInt
66
LLVMRustConstInt
7-
LLVMRustLoadCrate
8-
LLVMRustPrepareJIT
9-
LLVMRustExecuteJIT
7+
LLVMRustLoadLibrary
8+
LLVMRustJIT
109
LLVMRustParseBitcode
1110
LLVMRustParseAssemblyFile
1211
LLVMRustPrintPassTimings

0 commit comments

Comments
 (0)