1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
/* Copyright (C) 2005-2007 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
*
* MLton is released under a BSD-style license.
* See the file MLton-LICENSE for details.
*/
/* isObjptr returns true if p looks like an object pointer. */
bool isObjptr (objptr p) {
unsigned int shift = GC_MODEL_MINALIGN_SHIFT - GC_MODEL_OBJPTR_SHIFT;
objptr mask = ~((~((objptr)0)) << shift);
return (0 == (p & mask));
}
pointer objptrToPointer (objptr O, pointer B) {
uintptr_t O_ = (uintptr_t)O;
uintptr_t B_;
unsigned int S_ = GC_MODEL_OBJPTR_SHIFT;
uintptr_t P_;
pointer P;
if (GC_MODEL_OBJPTR_BASE) {
B_ = (uintptr_t)B;
} else {
B_ = 0;
}
P_ = ((O_ << S_) + B_);
P = (pointer)P_;
if (DEBUG_OBJPTR)
fprintf (stderr, "objptrToPointer ("FMTOBJPTR") = "FMTPTR"\n", O, (uintptr_t)P);
return P;
}
objptr pointerToObjptr (pointer P, pointer B) {
uintptr_t P_ = (uintptr_t)P;
uintptr_t B_;
unsigned int S_ = GC_MODEL_OBJPTR_SHIFT;
uintptr_t O_;
objptr O;
if (GC_MODEL_OBJPTR_BASE) {
B_ = (uintptr_t)B;
} else {
B_ = 0;
}
O_ = ((P_ - B_) >> S_);
O = (objptr)O_;
if (DEBUG_OBJPTR)
fprintf (stderr, "pointerToObjptr ("FMTPTR") = "FMTOBJPTR"\n", (uintptr_t)P, O);
return O;
}
/*
* Note that by indirectly fetching and storing object pointers, the
* following functions admit implementations that behave according to
* model characteristics determined at runtime. Hence, by making
* exclusive use of these functions (and adding a GC_state->model
* field set by the compiled program), we may be able to implement the
* runtime in a manner which is agnostic to the actual objptr
* representation.
*/
pointer fetchObjptrToPointer (pointer OP, pointer B) {
return objptrToPointer (*((objptr*)OP), B);
}
void storeObjptrFromPointer (pointer OP, pointer P, pointer B) {
*((objptr*)OP) = pointerToObjptr (P, B);
}
|