Skip to content

Commit dcbce68

Browse files
committed
---
yaml --- r: 1613 b: refs/heads/master c: 9b3db0e h: refs/heads/master i: 1611: 66e34d6 v: v3
1 parent 5973096 commit dcbce68

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 74d891517be8f6299b0626c26400dd54dd1aac6c
2+
refs/heads/master: 9b3db0ed445de1b513742770420ba4b60a025219

trunk/src/comp/back/x86.rs

+10
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ fn get_module_asm() -> str {
273273
ret _str.connect(glues, "\n\n");
274274
}
275275

276+
fn get_meta_sect_name() -> str {
277+
if (_str.eq(target_os(), "macos")) {
278+
ret "__DATA,__note.rustc";
279+
}
280+
if (_str.eq(target_os(), "win32")) {
281+
ret ".note.rustc";
282+
}
283+
ret ".note.rustc";
284+
}
285+
276286
fn get_data_layout() -> str {
277287
if (_str.eq(target_os(), "macos")) {
278288
ret "e-p:32:32-f64:32:64-i64:32:64-f80:128:128-n8:16:32";

trunk/src/comp/middle/metadata.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import std._str;
2+
import front.ast;
3+
import middle.trans;
4+
import back.x86;
5+
6+
import lib.llvm.llvm;
7+
import lib.llvm.llvm.ValueRef;
8+
import lib.llvm.False;
9+
10+
// Returns a Plain Old LLVM String.
11+
fn C_postr(str s) -> ValueRef {
12+
ret llvm.LLVMConstString(_str.buf(s), _str.byte_len(s), False);
13+
}
14+
15+
fn collect_meta_directives(@trans.crate_ctxt cx, @ast.crate crate)
16+
-> ValueRef {
17+
ret C_postr("Hello world!"); // TODO
18+
}
19+
20+
fn write_metadata(@trans.crate_ctxt cx, @ast.crate crate) {
21+
auto llmeta = collect_meta_directives(cx, crate);
22+
23+
auto llconst = trans.C_struct(vec(llmeta));
24+
auto llglobal = llvm.LLVMAddGlobal(cx.llmod, trans.val_ty(llconst),
25+
_str.buf("rust_metadata"));
26+
llvm.LLVMSetInitializer(llglobal, llconst);
27+
llvm.LLVMSetSection(llglobal, _str.buf(x86.get_meta_sect_name()));
28+
}
29+

trunk/src/comp/middle/trans.rs

+3
Original file line numberDiff line numberDiff line change
@@ -6192,6 +6192,9 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
61926192
trans_main_fn(cx, cx.crate_ptr);
61936193
}
61946194

6195+
// Translate the metadata.
6196+
middle.metadata.write_metadata(cx, crate);
6197+
61956198
check_module(llmod);
61966199

61976200
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output));

trunk/src/comp/rustc.rc

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mod front {
1414

1515
mod middle {
1616
mod fold;
17+
mod metadata;
1718
mod resolve;
1819
mod trans;
1920
mod ty;
@@ -40,6 +41,7 @@ mod util {
4041
}
4142

4243
auth driver.rustc.main = impure;
44+
auth middle.metadata = unsafe;
4345
auth middle.trans = unsafe;
4446
auth middle.trans.copy_args_to_allocas = impure;
4547
auth middle.trans.trans_block = impure;

0 commit comments

Comments
 (0)