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/compiler/ElabData/prim/primop.sig
ViewVC logotype

Annotation of /sml/trunk/compiler/ElabData/prim/primop.sig

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4986 - (view) (download) (as text)

1 : jhr 4431 (* primop.sig
2 :     *
3 :     * COPYRIGHT (c) 2017 The Fellowship of SML/NJ (http://www.smlnj.org)
4 :     * All rights reserved.
5 :     *)
6 : monnier 16
7 : jhr 4804 signature PRIMOP =
8 : jhr 4431 sig
9 : monnier 16
10 : jhr 4431 (* numkind includes kind and number of bits *)
11 : jhr 4804 datatype numkind
12 :     = INT of int
13 :     | UINT of int
14 : jhr 4431 | FLOAT of int
15 :     (* QUESTION: what about IntInf.int? *)
16 : jhr 4804
17 : jhr 4431 datatype arithop
18 : jhr 4432 = ADD | SUB | MUL | NEG (* int or float *)
19 : jhr 4986 | FDIV | FABS | FSQRT | FSIN | FCOS | FTAN (* floating point only *)
20 : jhr 4431 | LSHIFT | RSHIFT | RSHIFTL (* int only *)
21 :     | ANDB | ORB | XORB | NOTB (* int only *)
22 : jhr 4432 | DIV | MOD | QUOT | REM (* int only *)
23 : monnier 16
24 : jhr 4431 datatype cmpop
25 :     = GT | GTE | LT | LTE (* signed comparisons *)
26 :     | LEU | LTU | GEU | GTU (* unsigned comparisons *)
27 :     | EQL | NEQ (* equality *)
28 :     | FSGN (* floating point only *)
29 : monnier 16
30 : jhr 4431 (* datatype primop:
31 :     * Various primitive operations. Those that are designated "inline" (L:) in
32 :     * the comments are expanded into lambda code in terms of other operators,
33 :     * as are the "checked=true" versions of NUMSUBSCRIPT and NUMUPDATE (L?:).
34 :     * "Environmental" primops (occurring in the InLine structure) are indicated
35 :     * by "E:" in the comment.
36 : jhr 4889 *
37 :     * See dev-notes/conversions.md for an explanation of the conversion operators.
38 : jhr 4431 *)
39 :     datatype primop
40 :     = ARITH of { (* E: arithmetic ops *)
41 :     oper: arithop, overflow: bool, kind: numkind
42 :     }
43 :     | INLLSHIFT of numkind (* E: left shift *)
44 :     | INLRSHIFT of numkind (* E: right shift *)
45 :     | INLRSHIFTL of numkind (* E: right shift logical *)
46 :     | CMP of {oper: cmpop, kind: numkind} (* E: generic compare *)
47 :     | TESTU of int * int (* E: conversions to int, e.g. testu_31_31 *)
48 :     | TEST of int * int (* E: conversions to int, e.g. test_32_31_w *)
49 :     | TRUNC of int * int (* E: truncations to smaller int/word, e.g. trunc_32_31_i *)
50 :     | EXTEND of int * int (* E: extensions to int32, word32 *)
51 :     | COPY of int * int (* E: conversions, e.g. copy_32_32_ii *)
52 :     | TEST_INF of int (* E: intinf conversions, e.g. test_inf_31 *)
53 :     | TRUNC_INF of int (* E: intinf truncations, e.g. trunc_inf_31 *)
54 :     | EXTEND_INF of int (* E: intinf extensions, e.g. extend_8_inf *)
55 :     | COPY_INF of int (* E: conversions to intinf, e.g. copy_8_inf *)
56 :     | ROUND of { (* E: floor, round *)
57 : jhr 4986 floor: bool, from: int, to: int
58 : jhr 4431 }
59 :     | REAL of { (* E: real, real32 *)
60 : jhr 4986 from: int, to: int
61 : jhr 4431 }
62 :     | NUMSUBSCRIPT of { (* E: L?: ordof, etc. *)
63 :     kind: numkind, checked: bool, immutable: bool
64 :     }
65 :     | NUMUPDATE of { (* E: L?: store, etc. *)
66 :     kind: numkind, checked: bool
67 : jhr 4804 }
68 : jhr 4431 | SUBSCRIPT (* E: polymorphic array subscript *)
69 :     | SUBSCRIPTV (* E: poly vector subscript *)
70 :     | INLSUBSCRIPT (* E: L: poly array subscript *)
71 :     | INLSUBSCRIPTV (* E: L: poly vector subscript *)
72 :     | INLMKARRAY (* E: L: poly array creation *)
73 :     | PTREQL | PTRNEQ (* E: pointer equality *)
74 :     | POLYEQL | POLYNEQ (* E: polymorphic equality *)
75 :     | BOXED | UNBOXED (* E: boxity tests *)
76 :     | LENGTH (* E: vector, string, array, ... length *)
77 :     | OBJLENGTH (* E: length of arbitrary heap object *)
78 :     | CAST (* E: cast *)
79 :     | GETHDLR | SETHDLR (* E: get/set exn handler pointer *)
80 :     | GETVAR | SETVAR (* E: get/set var register *)
81 :     | MAKEREF (* E: allocate a ref cell *)
82 :     | CALLCC | CAPTURE | THROW (* E: continuation operations *)
83 :     | ISOLATE (* E: isolating a function *)
84 :     | DEREF (* E: dereferencing *)
85 :     | ASSIGN (* E: assignment *)
86 :     | UPDATE (* E: array or reference update (maybe boxed) *)
87 :     | INLUPDATE (* E: L: array update (maybe boxed) *)
88 :     | UNBOXEDUPDATE (* E: update array of integers WITH tags
89 :     * removed by Zhong, put back by Matthias
90 :     * (see FLINT/trans/primopmap.sml) *)
91 :     | GETTAG (* E: extract the tag portion of an
92 :     * object's descriptor as an ML int *)
93 :     | MKSPECIAL (* E: make a special object *)
94 :     | SETSPECIAL (* E: set the state of a special object *)
95 :     | GETSPECIAL (* E: get the state of a special object *)
96 :     | INLMIN of numkind (* E: L: min *)
97 :     | INLMAX of numkind (* E: L: max *)
98 :     | INLABS of numkind (* E: L: abs *)
99 :     | INLNOT (* E: L: bool not operator *)
100 :     | INLCOMPOSE (* E: L: compose "op o" operator *)
101 : jhr 4804 | INLBEFORE (* E: L: "before" operator *)
102 : jhr 4431 | INLIGNORE (* E: L: "ignore" function *)
103 :     (* primops to support new array representations *)
104 :     | NEW_ARRAY0 (* E: allocate zero-length array header *)
105 :     | GET_SEQ_DATA (* E: get data pointer from arr/vec header *)
106 :     | SUBSCRIPT_REC (* E: record subscript operation *)
107 :     | SUBSCRIPT_RAW64 (* E: raw64 subscript operation *)
108 :     | INLIDENTITY (* E: polymorphic identity *)
109 :     | CVT64 (* E: convert between external and
110 :     * internal representation of compiler
111 :     * simulated 64-bit scalars, e.g. w64p *)
112 :     (* Primops to support C FFI. *)
113 :     | RAW_LOAD of numkind (* E: load from arbitrary memory location *)
114 :     | RAW_STORE of numkind (* E: store to arbitrary memory location *)
115 :     (* E: make a call to a C-function;
116 : blume 773 * The primop carries C function prototype information and specifies
117 :     * which of its (ML-) arguments are floating point. C prototype
118 :     * information is for use by the backend, ML information is for
119 :     * use by the CPS converter. *)
120 : jhr 4431 | RAW_CCALL of {
121 : jhr 4432 c_proto: PrimCTypes.c_proto,
122 : jhr 4431 ml_args: ccall_type list,
123 :     ml_res_opt: ccall_type option,
124 :     reentrant: bool
125 :     } option
126 : leunga 1174 (* Allocate uninitialized storage on the heap.
127 :     * The record is meant to hold short-lived C objects, i.e., they
128 : jhr 4804 * are not ML pointers. The representation is
129 : dbm 4428 * the same as RECORD with tag tag_raw32 or tag_fblock.
130 : leunga 1174 *)
131 : jhr 4431 | RAW_RECORD of { fblock: bool } (* E: *)
132 : monnier 16
133 : jhr 4431 (* non-environmental primops (not found in InLine) *)
134 :     | UNBOXEDASSIGN (* assignment to integer reference *)
135 : mblume 1347
136 : jhr 4431 | WCAST (* ? *)
137 :     | MARKEXN (* mark an exception value with a string *)
138 : mblume 1683
139 : jhr 4431 | INL_ARRAY (* L: polymorphic array allocation *)
140 :     | INL_VECTOR (* L: polymorphic vector allocation *)
141 :     | INL_MONOARRAY of numkind (* L: monomorphic array allocation *)
142 :     | INL_MONOVECTOR of numkind (* L: monomorphic vector allocation *)
143 : dbm 4428
144 : jhr 4431 | MKETAG (* make a new exception tag *)
145 :     | WRAP (* box a value by wrapping it *)
146 :     | UNWRAP (* unbox a value by unwrapping it *)
147 : dbm 4428
148 : jhr 4431 and ccall_type =
149 :     CCI32 | (* passed as int32 *)
150 :     CCI64 | (* int64, currently unused *)
151 :     CCR64 | (* passed as real64 *)
152 :     CCML (* passed as Unsafe.Object.object *)
153 : dbm 4428
154 : jhr 4431 val IADD : primop (* default integer addition *)
155 :     val ISUB : primop (* default integer subtraction *)
156 :     val IMUL : primop
157 :     val IDIV : primop
158 :     val INEG : primop
159 : monnier 45
160 : jhr 4431 val FEQLd : primop
161 :     val IEQL : primop
162 :     val INEQ : primop
163 :     val IGT : primop
164 :     val ILT : primop
165 :     val ILE : primop
166 :     val IGE : primop
167 : dbm 4791 val UIEQL : primop (* for UINT kind, may not matter *)
168 : jhr 4804
169 : dbm 4791 val mkIEQL : int -> primop (* make equality primop for other sizes *)
170 :     val mkUIEQL : int -> primop (* and for unsigned (kind = UINT) *)
171 : monnier 16
172 : jhr 4431 val prNumkind : numkind -> string
173 :     val prPrimop: primop -> string
174 :     val mayRaise : primop -> bool
175 : monnier 16
176 : jhr 4431 (* This should return more than just a boolean.
177 :     * True means "can not be dead-code eliminated" *)
178 :     val effect : primop -> bool
179 : monnier 16
180 : jhr 4431 end (* signature PRIM_OP *)
181 : monnier 16

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