Skip to content

Commit 7bf1756

Browse files
committed
remove old directives
1 parent fb842d5 commit 7bf1756

17 files changed

+220
-580
lines changed

backend/amd64/emit.ml

+2-104
Original file line numberDiff line numberDiff line change
@@ -44,107 +44,6 @@ module ND = Asm_targets.Asm_directives_new
4444
module S = Asm_targets.Asm_symbol
4545
module L = Asm_targets.Asm_label
4646

47-
let rec to_x86_constant (c : ND.Directive.Constant.t) : X86_ast.constant =
48-
match c with
49-
| Signed_int i -> Const i
50-
| Unsigned_int i -> Const (Numbers.Uint64.to_int64 i)
51-
| This -> ConstThis
52-
| Named_thing s ->
53-
ConstLabel s
54-
(* both seem to be printed directly to the buffer without any conversion*)
55-
| Add (c1, c2) -> ConstAdd (to_x86_constant c1, to_x86_constant c2)
56-
| Sub (c1, c2) -> ConstSub (to_x86_constant c1, to_x86_constant c2)
57-
58-
let to_x86_constant_with_width (c : ND.Directive.Constant_with_width.t) :
59-
X86_ast.asm_line =
60-
let width = ND.Directive.Constant_with_width.width_in_bytes c in
61-
let const = ND.Directive.Constant_with_width.constant c in
62-
let const = to_x86_constant const in
63-
match width with
64-
| Eight -> Byte const
65-
(* on x86 Word is 2 bytes; warning this is not the same on Arm *)
66-
| Sixteen -> Word const
67-
| Thirty_two -> Long const
68-
| Sixty_four -> Quad const
69-
70-
let to_x86_directive (dir : ND.Directive.t) : X86_ast.asm_line list =
71-
let comment_lines comment =
72-
(* CR sspies: This check is usually done in the printing function of the new
73-
directives. Since we are skipping those at the moment (by emitting via
74-
the X86 DSL), we do the same check here in the conversion. *)
75-
if !Clflags.keep_asm_file && !Flambda_backend_flags.dasm_comments
76-
then Option.to_list (Option.map (fun s -> X86_ast.Comment s) comment)
77-
else []
78-
in
79-
match dir with
80-
| Align { bytes; data_section } ->
81-
[X86_ast.Align (data_section, bytes)]
82-
(* The data field is currently ignored by GAS and MASM, but used in the
83-
binary emitter. The bytes field is only converted to the final value when
84-
printing. *)
85-
| Bytes { str; comment } -> comment_lines comment @ [X86_ast.Bytes str]
86-
| Comment s -> comment_lines (Some s)
87-
| Const { constant; comment } ->
88-
comment_lines comment @ [to_x86_constant_with_width constant]
89-
| Direct_assignment (s, c) ->
90-
(* We use [.set s c] for direct assignments, since it evaluates [c]
91-
directly. The alternative, [s = c], is sensitive to relocations. *)
92-
[X86_ast.Set (s, to_x86_constant c)]
93-
| File { file_num = None; _ } ->
94-
Misc.fatal_error "file directive must always carry a number on x86"
95-
| File { file_num = Some file_num; filename } ->
96-
[X86_ast.File (file_num, filename)]
97-
| Global s -> [X86_ast.Global s]
98-
| Indirect_symbol s -> [X86_ast.Indirect_symbol s]
99-
| Loc { file_num; line; col; discriminator } ->
100-
(* Behavior differs for negative column values. x86 will not output
101-
anything, but new directives will output 0. *)
102-
[X86_ast.Loc { file_num; line; col; discriminator }]
103-
(* CR sspies: The [typ] matters only for MASM. The convention (implemented in
104-
asm directives) is that in the text section, we use Code (NONE) and in the
105-
data section, we use Machine_width_data (QWORD for amd64). The two will be
106-
emitted differently by MASM. Because some code such as the frame tables
107-
have moved from the data section to the text section (but were previously
108-
still emitted with QUAD), using the new directives below changes this
109-
behavior. *)
110-
| New_label (s, Code) -> [X86_ast.NewLabel (s, NONE)]
111-
| New_label (s, Machine_width_data) -> [X86_ast.NewLabel (s, QWORD)]
112-
| New_line -> [X86_ast.NewLine]
113-
| Private_extern s -> [X86_ast.Private_extern s]
114-
| Section { names; flags; args } ->
115-
[X86_ast.Section (names, flags, args, false)]
116-
(* delayed for this directive is always ignored in GAS printing, and section
117-
is not supported in binary emitter. In MASM, it only supports .text and
118-
.data. *)
119-
| Size (s, c) -> [X86_ast.Size (s, to_x86_constant c)]
120-
| Sleb128 { constant; comment } ->
121-
comment_lines comment @ [X86_ast.Sleb128 (to_x86_constant constant)]
122-
| Space { bytes } -> [Space bytes]
123-
| Type (n, st) ->
124-
let typ = ND.symbol_type_to_string st in
125-
[Type (n, typ)]
126-
| Uleb128 { constant; comment } ->
127-
comment_lines comment @ [X86_ast.Uleb128 (to_x86_constant constant)]
128-
| Cfi_adjust_cfa_offset n -> [X86_ast.Cfi_adjust_cfa_offset n]
129-
| Cfi_def_cfa_offset n -> [X86_ast.Cfi_def_cfa_offset n]
130-
| Cfi_endproc -> [X86_ast.Cfi_endproc]
131-
| Cfi_offset { reg; offset } -> [X86_ast.Cfi_offset (reg, offset)]
132-
| Cfi_startproc -> [X86_ast.Cfi_startproc]
133-
| Cfi_remember_state -> [X86_ast.Cfi_remember_state]
134-
| Cfi_restore_state -> [X86_ast.Cfi_restore_state]
135-
| Cfi_def_cfa_register r -> [X86_ast.Cfi_def_cfa_register r]
136-
| Protected s -> [X86_ast.Protected s]
137-
| Hidden s -> [X86_ast.Hidden s]
138-
| Weak s -> [X86_ast.Weak s]
139-
| External s -> [X86_ast.External (s, NEAR)]
140-
(* All uses of [.extrn] use NEAR as the type. *)
141-
| Reloc { offset; name = R_X86_64_PLT32; expr } ->
142-
[ X86_ast.Reloc
143-
{ offset = to_x86_constant offset;
144-
name = R_X86_64_PLT32;
145-
expr = to_x86_constant expr
146-
} ]
147-
14847
(** Turn a Linear label into an assembly label. The section is checked against the
14948
section tracked by [D] when emitting label definitions. *)
15049
let label_to_asm_label (l : label) ~(section : Asm_targets.Asm_section.t) : L.t
@@ -338,7 +237,7 @@ let emit_named_text_section ?(suffix = "") func_name =
338237
| _ ->
339238
ND.switch_to_section_raw
340239
~names:[Printf.sprintf ".text.caml.%s%s" (emit_symbol func_name) suffix]
341-
~flags:(Some "ax") ~args:["@progbits"];
240+
~flags:(Some "ax") ~args:["@progbits"] ~is_delayed:false;
342241
(* Warning: We set the internal section ref to Text here, because it
343242
currently does not supported named text sections. In the rest of this
344243
file, we pretend the section is called Text rather than the function
@@ -2222,8 +2121,7 @@ let begin_assembly unix =
22222121
ND.initialize ~big_endian:Arch.big_endian
22232122
~emit_assembly_comments:!Flambda_backend_flags.dasm_comments
22242123
(* As a first step, we emit by calling the corresponding x86 emit
2225-
directives. *) ~emit:(fun d ->
2226-
List.iter directive (to_x86_directive d));
2124+
directives. *) ~emit:(fun d -> directive (Directive d));
22272125
let code_begin = Cmm_helpers.make_symbol "code_begin" in
22282126
let code_end = Cmm_helpers.make_symbol "code_end" in
22292127
Emitaux.Dwarf_helpers.begin_dwarf ~code_begin ~code_end ~file_emitter;

