@@ -68,15 +68,20 @@ let to_x86_constant_with_width (c : ND.Directive.Constant_with_width.t) :
68
68
69
69
let to_x86_directive (dir : ND.Directive.t ) : X86_ast.asm_line list =
70
70
let comment_lines comment =
71
- Option. to_list (Option. map (fun s -> X86_ast. Comment s) comment)
71
+ (* CR sspies: This check is usually done in the printing function of the new
72
+ directives. Since we are skipping those at the moment (by emitting via
73
+ the X86 DSL), we do the same check here in the conversion. *)
74
+ if ! Clflags. keep_asm_file && ! Flambda_backend_flags. dasm_comments
75
+ then Option. to_list (Option. map (fun s -> X86_ast. Comment s) comment)
76
+ else []
72
77
in
73
78
match dir with
74
79
| Align { bytes } ->
75
80
[X86_ast. Align (false , bytes)]
76
81
(* The data field is currently ignored by both assembler backends. The bytes
77
82
field is only converted to the final value when printing. *)
78
83
| Bytes { str; comment } -> comment_lines comment @ [X86_ast. Bytes str]
79
- | Comment s -> [ X86_ast. Comment s]
84
+ | Comment s -> comment_lines ( Some s)
80
85
| Const { constant; comment } ->
81
86
comment_lines comment @ [to_x86_constant_with_width constant]
82
87
| Direct_assignment (s , c ) ->
@@ -108,7 +113,7 @@ let to_x86_directive (dir : ND.Directive.t) : X86_ast.asm_line list =
108
113
comment_lines comment @ [X86_ast. Sleb128 (to_x86_constant constant)]
109
114
| Space { bytes } -> [Space bytes]
110
115
| Type (n , st ) ->
111
- let typ = match st with Function -> " STT_FUNC " | Object -> " STT_OBJECT " in
116
+ let typ = ND. symbol_type_to_string st in
112
117
[Type (n, typ)]
113
118
| Uleb128 { constant; comment } ->
114
119
comment_lines comment @ [X86_ast. Uleb128 (to_x86_constant constant)]
@@ -117,6 +122,9 @@ let to_x86_directive (dir : ND.Directive.t) : X86_ast.asm_line list =
117
122
| Cfi_endproc -> [X86_ast. Cfi_endproc ]
118
123
| Cfi_offset { reg; offset } -> [X86_ast. Cfi_offset (reg, offset)]
119
124
| Cfi_startproc -> [X86_ast. Cfi_startproc ]
125
+ | Cfi_remember_state -> [X86_ast. Cfi_remember_state ]
126
+ | Cfi_restore_state -> [X86_ast. Cfi_restore_state ]
127
+ | Cfi_def_cfa_register r -> [X86_ast. Cfi_def_cfa_register r]
120
128
| Protected s -> [X86_ast. Protected s]
121
129
122
130
let _label s = D. label ~typ: QWORD s
@@ -619,105 +627,6 @@ let emit_jump_tables () =
619
627
List. iter emit_jump_table ! jump_tables;
620
628
jump_tables := []
621
629
622
- let file_emitter ~file_num ~file_name =
623
- ND. file ~file_num: (Some file_num) ~file_name
624
-
625
- let build_asm_directives () : (module Asm_targets.Asm_directives_intf.S) =
626
- (module Asm_targets.Asm_directives. Make (struct
627
- let emit_line line = ND. comment line
628
-
629
- let get_file_num file_name = Emitaux. get_file_num ~file_emitter file_name
630
-
631
- let debugging_comments_in_asm_files = ! Flambda_backend_flags. dasm_comments
632
-
633
- module D = struct
634
- type constant = ND.Directive.Constant .t
635
-
636
- let const_int64 num = ND.Directive.Constant. Signed_int num
637
-
638
- let const_label str = ND.Directive.Constant. Named_thing str
639
-
640
- let const_add c1 c2 = ND.Directive.Constant. Add (c1, c2)
641
-
642
- let const_sub c1 c2 = ND.Directive.Constant. Sub (c1, c2)
643
-
644
- (* CR sspies: The functions depending on [emit_directive] below break
645
- abstractions. This is intensional at the moment, because this is only
646
- the first step of getting rid of the first-class module entirely. *)
647
- let emit_directive d = List. iter directive (to_x86_directive d)
648
-
649
- type data_type =
650
- | NONE
651
- | DWORD
652
- | QWORD
653
- | VEC128
654
-
655
- let file = file_emitter
656
-
657
- let loc ~file_num ~line ~col ?discriminator () =
658
- ignore discriminator;
659
- D. loc ~file_num ~line ~col ?discriminator ()
660
-
661
- let comment str = D. comment str
662
-
663
- let label ?data_type str =
664
- let _ = data_type in
665
- emit_directive (New_label (str, Code ))
666
-
667
- let section ?delayed :_ name flags args =
668
- match name, flags, args with
669
- | [" .data" ], _ , _ -> ND. data ()
670
- | [" .text" ], _ , _ -> ND. text ()
671
- | name , flags , args -> ND. switch_to_section_raw ~names: name ~flags ~args
672
-
673
- let text () = D. text ()
674
-
675
- let new_line () = D. new_line ()
676
-
677
- let emit_constant const size =
678
- emit_directive
679
- (Const
680
- { constant = ND.Directive.Constant_with_width. create const size;
681
- comment = None
682
- })
683
-
684
- let global sym = emit_directive (Global sym)
685
-
686
- let protected sym =
687
- if not (is_macosx system) then emit_directive (Protected sym)
688
-
689
- let type_ sym typ_ =
690
- let typ_ : ND.symbol_type =
691
- match typ_ with
692
- | "@function" -> Function
693
- | "@object" -> Object
694
- | "STT_OBJECT" -> Object
695
- | "STT_FUNC" -> Function
696
- | _ -> Misc. fatal_error " Unsupported type"
697
- in
698
- emit_directive (Type (sym, typ_))
699
-
700
- let byte const = emit_constant const Eight
701
-
702
- let word const = emit_constant const Sixteen
703
-
704
- let long const = emit_constant const Thirty_two
705
-
706
- let qword const = emit_constant const Sixty_four
707
-
708
- let bytes str = ND. string str
709
-
710
- let uleb128 const =
711
- emit_directive (Uleb128 { constant = const; comment = None })
712
-
713
- let sleb128 const =
714
- emit_directive (Sleb128 { constant = const; comment = None })
715
-
716
- let direct_assignment var const =
717
- emit_directive (Direct_assignment (var, const))
718
- end
719
- end ))
720
-
721
630
(* Names for instructions *)
722
631
723
632
let instr_for_intop = function
@@ -1589,7 +1498,10 @@ let emit_instr ~first ~fallthrough i =
1589
1498
(* +0.0 *)
1590
1499
I. xorpd (res i 0 ) (res i 0 )
1591
1500
| _ ->
1592
- (* float32 constants still take up 8 bytes; we load the lower half. *)
1501
+ (* float32 constants take up 8 bytes when we emit them with
1502
+ [float_literal] (see the conversion from int32 to int64 below). Thus,
1503
+ we load the lower half. Note that this is different from Cmm 32-bit
1504
+ floats ([Csingle]), which are emitted as 4-byte constants. *)
1593
1505
let lbl = add_float_constant (Int64. of_int32 f) in
1594
1506
I. movss (mem64_rip REAL4 (emit_label lbl)) (res i 0 ))
1595
1507
| Lop (Const_float f ) -> (
@@ -2081,7 +1993,7 @@ let emit_instr ~first ~fallthrough i =
2081
1993
cfi_adjust_cfa_offset 8 ;
2082
1994
I. mov rsp (domain_field Domainstate. Domain_exn_handler );
2083
1995
stack_offset := ! stack_offset + 16
2084
- | Lpoptrap ->
1996
+ | Lpoptrap _ ->
2085
1997
emit_pop_trap_label () ;
2086
1998
I. pop (domain_field Domainstate. Domain_exn_handler );
2087
1999
cfi_adjust_cfa_offset (- 8 );
@@ -2118,7 +2030,7 @@ let emit_instr ~first ~fallthrough i =
2118
2030
let rec emit_all ~first ~fallthrough i =
2119
2031
match i.desc with
2120
2032
| Lend -> ()
2121
- | Lprologue | Lreloadretaddr | Lreturn | Lentertrap | Lpoptrap | Lop _
2033
+ | Lprologue | Lreloadretaddr | Lreturn | Lentertrap | Lpoptrap _ | Lop _
2122
2034
| Lcall_op _ | Llabel _ | Lbranch _
2123
2035
| Lcondbranch (_, _)
2124
2036
| Lcondbranch3 (_, _, _)
@@ -2260,15 +2172,14 @@ let begin_assembly unix =
2260
2172
(* We initialize the new assembly directives. *)
2261
2173
Asm_targets.Asm_label. initialize ~new_label: (fun () ->
2262
2174
Cmm. new_label () |> Label. to_int);
2263
- ND. initialize
2264
- ~big_endian: Arch. big_endian
2175
+ ND. initialize ~big_endian: Arch. big_endian
2176
+ ~emit_assembly_comments: ! Flambda_backend_flags. dasm_comments
2265
2177
(* As a first step, we emit by calling the corresponding x86 emit
2266
2178
directives. *) ~emit: (fun d ->
2267
2179
List. iter directive (to_x86_directive d));
2268
2180
let code_begin = Cmm_helpers. make_symbol " code_begin" in
2269
2181
let code_end = Cmm_helpers. make_symbol " code_end" in
2270
- Emitaux.Dwarf_helpers. begin_dwarf ~build_asm_directives ~code_begin ~code_end
2271
- ~file_emitter: D. file;
2182
+ Emitaux.Dwarf_helpers. begin_dwarf ~code_begin ~code_end ~file_emitter: D. file;
2272
2183
if is_win64 system
2273
2184
then (
2274
2185
D. extrn " caml_call_gc" NEAR ;
@@ -2412,7 +2323,7 @@ let emit_probe_handler_wrapper p =
2412
2323
name, handler_code_sym
2413
2324
| Lcall_op
2414
2325
(Lcall_ind | Ltailcall_ind | Lcall_imm _ | Ltailcall_imm _ | Lextcall _)
2415
- | Lprologue | Lend | Lreloadretaddr | Lreturn | Lentertrap | Lpoptrap
2326
+ | Lprologue | Lend | Lreloadretaddr | Lreturn | Lentertrap | Lpoptrap _
2416
2327
| Lop _ | Llabel _ | Lbranch _
2417
2328
| Lcondbranch (_, _)
2418
2329
| Lcondbranch3 (_, _, _)
@@ -2580,7 +2491,7 @@ let emit_probe_notes0 () =
2580
2491
| Lcall_op
2581
2492
( Lcall_ind | Ltailcall_ind | Lcall_imm _ | Ltailcall_imm _
2582
2493
| Lextcall _ )
2583
- | Lprologue | Lend | Lreloadretaddr | Lreturn | Lentertrap | Lpoptrap
2494
+ | Lprologue | Lend | Lreloadretaddr | Lreturn | Lentertrap | Lpoptrap _
2584
2495
| Lop _ | Llabel _ | Lbranch _
2585
2496
| Lcondbranch (_, _)
2586
2497
| Lcondbranch3 (_, _, _)
0 commit comments