@@ -2,13 +2,15 @@ import std._str;
2
2
import std. _vec ;
3
3
import std. _str . rustrt . sbuf ;
4
4
import std. _vec . rustrt . vbuf ;
5
+ import std. map . hashmap ;
5
6
6
7
import front. ast ;
7
8
import driver. session ;
8
9
import back. x86 ;
9
10
import back. abi ;
10
11
11
12
import util. common . istr ;
13
+ import util. common . new_str_hash ;
12
14
13
15
import lib. llvm . llvm ;
14
16
import lib. llvm . builder ;
@@ -27,6 +29,7 @@ type glue_fns = rec(ValueRef activate_glue,
27
29
28
30
type trans_ctxt = rec ( session . session sess,
29
31
ModuleRef llmod,
32
+ hashmap[ str, ValueRef ] upcalls ,
30
33
@glue_fns glues ,
31
34
str path ) ;
32
35
@@ -88,10 +91,36 @@ fn decl_upcall(ModuleRef llmod, uint _n) -> ValueRef {
88
91
ret decl_cdecl_fn ( llmod, s, args, T_int ( ) ) ;
89
92
}
90
93
91
-
92
94
type terminator = fn ( & trans_ctxt cx, builder b) ;
93
95
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
+
94
108
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
+ }
95
124
}
96
125
97
126
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) {
160
189
_vec. init_fn [ ValueRef ] ( bind decl_upcall ( llmod, _) ,
161
190
abi. n_upcall_glues as uint ) ) ;
162
191
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
+
164
198
trans_mod ( cx, crate . module) ;
165
199
166
200
llvm. LLVMWriteBitcodeToFile ( llmod, _str. buf ( "rust_out.bc" ) ) ;
0 commit comments