rust/src/rt/intrinsics/intrinsics.cpp

142 lines
3.6 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>
extern "C" CDECL void
2011-10-22 20:59:20 -07:00
upcall_fail(char const *expr, char const *file, size_t line);
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
2011-11-15 20:07:06 -08:00
rust_intrinsic_2_vec_len(size_t *retptr,
void *env,
type_desc *ty,
rust_vec **vp)
{
*retptr = (*vp)->fill / ty->size;
}
extern "C" void
2011-11-15 20:07:06 -08:00
rust_intrinsic_2_ptr_offset(void **retptr,
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
2011-11-15 20:07:06 -08:00
rust_intrinsic_2_cast(void *retptr,
void *env,
type_desc *t1,
type_desc *t2,
void *src)
2011-07-09 20:14:20 -07:00
{
if (t1->size != t2->size) {
upcall_fail("attempt to cast values of differing sizes",
2011-07-09 20:14:20 -07:00
__FILE__, __LINE__);
return;
}
memmove(retptr, src, t1->size);
2011-07-09 20:14:20 -07:00
}
extern "C" void
2011-11-15 20:07:06 -08:00
rust_intrinsic_2_addr_of(void **retptr,
void *env,
type_desc *ty,
void *valptr) {
*retptr = valptr;
}
2011-08-01 18:42:29 -07:00
extern "C" void
2011-11-15 20:07:06 -08:00
rust_intrinsic_2_recv(void **retptr,
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
2011-11-15 20:07:06 -08:00
rust_intrinsic_2_get_type_desc(void **retptr,
void *env,
type_desc* ty) {
*(type_desc**)retptr = ty;
}
2011-11-08 15:38:56 -08:00
extern "C" void
2011-11-15 20:07:06 -08:00
rust_intrinsic_2_task_sleep(void **retptr,
void *env,
size_t time_in_us) {
rust_task_sleep(time_in_us);
}
extern "C" void
rust_intrinsic_vec_len(void *task,
size_t *retptr,
type_desc *ty,
rust_vec **vp)
{
rust_intrinsic_2_vec_len(retptr, NULL, ty, vp);
}
extern "C" void
rust_intrinsic_ptr_offset(void *task,
void **retptr,
type_desc *ty,
void *ptr,
uintptr_t count)
{
rust_intrinsic_2_ptr_offset(retptr, NULL, ty, ptr, count);
}
extern "C" void
rust_intrinsic_cast(void *task,
void *retptr,
type_desc *t1,
type_desc *t2,
void *src)
{
rust_intrinsic_2_cast(retptr, NULL, t1, t2, src);
}
extern "C" void
rust_intrinsic_addr_of(void *task,
void **retptr,
type_desc *ty,
void *valptr) {
rust_intrinsic_2_addr_of(retptr, NULL, ty, valptr);
}
extern "C" void
rust_intrinsic_recv(void *task,
void **retptr,
type_desc *ty,
rust_port *port) {
rust_intrinsic_2_recv(retptr, NULL, ty, port);
2011-11-08 15:38:56 -08:00
}
2011-11-15 20:07:06 -08:00
extern "C" void
rust_intrinsic_get_type_desc(void *task,
void **retptr,
type_desc* ty) {
rust_intrinsic_2_get_type_desc(retptr, NULL, ty);
}
extern "C" void
rust_intrinsic_task_sleep(void *task,
void **retptr,
size_t time_in_us) {
rust_task_sleep(time_in_us);
}