| 1 |
(* c-calls.sig |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 2002 Bell Labs, Lucent Technologies |
| 4 |
*) |
| 5 |
|
| 6 |
signature C_CALLS = |
| 7 |
sig |
| 8 |
|
| 9 |
structure T : MLTREE |
| 10 |
|
| 11 |
datatype c_arg |
| 12 |
= ARG of T.rexp |
| 13 |
(* rexp specifies integer or pointer; if the |
| 14 |
* corresponding parameter is a C struct, then |
| 15 |
* this argument is the address of the struct. |
| 16 |
*) |
| 17 |
| FARG of T.fexp |
| 18 |
(* fexp specifies floating-point argument *) |
| 19 |
| ARGS of c_arg list |
| 20 |
(* list of arguments corresponding to the contents of a C struct *) |
| 21 |
|
| 22 |
(* this constant is the offset from the caller's SP to the low-address of the |
| 23 |
* parameter area (see the paramAlloc callback below). |
| 24 |
*) |
| 25 |
val paramAreaOffset : int |
| 26 |
|
| 27 |
(* The MLRISC type that describes the natural size of integer arguments (i.e., what |
| 28 |
* small integers are promoted to). |
| 29 |
*) |
| 30 |
val naturalIntSz : T.ty |
| 31 |
|
| 32 |
(* translate a C function call with the given argument list into |
| 33 |
* a MLRISC statement list. The arguments are as follows: |
| 34 |
* |
| 35 |
* name -- an expression that speficies the function. |
| 36 |
* proto -- the function's prototype |
| 37 |
* paramAlloc -- this callback takes the size and alignment |
| 38 |
* constraints on the parameter-passing area |
| 39 |
* in the stack. If it returns true, then the |
| 40 |
* space for the parameters is allocated by |
| 41 |
* client; otherwise genCall allocates the space. |
| 42 |
* structRet -- this callback takes the size and alignment |
| 43 |
* of space required for returning a struct |
| 44 |
* value. It returns the address of the |
| 45 |
* reserved space. |
| 46 |
* saveRestoreDedicated -- this callback takes a list of registers |
| 47 |
* that the call kills and should return an |
| 48 |
* instruction sequence to save/restore any |
| 49 |
* registers that the client run-time model |
| 50 |
* expects to be preserved (e.g., allocation |
| 51 |
* pointers). |
| 52 |
* callComment -- if present, the comment string is attached |
| 53 |
* the CALL instruction as a COMMENT annotation. |
| 54 |
* args -- the arguments to the call. The assumption is |
| 55 |
* that any required sign or zero extension has |
| 56 |
* already been done. |
| 57 |
* |
| 58 |
* The result of genCall is a mlrisc list specifying where the result |
| 59 |
* is and the MLRisc statements that implement the calling sequence. |
| 60 |
* Functions with void return type have no result, most others have |
| 61 |
* one result, but some conventions may flatten larger arguments into |
| 62 |
* multiple registers (e.g., a register pair for long long results). |
| 63 |
* |
| 64 |
* The implementation of genCall will return a statement sequence with the |
| 65 |
* following order: |
| 66 |
* |
| 67 |
* <argument area allocation> |
| 68 |
* <setup arguments> |
| 69 |
* <save dedicated registers> |
| 70 |
* <call C function> |
| 71 |
* <restore dedicated registers> |
| 72 |
* <free argument area> |
| 73 |
* <copy result into fresh registers> |
| 74 |
* |
| 75 |
* WARNING: if the client's implementation of structRet uses the stack |
| 76 |
* pointer to address the struct-return area, then paramAlloc should always |
| 77 |
* handle allocating space for the parameter area (i.e., return true). |
| 78 |
*) |
| 79 |
val genCall : { |
| 80 |
name : T.rexp, |
| 81 |
proto : CTypes.c_proto, |
| 82 |
paramAlloc : {szb : int, align : int} -> bool, |
| 83 |
structRet : {szb : int, align : int} -> T.rexp, |
| 84 |
saveRestoreDedicated : |
| 85 |
T.mlrisc list -> {save: T.stm list, restore: T.stm list}, |
| 86 |
callComment : string option, |
| 87 |
args : c_arg list |
| 88 |
} -> { |
| 89 |
callseq : T.stm list, |
| 90 |
result: T.mlrisc list |
| 91 |
} |
| 92 |
|
| 93 |
(* the location of arguments/parameters; offsets are given with respect to the |
| 94 |
* low end of the parameter area (see paramAreaOffset above). |
| 95 |
*) |
| 96 |
datatype arg_location |
| 97 |
= Reg of T.ty * T.reg * T.I.machine_int option |
| 98 |
(* integer/pointer argument in register *) |
| 99 |
| FReg of T.fty * T.reg * T.I.machine_int option |
| 100 |
(* floating-point argument in register *) |
| 101 |
| Stk of T.ty * T.I.machine_int (* integer/pointer argument in parameter area *) |
| 102 |
| FStk of T.fty * T.I.machine_int (* floating-point argument in parameter area *) |
| 103 |
| Args of arg_location list |
| 104 |
|
| 105 |
val layout : CTypes.c_proto -> { |
| 106 |
argLocs : arg_location list, (* argument/parameter assignment *) |
| 107 |
argMem : {szb : int, align : int}, (* memory requirements for stack-allocated *) |
| 108 |
(* arguments; this value can be passed to *) |
| 109 |
(* the paramAlloc callback. *) |
| 110 |
resLoc : arg_location option, (* result location; NONE for void functions *) |
| 111 |
structRetLoc : {szb : int, align : int} option |
| 112 |
} |
| 113 |
|
| 114 |
(* Callee-save registers as defined in the C calling convention. Note that |
| 115 |
* these do not include special registers (e.g., stack and frame-pointers) |
| 116 |
* that are preserved across calls. |
| 117 |
*) |
| 118 |
val calleeSaveRegs : T.reg list (* C callee-save registers *) |
| 119 |
val calleeSaveFRegs : T.reg list (* C callee-save floating-point registers *) |
| 120 |
|
| 121 |
end |