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/compiler/ElabData/prim/primop.sig
 [smlnj] / sml / trunk / compiler / ElabData / prim / primop.sig

# Diff of /sml/trunk/compiler/ElabData/prim/primop.sig

sml/trunk/compiler/FLINT/kernel/primop.sig revision 2162, Thu Nov 2 21:20:47 2006 UTC sml/trunk/compiler/ElabData/prim/primop.sig revision 4804, Wed Sep 12 19:08:32 2018 UTC
# Line 1  Line 1
1  (* Copyright 1996 by AT&T Bell Laboratories *)  (* primop.sig
2  (* primop.sig *)   *
3     * COPYRIGHT (c) 2017 The Fellowship of SML/NJ (http://www.smlnj.org)
5     *)
6
7  (*********************************************************************  (*********************************************************************
8                     Integer/Word Conversions Explained                     Integer/Word Conversions Explained
# Line 118  Line 121
121  can be eliminated.  can be eliminated.
122  *********************************************************************)  *********************************************************************)
123
124  signature PRIM_OP =  signature PRIMOP =
125  sig  sig
126
127  (* numkind includes kind and number of bits *)  (* numkind includes kind and number of bits *)
# Line 126  Line 129
129    = INT of int    = INT of int
130    | UINT of int    | UINT of int
131    | FLOAT of int    | FLOAT of int
132    (* QUESTION: what about IntInf.int? *)
133
134  datatype arithop  datatype arithop
135    = + | - | * | / | ~                           (* int or float *)        = ADD | SUB | MUL | NEG                   (* int or float *)
136    | ABS | FSQRT | FSIN | FCOS | FTAN            (* floating point only *)        | FDIV | ABS | FSQRT | FSIN | FCOS | FTAN (* floating point only *)
137    | LSHIFT | RSHIFT | RSHIFTL                   (* int only *)    | LSHIFT | RSHIFT | RSHIFTL                   (* int only *)
138    | ANDB | ORB | XORB | NOTB                    (* int only *)    | ANDB | ORB | XORB | NOTB                    (* int only *)
139    | REM | DIV | MOD                             (* int only *)        | DIV | MOD | QUOT | REM                  (* int only *)

datatype cmpop = > | >= | < | <= | LEU | LTU | GEU | GTU | EQL | NEQ
140
141  (*      datatype cmpop
142   * Various primitive operations.  Those that are designated "inline" are        = GT | GTE | LT | LTE                     (* signed comparisons *)
143   * expanded into lambda code in terms of other operators,        | LEU | LTU | GEU | GTU                   (* unsigned comparisons *)
144   * as is the "checked=true" version of NUMSUBSCRIPT or NUMUPDATE.        | EQL | NEQ                               (* equality *)
145   * NUMSUBSCRIPT and NUMUPDATE are for arrays of floats or integers        | FSGN                                    (* floating point only *)
146   * stored WITHOUT boxing or tags.
147      (* datatype primop:
148       * Various primitive operations. Those that are designated "inline" (L:) in
149       * the comments are expanded into lambda code in terms of other operators,
150       * as are the "checked=true" versions of NUMSUBSCRIPT and NUMUPDATE (L?:).
151       * "Environmental" primops (occurring in the InLine structure) are indicated
152       * by "E:" in the comment.
153   *)   *)
154  datatype primop  datatype primop
155    = ARITH of {oper: arithop, overflow: bool, kind: numkind}        = ARITH of {                              (* E: arithmetic ops *)
156    | INLLSHIFT of numkind              oper: arithop, overflow: bool, kind: numkind
157    | INLRSHIFT of numkind            }
158    | INLRSHIFTL of numkind        | INLLSHIFT of numkind                    (* E: left shift *)
159    | CMP of {oper: cmpop, kind: numkind}        | INLRSHIFT of numkind                    (* E: right shift *)
160          | INLRSHIFTL of numkind                   (* E: right shift logical *)
161    | TESTU of int * int        | CMP of {oper: cmpop, kind: numkind}     (* E: generic compare *)
162    | TEST of int * int        | TESTU of int * int                      (* E: conversions to int, e.g. testu_31_31 *)
163    | TRUNC of int * int        | TEST of int * int                       (* E: conversions to int, e.g. test_32_31_w *)
164    | EXTEND of int * int        | TRUNC of int * int                      (* E: truncations to smaller int/word, e.g. trunc_32_31_i *)
165    | COPY of int * int        | EXTEND of int * int                     (* E: extensions to int32, word32 *)
166          | COPY of int * int                       (* E: conversions, e.g. copy_32_32_ii *)
167    | TEST_INF of int                     (* inf -> i *)        | TEST_INF of int                         (* E: intinf conversions, e.g. test_inf_31 *)
168    | TRUNC_INF of int                    (* inf -> i *)        | TRUNC_INF of int                        (* E: intinf truncations, e.g. trunc_inf_31 *)
169    | EXTEND_INF of int                   (* i -> inf *)        | EXTEND_INF of int                       (* E: intinf extensions, e.g. extend_8_inf *)
170    | COPY_INF of int                     (* i -> inf *)        | COPY_INF of int                         (* E: conversions to intinf, e.g. copy_8_inf *)
171          | ROUND of {                              (* E: floor, round *)
172    | ROUND of {floor: bool, fromkind: numkind, tokind: numkind}              floor: bool, fromkind: numkind, tokind: numkind
173    | REAL of {fromkind: numkind, tokind: numkind}            }
174          | REAL of {                               (* E: real, real32 *)
175    | NUMSUBSCRIPT of {kind: numkind, checked: bool, immutable: bool}              fromkind: numkind, tokind: numkind
176    | NUMUPDATE of {kind: numkind, checked: bool}            }
177          | NUMSUBSCRIPT of {                       (* E: L?: ordof, etc. *)
178    | SUBSCRIPT                  (* polymorphic array subscript *)              kind: numkind, checked: bool, immutable: bool
179    | SUBSCRIPTV                 (* poly vector subscript *)            }
180    | INLSUBSCRIPT               (* inline poly array subscript *)        | NUMUPDATE of {                          (* E: L?: store, etc. *)
181    | INLSUBSCRIPTV              (* inline poly vector subscript *)              kind: numkind, checked: bool
182    | INLMKARRAY                 (* inline poly array creation *)            }
183          | SUBSCRIPT                               (* E: polymorphic array subscript *)
184    | PTREQL | PTRNEQ            (* pointer equality *)        | SUBSCRIPTV                              (* E: poly vector subscript *)
185    | POLYEQL | POLYNEQ          (* polymorphic equality *)        | INLSUBSCRIPT                            (* E: L: poly array subscript *)
186    | BOXED | UNBOXED            (* boxity tests *)        | INLSUBSCRIPTV                           (* E: L: poly vector subscript *)
187    | LENGTH                     (* vector, string, array, ... length *)        | INLMKARRAY                              (* E: L: poly array creation *)
188    | OBJLENGTH                  (* length of arbitrary heap object *)        | PTREQL | PTRNEQ                         (* E: pointer equality *)
189    | CAST        | POLYEQL | POLYNEQ                       (* E: polymorphic equality *)
190    | WCAST        | BOXED | UNBOXED                         (* E: boxity tests *)
191    | GETRUNVEC                  (* get the pointer to the run-vector *)        | LENGTH                                  (* E: vector, string, array, ... length *)
192    | MARKEXN                    (* mark an exception value with a string *)        | OBJLENGTH                               (* E: length of arbitrary heap object *)
193    | GETHDLR | SETHDLR          (* get/set exn handler pointer *)        | CAST                                    (* E: cast *)
194    | GETVAR | SETVAR            (* get/set var register *)        | GETHDLR | SETHDLR                       (* E: get/set exn handler pointer *)
195    | GETPSEUDO | SETPSEUDO      (* get/set pseudo registers *)        | GETVAR | SETVAR                         (* E: get/set var register *)
196    | SETMARK | DISPOSE          (* capture/dispose frames *)        | GETPSEUDO | SETPSEUDO                   (* E: get/set pseudo registers *)
197    | MAKEREF                    (* allocate a ref cell *)        | SETMARK | DISPOSE                       (* E: capture/dispose frames *)
198    | CALLCC | CAPTURE | THROW   (* continuation operations *)        | MAKEREF                                 (* E: allocate a ref cell *)
199    | ISOLATE                    (* isolating a function *)        | CALLCC | CAPTURE | THROW                (* E: continuation operations *)
200    | DEREF                      (* dereferencing *)        | ISOLATE                                 (* E: isolating a function *)
201    | ASSIGN                     (* assignment *)        | DEREF                                   (* E: dereferencing *)
202    | UNBOXEDASSIGN              (* assignment to integer reference *)        | ASSIGN                                  (* E: assignment *)
203    | UPDATE                     (* array update (maybe boxed) *)        | UPDATE                                  (* E: array or reference update (maybe boxed) *)
204    | INLUPDATE                  (* inline array update (maybe boxed) *)        | INLUPDATE                               (* E: L: array update (maybe boxed) *)
205    | BOXEDUPDATE                (* boxed array update *)        | UNBOXEDUPDATE                           (* E: update array of integers WITH tags
206    | UNBOXEDUPDATE              (* update array of integers WITH tags *)                                                   * removed by Zhong, put back by Matthias
207                                                     * (see FLINT/trans/primopmap.sml) *)
208    | GETTAG                     (* extract the tag portion of an *)        | GETTAG                                  (* E: extract the tag portion of an
209                                 (* object's descriptor as an ML int *)                                                   * object's descriptor as an ML int *)
210    | MKSPECIAL                  (* make a special object *)        | MKSPECIAL                               (* E: make a special object *)
211    | SETSPECIAL                 (* set the state of a special object *)        | SETSPECIAL                              (* E: set the state of a special object *)
212    | GETSPECIAL                 (* get the state of a special object *)        | GETSPECIAL                              (* E: get the state of a special object *)
213    | USELVAR | DEFLVAR        | INLMIN of numkind                       (* E: L: min *)
214    | INLMIN of numkind          (* inline min *)        | INLMAX of numkind                       (* E: L: max *)
215    | INLMAX of numkind          (* inline max *)        | INLABS of numkind                       (* E: L: abs *)
216    | INLABS of numkind          (* inline abs *)        | INLNOT                                  (* E: L: bool not operator *)
217    | INLNOT                     (* inline bool not operator *)        | INLCOMPOSE                              (* E: L: compose "op o"  operator *)
218    | INLCOMPOSE                 (* inline compose "op o"  operator *)        | INLBEFORE                               (* E: L: "before" operator *)
219    | INLBEFORE                  (* inline "before" operator *)        | INLIGNORE                               (* E: L: "ignore" function *)
220    | INLIGNORE                  (* inline "ignore" function *)      (* primops to support new array representations *)
221    | INL_ARRAY                  (* inline polymorphic array allocation *)        | NEW_ARRAY0                              (* E: allocate zero-length array header *)
222    | INL_VECTOR                 (* inline polymorphic vector allocation *)        | GET_SEQ_DATA                            (* E: get data pointer from arr/vec header *)
223    | INL_MONOARRAY of numkind   (* inline monomorphic array allocation *)        | SUBSCRIPT_REC                           (* E: record subscript operation *)
224    | INL_MONOVECTOR of numkind  (* inline monomorphic vector allocation *)        | SUBSCRIPT_RAW64                         (* E: raw64 subscript operation *)
225          | INLIDENTITY                             (* E: polymorphic identity *)
226    | MKETAG                     (* make a new exception tag *)        | CVT64                                   (* E: convert between external and
227    | WRAP                       (* box a value by wrapping it *)                                                   * internal representation of compiler
228    | UNWRAP                     (* unbox a value by unwrapping it *)                                                   * simulated 64-bit scalars, e.g. w64p *)
229  (* Primops to support new array representations *)      (* Primops to support C FFI. *)
230    | NEW_ARRAY0                  (* allocate zero-length array header *)        | RAW_LOAD of numkind                     (* E: load from arbitrary memory location *)
231    | GET_SEQ_DATA                (* get data pointer from arr/vec header *)        | RAW_STORE of numkind                    (* E: store to arbitrary memory location *)
232    | SUBSCRIPT_REC               (* record subscript operation *)      (* E: make a call to a C-function;
| SUBSCRIPT_RAW64             (* raw64 subscript operation *)
(* Primops to support new experimental C FFI. *)
| RAW_STORE of numkind        (* store to arbitrary memory location *)
(* make a call to a C-function;
233       * The primop carries C function prototype information and specifies       * The primop carries C function prototype information and specifies
234       * which of its (ML-) arguments are floating point. C prototype       * which of its (ML-) arguments are floating point. C prototype
235       * information is for use by the backend, ML information is for       * information is for use by the backend, ML information is for
236       * use by the CPS converter. *)       * use by the CPS converter. *)
237    | RAW_CCALL of { c_proto: CTypes.c_proto,        | RAW_CCALL of {
238                c_proto: PrimCTypes.c_proto,
239                     ml_args: ccall_type list,                     ml_args: ccall_type list,
240                     ml_res_opt: ccall_type option,                     ml_res_opt: ccall_type option,
241                     reentrant : bool                     reentrant : bool
# Line 239  Line 243
243     (* Allocate uninitialized storage on the heap.     (* Allocate uninitialized storage on the heap.
244      * The record is meant to hold short-lived C objects, i.e., they      * The record is meant to hold short-lived C objects, i.e., they
245      * are not ML pointers.  The representation is      * are not ML pointers.  The representation is
246      * the same as RECORD with tag tag_raw32 (fblock = false),      * the same as RECORD with tag tag_raw32 or tag_fblock.
* or tag_fblock (fblock = true).
247      *)      *)
248    | RAW_RECORD of { fblock: bool }        | RAW_RECORD of { fblock: bool }  (* E: *)
249
250    | INLIDENTITY                         (* polymorphic identity *)      (* non-environmental primops (not found in InLine) *)
251          | UNBOXEDASSIGN                   (* assignment to integer reference *)
252
253    | CVT64                               (* convert between external and        | WCAST                           (* ? *)
254                                           * internal representation of        | MARKEXN                         (* mark an exception value with a string *)
255                                           * simulated 64-bit scalars *)
256          | INL_ARRAY                       (* L: polymorphic array allocation *)
257          | INL_VECTOR                      (* L: polymorphic vector allocation *)
258          | INL_MONOARRAY of numkind        (* L: monomorphic array allocation *)
259          | INL_MONOVECTOR of numkind       (* L: monomorphic vector allocation *)
260
261          | MKETAG                          (* make a new exception tag *)
262          | WRAP                            (* box a value by wrapping it *)
263          | UNWRAP                          (* unbox a value by unwrapping it *)
264
265  and ccall_type =  and ccall_type =
266      CCI32 |                             (* passed as int32 *)      CCI32 |                             (* passed as int32 *)
# Line 269  Line 281
281  val ILT : primop  val ILT : primop
282  val ILE : primop  val ILE : primop
283  val IGE : primop  val IGE : primop
284        val UIEQL : primop  (* for UINT kind, may not matter *)
285
286        val mkIEQL : int -> primop   (* make equality primop for other sizes *)
287        val mkUIEQL : int -> primop  (* and for unsigned (kind = UINT) *)
288
289  val prNumkind : numkind -> string  val prNumkind : numkind -> string
290  val prPrimop: primop -> string  val prPrimop: primop -> string
291  val mayRaise : primop -> bool  val mayRaise : primop -> bool
292
293  (* This should return more than just a boolean.  (* This should return more than just a boolean.
294   * True means "can not be dead-code eliminated" *)   * True means "can not be dead-code eliminated" *)
295  val effect : primop -> bool  val effect : primop -> bool

Legend:
 Removed from v.2162 changed lines Added in v.4804