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 /sml/trunk/src/MLRISC/ppc/c-calls/ppc-macosx.sml
ViewVC logotype

Diff of /sml/trunk/src/MLRISC/ppc/c-calls/ppc-macosx.sml

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

revision 1437, Tue Jan 6 17:00:20 2004 UTC revision 1438, Mon Jan 12 03:12:20 2004 UTC
# Line 47  Line 47 
47   *    Function arguments:   *    Function arguments:
48   *      * arguments (except for floating-point values) are passed in   *      * arguments (except for floating-point values) are passed in
49   *        registers GPR3-GPR10   *        registers GPR3-GPR10
50     *
51     * Note also that stack frames are supposed to be 16-byte aligned.
52   *)   *)
53    
54  (* we extend the interface to support generating the stubs needed for  (* we extend the interface to support generating the stubs needed for
# Line 56  Line 58 
58  signature PPC_MACOSX_C_CALLS =  signature PPC_MACOSX_C_CALLS =
59    sig    sig
60      include C_CALLS      include C_CALLS
61    
62    (*
63        val genStub : {
64                name  : T.rexp,
65                proto : CTypes.c_proto,
66                paramAlloc : {szb : int, align : int} -> bool,
67                structRet : {szb : int, align : int} -> T.rexp,
68                saveRestoreDedicated :
69                  T.mlrisc list -> {save: T.stm list, restore: T.stm list},
70                callComment : string option,
71                args : c_arg list
72              } -> {
73                callseq : T.stm list,
74                result: T.mlrisc list
75              }
76    *)
77    
78    end;    end;
79    
80  functor PPCMacOSX_CCalls (  functor PPCMacOSX_CCalls (
# Line 111  Line 130 
130        | addli (x, d) = let        | addli (x, d) = let
131              val d' = T.I.fromInt (32, d)              val d' = T.I.fromInt (32, d)
132          in          in
133              case x of              case x
134                  T.ADD (_, r, T.LI d) =>               of T.ADD (_, r, T.LI d) =>
135                  T.ADD (32, r, T.LI (T.I.ADD (32, d, d')))                  T.ADD (32, r, T.LI (T.I.ADD (32, d, d')))
136                | _ => T.ADD (32, x, T.LI d')                | _ => T.ADD (32, x, T.LI d')
137          end          end
# Line 124  Line 143 
143    
144      fun roundup (i, a) = a * ((i + a - 1) div a)      fun roundup (i, a) = a * ((i + a - 1) div a)
145    
146        fun intSizeAndAlign Ty.I_char = (1, 1)
147          | intSizeAndAlign Ty.I_short = (2, 2)
148          | intSizeAndAlign Ty.I_int = (4, 4)
149          | intSizeAndAlign Ty.I_long = (4, 4)
150          | intSizeAndAlign Ty.I_long_long = (8, 8)
151    
152      (* calculate size and alignment for a C type *)      (* calculate size and alignment for a C type *)
153      fun szal (Ty.C_void | Ty.C_float | Ty.C_PTR |      fun szal (T.C_unsigned ty) = intSizeAndAlign ty
154                Ty.C_signed (Ty.I_int | Ty.I_long) |        | szal (T.C_signed ty) = intSizeAndAlign ty
155                Ty.C_unsigned (Ty.I_int | Ty.I_long)) = (4, 4)        | szal Ty.C_void = raise Fail "unexpected void type"
156        | szal (Ty.C_double |        | szal Ty.C_float = (4, 4)
157                Ty.C_signed Ty.I_long_long |        | szal Ty.C_PTR = (4, 4)
158                Ty.C_unsigned Ty.I_long_long) = (8, 8)        | szal Ty.C_double = (8, 8)
159        | szal (Ty.C_long_double) = (16, 8)        | szal (Ty.C_long_double) = (8, 8)
       | szal (Ty.C_signed Ty.I_char | Ty.C_unsigned Ty.I_char) = (1, 1)  
       | szal (Ty.C_signed Ty.I_short | Ty.C_unsigned Ty.I_short) = (2, 2)  
160        | szal (Ty.C_ARRAY (t, n)) = let val (s, a) = szal t in (n * s, a) end        | szal (Ty.C_ARRAY (t, n)) = let val (s, a) = szal t in (n * s, a) end
161        | szal (Ty.C_STRUCT l) =        | szal (Ty.C_STRUCT l) = let
162          let (* i: next free memory address (relative to struct start);  (* FIXME: the rules for structs are more complicated (and they also depend
163     * on the alignment mode).  In Power alignment, 8-byte quantites like
164     * long long and double are 4-byte aligned in structs.
165     *)
166            (* i: next free memory address (relative to struct start);
167               * a: current total alignment,               * a: current total alignment,
168               * l: list of struct member types *)           * l: list of struct member types
169             *)
170              fun pack (i, a, []) =              fun pack (i, a, []) =
171                  (* when we are done with all elements, the total size                  (* when we are done with all elements, the total size
172                   * of the struct must be padded out to its own alignment *)               * of the struct must be padded out to its own alignment
173                 *)
174                  (roundup (i, a), a)                  (roundup (i, a), a)
175                | pack (i, a, t :: tl) = let                | pack (i, a, t :: tl) = let
176                      val (ts, ta) = szal t (* size and alignment for member *)                      val (ts, ta) = szal t (* size and alignment for member *)

Legend:
Removed from v.1437  
changed lines
  Added in v.1438

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