@@ -53,8 +53,8 @@ state obj namegen(mutable int i) {
53
53
type glue_fns = rec ( ValueRef activate_glue ,
54
54
ValueRef yield_glue ,
55
55
ValueRef exit_task_glue ,
56
- vec[ ValueRef ] upcall_glues_rust ,
57
- vec[ ValueRef ] upcall_glues_cdecl ,
56
+ vec[ ValueRef ] native_glues_rust ,
57
+ vec[ ValueRef ] native_glues_cdecl ,
58
58
ValueRef no_op_type_glue ,
59
59
ValueRef memcpy_glue ,
60
60
ValueRef bzero_glue ,
@@ -64,12 +64,31 @@ type tydesc_info = rec(ValueRef tydesc,
64
64
ValueRef take_glue ,
65
65
ValueRef drop_glue ) ;
66
66
67
+ /*
68
+ * A note on nomenclature of linking: "upcall", "extern" and "native".
69
+ *
70
+ * An "extern" is an LLVM symbol we wind up emitting an undefined external
71
+ * reference to. This means "we don't have the thing in this compilation unit,
72
+ * please make sure you link it in at runtime". This could be a reference to
73
+ * C code found in a C library, or rust code found in a rust crate.
74
+ *
75
+ * A "native" is a combination of an extern that references C code, plus a
76
+ * glue-code stub that "looks like" a rust function, emitted here, plus a
77
+ * generic N-ary bit of asm glue (found over in back/x86.rs) that performs a
78
+ * control transfer into C from rust. Natives may be normal C library code.
79
+ *
80
+ * An upcall is a native call generated by the compiler (not corresponding to
81
+ * any user-written call in the code) into librustrt, to perform some helper
82
+ * task such as bringing a task to life, allocating memory, etc.
83
+ *
84
+ */
85
+
67
86
state type crate_ctxt = rec ( session. session sess,
68
87
ModuleRef llmod,
69
88
target_data td,
70
89
type_names tn,
71
90
ValueRef crate_ptr,
72
- hashmap[ str, ValueRef ] upcalls ,
91
+ hashmap[ str, ValueRef ] externs ,
73
92
hashmap[ str, ValueRef ] intrinsics,
74
93
hashmap[ str, ValueRef ] item_names,
75
94
hashmap[ ast. def_id , ValueRef ] item_ids,
@@ -852,14 +871,14 @@ fn decl_glue(ModuleRef llmod, type_names tn, str s) -> ValueRef {
852
871
ret decl_cdecl_fn ( llmod, s, T_fn ( vec ( T_taskptr ( tn) ) , T_void ( ) ) ) ;
853
872
}
854
873
855
- fn decl_upcall_glue ( ModuleRef llmod, type_names tn,
874
+ fn decl_native_glue ( ModuleRef llmod, type_names tn,
856
875
bool pass_task , uint _n) -> ValueRef {
857
876
// It doesn't actually matter what type we come up with here, at the
858
- // moment, as we cast the upcall function pointers to int before passing
859
- // them to the indirect upcall -invocation glue. But eventually we'd like
877
+ // moment, as we cast the native function pointers to int before passing
878
+ // them to the indirect native -invocation glue. But eventually we'd like
860
879
// to call them directly, once we have a calling convention worked out.
861
880
let int n = _n as int ;
862
- let str s = abi. upcall_glue_name ( n, pass_task) ;
881
+ let str s = abi. native_glue_name ( n, pass_task) ;
863
882
let vec[ TypeRef ] args = vec ( T_int ( ) ) ; // callee
864
883
if ( !pass_task) {
865
884
args += vec ( T_int ( ) ) ; // taskptr, will not be passed
@@ -869,42 +888,42 @@ fn decl_upcall_glue(ModuleRef llmod, type_names tn,
869
888
ret decl_fastcall_fn ( llmod, s, T_fn ( args, T_int ( ) ) ) ;
870
889
}
871
890
872
- fn get_upcall ( & hashmap[ str, ValueRef ] upcalls ,
891
+ fn get_extern ( & hashmap[ str, ValueRef ] externs ,
873
892
ModuleRef llmod, str name , int n_args ) -> ValueRef {
874
- if ( upcalls . contains_key ( name) ) {
875
- ret upcalls . get ( name) ;
893
+ if ( externs . contains_key ( name) ) {
894
+ ret externs . get ( name) ;
876
895
}
877
896
auto inputs = _vec. init_elt [ TypeRef ] ( T_int ( ) , n_args as uint ) ;
878
897
auto output = T_int ( ) ;
879
898
auto f = decl_cdecl_fn ( llmod, name, T_fn ( inputs, output) ) ;
880
- upcalls . insert ( name, f) ;
899
+ externs . insert ( name, f) ;
881
900
ret f;
882
901
}
883
902
884
903
fn trans_upcall ( @block_ctxt cx , str name , vec[ ValueRef ] args ) -> result {
885
904
auto cxx = cx. fcx . ccx ;
886
905
auto lltaskptr = cx. build . PtrToInt ( cx. fcx . lltaskptr , T_int ( ) ) ;
887
906
auto args2 = vec ( lltaskptr) + args;
888
- auto t = trans_upcall2 ( cx. build , cxx. glues , lltaskptr,
889
- cxx. upcalls , cxx. tn , cxx. llmod , name, true , args2) ;
907
+ auto t = trans_native ( cx. build , cxx. glues , lltaskptr,
908
+ cxx. externs , cxx. tn , cxx. llmod , name, true , args2) ;
890
909
ret res( cx, t) ;
891
910
}
892
911
893
- fn trans_upcall2 ( builder b, @glue_fns glues , ValueRef lltaskptr ,
894
- & hashmap[ str, ValueRef ] upcalls ,
895
- type_names tn, ModuleRef llmod, str name ,
896
- bool pass_task , vec[ ValueRef ] args ) -> ValueRef {
912
+ fn trans_native ( builder b, @glue_fns glues , ValueRef lltaskptr ,
913
+ & hashmap[ str, ValueRef ] externs ,
914
+ type_names tn, ModuleRef llmod, str name ,
915
+ bool pass_task , vec[ ValueRef ] args ) -> ValueRef {
897
916
let int n = ( _vec. len [ ValueRef ] ( args) as int ) ;
898
- let ValueRef llupcall = get_upcall ( upcalls , llmod, name, n) ;
899
- llupcall = llvm. LLVMConstPointerCast ( llupcall , T_int ( ) ) ;
917
+ let ValueRef llnative = get_extern ( externs , llmod, name, n) ;
918
+ llnative = llvm. LLVMConstPointerCast ( llnative , T_int ( ) ) ;
900
919
901
920
let ValueRef llglue;
902
921
if ( pass_task) {
903
- llglue = glues. upcall_glues_rust . ( n) ;
922
+ llglue = glues. native_glues_rust . ( n) ;
904
923
} else {
905
- llglue = glues. upcall_glues_cdecl . ( n) ;
924
+ llglue = glues. native_glues_cdecl . ( n) ;
906
925
}
907
- let vec[ ValueRef ] call_args = vec ( llupcall ) ;
926
+ let vec[ ValueRef ] call_args = vec ( llnative ) ;
908
927
909
928
if ( !pass_task) {
910
929
call_args += vec ( lltaskptr) ;
@@ -5771,8 +5790,8 @@ fn decl_native_fn_and_pair(@crate_ctxt cx,
5771
5790
arg_n += 1 u;
5772
5791
}
5773
5792
5774
- auto r = trans_upcall2 ( bcx. build, cx. glues, lltaskptr, cx. upcalls , cx. tn,
5775
- cx. llmod, name, pass_task, call_args) ;
5793
+ auto r = trans_native ( bcx. build, cx. glues, lltaskptr, cx. externs , cx. tn,
5794
+ cx. llmod, name, pass_task, call_args) ;
5776
5795
auto rptr = bcx. build. BitCast ( fcx. llretptr, T_ptr ( T_i32 ( ) ) ) ;
5777
5796
bcx. build. Store ( r, rptr) ;
5778
5797
bcx. build. RetVoid ( ) ;
@@ -5967,7 +5986,7 @@ fn i2p(ValueRef v, TypeRef t) -> ValueRef {
5967
5986
}
5968
5987
5969
5988
fn trans_exit_task_glue ( @glue_fns glues ,
5970
- & hashmap[ str, ValueRef ] upcalls ,
5989
+ & hashmap[ str, ValueRef ] externs ,
5971
5990
type_names tn, ModuleRef llmod) {
5972
5991
let vec[ TypeRef ] T_args = vec ( ) ;
5973
5992
let vec[ ValueRef ] V_args = vec ( ) ;
@@ -5979,8 +5998,8 @@ fn trans_exit_task_glue(@glue_fns glues,
5979
5998
auto build = new_builder ( entrybb) ;
5980
5999
auto tptr = build. PtrToInt ( lltaskptr, T_int ( ) ) ;
5981
6000
auto V_args2 = vec ( tptr) + V_args ;
5982
- trans_upcall2 ( build, glues, lltaskptr,
5983
- upcalls , tn, llmod, "upcall_exit" , true , V_args2 ) ;
6001
+ trans_native ( build, glues, lltaskptr,
6002
+ externs , tn, llmod, "upcall_exit" , true , V_args2 ) ;
5984
6003
build. RetVoid ( ) ;
5985
6004
}
5986
6005
@@ -6415,7 +6434,7 @@ fn make_glues(ModuleRef llmod, type_names tn) -> @glue_fns {
6415
6434
yield_glue = decl_glue ( llmod, tn, abi. yield_glue_name ( ) ) ,
6416
6435
/*
6417
6436
* Note: the signature passed to decl_cdecl_fn here looks unusual
6418
- * because it is. It corresponds neither to an upcall signature
6437
+ * because it is. It corresponds neither to a native signature
6419
6438
* nor a normal rust-ABI signature. In fact it is a fake
6420
6439
* signature, that exists solely to acquire the task pointer as
6421
6440
* an argument to the upcall. It so happens that the runtime sets
@@ -6430,14 +6449,14 @@ fn make_glues(ModuleRef llmod, type_names tn) -> @glue_fns {
6430
6449
T_taskptr ( tn) ) ,
6431
6450
T_void ( ) ) ) ,
6432
6451
6433
- upcall_glues_rust =
6434
- _vec. init_fn [ ValueRef ] ( bind decl_upcall_glue ( llmod, tn, true ,
6452
+ native_glues_rust =
6453
+ _vec. init_fn [ ValueRef ] ( bind decl_native_glue ( llmod, tn, true ,
6435
6454
_) ,
6436
- abi. n_upcall_glues + 1 as uint ) ,
6437
- upcall_glues_cdecl =
6438
- _vec. init_fn [ ValueRef ] ( bind decl_upcall_glue ( llmod, tn, false ,
6455
+ abi. n_native_glues + 1 as uint ) ,
6456
+ native_glues_cdecl =
6457
+ _vec. init_fn [ ValueRef ] ( bind decl_native_glue ( llmod, tn, false ,
6439
6458
_) ,
6440
- abi. n_upcall_glues + 1 as uint ) ,
6459
+ abi. n_native_glues + 1 as uint ) ,
6441
6460
no_op_type_glue = decl_no_op_type_glue ( llmod, tn) ,
6442
6461
memcpy_glue = decl_memcpy_glue ( llmod) ,
6443
6462
bzero_glue = decl_bzero_glue ( llmod) ,
@@ -6503,7 +6522,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
6503
6522
td = td,
6504
6523
tn = tn,
6505
6524
crate_ptr = crate_ptr,
6506
- upcalls = new_str_hash[ ValueRef ] ( ) ,
6525
+ externs = new_str_hash[ ValueRef ] ( ) ,
6507
6526
intrinsics = intrinsics,
6508
6527
item_names = new_str_hash[ ValueRef ] ( ) ,
6509
6528
item_ids = new_def_hash[ ValueRef ] ( ) ,
0 commit comments