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 3039 - (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 :     structure SVID = SVIDFn(structure T = T)
18 :     structure CCall = SVID.CCall
19 :     structure SA = SVID.SA
20 :    
21 :     datatype argument = I of int | R of real | B of bool | S of string
22 :    
23 :     val wordTy = 64
24 :     val mem = T.Region.memory
25 :     val stack = T.Region.stack
26 :    
27 :     fun lit i = T.LI (T.I.fromInt (wordTy, i))
28 :    
29 :     val GPR = 0
30 :     val FPR = 1
31 :     val STK = 2
32 :    
33 :     fun argToCTy (I _) = CTy.C_signed CTy.I_int
34 :     | argToCTy (R _) = CTy.C_double
35 :     | argToCTy (B _) = CTy.C_signed CTy.I_int
36 :     | argToCTy (S _) = CTy.C_PTR
37 :    
38 :     (* one step of staged allocation *)
39 :     fun allocateArg step (arg, (str, locs)) = let
40 :     val slot = SVID.slotOfCTy(argToCTy arg)
41 :     val (str', [loc]) = SA.doStagedAllocation(str, step, [slot])
42 :     in
43 :     (str', loc :: locs)
44 :     end
45 :    
46 :     fun encodeLoc (_, SA.REG (_, r), SVID.K_GPR) = (GPR, CB.physicalRegisterNum r)
47 :     | encodeLoc (_, SA.REG (_, r), SVID.K_FPR) = (FPR, CB.physicalRegisterNum r)
48 :     | encodeLoc (_, SA.BLOCK_OFFSET offB, SVID.K_GPR) = (STK, offB)
49 :     | encodeLoc (_, SA.BLOCK_OFFSET offB, SVID.K_FPR) = (STK, offB)
50 :    
51 :     (* takes a vararg and a location and returns the vararg triplet *)
52 :     fun varArgTriplet (arg, loc) = let
53 :     val (k, l) = encodeLoc loc
54 :     in
55 :     (arg, k, l)
56 :     end
57 :    
58 :     (* takes a list of varargs and returns vararg triplets *)
59 :     fun encodeArgs args = let
60 :     val step = SA.mkStep SVID.CCs.callStages
61 :     val (str, locs) = List.foldl (allocateArg step) (SVID.CCs.str0, []) args
62 :     in
63 :     ListPair.mapEq varArgTriplet (args, List.rev locs)
64 :     end
65 :    
66 :     fun callWithArgs (cFun, args) = let
67 :     val triplets = encodeArgs args
68 :     in
69 :     raise Fail "jump to the interpreter"
70 :     end
71 :    
72 :     end (* AMD64VarargCCallFn *)

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