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

SCM Repository

[smlnj] Diff of /MLRISC/trunk/staged-allocation/vararg-c-call-fn.sml
ViewVC logotype

Diff of /MLRISC/trunk/staged-allocation/vararg-c-call-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3050, Fri May 30 05:11:56 2008 UTC revision 3051, Fri May 30 06:29:06 2008 UTC
# Line 23  Line 23 
23    
24      datatype argument = I of int | R of real | B of bool | S of string      datatype argument = I of int | R of real | B of bool | S of string
25    
     fun argToCTy (I _) = CTy.C_signed CTy.I_int  
       | argToCTy (R _) = CTy.C_double  
       | argToCTy (B _) = CTy.C_signed CTy.I_int  
       | argToCTy (S _) = CTy.C_PTR  
   
     val wordSzB = wordTy div 8  
26      val mem = T.Region.memory      val mem = T.Region.memory
27      val stack = T.Region.stack      val stack = T.Region.stack
28    
# Line 39  Line 33 
33      val GPR = 0      val GPR = 0
34      val FPR = 1      val FPR = 1
35      val STK = 2      val STK = 2
36        val FSTK = 3
37    
38      val intTy = wordTy      val intTy = wordTy
39        val maxArgSzB = 8
40    
41    (* offsets into the triplet *)    (* offsets into the triplet *)
42      val argOff = 0      val argOff = 0
43      val kindOff = 1      val kindOff = 1
44      val locOff = 2      val locOff = 2
45    
46      fun offTrip (arg, off) = T.LOAD(wordTy, T.ADD(wordTy, arg, lit (off*wordSzB)), mem)      fun offTrip (arg, off) = T.LOAD(wordTy, T.ADD(wordTy, arg, lit (off*maxArgSzB)), mem)
47      fun offTripF (arg, off) = T.FLOAD(64, T.ADD(wordTy, arg, lit (off*wordSzB)), mem)      fun offTripF (arg, off) = T.FLOAD(64, T.ADD(wordTy, arg, lit (off*maxArgSzB)), mem)
48    
49      val regToInt = CB.physicalRegisterNum      val regToInt = CB.physicalRegisterNum
50      fun labelOfReg (k, r) = Label.global ("put"^k^Int.toString (regToInt r))      fun labelOfReg (k, r) = Label.global ("put"^k^Int.toString (regToInt r))
# Line 56  Line 52 
52      val interpLab = Label.global "interp"      val interpLab = Label.global "interp"
53      fun chooseRegsLab k = Label.global ("chooseRegs"^k)      fun chooseRegsLab k = Label.global ("chooseRegs"^k)
54      val chooseStkLab = Label.global "chooseStk"      val chooseStkLab = Label.global "chooseStk"
55        val chooseFStkLab = Label.global "chooseFStk"
56      val chooseKindsLab = Label.global "chooseKinds"      val chooseKindsLab = Label.global "chooseKinds"
57    
58    (* store the argument at the stack offset *)    (* store the argument at the stack offset *)
# Line 65  Line 62 
62             T.JMP (T.LABEL interpLab, [])             T.JMP (T.LABEL interpLab, [])
63          ]          ]
64    
65      (* store the argument at the stack offset *)
66        fun genStoreFStk arg = [
67               T.DEFINE chooseFStkLab,
68               T.FSTORE(64, T.ADD (wordTy, spReg, offTrip(arg, locOff)), offTripF(arg, argOff), mem),
69               T.JMP (T.LABEL interpLab, [])
70            ]
71    
72    (* place the argument into the parameter register and jump back to the interpreter *)    (* place the argument into the parameter register and jump back to the interpreter *)
73      fun genPutGpr arg r = [      fun genPutGpr arg r = [
74             T.DEFINE (labelOfReg ("gpr", r)),             T.DEFINE (labelOfReg ("gpr", r)),
# Line 98  Line 102 
102             T.DEFINE chooseKindsLab,             T.DEFINE chooseKindsLab,
103             T.BCC(T.CMP(wordTy, T.EQ, offTrip(arg, kindOff), lit GPR), chooseRegsLab "gpr"),             T.BCC(T.CMP(wordTy, T.EQ, offTrip(arg, kindOff), lit GPR), chooseRegsLab "gpr"),
104             T.BCC(T.CMP(wordTy, T.EQ, offTrip(arg, kindOff), lit FPR), chooseRegsLab "fpr"),             T.BCC(T.CMP(wordTy, T.EQ, offTrip(arg, kindOff), lit FPR), chooseRegsLab "fpr"),
105             T.BCC(T.CMP(wordTy, T.EQ, offTrip(arg, kindOff), lit STK), chooseStkLab)             T.BCC(T.CMP(wordTy, T.EQ, offTrip(arg, kindOff), lit STK), chooseStkLab),
106               T.BCC(T.CMP(wordTy, T.EQ, offTrip(arg, kindOff), lit FSTK), chooseFStkLab)
107          ]          ]
108    
109      val NIL = 0      val NIL = 0
# Line 140  Line 145 
145             val loadGprs = List.concat (List.map (genPutGpr arg) gprParams)             val loadGprs = List.concat (List.map (genPutGpr arg) gprParams)
146             val loadFprs = List.concat (List.map (genPutFpr arg) fprParams)             val loadFprs = List.concat (List.map (genPutFpr arg) fprParams)
147             val storeStk = genStoreStk arg             val storeStk = genStoreStk arg
148               val storeFStk = genStoreFStk arg
149             in             in
150                List.concat [                List.concat [
151                   interpInstrs,                   interpInstrs,
# Line 149  Line 155 
155                   loadGprs,                   loadGprs,
156                   loadFprs,                   loadFprs,
157                   storeStk,                   storeStk,
158                     storeFStk,
159                   genCallC cFun                   genCallC cFun
160                ]                ]
161             end             end
162    
163        val regToInt = CB.physicalRegisterNum
164    
165        fun argToCTy (I _) = CTy.C_signed CTy.I_int
166          | argToCTy (R _) = CTy.C_double
167          | argToCTy (B _) = CTy.C_signed CTy.I_int
168          | argToCTy (S _) = CTy.C_PTR
169    
170      (* runtime friendly representation of the C location *)
171        fun encodeCLoc (CCall.C_GPR (ty, r)) = (GPR, regToInt r)
172          | encodeCLoc (CCall.C_FPR (ty, r)) = (FPR, regToInt r)
173          | encodeCLoc (CCall.C_STK (ty, off)) = (STK, T.I.toInt (wordTy, off))
174          | encodeCLoc (CCall.C_FSTK (ty, off)) = (FSTK, T.I.toInt (wordTy, off))
175    
176      (* takes a vararg and a location and returns the vararg triplet *)
177        fun varArgTriplet (arg, loc) = let
178               val (k, l) = encodeCLoc loc
179               in
180                 (arg, k, l)
181               end
182    
183       (* package the arguments with their locations *)
184        fun encodeArgs args = let
185                val argTys = List.map argToCTy args
186                val {argLocs, ...} = CCall.layout {conv="c-call", retTy=CTy.C_void, paramTys=argTys}
187              (* expect single locations, as we do not pass aggregates to vararg functions *)
188                val argLocs = List.map List.hd argLocs
189                in
190                    ListPair.mapEq varArgTriplet (args, List.rev argLocs)
191                end
192    
193    end (* AMD64VarargCCallFn *)    end (* AMD64VarargCCallFn *)

Legend:
Removed from v.3050  
changed lines
  Added in v.3051

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