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 /sml/trunk/src/compiler/CodeGen/cpscompile/argPassing.sml
ViewVC logotype

Annotation of /sml/trunk/src/compiler/CodeGen/cpscompile/argPassing.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 69 - (view) (download)
Original Path: sml/branches/SMLNJ/src/compiler/CodeGen/cpscompile/argPassing.sml

1 : monnier 16 (* argPassing.sml --- parameter passing convention for standard
2 :     * and known functions.
3 :     *
4 :     * COPYRIGHT (c) 1996 AT&T Bell Laboratories.
5 :     *
6 :     *)
7 :     functor ArgPassing (structure Cells : CELLS
8 :     structure C : CPSREGS
9 :     structure MS : MACH_SPEC) : ARG_PASSING =
10 :     struct
11 :     structure T : MLTREE = C.T
12 :    
13 :     fun error msg = ErrorMsg.impossible ("ArgPassing." ^ msg)
14 :    
15 :     val k = MS.numCalleeSaves
16 :     val kf = MS.numFloatCalleeSaves
17 :    
18 :     val stdlink = T.GPR C.stdlink
19 :     val stdclos = T.GPR C.stdclos
20 :     val stdarg = T.GPR C.stdarg
21 :     val stdcont = T.GPR C.stdcont
22 :    
23 :     val gpregs = stdlink::stdclos::stdarg::stdcont::map T.GPR C.miscregs
24 :     val fpregs = map T.FPR (C.savedfpregs @ C.floatregs)
25 :    
26 :     fun fromto(i, j, regs) = let
27 :     fun from(0, acc) = acc
28 :     | from(n, x::xs) = from(n-1, xs)
29 :     fun to(k, []) = []
30 :     | to(k, r::rs) = if k > j then [] else r::to(k+1, rs)
31 :     in
32 :     to(i, from(i,regs))
33 :     end
34 :    
35 :     fun gprfromto(i, j) = fromto(i, j, gpregs)
36 :     fun fprfromto(i, j) = fromto(i, j, fpregs)
37 :     val calleesaveregs = gprfromto(4, k+3) @ fprfromto(0, kf-1)
38 :    
39 : monnier 69 fun cut_head(n,l) =
40 :     if n = 0 then l
41 :     else (case l of a::r => cut_head(n-1,r)
42 :     | _ => error "codegen cuthead 444")
43 : monnier 16
44 :     fun isFlt CPS.FLTt = true | isFlt _ = false
45 :    
46 :     fun scan(t::z, gp, fp) =
47 :     if isFlt t then (hd fp)::(scan(z,gp,tl fp))
48 :     else (hd gp)::(scan(z,tl gp,fp))
49 :     | scan([], _, _) = []
50 :    
51 :     fun standardEscape args = let
52 :     val rest = cut_head(k+kf+3, args)
53 :     val len = length(args)
54 :     val gpr = stdarg :: gprfromto(k+4, len)
55 :     val fpr = fprfromto(kf,len)
56 :     in stdlink::stdclos::stdcont::calleesaveregs @ scan(rest,gpr,fpr)
57 :     end
58 :    
59 :     fun standardCont args = let
60 :     val rest = if k > 0 then cut_head(k+kf+1,args) else cut_head(2,args)
61 :     val len = length(args)
62 :     val gpr = stdarg::gprfromto(k+4, 1+len)
63 :     val fpr = fprfromto(kf,len)
64 :     in
65 :     if k > 0 then stdcont::(calleesaveregs @ scan(rest,gpr,fpr))
66 :     else stdlink::stdcont::scan(rest,gpr,fpr)
67 :     end
68 :    
69 :     fun standard(CPS.CNTt, tl) = standardCont tl
70 :     | standard(_, tl) = standardEscape tl
71 :    
72 :     (* known functions have parameters passed in fresh temporaries. *)
73 :     fun known(CPS.FLTt::rest) = T.FPR(T.FREG(Cells.newFreg())):: known rest
74 :     | known(_::rest) = T.GPR(T.REG(Cells.newReg())):: known rest
75 :     | known [] = []
76 :    
77 :     (* use an arbitary but fixed set of registers. *)
78 :     fun fixed ctys = let
79 :     fun iter(CPS.FLTt::rest, regs, f::fregs) = f::iter(rest, regs, fregs)
80 :     | iter(_::rest, r::regs, fregs) = r::iter(rest, regs, fregs)
81 :     | iter([], _, _) = []
82 :     in iter(ctys, gpregs, fpregs)
83 :     end
84 :     end
85 :    
86 :    
87 :     (*
88 :     * $Log: argPassing.sml,v $
89 :     * Revision 1.1.1.1 1997/01/14 01:38:33 george
90 :     * Version 109.24
91 :     *
92 :     *)

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