Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /MLRISC/trunk/staged-allocation/c-call-sig.sml
ViewVC logotype

Annotation of /MLRISC/trunk/staged-allocation/c-call-sig.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3049 - (view) (download)

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

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0