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 16 - (view) (download)

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 :     fun cut_head(n,l as (a::r)) = if n=0 then l else cut_head(n-1, r)
40 :     | cut_head(_, []) = []
41 :    
42 :     fun isFlt CPS.FLTt = true | isFlt _ = false
43 :    
44 :     fun scan(t::z, gp, fp) =
45 :     if isFlt t then (hd fp)::(scan(z,gp,tl fp))
46 :     else (hd gp)::(scan(z,tl gp,fp))
47 :     | scan([], _, _) = []
48 :    
49 :     fun standardEscape args = let
50 :     val rest = cut_head(k+kf+3, args)
51 :     val len = length(args)
52 :     val gpr = stdarg :: gprfromto(k+4, len)
53 :     val fpr = fprfromto(kf,len)
54 :     in stdlink::stdclos::stdcont::calleesaveregs @ scan(rest,gpr,fpr)
55 :     end
56 :    
57 :     fun standardCont args = let
58 :     val rest = if k > 0 then cut_head(k+kf+1,args) else cut_head(2,args)
59 :     val len = length(args)
60 :     val gpr = stdarg::gprfromto(k+4, 1+len)
61 :     val fpr = fprfromto(kf,len)
62 :     in
63 :     if k > 0 then stdcont::(calleesaveregs @ scan(rest,gpr,fpr))
64 :     else stdlink::stdcont::scan(rest,gpr,fpr)
65 :     end
66 :    
67 :     fun standard(CPS.CNTt, tl) = standardCont tl
68 :     | standard(_, tl) = standardEscape tl
69 :    
70 :     (* known functions have parameters passed in fresh temporaries. *)
71 :     fun known(CPS.FLTt::rest) = T.FPR(T.FREG(Cells.newFreg())):: known rest
72 :     | known(_::rest) = T.GPR(T.REG(Cells.newReg())):: known rest
73 :     | known [] = []
74 :    
75 :     (* use an arbitary but fixed set of registers. *)
76 :     fun fixed ctys = let
77 :     fun iter(CPS.FLTt::rest, regs, f::fregs) = f::iter(rest, regs, fregs)
78 :     | iter(_::rest, r::regs, fregs) = r::iter(rest, regs, fregs)
79 :     | iter([], _, _) = []
80 :     in iter(ctys, gpregs, fpregs)
81 :     end
82 :     end
83 :    
84 :    
85 :     (*
86 :     * $Log: argPassing.sml,v $
87 :     * Revision 1.1.1.1 1997/01/14 01:38:33 george
88 :     * Version 109.24
89 :     *
90 :     *)

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