Skip to content

Commit 274128c

Browse files
committed
Add trans.get_upcall and skeleton for trans_log.
1 parent 730439c commit 274128c

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/comp/middle/trans.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import std._str;
22
import std._vec;
33
import std._str.rustrt.sbuf;
44
import std._vec.rustrt.vbuf;
5+
import std.map.hashmap;
56

67
import front.ast;
78
import driver.session;
89
import back.x86;
910
import back.abi;
1011

1112
import util.common.istr;
13+
import util.common.new_str_hash;
1214

1315
import lib.llvm.llvm;
1416
import lib.llvm.builder;
@@ -27,6 +29,7 @@ type glue_fns = rec(ValueRef activate_glue,
2729

2830
type trans_ctxt = rec(session.session sess,
2931
ModuleRef llmod,
32+
hashmap[str,ValueRef] upcalls,
3033
@glue_fns glues,
3134
str path);
3235

@@ -88,10 +91,36 @@ fn decl_upcall(ModuleRef llmod, uint _n) -> ValueRef {
8891
ret decl_cdecl_fn(llmod, s, args, T_int());
8992
}
9093

91-
9294
type terminator = fn(&trans_ctxt cx, builder b);
9395

96+
fn get_upcall(&trans_ctxt cx, str name, int n_args) -> ValueRef {
97+
if (cx.upcalls.contains_key(name)) {
98+
ret cx.upcalls.get(name);
99+
}
100+
auto inputs = vec(T_ptr(T_task()));
101+
inputs += _vec.init_elt[TypeRef](T_int(), n_args as uint);
102+
auto output = T_nil();
103+
auto f = decl_cdecl_fn(cx.llmod, name, inputs, output);
104+
cx.upcalls.insert(name, f);
105+
ret f;
106+
}
107+
94108
fn trans_log(&trans_ctxt cx, builder b, &ast.atom a) {
109+
alt (a) {
110+
case (ast.atom_lit(?lit)) {
111+
alt (*lit) {
112+
case (ast.lit_int(?i)) {
113+
cx.sess.unimpl("log int");
114+
}
115+
case (_) {
116+
cx.sess.unimpl("literal variant in trans_log");
117+
}
118+
}
119+
}
120+
case (_) {
121+
cx.sess.unimpl("atom variant in trans_log");
122+
}
123+
}
95124
}
96125

97126
fn trans_stmt(&trans_ctxt cx, builder b, &ast.stmt s, terminator t) {
@@ -160,7 +189,12 @@ fn trans_crate(session.session sess, ast.crate crate) {
160189
_vec.init_fn[ValueRef](bind decl_upcall(llmod, _),
161190
abi.n_upcall_glues as uint));
162191

163-
auto cx = rec(sess=sess, llmod=llmod, glues=glues, path="");
192+
auto cx = rec(sess = sess,
193+
llmod = llmod,
194+
upcalls = new_str_hash[ValueRef](),
195+
glues = glues,
196+
path = "");
197+
164198
trans_mod(cx, crate.module);
165199

166200
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf("rust_out.bc"));

0 commit comments

Comments
 (0)