rustc: Add some stub metadata to each crate

This commit is contained in:
Patrick Walton 2011-03-11 15:35:20 -08:00
parent 74d891517b
commit 9b3db0ed44
4 changed files with 44 additions and 0 deletions

View file

@ -273,6 +273,16 @@ fn get_module_asm() -> str {
ret _str.connect(glues, "\n\n");
}
fn get_meta_sect_name() -> str {
if (_str.eq(target_os(), "macos")) {
ret "__DATA,__note.rustc";
}
if (_str.eq(target_os(), "win32")) {
ret ".note.rustc";
}
ret ".note.rustc";
}
fn get_data_layout() -> str {
if (_str.eq(target_os(), "macos")) {
ret "e-p:32:32-f64:32:64-i64:32:64-f80:128:128-n8:16:32";

View file

@ -0,0 +1,29 @@
import std._str;
import front.ast;
import middle.trans;
import back.x86;
import lib.llvm.llvm;
import lib.llvm.llvm.ValueRef;
import lib.llvm.False;
// Returns a Plain Old LLVM String.
fn C_postr(str s) -> ValueRef {
ret llvm.LLVMConstString(_str.buf(s), _str.byte_len(s), False);
}
fn collect_meta_directives(@trans.crate_ctxt cx, @ast.crate crate)
-> ValueRef {
ret C_postr("Hello world!"); // TODO
}
fn write_metadata(@trans.crate_ctxt cx, @ast.crate crate) {
auto llmeta = collect_meta_directives(cx, crate);
auto llconst = trans.C_struct(vec(llmeta));
auto llglobal = llvm.LLVMAddGlobal(cx.llmod, trans.val_ty(llconst),
_str.buf("rust_metadata"));
llvm.LLVMSetInitializer(llglobal, llconst);
llvm.LLVMSetSection(llglobal, _str.buf(x86.get_meta_sect_name()));
}

View file

@ -6192,6 +6192,9 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
trans_main_fn(cx, cx.crate_ptr);
}
// Translate the metadata.
middle.metadata.write_metadata(cx, crate);
check_module(llmod);
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output));

View file

@ -14,6 +14,7 @@ mod front {
mod middle {
mod fold;
mod metadata;
mod resolve;
mod trans;
mod ty;
@ -40,6 +41,7 @@ mod util {
}
auth driver.rustc.main = impure;
auth middle.metadata = unsafe;
auth middle.trans = unsafe;
auth middle.trans.copy_args_to_allocas = impure;
auth middle.trans.trans_block = impure;