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/c-call/varargs/interp/x86-64-gen-fn.sml
ViewVC logotype

Diff of /MLRISC/trunk/c-call/varargs/interp/x86-64-gen-fn.sml

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

MLRISC/trunk/c-call/varargs/interp/x86-64-gen-interp-fn.sml revision 3213, Fri Aug 15 18:53:13 2008 UTC MLRISC/trunk/c-call/varargs/interp/x86-64-gen-fn.sml revision 3217, Mon Aug 18 21:17:43 2008 UTC
# Line 1  Line 1 
1  (* amd64-vararg-ccall-fn.sml  (* x86-64-gen.sml
2   *   *
3   * C calling conventions for the AMD64. We use the technique of Staged Allocation (see   * X86-64-specific portion of the interpreter.
  * MLRISC/staged-allocation).  
  *  
  * Mike Rainey (mrainey@cs.uchicago.edu)  
4   *)   *)
5    
6  functor AMD64GenInterpFn (  functor X86_64Gen (
7      structure T : MLTREE      structure T : MLTREE
8      val push : T.rexp -> T.stm      val push : T.rexp -> T.stm
9      val leave : T.stm      val leave : T.stm
# Line 16  Line 13 
13      structure C = AMD64Cells      structure C = AMD64Cells
14      structure CB = CellsBasis      structure CB = CellsBasis
15      structure CTy = CType      structure CTy = CType
16      structure CCall = AMD64SVIDFn(structure T = T)      structure Gen = GenFn (
     structure GenInterp = GenInterpFn(  
17                                structure T = T                                structure T = T
18                                val callerSaveRegs = CCall.callerSaveRegs          val gprs = C.rax :: CCall.CCs.gprParamRegs
19                                val callerSaveFRegs = CCall.callerSaveFRegs          val fprs = CCall.CCs.fprParamRegs
20                                val gprParams = C.rax :: CCall.CCs.gprParamRegs          val gprWidths = [8, 16, 32, 64]
21                                val fprParams = CCall.CCs.fprParamRegs          val fprWidths = [32, 64]
22                                val gprTys = [32, 64]          val spReg = T.REG(64, C.rsp)
23                                val fprTys = [32, 64]          val defaultWidth = 64
24                                val spReg = CCall.spReg          val callerSaves = CCall.callerSaveRegs
25                                val wordTy = 64          val callerSavesF = CCall.callerSaveFRegs)
26                              )  
27      (* default bit width *)
28      val wordTy = 64      val defTy = 64
29      fun lit i = T.LI (T.I.fromInt (wordTy, i))      val defSzB = defTy div 8
30        fun lit i = T.LI (T.I.fromInt (defTy, i))
31      fun callWithArgs (cFun, args) = let  
32      (* get the ith argument in the calling sequence *)
33        fun getArg i = T.REG(64, List.nth(CCall.CCs.gprParamRegs, i))
34    
35      (* MLRISC code for the x86 64 vararg interpreter *)
36        fun gen () = let
37               val largsReg = C.newReg()
38               val frameSzB = 1024*4-2*4
39               val interpFunPtr = getArg 0
40               val endOfLargs = getArg 2
41             in             in
               raise Fail "jump to the interpreter"  
            end  
   
     fun genVarargs () = let  
            val lab = Label.global "varargs"  
          (* arg0 *)  
            val cFun = T.REG(wordTy, C.rdi)  
            val argsReg = C.newReg()  
          (* arg1 *)  
            val args = T.REG(wordTy, C.rsi)  
          (* arg2 *)  
            val endOfArgs = T.REG(wordTy, C.rdx)  
            in  
                (lab,  
42                  List.concat [                  List.concat [
43                   (* the abi specifies that rax contains the number of floating-point arguments *)                (* preserve callee-save registers *)
44                     [T.MV(wordTy, C.rax, lit (List.length CCall.CCs.fprParamRegs))],                  [T.LIVE calleeSaveRegs],
45                  (* the abi specifies that rax contains *at least* the number of floating-point arguments *)
46                    [T.MV(defTy, C.rax, lit (List.length CCall.CCs.fprParamRegs))],
47                     [push (T.REG(64, C.rbp)),                     [push (T.REG(64, C.rbp)),
48                      T.COPY (wordTy, [C.rbp], [C.rsp])],                   T.COPY (defTy, [C.rbp], [C.rsp])],
49                     [T.MV(wordTy, argsReg, args)],                  [T.MV(defTy, argsReg, args)],
50                     GenInterp.genVarargs(cFun, argsReg, endOfArgs),                  Gen.gen {interpFunPtr=interpFunPtr, largsReg=largsReg, endOfLargs=endOfLargs},
51                     [leave],                     [leave],
52                    [T.LIVE calleeSaveRegs],
53                     [T.RET []]                     [T.RET []]
54                     ])                ]
55               end
56    
57        fun main (cmd, args) = let
58               val _ = Label.reset()
59               val lab = Label.global Consts.varargInterpreter
60               val stms = gen()
61               val asmOutStrm = TextIO.openOut "vararg-interp-x86-64.s"
62               val _ = TextIO.output(asmOutStrm, Consts.header^"\n")
63               fun doit () = X86MLRISCGen.dumpOutput(X86MLRISCGen.codegen'(lab, stms, [T.GPR (T.REG (defTy, C.rax))]))
64               val _ = AsmStream.withStream asmOutStrm doit ()
65               val _ = TextIO.closeOut asmOutStrm
66               in
67                  0
68             end             end
69    
70    end (* AMD64VarargCCallFn *)    end (* X86_64Gen *)

Legend:
Removed from v.3213  
changed lines
  Added in v.3217

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