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/mkRecord.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 168 - (view) (download)

1 : monnier 16 (* mk-record.sml --- translate a CPS.RECORD to MLRISC
2 :     *
3 :     * COPYRIGHT (c) 1996 AT&T Bell Laboratories.
4 :     *
5 :     *)
6 :    
7 :     (* TODO:
8 :     * Some CPS.RECORDs can be created using a tight loop implementing
9 :     * a block copy.
10 :     *)
11 :    
12 :     functor MkRecord
13 :     (structure C: CPSREGS where T.Region = CPSRegions
14 : monnier 167 structure MLTreeComp : MLTREECOMP where T = C.T
15 :     (* DBM: sharing/defn conflict ---
16 :     sharing C.T = MLTreeComp.T
17 :     *)
18 :     ) : MK_RECORD =
19 : monnier 16 struct
20 :     structure T : MLTREE = C.T
21 :     structure R = CPSRegions
22 :    
23 :     fun error msg = ErrorMsg.impossible ("MkRecord." ^ msg)
24 :    
25 :     val emit = MLTreeComp.mlriscComp
26 :    
27 :     val dummyRegion = (R.RVAR 0, R.RO_MEM, CPS.OFFp 0)
28 :    
29 :     val T.REG allocptrR = C.allocptr
30 :    
31 :     fun ea(r, 0) = r
32 :     | ea(r, n) = T.ADD(r, T.LI(n))
33 :    
34 :     fun indexEA(r, 0) = r
35 :     | indexEA(r, n) = T.ADD(r, T.LI(n*4))
36 :    
37 :     fun record {desc, fields, ans, mem, hp} = let
38 :     val descRegion::regions =
39 :     case mem
40 :     of R.RO_MEM => dummyRegion:: map (fn _ => dummyRegion) fields
41 :     | R.RECORD vl => vl
42 :    
43 :     fun getfield(r, CPS.SELp(n, p), R.RO_MEM) =
44 :     getfield(T.LOAD32(indexEA(r, n), R.RO_MEM), p, R.RO_MEM)
45 :     | getfield(r, CPS.SELp(n, p), R.RECORD vl) = let
46 :     val (def, root, ap) = List.nth(vl, n+1)
47 :     in getfield(T.LOAD32(indexEA(r, n), def), p, R.trace(root, ap))
48 :     end
49 :     | getfield(r, CPS.SELp(n, p), R.OFFSET(i, vl)) = let
50 :     val (def, root, ap) = List.nth(vl, n+i+1)
51 :     in getfield(T.LOAD32(indexEA(r, n), def), p, R.trace(root, ap))
52 :     end
53 :     | getfield(r, CPS.OFFp 0, _) = r
54 :     | getfield(r, CPS.OFFp n, _) = T.ADD(r, T.LI(n*4))
55 :    
56 :     fun storeFields ([], _, []) = ()
57 :     | storeFields ((v, p)::rest, n, (def, root, _)::regions) =
58 :     (emit(T.STORE32(T.ADD(C.allocptr, T.LI n), getfield(v,p,root), def));
59 :     storeFields(rest, n + 4, regions))
60 :     in
61 :     emit(T.STORE32(ea(C.allocptr, hp), desc, #1 descRegion));
62 :     storeFields(fields, hp+4, regions);
63 :     emit(T.MV(ans, T.ADD(C.allocptr, T.LI(hp+4))))
64 :     end
65 :    
66 :     fun frecord {desc, fields, ans, mem, hp} = let
67 :     val descRegion::regions =
68 :     case mem
69 :     of R.RO_MEM => dummyRegion:: map (fn _ => dummyRegion) fields
70 :     | R.RECORD vl => vl
71 :    
72 :     fun fgetfield(T.FPR fp, CPS.OFFp 0, _) = fp
73 :     | fgetfield(T.GPR r, path, mem) = let
74 :     fun fea(r, 0) = r
75 :     | fea(r, n) = T.ADD(r, T.LI(n*8))
76 :    
77 :     fun chase(r, CPS.SELp(n, CPS.OFFp 0), R.RO_MEM) =
78 :     T.LOADD(fea(r,n), R.RO_MEM)
79 :     | chase(r, CPS.SELp(n, CPS.OFFp 0), R.RECORD vl) = let
80 :     val (def, _, _) = List.nth(vl, n+1)
81 :     in T.LOADD(fea(r, n), def)
82 :     end
83 :     | chase(r, CPS.SELp(n, CPS.OFFp 0), R.OFFSET(i, vl)) = let
84 :     val (def, _, _) = List.nth(vl, n+i+1)
85 :     in T.LOADD(fea(r, n), def)
86 :     end
87 :     | chase(r, CPS.SELp(n,p), R.RO_MEM) =
88 :     chase(T.LOAD32(indexEA(r, n), R.RO_MEM), p, R.RO_MEM)
89 :     | chase(r, CPS.SELp(j,p), R.RECORD vl) = let
90 :     val (def, root, ap) = List.nth(vl, j+1)
91 :     in chase(T.LOAD32(indexEA(r,j), def), p, R.trace(root, ap))
92 :     end
93 :     | chase(r, CPS.SELp(j,p), R.OFFSET(i, vl)) = let
94 :     val (def, root, ap) = List.nth(vl, i+j+1)
95 :     in chase(T.LOAD32(indexEA(r,j), def), p, R.trace(root, ap))
96 :     end
97 :     in chase(r, path, mem)
98 :     end
99 :    
100 :     fun fstoreFields ([], _, []) = ()
101 :     | fstoreFields ((v, p)::rest, n, (def, root, _)::regions) =
102 :     (emit(T.STORED(T.ADD(C.allocptr, T.LI n), fgetfield(v,p,root), def));
103 :     fstoreFields(rest, n + 8, regions))
104 :     in
105 :     emit(T.STORE32(ea(C.allocptr, hp), desc, #1 descRegion));
106 :     fstoreFields(fields, hp+4, regions);
107 :     emit(T.MV(ans, T.ADD(C.allocptr, T.LI(hp+4))))
108 :     end
109 :     end
110 :    
111 :     (*
112 : monnier 167 * $Log: mkRecord.sml,v $
113 :     * Revision 1.1.1.1 1998/04/08 18:39:54 george
114 :     * Version 110.5
115 :     *
116 : monnier 16 *)

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