Skip to content

Commit 7c060c6

Browse files
committed
merge
2 parents 56b5369 + c86a597 commit 7c060c6

File tree

156 files changed

+1987
-1717
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+1987
-1717
lines changed

backend/amd64/emit.ml

+22-111
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,20 @@ let to_x86_constant_with_width (c : ND.Directive.Constant_with_width.t) :
6868

6969
let to_x86_directive (dir : ND.Directive.t) : X86_ast.asm_line list =
7070
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 []
7277
in
7378
match dir with
7479
| Align { bytes } ->
7580
[X86_ast.Align (false, bytes)]
7681
(* The data field is currently ignored by both assembler backends. The bytes
7782
field is only converted to the final value when printing. *)
7883
| Bytes { str; comment } -> comment_lines comment @ [X86_ast.Bytes str]
79-
| Comment s -> [X86_ast.Comment s]
84+
| Comment s -> comment_lines (Some s)
8085
| Const { constant; comment } ->
8186
comment_lines comment @ [to_x86_constant_with_width constant]
8287
| Direct_assignment (s, c) ->
@@ -108,7 +113,7 @@ let to_x86_directive (dir : ND.Directive.t) : X86_ast.asm_line list =
108113
comment_lines comment @ [X86_ast.Sleb128 (to_x86_constant constant)]
109114
| Space { bytes } -> [Space bytes]
110115
| 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
112117
[Type (n, typ)]
113118
| Uleb128 { constant; comment } ->
114119
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 =
117122
| Cfi_endproc -> [X86_ast.Cfi_endproc]
118123
| Cfi_offset { reg; offset } -> [X86_ast.Cfi_offset (reg, offset)]
119124
| 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]
120128
| Protected s -> [X86_ast.Protected s]
121129

122130
let _label s = D.label ~typ:QWORD s
@@ -619,105 +627,6 @@ let emit_jump_tables () =
619627
List.iter emit_jump_table !jump_tables;
620628
jump_tables := []
621629

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-
721630
(* Names for instructions *)
722631

723632
let instr_for_intop = function
@@ -1589,7 +1498,10 @@ let emit_instr ~first ~fallthrough i =
15891498
(* +0.0 *)
15901499
I.xorpd (res i 0) (res i 0)
15911500
| _ ->
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. *)
15931505
let lbl = add_float_constant (Int64.of_int32 f) in
15941506
I.movss (mem64_rip REAL4 (emit_label lbl)) (res i 0))
15951507
| Lop (Const_float f) -> (
@@ -2081,7 +1993,7 @@ let emit_instr ~first ~fallthrough i =
20811993
cfi_adjust_cfa_offset 8;
20821994
I.mov rsp (domain_field Domainstate.Domain_exn_handler);
20831995
stack_offset := !stack_offset + 16
2084-
| Lpoptrap ->
1996+
| Lpoptrap _ ->
20851997
emit_pop_trap_label ();
20861998
I.pop (domain_field Domainstate.Domain_exn_handler);
20871999
cfi_adjust_cfa_offset (-8);
@@ -2118,7 +2030,7 @@ let emit_instr ~first ~fallthrough i =
21182030
let rec emit_all ~first ~fallthrough i =
21192031
match i.desc with
21202032
| Lend -> ()
2121-
| Lprologue | Lreloadretaddr | Lreturn | Lentertrap | Lpoptrap | Lop _
2033+
| Lprologue | Lreloadretaddr | Lreturn | Lentertrap | Lpoptrap _ | Lop _
21222034
| Lcall_op _ | Llabel _ | Lbranch _
21232035
| Lcondbranch (_, _)
21242036
| Lcondbranch3 (_, _, _)
@@ -2260,15 +2172,14 @@ let begin_assembly unix =
22602172
(* We initialize the new assembly directives. *)
22612173
Asm_targets.Asm_label.initialize ~new_label:(fun () ->
22622174
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
22652177
(* As a first step, we emit by calling the corresponding x86 emit
22662178
directives. *) ~emit:(fun d ->
22672179
List.iter directive (to_x86_directive d));
22682180
let code_begin = Cmm_helpers.make_symbol "code_begin" in
22692181
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;
22722183
if is_win64 system
22732184
then (
22742185
D.extrn "caml_call_gc" NEAR;
@@ -2412,7 +2323,7 @@ let emit_probe_handler_wrapper p =
24122323
name, handler_code_sym
24132324
| Lcall_op
24142325
(Lcall_ind | Ltailcall_ind | Lcall_imm _ | Ltailcall_imm _ | Lextcall _)
2415-
| Lprologue | Lend | Lreloadretaddr | Lreturn | Lentertrap | Lpoptrap
2326+
| Lprologue | Lend | Lreloadretaddr | Lreturn | Lentertrap | Lpoptrap _
24162327
| Lop _ | Llabel _ | Lbranch _
24172328
| Lcondbranch (_, _)
24182329
| Lcondbranch3 (_, _, _)
@@ -2580,7 +2491,7 @@ let emit_probe_notes0 () =
25802491
| Lcall_op
25812492
( Lcall_ind | Ltailcall_ind | Lcall_imm _ | Ltailcall_imm _
25822493
| Lextcall _ )
2583-
| Lprologue | Lend | Lreloadretaddr | Lreturn | Lentertrap | Lpoptrap
2494+
| Lprologue | Lend | Lreloadretaddr | Lreturn | Lentertrap | Lpoptrap _
25842495
| Lop _ | Llabel _ | Lbranch _
25852496
| Lcondbranch (_, _)
25862497
| Lcondbranch3 (_, _, _)

0 commit comments

Comments
 (0)