@@ -435,6 +435,14 @@ let parse_int_payload attr =
435
435
" A constant payload of type int was expected" ;
436
436
None
437
437
438
+ let parse_ident_payload attr =
439
+ match ident_of_payload attr.attr_payload with
440
+ | Some i -> Some i
441
+ | None ->
442
+ warn_payload attr.attr_loc attr.attr_name.txt
443
+ " A constant payload of type ident was expected" ;
444
+ None
445
+
438
446
let clflags_attribute_without_payload attr ~name clflags_ref =
439
447
when_attribute_is [name; " ocaml." ^ name] attr ~f: (fun () ->
440
448
match parse_empty_payload attr with
@@ -490,6 +498,20 @@ let inline_attribute attr =
490
498
Clflags.Float_arg_helper. parse s err_msg Clflags. inline_threshold
491
499
| None -> warn_payload attr.attr_loc attr.attr_name.txt err_msg)
492
500
501
+ let parse_attribute_with_ident_payload attr ~name ~f =
502
+ when_attribute_is [name; " ocaml." ^ name] attr ~f: (fun () ->
503
+ match parse_ident_payload attr with
504
+ | Some i -> f i
505
+ | None -> () )
506
+
507
+ let zero_alloc_attribute (attr : Parsetree.attribute ) =
508
+ parse_attribute_with_ident_payload attr
509
+ ~name: " zero_alloc" ~f: (function
510
+ | "check" -> Clflags. zero_alloc_check := true
511
+ | _ ->
512
+ warn_payload attr.attr_loc attr.attr_name.txt
513
+ " Only 'check' is supported" )
514
+
493
515
let afl_inst_ratio_attribute attr =
494
516
clflags_attribute_with_int_payload attr
495
517
~name: " afl_inst_ratio" Clflags. afl_inst_ratio
@@ -508,7 +530,8 @@ let parse_standard_implementation_attributes attr =
508
530
inline_attribute attr;
509
531
afl_inst_ratio_attribute attr;
510
532
flambda_o3_attribute attr;
511
- flambda_oclassic_attribute attr
533
+ flambda_oclassic_attribute attr;
534
+ zero_alloc_attribute attr
512
535
513
536
let has_local_opt attrs =
514
537
has_attribute [" ocaml.local_opt" ; " local_opt" ] attrs
0 commit comments