| 1 |
(* memaccess.sig |
| 2 |
* 2005 Matthew Fluet ([email protected]) |
| 3 |
* Adapted for MLton. |
| 4 |
*) |
| 5 |
|
| 6 |
(* memaccess.sig |
| 7 |
* |
| 8 |
* Primitives for "raw" memory access. |
| 9 |
* |
| 10 |
* Copyright (c) 2004 by The Fellowship of SML/NJ |
| 11 |
* |
| 12 |
* Author: Matthias Blume ([email protected]) |
| 13 |
*) |
| 14 |
signature CMEMACCESS = sig |
| 15 |
|
| 16 |
eqtype addr |
| 17 |
|
| 18 |
val null : addr |
| 19 |
val isNull : addr -> bool |
| 20 |
val ++ : addr * int -> addr |
| 21 |
val -- : addr * addr -> int |
| 22 |
val compare : addr * addr -> order |
| 23 |
val bcopy : { from: addr, to: addr, bytes: word } -> unit |
| 24 |
|
| 25 |
(* actual sizes of C types (not their ML representations) in bytes *) |
| 26 |
val addr_size : word |
| 27 |
val char_size : word |
| 28 |
val short_size : word |
| 29 |
val int_size : word |
| 30 |
val long_size : word |
| 31 |
val longlong_size : word |
| 32 |
val float_size : word |
| 33 |
val double_size : word |
| 34 |
|
| 35 |
(* fetching from memory *) |
| 36 |
val load_addr : addr -> addr |
| 37 |
val load_schar : addr -> MLRep.Char.Signed.int |
| 38 |
val load_uchar : addr -> MLRep.Char.Unsigned.word |
| 39 |
val load_sshort : addr -> MLRep.Short.Signed.int |
| 40 |
val load_ushort : addr -> MLRep.Short.Unsigned.word |
| 41 |
val load_sint : addr -> MLRep.Int.Signed.int |
| 42 |
val load_uint : addr -> MLRep.Int.Unsigned.word |
| 43 |
val load_slong : addr -> MLRep.Long.Signed.int |
| 44 |
val load_ulong : addr -> MLRep.Long.Unsigned.word |
| 45 |
val load_slonglong : addr -> MLRep.LongLong.Signed.int |
| 46 |
val load_ulonglong : addr -> MLRep.LongLong.Unsigned.word |
| 47 |
val load_float : addr -> MLRep.Float.real |
| 48 |
val load_double : addr -> MLRep.Double.real |
| 49 |
|
| 50 |
(* storing into memory *) |
| 51 |
val store_addr : addr * addr -> unit |
| 52 |
val store_schar : addr * MLRep.Char.Signed.int -> unit |
| 53 |
val store_uchar : addr * MLRep.Char.Unsigned.word -> unit |
| 54 |
val store_sshort : addr * MLRep.Short.Signed.int -> unit |
| 55 |
val store_ushort : addr * MLRep.Short.Unsigned.word -> unit |
| 56 |
val store_sint : addr * MLRep.Int.Signed.int -> unit |
| 57 |
val store_uint : addr * MLRep.Int.Unsigned.word -> unit |
| 58 |
val store_slong : addr * MLRep.Long.Signed.int -> unit |
| 59 |
val store_ulong : addr * MLRep.Long.Unsigned.word -> unit |
| 60 |
val store_slonglong : addr * MLRep.LongLong.Signed.int -> unit |
| 61 |
val store_ulonglong : addr * MLRep.LongLong.Unsigned.word -> unit |
| 62 |
val store_float : addr * MLRep.Float.real -> unit |
| 63 |
val store_double : addr * MLRep.Double.real -> unit |
| 64 |
|
| 65 |
val int_bits : word |
| 66 |
|
| 67 |
(* types used in C calling convention *) |
| 68 |
type cc_addr |
| 69 |
type cc_schar |
| 70 |
type cc_uchar |
| 71 |
type cc_sshort |
| 72 |
type cc_ushort |
| 73 |
type cc_sint |
| 74 |
type cc_uint |
| 75 |
type cc_slong |
| 76 |
type cc_ulong |
| 77 |
type cc_slonglong |
| 78 |
type cc_ulonglong |
| 79 |
type cc_float |
| 80 |
type cc_double |
| 81 |
|
| 82 |
(* wrapping and unwrapping for cc types *) |
| 83 |
val wrap_addr : addr -> cc_addr |
| 84 |
val wrap_schar : MLRep.Char.Signed.int -> cc_schar |
| 85 |
val wrap_uchar : MLRep.Char.Unsigned.word -> cc_uchar |
| 86 |
val wrap_sshort : MLRep.Short.Signed.int -> cc_sshort |
| 87 |
val wrap_ushort : MLRep.Short.Unsigned.word -> cc_ushort |
| 88 |
val wrap_sint : MLRep.Int.Signed.int -> cc_sint |
| 89 |
val wrap_uint : MLRep.Int.Unsigned.word -> cc_uint |
| 90 |
val wrap_slong : MLRep.Long.Signed.int -> cc_slong |
| 91 |
val wrap_ulong : MLRep.Long.Unsigned.word -> cc_ulong |
| 92 |
val wrap_slonglong : MLRep.LongLong.Signed.int -> cc_slonglong |
| 93 |
val wrap_ulonglong : MLRep.LongLong.Unsigned.word -> cc_ulonglong |
| 94 |
val wrap_float : MLRep.Float.real -> cc_float |
| 95 |
val wrap_double : MLRep.Double.real -> cc_double |
| 96 |
|
| 97 |
val unwrap_addr : cc_addr -> addr |
| 98 |
val unwrap_schar : cc_schar -> MLRep.Char.Signed.int |
| 99 |
val unwrap_uchar : cc_uchar -> MLRep.Char.Unsigned.word |
| 100 |
val unwrap_sshort : cc_sshort -> MLRep.Short.Signed.int |
| 101 |
val unwrap_ushort : cc_ushort -> MLRep.Short.Unsigned.word |
| 102 |
val unwrap_sint : cc_sint -> MLRep.Int.Signed.int |
| 103 |
val unwrap_uint : cc_uint -> MLRep.Int.Unsigned.word |
| 104 |
val unwrap_slong : cc_slong -> MLRep.Long.Signed.int |
| 105 |
val unwrap_ulong : cc_ulong -> MLRep.Long.Unsigned.word |
| 106 |
val unwrap_slonglong : cc_slonglong -> MLRep.LongLong.Signed.int |
| 107 |
val unwrap_ulonglong : cc_ulonglong -> MLRep.LongLong.Unsigned.word |
| 108 |
val unwrap_float : cc_float -> MLRep.Float.real |
| 109 |
val unwrap_double : cc_double -> MLRep.Double.real |
| 110 |
|
| 111 |
(* unsafe pointer <-> int conversion *) |
| 112 |
val p2i : addr -> MLRep.Long.Unsigned.word |
| 113 |
val i2p : MLRep.Long.Unsigned.word -> addr |
| 114 |
end |