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

Diff of /MLRISC/trunk/c-call/gen/c-call-fn.sml

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

revision 3176, Thu Jul 31 22:38:49 2008 UTC revision 3177, Fri Aug 1 22:53:25 2008 UTC
# Line 65  Line 65 
65        | elimNarrow (SA.COMBINE(l1, l2)) = SA.COMBINE(elimNarrow l1, elimNarrow l2)        | elimNarrow (SA.COMBINE(l1, l2)) = SA.COMBINE(elimNarrow l1, elimNarrow l2)
66        | elimNarrow loc = loc        | elimNarrow loc = loc
67    
68      (* write argument data to a machine location      (* write a C argument (non aggregate) to a machine location
69       *   - arg is the argument data       *   - arg is the argument data
70       *   - i is an offset into the argument data (i.e., to access a member of a struct)       *   - off is an offset into the argument data
71       *   - loc is the machine location       *   - loc is the machine location
72       *   - stms is the accumulator of machine instructions       *   - stms is the accumulator of machine instructions
73       *)       *)
74      fun writeLoc arg (i, loc, stms) = (      fun writeLoc arg (off, loc, stms) = (
75            case (arg, loc)            case (arg, loc)
76             of (ARG (e as T.REG _), SA.BLOCK_OFFSET(w, (K.GPR | K.STK), offset)) =>             of (ARG (e as T.REG _), SA.BLOCK_OFFSET(w, (K.GPR | K.STK), offset)) =>
77                (* register to stack (gpr) *)                (* register to stack (gpr) *)
# Line 81  Line 81 
81                T.STORE(w, offSp offset, T.SX(w, w', e), stack) :: stms                T.STORE(w, offSp offset, T.SX(w, w', e), stack) :: stms
82              | (ARG (T.LOAD (ty, e, rgn)), SA.REG (w, K.GPR, r)) =>              | (ARG (T.LOAD (ty, e, rgn)), SA.REG (w, K.GPR, r)) =>
83                (* memory to register (gpr) *)                (* memory to register (gpr) *)
84                copyToReg(w, r, T.LOAD (ty, T.ADD(wordTy, e, lit (i*8)), rgn)) @ stms                copyToReg(w, r, T.LOAD (ty, T.ADD(wordTy, e, off), rgn)) @ stms
85              | (ARG (T.LOAD (ty, e, rgn)), SA.NARROW(SA.REG (w, K.GPR, r), w', K.GPR)) =>              | (ARG (T.LOAD (ty, e, rgn)), SA.NARROW(SA.REG (w, K.GPR, r), w', K.GPR)) =>
86                (* memory to register with conversion (gpr) *)                (* memory to register with conversion (gpr) *)
87                copyToReg(w, r, T.SX(w, w', T.LOAD (w', T.ADD(wordTy, e, lit (i*8)), rgn))) @ stms                copyToReg(w, r, T.SX(w, w', T.LOAD (w', T.ADD(wordTy, e, off), rgn))) @ stms
88              | (ARG (T.LOAD (ty, e, rgn)), SA.BLOCK_OFFSET(w, (K.GPR | K.STK), offset)) => let              | (ARG (T.LOAD (ty, e, rgn)), SA.BLOCK_OFFSET(w, (K.GPR | K.STK), offset)) => let
89                (* memory to stack (gpr) *)                (* memory to stack (gpr) *)
90                  val tmp = C.newReg ()                  val tmp = C.newReg ()
91                  in                  in
92                    T.STORE (ty, offSp offset, T.REG (ty, tmp), stack) ::                    T.STORE (ty, offSp offset, T.REG (ty, tmp), stack) ::
93                    T.MV (ty, tmp, T.LOAD (ty, T.ADD(wordTy, e, lit (i*8)), rgn)) :: stms                    T.MV (ty, tmp, T.LOAD (ty, T.ADD(wordTy, e, off), rgn)) :: stms
94                  end                  end
95              | (ARG (T.LOAD (ty, e, rgn)), SA.NARROW(SA.BLOCK_OFFSET(w, (K.GPR | K.STK), offset), w', K.GPR)) => let              | (ARG (T.LOAD (ty, e, rgn)), SA.NARROW(SA.BLOCK_OFFSET(w, (K.GPR | K.STK), offset), w', K.GPR)) => let
96                (* memory to stack with conversion (gpr) *)                (* memory to stack with conversion (gpr) *)
97                  val tmp = C.newReg ()                  val tmp = C.newReg ()
98                  in                  in
99                    T.STORE (w, offSp offset, T.REG (w, tmp), stack) ::                    T.STORE (w, offSp offset, T.REG (w, tmp), stack) ::
100                    T.MV (w, tmp, T.SX(w, w', T.LOAD (w', T.ADD(wordTy, e, lit (i*8)), rgn))) :: stms                    T.MV (w, tmp, T.SX(w, w', T.LOAD (w', T.ADD(wordTy, e, off), rgn))) :: stms
101                  end                  end
102              | (ARG e, SA.BLOCK_OFFSET(w, (K.GPR | K.STK), offset)) => let              | (ARG e, SA.BLOCK_OFFSET(w, (K.GPR | K.STK), offset)) => let
103                (* expression to stack (gpr) *)                (* expression to stack (gpr) *)
# Line 116  Line 116 
116                T.FSTORE (w, offSp offset, e, stack) :: stms                T.FSTORE (w, offSp offset, e, stack) :: stms
117              | (ARG (T.LOAD (ty, e, rgn)), SA.REG(w, K.FPR, r)) =>              | (ARG (T.LOAD (ty, e, rgn)), SA.REG(w, K.FPR, r)) =>
118                (* memory to register (fpr) *)                (* memory to register (fpr) *)
119                copyToFReg(w, r, T.FLOAD (ty, T.ADD(wordTy, e, lit (i*8)), rgn)) @ stms                copyToFReg(w, r, T.FLOAD (ty, T.ADD(wordTy, e, off), rgn)) @ stms
120              | (FARG (T.FLOAD (ty, e, rgn)), SA.BLOCK_OFFSET(w, (K.FPR | K.FSTK), offset)) => let              | (FARG (T.FLOAD (ty, e, rgn)), SA.BLOCK_OFFSET(w, (K.FPR | K.FSTK), offset)) => let
121                (* memory to stack (fpr) *)                (* memory to stack (fpr) *)
122                  val tmp = C.newFreg ()                  val tmp = C.newFreg ()
123                  in                  in
124                    T.FSTORE (w, offSp offset, T.FREG (w, tmp), stack) ::                    T.FSTORE (w, offSp offset, T.FREG (w, tmp), stack) ::
125                    T.FMV (w, tmp, T.FLOAD (ty, T.ADD(wordTy, e, lit (i*8)), rgn)) :: stms                    T.FMV (w, tmp, T.FLOAD (ty, T.ADD(wordTy, e, off), rgn)) :: stms
126                  end                  end
127              | (FARG e, SA.BLOCK_OFFSET(w, (K.FPR | K.FSTK), offset)) => let              | (FARG e, SA.BLOCK_OFFSET(w, (K.FPR | K.FSTK), offset)) => let
128                (* expression to stack (fpr) *)                (* expression to stack (fpr) *)
# Line 136  Line 136 
136              | _ => raise Fail "invalid arg / loc pair"              | _ => raise Fail "invalid arg / loc pair"
137            (* end case *))            (* end case *))
138    
139    (* write a C argument to some parameter locations *)    (* write a C argument (possibly an aggregate) to some parameter locations *)
140      fun writeLocs' (arg, locs, stms) = let      fun writeLocs' (arg, locs, stms) = let
141            val locs = List.map elimNarrow locs            val locs = List.map elimNarrow locs
142            (* offsets of the members of the struct *)
143              val membOffs = List.tabulate(List.length locs, fn i => lit(i*8))
144            in            in
145               ListPair.foldl (writeLoc arg) stms (List.tabulate(List.length locs, fn i => i), locs)               ListPair.foldl (writeLoc arg) stms (membOffs, locs)
146            end            end
147    
148    (* write C arguments to parameter locations; also return any used GPRs or FPRs *)    (* write C arguments to parameter locations; also return any used GPRs or FPRs *)

Legend:
Removed from v.3176  
changed lines
  Added in v.3177

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