2011-06-15 13:19:50 -05:00
|
|
|
|
2011-05-17 13:41:41 -05:00
|
|
|
import std::str;
|
2011-05-12 10:24:54 -05:00
|
|
|
import middle::trans;
|
2011-06-27 17:20:17 -05:00
|
|
|
import front::ast::crate;
|
2011-05-12 10:24:54 -05:00
|
|
|
import back::x86;
|
|
|
|
import lib::llvm::llvm;
|
|
|
|
import lib::llvm::llvm::ValueRef;
|
|
|
|
import lib::llvm::False;
|
2011-03-11 17:35:20 -06:00
|
|
|
|
2011-06-27 16:00:04 -05:00
|
|
|
export write_metadata;
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
// Returns a Plain Old LLVM String:
|
2011-05-09 18:09:00 -05:00
|
|
|
fn C_postr(&str s) -> ValueRef {
|
2011-05-17 13:41:41 -05:00
|
|
|
ret llvm::LLVMConstString(str::buf(s), str::byte_len(s), False);
|
2011-03-11 17:35:20 -06:00
|
|
|
}
|
|
|
|
|
2011-06-19 15:41:21 -05:00
|
|
|
fn write_metadata(&@trans::crate_ctxt cx, &@crate crate) {
|
2011-06-15 13:19:50 -05:00
|
|
|
if (!cx.sess.get_opts().shared) { ret; }
|
2011-06-27 17:20:17 -05:00
|
|
|
auto llmeta = C_postr(encoder::encode_metadata(cx, crate));
|
2011-05-16 20:21:22 -05:00
|
|
|
auto llconst = trans::C_struct([llmeta]);
|
2011-06-15 13:19:50 -05:00
|
|
|
auto llglobal =
|
|
|
|
llvm::LLVMAddGlobal(cx.llmod, trans::val_ty(llconst),
|
|
|
|
str::buf("rust_metadata"));
|
2011-05-12 10:24:54 -05:00
|
|
|
llvm::LLVMSetInitializer(llglobal, llconst);
|
2011-05-17 13:41:41 -05:00
|
|
|
llvm::LLVMSetSection(llglobal, str::buf(x86::get_meta_sect_name()));
|
2011-03-11 17:35:20 -06:00
|
|
|
}
|
2011-06-27 17:20:17 -05:00
|
|
|
|
2011-03-26 19:35:51 -05:00
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|
|
|
|
//
|