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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3049 - (view) (download)

1 : mrainey 3039 (* amd64-vararg-ccall-fn.sml
2 :     *
3 :     * C calling conventions for the AMD64. We use the technique of Staged Allocation (see
4 :     * MLRISC/staged-allocation).
5 :     *
6 :     * Mike Rainey (mrainey@cs.uchicago.edu)
7 :     *)
8 :    
9 :     functor AMD64VarargCCallFn (
10 :     structure T : MLTREE
11 :     ) = struct
12 :    
13 :     structure T = T
14 :     structure C = AMD64Cells
15 :     structure CB = CellsBasis
16 :     structure CTy = CTypes
17 : mrainey 3042 structure SVID = AMD64SVIDFn(structure T = T)
18 : mrainey 3049 structure VarargCCall = VarargCCallFn(
19 :     structure T = T
20 :     structure CCall = SVID
21 :     val gprParams = List.map #2 SVID.CCs.gprParams
22 :     val fprParams = List.map #2 SVID.CCs.fprParams
23 :     val spReg = SVID.spReg
24 :     val wordTy = 64
25 :     val newReg = C.newReg
26 :     )
27 : mrainey 3039 structure SA = SVID.SA
28 :    
29 :     val wordTy = 64
30 :     fun lit i = T.LI (T.I.fromInt (wordTy, i))
31 : mrainey 3042 val regToInt = CB.physicalRegisterNum
32 :    
33 : mrainey 3039 (* one step of staged allocation *)
34 :     fun allocateArg step (arg, (str, locs)) = let
35 : mrainey 3049 val slot = SVID.slotOfCTy(VarargCCall.argToCTy arg)
36 : mrainey 3039 val (str', [loc]) = SA.doStagedAllocation(str, step, [slot])
37 :     in
38 :     (str', loc :: locs)
39 :     end
40 :    
41 : mrainey 3049 fun encodeLoc (_, SA.REG (_, r), SVID.K_GPR) = (VarargCCall.GPR, regToInt r)
42 :     | encodeLoc (_, SA.REG (_, r), SVID.K_FPR) = (VarargCCall.FPR, regToInt r)
43 :     | encodeLoc (_, SA.BLOCK_OFFSET offB, SVID.K_GPR) = (VarargCCall.STK, offB)
44 :     | encodeLoc (_, SA.BLOCK_OFFSET offB, SVID.K_FPR) = (VarargCCall.STK, offB)
45 : mrainey 3042 | encodeLoc (_, SA.NARROW (loc, w', k), _) = encodeLoc (w', loc, k)
46 : mrainey 3039
47 :     (* takes a vararg and a location and returns the vararg triplet *)
48 :     fun varArgTriplet (arg, loc) = let
49 :     val (k, l) = encodeLoc loc
50 :     in
51 :     (arg, k, l)
52 :     end
53 :    
54 :     (* takes a list of varargs and returns vararg triplets *)
55 :     fun encodeArgs args = let
56 :     val step = SA.mkStep SVID.CCs.callStages
57 :     val (str, locs) = List.foldl (allocateArg step) (SVID.CCs.str0, []) args
58 :     in
59 :     ListPair.mapEq varArgTriplet (args, List.rev locs)
60 :     end
61 :    
62 :     fun callWithArgs (cFun, args) = let
63 :     val triplets = encodeArgs args
64 :     in
65 :     raise Fail "jump to the interpreter"
66 :     end
67 :    
68 : mrainey 3049 fun genVarargs (cFun, args) =
69 :     T.MV(wordTy, C.rax, lit (List.length SVID.CCs.fprParams)) :: VarargCCall.genVarargs(cFun, args)
70 :    
71 : mrainey 3039 end (* AMD64VarargCCallFn *)

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