forked from ocaml-flambda/flambda-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimitive.mli
134 lines (113 loc) · 5.32 KB
/
primitive.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 1996 Institut National de Recherche en Informatique et *)
(* en Automatique. *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
(* Description of primitive functions *)
type boxed_integer = Pnativeint | Pint32 | Pint64
type boxed_float = Pfloat64 | Pfloat32
type boxed_vector = Pvec128
(* Representation of arguments/result for the native code version
of a primitive *)
type native_repr =
| Repr_poly
| Same_as_ocaml_repr of Jkind_types.Sort.Const.t
| Unboxed_float of boxed_float
| Unboxed_vector of boxed_vector
| Unboxed_integer of boxed_integer
| Untagged_immediate
(* See [middle_end/semantics_of_primitives.mli] *)
type effects = No_effects | Only_generative_effects | Arbitrary_effects
type coeffects = No_coeffects | Has_coeffects
type mode =
| Prim_local
| Prim_global
| Prim_poly
(* [Prim_poly] arguments and results are subject to mode inference,
allowing e.g. (+.) to work on local or global floats. After
typechecking, all [Prim_poly] modes on a given primitive application
will be instantiated either all to [Local] or all to [Global] *)
type 'repr description_gen = private
{ prim_name: string; (* Name of primitive or C function *)
prim_arity: int; (* Number of arguments *)
prim_alloc: bool; (* Does it allocates or raise? *)
prim_c_builtin: bool;
(* When [prim_c_builtin] is true, the native compiler is allowed to rewrite
calls to the external C function that implements this primitive,
based on its name [prim_name], into a predetermined instruction sequence.
[prim_c_builtin] is ignored on compiler primitives
whose name [prim_name] starts with %. *)
prim_effects: effects;
prim_coeffects: coeffects;
prim_native_name: string; (* Name of C function for the nat. code gen. *)
prim_native_repr_args: (mode * 'repr) list;
prim_native_repr_res: mode * 'repr;
prim_is_layout_poly: bool }
type description = native_repr description_gen
(* Invariant [List.length d.prim_native_repr_args = d.prim_arity] *)
(** [make_prim_repr_args n x] is the same as [List.init n (fun _ -> x)].
Keeping this function here to be close to upstream. It's
intended for use with [make]. *)
val make_prim_repr_args : int -> 'a -> 'a list
val make
: name:string
-> alloc:bool
-> c_builtin:bool
-> effects:effects
-> coeffects:coeffects
-> native_name:string
-> native_repr_args: (mode * 'repr) list
-> native_repr_res: mode * 'repr
-> is_layout_poly: bool
-> 'repr description_gen
val parse_declaration
: Parsetree.value_description
-> native_repr_args:(mode * native_repr) list
-> native_repr_res:(mode * native_repr)
-> is_layout_poly:bool
-> description
val print
: description
-> Outcometree.out_val_decl
-> Outcometree.out_val_decl
val native_name: 'a description_gen -> string
val byte_name: 'a description_gen -> string
val equal_boxed_integer : boxed_integer -> boxed_integer -> bool
val equal_boxed_float : boxed_float -> boxed_float -> bool
val equal_boxed_vector : boxed_vector -> boxed_vector -> bool
val equal_native_repr : native_repr -> native_repr -> bool
val equal_effects : effects -> effects -> bool
val equal_coeffects : coeffects -> coeffects -> bool
(** [native_name_is_externa] returns [true] iff the [native_name] for the
given primitive identifies that the primitive is not implemented in the
compiler itself. *)
val native_name_is_external : description -> bool
(** Check if a primitive has the correct native representations for its
argument/return types. This check is done based on the primitive name and
only imposes constraints on built-in primitives. Raises if the check
fails. *)
val prim_has_valid_reprs : loc:Location.t -> description -> unit
(** Check if a primitive can have layout [any] anywhere within its type
declaration. Returns [false] for built-in primitives that inspect
the layout of type parameters ([%array_length] for example). *)
val prim_can_contain_layout_any : description -> bool
type error =
| Old_style_float_with_native_repr_attribute
| Old_style_float_with_non_value
| Old_style_noalloc_with_noalloc_attribute
| No_native_primitive_with_repr_attribute
| No_native_primitive_with_non_value
| Inconsistent_attributes_for_effects
| Inconsistent_noalloc_attributes_for_effects
| Invalid_representation_polymorphic_attribute
| Invalid_native_repr_for_primitive of string
exception Error of Location.t * error