backend/arm64/emit.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,8 @@ let emit_literals p align emit_literal =
774774
D.switch_to_section_raw
775775
~names:["__TEXT,__literal" ^ Int.to_string align]
776776
~flags:None
777-
~args:[Int.to_string align ^ "byte_literals"];
777+
~args:[Int.to_string align ^ "byte_literals"]
778+
~is_delayed:false;
778779
(* CR sspies: The following section is incorrect. We are in a data section
779780
here. Fix this when cleaning up the section mechanism. *)
780781
D.unsafe_set_internal_section_ref Text);
@@ -1233,7 +1234,7 @@ let emit_named_text_section func_name =
12331234
the new asm directives. *)
12341235
D.switch_to_section_raw
12351236
~names:[".text.caml." ^ S.encode (S.create func_name)]
1236-
~flags:(Some "ax") ~args:["%progbits"];
1237+
~flags:(Some "ax") ~args:["%progbits"] ~is_delayed:false;
12371238
(* Warning: We set the internal section ref to Text here, because it
12381239
currently does not supported named text sections. In the rest of this
12391240
file, we pretend the section is called Text rather than the function

backend/asm_targets/asm_directives.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ module Make (A : Asm_directives_intf.Arg) : Asm_directives_intf.S = struct
135135
()
136136
| _ ->
137137
current_dwarf_section_ref := Some section;
138-
let ({ names; flags; args } : Asm_section.section_details) =
138+
let ({ names; flags; args; is_delayed } : Asm_section.section_details) =
139139
Asm_section.details section ~first_occurrence
140140
in
141141
if not first_occurrence then new_line ();
142-
D.section ~delayed:(Asm_section.is_delayed section) names flags args;
142+
D.section ~delayed:is_delayed names flags args;
143143
if first_occurrence then define_label (Asm_label.for_section section)
144144

145145
let initialize () =

0 commit comments

Comments
 (0)