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/x86/staged-allocation/ia32-vararg-ccall-fn.sml
ViewVC logotype

Annotation of /MLRISC/trunk/x86/staged-allocation/ia32-vararg-ccall-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3068 - (view) (download)

1 : mrainey 3049 (* ia32-vararg-ccall-fn.sml
2 :     *
3 :     * C calling conventions for the X86. We use the technique of Staged Allocation (see
4 :     * MLRISC/staged-allocation).
5 :     *
6 :     * Mike Rainey (mrainey@cs.uchicago.edu)
7 :     *)
8 :    
9 :     functor IA32VarargCCallFn (
10 :     structure T : MLTREE
11 :     val abi : string
12 :     val ix : (T.stm,T.rexp,T.fexp,T.ccexp) X86InstrExt.sext -> T.sext
13 :     (* Note that the fast_loating_point flag must match the one passed
14 :     * to the code generator module.
15 :     *)
16 :     val fast_floating_point : bool ref
17 : mrainey 3054 val push : T.rexp -> T.stm
18 :     val leave : T.stm
19 : mrainey 3049 ) = struct
20 :    
21 : mrainey 3054 val wordTy = 32
22 :    
23 : mrainey 3049 structure T = T
24 :     structure C = X86Cells
25 :     structure CB = CellsBasis
26 :     structure CTy = CTypes
27 : mrainey 3051 structure CCall = IA32SVIDFn(
28 : mrainey 3049 structure T = T
29 :     val abi = abi
30 :     val ix = ix
31 :     val fast_floating_point = fast_floating_point
32 :     )
33 :     structure VarargCCall = VarargCCallFn(
34 :     structure T = T
35 : mrainey 3051 structure CCall = CCall
36 : mrainey 3049 val gprParams = []
37 :     val fprParams = []
38 : mrainey 3054 val gprTys = [32]
39 :     val fprTys = [32, 64]
40 : mrainey 3051 val spReg = CCall.spReg
41 : mrainey 3054 val wordTy = wordTy
42 : mrainey 3049 val newReg = C.newReg
43 :     )
44 :    
45 : mrainey 3054 fun lit i = T.LI (T.I.fromInt (wordTy, i))
46 : mrainey 3051
47 : mrainey 3054 (* get the ith argument in the calling sequence *)
48 : mrainey 3062 fun getArg i =
49 :     T.LOAD(wordTy, T.ADD(wordTy, T.REG(wordTy, C.ebp), lit (4*i+8)), T.Region.memory)
50 : mrainey 3054
51 :     fun genVarargs () = let
52 :     val lab = Label.global "varargs"
53 : mrainey 3068 val argsReg = C.newReg()
54 : mrainey 3064 (* we align the frame to a 16-bytes to support Mac OS. *)
55 :     val frameSzB = 1024*4-2*4
56 : mrainey 3068 val cFun = getArg 0
57 :     val endOfArgs = getArg 2
58 : mrainey 3054 in
59 :     (lab,
60 :     List.concat [
61 : mrainey 3063 [T.LIVE CCall.CCs.calleeSaveRegs],
62 : mrainey 3054 [push (T.REG(wordTy, C.ebp)),
63 :     T.COPY (wordTy, [C.ebp], [C.esp])],
64 : mrainey 3068 [T.MV(wordTy, argsReg, getArg 1)],
65 : mrainey 3054 (* allocate stack space for the arguments *)
66 : mrainey 3064 [T.MV(wordTy, C.esp, T.SUB(wordTy, T.REG(wordTy, C.esp), lit frameSzB))],
67 : mrainey 3068 VarargCCall.genVarargs (cFun, argsReg, endOfArgs),
68 : mrainey 3054 [leave],
69 : mrainey 3063 [T.LIVE CCall.CCs.calleeSaveRegs],
70 : mrainey 3054 [T.RET []]
71 :     ])
72 :     end
73 :    
74 : mrainey 3049 end

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