Debian Codegraph @

lib/mlrisc-lib/MLRISC/c-call/gen/c-call-sig.sml

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