| 1 |
(* x86-64-gen.sml |
| 2 |
* |
| 3 |
* X86-64-specific portion of the interpreter. |
| 4 |
*) |
| 5 |
|
| 6 |
functor X86_64GenFn ( |
| 7 |
structure T : MLTREE |
| 8 |
val push : T.rexp -> T.stm |
| 9 |
val leave : T.stm |
| 10 |
) = struct |
| 11 |
|
| 12 |
structure T = T |
| 13 |
structure C = AMD64Cells |
| 14 |
structure CB = CellsBasis |
| 15 |
structure CTy = CType |
| 16 |
structure Gen = GenFn ( |
| 17 |
structure T = T |
| 18 |
val gprs = C.rax :: CCall.CCs.gprParamRegs |
| 19 |
val fprs = CCall.CCs.fprParamRegs |
| 20 |
val gprWidths = [8, 16, 32, 64] |
| 21 |
val fprWidths = [32, 64] |
| 22 |
val spReg = T.REG(64, C.rsp) |
| 23 |
val defaultWidth = 64 |
| 24 |
val callerSaves = CCall.callerSaveRegs |
| 25 |
val callerSavesF = CCall.callerSaveFRegs) |
| 26 |
|
| 27 |
(* default bit width *) |
| 28 |
val defTy = 64 |
| 29 |
val defSzB = defTy div 8 |
| 30 |
fun lit i = T.LI (T.I.fromInt (defTy, i)) |
| 31 |
|
| 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 |
| 42 |
List.concat [ |
| 43 |
(* preserve callee-save registers *) |
| 44 |
[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)), |
| 48 |
T.COPY (defTy, [C.rbp], [C.rsp])], |
| 49 |
[T.MV(defTy, argsReg, args)], |
| 50 |
Gen.gen {interpFunPtr=interpFunPtr, largsReg=largsReg, endOfLargs=endOfLargs}, |
| 51 |
[leave], |
| 52 |
[T.LIVE calleeSaveRegs], |
| 53 |
[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 |
| 69 |
|
| 70 |
end (* X86_64Gen *) |