rust/src/rt/intrinsics/intrinsics.cpp

76 lines
1.9 KiB
C++
Raw Normal View History

// Use `clang++ -emit-llvm -S -arch i386 -O3 -I../isaac -I../uthash
// -I../arch/i386 -fno-stack-protector -o intrinsics.ll intrinsics.cpp`
#include "../rust_internal.h"
#include "../rust_scheduler.h"
2011-07-09 20:14:20 -07:00
#include <cstdlib>
#include <cstring>
2011-11-08 15:38:56 -08:00
extern "C" CDECL void
port_recv(uintptr_t *dptr, rust_port *port);
extern "C" CDECL void
rust_task_sleep(size_t time_in_us);
extern "C" void
rust_intrinsic_vec_len(size_t *retptr,
2011-11-15 20:07:06 -08:00
void *env,
type_desc *ty,
rust_vec **vp)
{
*retptr = (*vp)->fill / ty->size;
}
extern "C" void
rust_intrinsic_ptr_offset(void **retptr,
2011-11-15 20:07:06 -08:00
void *env,
type_desc *ty,
void *ptr,
uintptr_t count)
{
*retptr = &((uint8_t *)ptr)[ty->size * count];
}
2011-07-09 20:14:20 -07:00
extern "C" void
rust_intrinsic_cast(void *retptr,
2011-11-15 20:07:06 -08:00
void *env,
type_desc *t1,
type_desc *t2,
void *src)
2011-07-09 20:14:20 -07:00
{
// assert t1->size == t2->size
// FIXME: This should be easily expressible in rust
memmove(retptr, src, t1->size);
2011-07-09 20:14:20 -07:00
}
extern "C" void
rust_intrinsic_addr_of(void **retptr,
2011-11-15 20:07:06 -08:00
void *env,
type_desc *ty,
void *valptr) {
*retptr = valptr;
}
2011-08-01 18:42:29 -07:00
extern "C" void
rust_intrinsic_recv(void **retptr,
2011-11-15 20:07:06 -08:00
void *env,
type_desc *ty,
2011-08-01 18:42:29 -07:00
rust_port *port) {
port_recv((uintptr_t*)retptr, port);
2011-08-01 18:42:29 -07:00
}
extern "C" void
rust_intrinsic_get_type_desc(void **retptr,
2011-11-15 20:07:06 -08:00
void *env,
type_desc* ty) {
*(type_desc**)retptr = ty;
}
2011-11-08 15:38:56 -08:00
extern "C" void
rust_intrinsic_task_sleep(void **retptr,
2011-11-15 20:07:06 -08:00
void *env,
size_t time_in_us) {
rust_task_sleep(time_in_us);
}