aboutsummaryrefslogtreecommitdiff
path: root/src/comp/middle/metadata.rs
blob: 433d7147024b4f193f483a79c69ad32e0f27d2b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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()));
}