move sys fns into c-stack-cdecl and get_type_desc() into rusti

there is one test failure, stdtest/sys.rs, which inexplicably
(thus far) fails to compile because it invokes
sys::rustrt::last_os_error() instead of invoking
sys::last_os_error().  If stdtest/sys.rs is updated to invoke
the wrapper, it passes.  Still tracing the source of this error.
This commit is contained in:
Niko Matsakis 2011-10-21 11:06:33 -07:00 committed by Brian Anderson
parent 0598635bdc
commit 02d7a1e781
7 changed files with 97 additions and 92 deletions

View File

@ -6,21 +6,24 @@ tag type_desc {
type_desc(@type_desc);
}
native "rust" mod rustrt {
native "c-stack-cdecl" mod rustrt {
// Explicitly re-export native stuff we want to be made
// available outside this crate. Otherwise it's
// visible-in-crate, but not re-exported.
fn last_os_error() -> str;
fn size_of<T>() -> uint;
fn align_of<T>() -> uint;
fn size_of(td: *type_desc) -> uint;
fn align_of(td: *type_desc) -> uint;
fn refcount<T>(t: @T) -> uint;
fn do_gc();
fn unsupervise();
}
native "rust-intrinsic" mod rusti {
fn get_type_desc<T>() -> *type_desc;
}
fn get_type_desc<T>() -> *type_desc {
ret rustrt::get_type_desc::<T>();
ret rusti::get_type_desc::<T>();
}
fn last_os_error() -> str {
@ -28,11 +31,11 @@ fn last_os_error() -> str {
}
fn size_of<T>() -> uint {
ret rustrt::size_of::<T>();
ret rustrt::size_of(get_type_desc::<T>());
}
fn align_of<T>() -> uint {
ret rustrt::align_of::<T>();
ret rustrt::align_of(get_type_desc::<T>());
}
fn refcount<T>(t: @T) -> uint {

View File

@ -26,7 +26,6 @@ native "rust" mod rustrt {
fn task_sleep(time_in_us: uint);
fn task_yield();
fn task_join(t: task_id) -> int;
fn unsupervise();
fn pin_task();
fn unpin_task();
fn get_task_id() -> task_id;
@ -85,7 +84,7 @@ fn join_id(t: task_id) -> task_result {
alt rustrt::task_join(t) { 0 { tr_success } _ { tr_failure } }
}
fn unsupervise() { ret rustrt::unsupervise(); }
fn unsupervise() { ret sys::unsupervise(); }
fn pin() { rustrt::pin_task(); }

View File

@ -48,3 +48,9 @@ rust_intrinsic_recv(rust_task *task, void **retptr, type_desc *ty,
port_recv((uintptr_t*)retptr, port);
}
extern "C" void
rust_intrinsic_get_type_desc(rust_task *task, void **retptr,
type_desc* ty) {
*(type_desc**)retptr = ty;
}

View File

@ -1,96 +1,99 @@
; ModuleID = 'intrinsics.cpp'
target triple = "@CFG_LLVM_TRIPLE@"
%struct.rust_task = type { i32, %struct.stk_seg*, i32, i32, %struct.gc_alloc*, %struct.rust_scheduler*, %class.rust_crate_cache*, %class.rust_kernel*, i8*, %class.rust_task_list*, %struct.rust_cond*, i8*, %struct.rust_task*, i32, i32, i32, %class.timer, i32*, %class.array_list, %class.context, i32, i32, %class.memory_region, %"class.rust_task::wakeup_callback"*, i8, i8, %class.lock_and_signal }
%struct.stk_seg = type { i32, i32, [0 x i8] }
%struct.gc_alloc = type { %struct.gc_alloc*, %struct.gc_alloc*, i32, [0 x i8] }
%struct.rust_scheduler = type { %class.rust_thread, %struct.rc_base, i32, %class.rust_log, i32, %class.rust_srv*, i8*, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_crate_cache, %struct.randctx, %class.rust_kernel*, i32, %class.hash_map, %class.hash_map.3, i32, %class.lock_and_signal, i32, %struct._opaque_pthread_attr_t, %struct.rust_env* }
%class.rust_thread = type { i32 (...)**, i8, %struct._opaque_pthread_t* }
%struct._opaque_pthread_t = type { i32, %struct.__darwin_pthread_handler_rec*, [596 x i8] }
%struct.__darwin_pthread_handler_rec = type { {}*, i8*, %struct.__darwin_pthread_handler_rec* }
%struct.rc_base = type { i32 }
%class.rust_log = type { i32 (...)**, %class.rust_srv*, %struct.rust_scheduler*, i8 }
%class.rust_srv = type { i32 (...)**, %struct.rust_env*, %class.memory_region }
%struct.rust_env = type { i32, i32, i8*, i8, i8, i8* }
%class.memory_region = type { i32 (...)**, %class.rust_srv*, %class.memory_region*, i32, %class.array_list.0, i8, i8, %class.lock_and_signal, i8 }
%class.array_list.0 = type { i32, %"struct.memory_region::alloc_header"**, i32 }
%"struct.memory_region::alloc_header" = type { i32, i32, i8*, [0 x i8] }
%class.lock_and_signal = type { i32 (...)**, %struct._opaque_pthread_cond_t, %struct._opaque_pthread_mutex_t, %struct._opaque_pthread_t*, i8, i8 }
%struct._opaque_pthread_cond_t = type { i32, [24 x i8] }
%struct._opaque_pthread_mutex_t = type { i32, [40 x i8] }
%class.rust_task_list = type { %class.indexed_list, %struct.rust_scheduler*, i8* }
%class.indexed_list = type { i32 (...)**, %class.array_list }
%0 = type { i32, %"struct.memory_region::alloc_header"**, i32 }
%1 = type { i32, %struct.rust_scheduler**, i32 }
%2 = type { %"struct.hash_map<long, rust_task *>::map_entry"* }
%3 = type { %struct.rust_task*, i32, i32, %class.rust_chan** }
%class.array_list = type { i32, %struct.rust_task**, i32 }
%class.circular_buffer = type { %class.rust_kernel*, i32, i32, i32, i32, i8* }
%class.context = type { %struct.registers_t, %class.context* }
%"class.debug::task_debug_info" = type { %"class.std::map" }
%class.hash_map = type { %"struct.hash_map<long, rust_port *>::map_entry"* }
%class.indexed_list = type { i32 (...)**, %class.array_list }
%class.lock_and_signal = type { i32 (...)**, %struct._opaque_pthread_cond_t, %struct._opaque_pthread_mutex_t, %struct._opaque_pthread_t*, i8, i8 }
%class.memory_region = type { i32 (...)**, %class.rust_srv*, %class.memory_region*, i32, %0, i8, i8, %class.lock_and_signal }
%class.ptr_vec = type { %struct.rust_task*, i32, i32, %struct.rust_token** }
%class.rust_chan = type { i32, %class.rust_kernel*, %struct.rust_task*, %class.rust_port*, i32, %class.circular_buffer }
%class.rust_crate_cache = type { %struct.type_desc*, %struct.rust_scheduler*, i32 }
%struct.type_desc = type { %struct.type_desc**, i32, i32, {}*, {}*, {}*, {}*, {}*, {}*, i32, {}*, %struct.UT_hash_handle, i32, [0 x %struct.type_desc*] }
%class.rust_kernel = type { i32 (...)**, %class.memory_region, %class.rust_log, %class.rust_srv*, %class.lock_and_signal, %1, %struct.randctx, i32, %2, i32, i32, i32, %struct.rust_env* }
%class.rust_log = type { i32 (...)**, %class.rust_srv*, %struct.rust_scheduler*, i8 }
%class.rust_obstack = type { %struct.rust_obstack_chunk*, %struct.rust_task* }
%class.rust_port = type { i32, i32, %class.rust_kernel*, %struct.rust_task*, %class.rust_chan*, i32, %class.ptr_vec, %3, %class.lock_and_signal }
%class.rust_srv = type { i32 (...)**, %struct.rust_env*, %class.memory_region }
%"class.rust_task::wakeup_callback" = type { i32 (...)** }
%class.rust_task_list = type { %class.indexed_list, %struct.rust_scheduler*, i8* }
%class.rust_thread = type { i32 (...)**, i8, %struct._opaque_pthread_t* }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<void *, std::pair<void *const, const type_desc *>, std::_Select1st<std::pair<void *const, const type_desc *> >, std::less<void *>, std::allocator<std::pair<void *const, const type_desc *> > >::_Rb_tree_impl" }
%"class.std::map" = type { %"class.std::_Rb_tree" }
%class.timer = type { i32 (...)**, i64, i64 }
%struct.UT_hash_bucket = type { %struct.UT_hash_handle*, i32, i32 }
%struct.UT_hash_handle = type { %struct.UT_hash_table*, i8*, i8*, %struct.UT_hash_handle*, %struct.UT_hash_handle*, i8*, i32, i32 }
%struct.UT_hash_table = type { %struct.UT_hash_bucket*, i32, i32, i32, %struct.UT_hash_handle*, i32, i32, i32, i32, i32 }
%struct.UT_hash_bucket = type { %struct.UT_hash_handle*, i32, i32 }
%struct.randctx = type { i32, [256 x i32], [256 x i32], i32, i32, i32 }
%class.rust_kernel = type { i32 (...)**, %class.memory_region, %class.rust_log, %class.rust_srv*, %class.lock_and_signal, %class.array_list.4, %struct.randctx, i32, i32, i32, %struct.rust_env* }
%class.array_list.4 = type { i32, %struct.rust_scheduler**, i32 }
%class.hash_map = type { %"struct.hash_map<rust_task *, rust_task *>::map_entry"* }
%"struct.hash_map<rust_task *, rust_task *>::map_entry" = type opaque
%class.hash_map.3 = type { %"struct.hash_map<rust_port *, rust_port *>::map_entry"* }
%"struct.hash_map<rust_port *, rust_port *>::map_entry" = type opaque
%struct.__darwin_pthread_handler_rec = type { void (i8*)*, i8*, %struct.__darwin_pthread_handler_rec* }
%struct._opaque_pthread_attr_t = type { i32, [36 x i8] }
%struct.rust_cond = type { i8 }
%class.timer = type { i32 (...)**, i64, i64 }
%class.context = type { %struct.registers_t, %class.context* }
%struct._opaque_pthread_cond_t = type { i32, [24 x i8] }
%struct._opaque_pthread_mutex_t = type { i32, [40 x i8] }
%struct._opaque_pthread_t = type { i32, %struct.__darwin_pthread_handler_rec*, [596 x i8] }
%struct.chan_handle = type { i32, i32 }
%"struct.hash_map<long, rust_port *>::map_entry" = type opaque
%"struct.hash_map<long, rust_task *>::map_entry" = type opaque
%"struct.memory_region::alloc_header" = type { i32, i32, i8*, i32, [0 x i8] }
%struct.randctx = type { i32, [256 x i32], [256 x i32], i32, i32, i32 }
%struct.registers_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, i16, i32, i32 }
%"class.rust_task::wakeup_callback" = type { i32 (...)** }
%struct.rc_base.5 = type { i32 }
%struct.rust_vec = type { i32, i32, [ 0 x i8 ] }
%class.rust_port = type { i32, %class.rust_kernel*, %struct.rust_task*, i32, %class.ptr_vec, %class.ptr_vec.7, %class.rust_chan*, %class.lock_and_signal }
%class.ptr_vec = type { %struct.rust_task*, i32, i32, %struct.rust_token** }
%struct.rust_cond = type { i8 }
%struct.rust_env = type { i32, i32, i8*, i8, i8, i8* }
%struct.rust_obstack_chunk = type { %struct.rust_obstack_chunk*, i32, i32, i32, [0 x i8] }
%struct.rust_scheduler = type { %class.rust_thread, i32, i32, %class.rust_log, i32, %class.rust_srv*, i8*, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_crate_cache, %struct.randctx, %class.rust_kernel*, i32, i32, %class.lock_and_signal, i32, %struct._opaque_pthread_attr_t, %struct.rust_env*, %class.context }
%struct.rust_shape_tables = type { i8*, i8* }
%struct.rust_task = type { %struct.rust_task_user, i32, %class.context, %struct.rust_vec*, i32, %struct.rust_scheduler*, %class.rust_crate_cache*, %class.rust_kernel*, i8*, %class.rust_task_list*, %struct.rust_cond*, i8*, %struct.rust_task*, i32, i32, %class.timer, i32*, %class.array_list, i32, i32, %class.memory_region, %"class.rust_task::wakeup_callback"*, i8, i8, i8, %class.lock_and_signal, %class.hash_map, %class.rust_obstack, %"class.std::map", i32, %"class.debug::task_debug_info" }
%struct.rust_task_user = type { i32, i32, %struct.chan_handle, i32 }
%struct.rust_token = type opaque
%class.ptr_vec.7 = type { %struct.rust_task*, i32, i32, %class.rust_chan** }
%class.rust_chan = type { i32, %class.rust_kernel*, %struct.rust_task*, %class.rust_port*, i32, %class.circular_buffer }
%class.circular_buffer = type { %class.rust_kernel*, i32, i32, i32, i32, i8* }
%struct.rust_vec = type { i32, i32, [0 x i8] }
%"struct.std::_Rb_tree<void *, std::pair<void *const, const type_desc *>, std::_Select1st<std::pair<void *const, const type_desc *> >, std::less<void *>, std::allocator<std::pair<void *const, const type_desc *> > >::_Rb_tree_impl" = type { %struct.rust_cond, %"struct.std::_Rb_tree_node_base", i32 }
%"struct.std::_Rb_tree_node_base" = type { i32, %"struct.std::_Rb_tree_node_base"*, %"struct.std::_Rb_tree_node_base"*, %"struct.std::_Rb_tree_node_base"* }
%struct.type_desc = type { %struct.type_desc**, i32, i32, void (i8*, %struct.rust_task*, i8*, %struct.type_desc**, i8*)*, void (i8*, %struct.rust_task*, i8*, %struct.type_desc**, i8*)*, void (i8*, %struct.rust_task*, i8*, %struct.type_desc**, i8*)*, i8*, void (i8*, %struct.rust_task*, i8*, %struct.type_desc**, i8*)*, void (i8*, %struct.rust_task*, i8*, %struct.type_desc**, i8*)*, i32, void (i8*, %struct.rust_task*, i8*, %struct.type_desc**, i8*, i8*, i8)*, i8*, %struct.rust_shape_tables*, i32, i32, %struct.UT_hash_handle, i32, [0 x %struct.type_desc*] }
@.str = private unnamed_addr constant [42 x i8] c"attempt to cast values of differing sizes\00", align 1
@.str1 = private unnamed_addr constant [15 x i8] c"intrinsics.cpp\00", align 1
@.str = private unnamed_addr constant [42 x i8] c"attempt to cast values of differing sizes\00"
@.str1 = private unnamed_addr constant [15 x i8] c"intrinsics.cpp\00"
define linkonce_odr void @rust_intrinsic_vec_len(%struct.rust_task* nocapture %task, i32* nocapture %retptr, %struct.type_desc* nocapture %ty, %struct.rust_vec** nocapture %v) nounwind {
entry:
%ptr1 = load %struct.rust_vec** %v, align 4, !tbaa !0
%fill1 = getelementptr inbounds %struct.rust_vec* %ptr1, i32 0, i32 0
%tmp2 = load i32* %fill1, align 4, !tbaa !0
%size = getelementptr inbounds %struct.type_desc* %ty, i32 0, i32 1
%tmp20 = load i32* %size, align 4, !tbaa !0
%div = udiv i32 %tmp2, %tmp20
store i32 %div, i32* %retptr, align 4, !tbaa !0
define void @rust_intrinsic_vec_len(%struct.rust_task* nocapture %task, i32* nocapture %retptr, %struct.type_desc* nocapture %ty, %struct.rust_vec** nocapture %vp) nounwind {
%1 = load %struct.rust_vec** %vp, align 4
%2 = getelementptr inbounds %struct.rust_vec* %1, i32 0, i32 0
%3 = load i32* %2, align 4
%4 = getelementptr inbounds %struct.type_desc* %ty, i32 0, i32 1
%5 = load i32* %4, align 4
%6 = udiv i32 %3, %5
store i32 %6, i32* %retptr, align 4
ret void
}
define linkonce_odr void @rust_intrinsic_ptr_offset(%struct.rust_task* nocapture %task, i8** nocapture %retptr, %struct.type_desc* nocapture %ty, i8* %ptr, i32 %count) nounwind {
entry:
%size = getelementptr inbounds %struct.type_desc* %ty, i32 0, i32 1
%tmp1 = load i32* %size, align 4, !tbaa !0
%mul = mul i32 %tmp1, %count
%arrayidx = getelementptr inbounds i8* %ptr, i32 %mul
store i8* %arrayidx, i8** %retptr, align 4, !tbaa !3
define void @rust_intrinsic_ptr_offset(%struct.rust_task* nocapture %task, i8** nocapture %retptr, %struct.type_desc* nocapture %ty, i8* %ptr, i32 %count) nounwind {
%1 = getelementptr inbounds %struct.type_desc* %ty, i32 0, i32 1
%2 = load i32* %1, align 4
%3 = mul i32 %2, %count
%4 = getelementptr inbounds i8* %ptr, i32 %3
store i8* %4, i8** %retptr, align 4
ret void
}
define linkonce_odr void @rust_intrinsic_cast(%struct.rust_task* %task, i8* nocapture %retptr, %struct.type_desc* nocapture %t1, %struct.type_desc* nocapture %t2, i8* nocapture %src) {
entry:
%size = getelementptr inbounds %struct.type_desc* %t1, i32 0, i32 1
%tmp1 = load i32* %size, align 4, !tbaa !0
%size3 = getelementptr inbounds %struct.type_desc* %t2, i32 0, i32 1
%tmp4 = load i32* %size3, align 4, !tbaa !0
%cmp = icmp eq i32 %tmp1, %tmp4
br i1 %cmp, label %if.end, label %if.then
define void @rust_intrinsic_cast(%struct.rust_task* %task, i8* nocapture %retptr, %struct.type_desc* nocapture %t1, %struct.type_desc* nocapture %t2, i8* nocapture %src) {
%1 = getelementptr inbounds %struct.type_desc* %t1, i32 0, i32 1
%2 = load i32* %1, align 4
%3 = getelementptr inbounds %struct.type_desc* %t2, i32 0, i32 1
%4 = load i32* %3, align 4
%5 = icmp eq i32 %2, %4
br i1 %5, label %7, label %6
if.then: ; preds = %entry
tail call void @upcall_fail(i8* getelementptr inbounds ([42 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8]* @.str1, i32 0, i32 0), i32 45)
br label %return
if.end: ; preds = %entry
tail call void @llvm.memmove.p0i8.p0i8.i32(i8* %retptr, i8* %src, i32 %tmp1, i32 1, i1 false)
br label %return
; <label>:7 ; preds = %0
tail call void @llvm.memmove.p0i8.p0i8.i32(i8* %retptr, i8* %src, i32 %2, i32 1, i1 false)
br label %8
return: ; preds = %if.end, %if.then
; <label>:8 ; preds = %7, %6
ret void
}
@ -98,9 +101,8 @@ declare void @upcall_fail(i8*, i8*, i32)
declare void @llvm.memmove.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
define linkonce_odr void @rust_intrinsic_addr_of(%struct.rust_task* nocapture %task, i8** nocapture %retptr, %struct.type_desc* nocapture %ty, i8* %valptr) nounwind {
entry:
store i8* %valptr, i8** %retptr, align 4, !tbaa !3
define void @rust_intrinsic_addr_of(%struct.rust_task* nocapture %task, i8** nocapture %retptr, %struct.type_desc* nocapture %ty, i8* %valptr) nounwind {
store i8* %valptr, i8** %retptr, align 4
ret void
}
@ -113,7 +115,8 @@ entry:
declare void @port_recv(i32*, %class.rust_port*)
!0 = metadata !{metadata !"long", metadata !1}
!1 = metadata !{metadata !"omnipotent char", metadata !2}
!2 = metadata !{metadata !"Simple C/C++ TBAA", null}
!3 = metadata !{metadata !"any pointer", metadata !1}
define void @rust_intrinsic_get_type_desc(%struct.rust_task* nocapture %task, i8** nocapture %retptr, %struct.type_desc* %ty) nounwind {
%ty.c = bitcast %struct.type_desc* %ty to i8*
store i8* %ty.c, i8** %retptr, align 4
ret void
}

View File

@ -92,7 +92,7 @@ leak(void *thing) {
}
extern "C" CDECL intptr_t
refcount(type_desc *t, intptr_t *v) {
refcount(intptr_t *v) {
// Passed-in value has refcount 1 too high
// because it was ref'ed while making the call.
return (*v) - 1;
@ -109,11 +109,6 @@ unsupervise() {
task->unsupervise();
}
extern "C" CDECL type_desc*
get_type_desc(void *unused_task, type_desc* t) {
return t;
}
extern "C" CDECL void
vec_reserve_shared(type_desc* ty, rust_vec** vp,
size_t n_elts) {

View File

@ -62,7 +62,6 @@ vec_from_buf_shared
task_sleep
task_yield
task_join
get_type_desc
unsupervise
upcall_alloc_c_stack
upcall_call_c_stack

View File

@ -1,5 +1,5 @@
use std;
import std::sys::rustrt::refcount;
import std::sys::refcount;
fn main() unsafe {
let i = ~@1;