Skip to content

Commit 06121f9

Browse files
committed
---
yaml --- r: 710 b: refs/heads/master c: 04a55df h: refs/heads/master v: v3
1 parent 5793954 commit 06121f9

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 4d172833710f580c777cb5c1938a8991cc38cd08
2+
refs/heads/master: 04a55df54bb389abf95c0639bd6246f06cd6c38f

trunk/src/comp/driver/rustc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main(vec[str] args) {
1818
auto p = parser.new_parser(sess, filename);
1919
log "opened file: " + filename;
2020
auto crate = parser.parse_crate(p);
21-
trans.translate_crate(sess, crate);
21+
trans.trans_crate(sess, crate);
2222
}
2323
i += 1;
2424
}

trunk/src/comp/lib/llvm.rs

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ type LongLong = i64;
2525
type Long = i32;
2626
type Bool = int;
2727

28+
fn True() -> Bool { ret 1; }
29+
fn False() -> Bool { ret 0; }
30+
31+
2832
native mod llvm = llvm_lib {
2933

3034
type ModuleRef;

trunk/src/comp/me/trans.rs

+58-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,74 @@
11
import std._str;
2+
import std._vec;
3+
import std._str.rustrt.sbuf;
4+
import std._vec.rustrt.vbuf;
25

36
import fe.ast;
47
import driver.session;
58

69
import lib.llvm.llvm;
710
import lib.llvm.builder;
11+
import lib.llvm.llvm.ModuleRef;
12+
import lib.llvm.llvm.ValueRef;
13+
import lib.llvm.llvm.TypeRef;
14+
import lib.llvm.llvm.BuilderRef;
15+
import lib.llvm.llvm.BasicBlockRef;
816

17+
import lib.llvm.False;
18+
import lib.llvm.True;
919

10-
fn translate_crate(session.session sess, ast.crate crate) {
20+
fn T_nil() -> TypeRef {
21+
ret llvm.LLVMVoidType();
22+
}
23+
24+
fn T_int() -> TypeRef {
25+
ret llvm.LLVMInt32Type();
26+
}
27+
28+
fn T_fn(vec[TypeRef] inputs, TypeRef output) -> TypeRef {
29+
ret llvm.LLVMFunctionType(output,
30+
_vec.buf[TypeRef](inputs),
31+
_vec.len[TypeRef](inputs),
32+
False());
33+
}
34+
35+
fn trans_fn(ModuleRef llmod, str name, &ast._fn f) {
36+
let vec[TypeRef] args = vec();
37+
let TypeRef llty = T_fn(args, T_nil());
38+
let ValueRef llfn =
39+
llvm.LLVMAddFunction(llmod, _str.buf(name), llty);
40+
}
41+
42+
fn trans_block(ast.block b, ValueRef llfn) {
43+
let BasicBlockRef llbb =
44+
llvm.LLVMAppendBasicBlock(llfn, 0 as sbuf);
45+
let BuilderRef llbuild = llvm.LLVMCreateBuilder();
46+
llvm.LLVMPositionBuilderAtEnd(llbuild, llbb);
47+
auto b = builder(llbuild);
48+
}
49+
50+
fn trans_mod_item(ModuleRef llmod, str name, &ast.item item) {
51+
alt (item) {
52+
case (ast.item_fn(?f)) {
53+
trans_fn(llmod, name, *f);
54+
}
55+
case (ast.item_mod(?m)) {
56+
trans_mod(llmod, name, *m);
57+
}
58+
}
59+
}
60+
61+
fn trans_mod(ModuleRef llmod, str name, &ast._mod m) {
62+
for each (tup(str, ast.item) pair in m.items()) {
63+
trans_mod_item(llmod, name + "." + pair._0, pair._1);
64+
}
65+
}
66+
67+
fn trans_crate(session.session sess, ast.crate crate) {
1168
auto llmod =
1269
llvm.LLVMModuleCreateWithNameInContext(_str.buf("rust_out"),
1370
llvm.LLVMGetGlobalContext());
1471

15-
auto b = builder(llvm.LLVMCreateBuilder());
1672

1773
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf("rust_out.bc"));
1874
llvm.LLVMDisposeModule(llmod);

0 commit comments

Comments
 (0)