@@ -30,6 +30,7 @@ type description =
30
30
{ prim_name : string ; (* Name of primitive or C function *)
31
31
prim_arity : int ; (* Number of arguments *)
32
32
prim_alloc : bool ; (* Does it allocates or raise? *)
33
+ prim_c_builtin : bool ; (* Is the compiler allowed to replace it? *)
33
34
prim_native_name : string ; (* Name of C function for the nat. code gen. *)
34
35
prim_native_repr_args : native_repr list ;
35
36
prim_native_repr_res : native_repr }
@@ -69,14 +70,17 @@ let simple ~name ~arity ~alloc =
69
70
{prim_name = name;
70
71
prim_arity = arity;
71
72
prim_alloc = alloc;
73
+ prim_c_builtin = false ;
72
74
prim_native_name = " " ;
73
75
prim_native_repr_args = make_native_repr_args arity Same_as_ocaml_repr ;
74
76
prim_native_repr_res = Same_as_ocaml_repr }
75
77
76
- let make ~name ~alloc ~native_name ~native_repr_args ~native_repr_res =
78
+ let make ~name ~alloc ~c_builtin
79
+ ~native_name ~native_repr_args ~native_repr_res =
77
80
{prim_name = name;
78
81
prim_arity = List. length native_repr_args;
79
82
prim_alloc = alloc;
83
+ prim_c_builtin = c_builtin;
80
84
prim_native_name = native_name;
81
85
prim_native_repr_args = native_repr_args;
82
86
prim_native_repr_res = native_repr_res}
@@ -98,6 +102,10 @@ let parse_declaration valdecl ~native_repr_args ~native_repr_res =
98
102
Attr_helper. has_no_payload_attribute [" noalloc" ; " ocaml.noalloc" ]
99
103
valdecl.pval_attributes
100
104
in
105
+ let builtin_attribute =
106
+ Attr_helper. has_no_payload_attribute [" builtin" ; " ocaml.builtin" ]
107
+ valdecl.pval_attributes
108
+ in
101
109
if old_style_float &&
102
110
not (List. for_all is_ocaml_repr native_repr_args &&
103
111
is_ocaml_repr native_repr_res) then
@@ -131,6 +139,7 @@ let parse_declaration valdecl ~native_repr_args ~native_repr_res =
131
139
{prim_name = name;
132
140
prim_arity = arity;
133
141
prim_alloc = not noalloc;
142
+ prim_c_builtin = builtin_attribute;
134
143
prim_native_name = native_name;
135
144
prim_native_repr_args = native_repr_args;
136
145
prim_native_repr_res = native_repr_res}
@@ -155,6 +164,7 @@ let rec add_native_repr_attributes ty attrs =
155
164
let oattr_unboxed = { oattr_name = " unboxed" }
156
165
let oattr_untagged = { oattr_name = " untagged" }
157
166
let oattr_noalloc = { oattr_name = " noalloc" }
167
+ let oattr_builtin = { oattr_name = " builtin" }
158
168
159
169
let print p osig_val_decl =
160
170
let prims =
@@ -169,6 +179,7 @@ let print p osig_val_decl =
169
179
let all_unboxed = for_all is_unboxed in
170
180
let all_untagged = for_all is_untagged in
171
181
let attrs = if p.prim_alloc then [] else [oattr_noalloc] in
182
+ let attrs = if p.prim_c_builtin then oattr_builtin::attrs else attrs in
172
183
let attrs =
173
184
if all_unboxed then
174
185
oattr_unboxed :: attrs
0 commit comments