| 1 |
(* c-type.sml |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 1999 Bell Labs, Lucent Technologies |
| 4 |
* |
| 5 |
* A representation of C Types for specifying the arguments and results |
| 6 |
* of C function calls. |
| 7 |
*) |
| 8 |
|
| 9 |
|
| 10 |
structure CType = |
| 11 |
struct |
| 12 |
|
| 13 |
datatype c_type |
| 14 |
= C_void |
| 15 |
| C_float |
| 16 |
| C_double |
| 17 |
| C_long_double |
| 18 |
| C_unsigned of c_int |
| 19 |
| C_signed of c_int |
| 20 |
| C_PTR |
| 21 |
| C_ARRAY of (c_type * int) |
| 22 |
| C_STRUCT of c_type list |
| 23 |
| C_UNION of c_type list |
| 24 |
|
| 25 |
and c_int |
| 26 |
= I_char |
| 27 |
| I_short |
| 28 |
| I_int |
| 29 |
| I_long |
| 30 |
| I_long_long |
| 31 |
|
| 32 |
|
| 33 |
(* multiple calling conventions on a single architecture *) |
| 34 |
type calling_convention = string |
| 35 |
|
| 36 |
(* prototype describing C function *) |
| 37 |
type c_proto = { |
| 38 |
conv : calling_convention, |
| 39 |
retTy : c_type, |
| 40 |
paramTys : c_type list |
| 41 |
} |
| 42 |
|
| 43 |
(* eliminate aggregates in a C type *) |
| 44 |
fun flattenCTy cTy = (case cTy |
| 45 |
of (C_STRUCT cTys | |
| 46 |
C_UNION cTys ) => List.concat (List.map flattenCTy cTys) |
| 47 |
| C_ARRAY (cTy, n) => List.tabulate (n, fn _ => cTy) |
| 48 |
| cTy => [cTy]) |
| 49 |
|
| 50 |
|
| 51 |
end |