rust/src/rt/intrinsics/intrinsics.cpp

49 lines
1.3 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"
2011-07-09 20:14:20 -07:00
#include <cstdlib>
#include <cstring>
extern "C" CDECL void
upcall_fail(rust_task *task, char const *expr, char const *file, size_t line);
extern "C" void
rust_intrinsic_vec_len(rust_task *task, size_t *retptr, type_desc *ty,
rust_vec **vp)
{
*retptr = (*vp)->fill / ty->size;
}
extern "C" void
rust_intrinsic_ptr_offset(rust_task *task, void **retptr, 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(rust_task *task, void *retptr, type_desc *t1,
type_desc *t2, void *src)
2011-07-09 20:14:20 -07:00
{
if (t1->size != t2->size) {
upcall_fail(task, "attempt to cast values of differing sizes",
__FILE__, __LINE__);
return;
}
memmove(retptr, src, t1->size);
2011-07-09 20:14:20 -07:00
}
extern "C" void
rust_intrinsic_addr_of(rust_task *task, void **retptr, type_desc *ty,
void *valptr) {
*retptr = valptr;
}
2011-08-01 18:42:29 -07:00
extern "C" void
rust_intrinsic_recv(rust_task *task, void **retptr, type_desc *ty,
rust_port *port) {
port_recv(task, (uintptr_t*)retptr, port);
2011-08-01 18:42:29 -07:00
}