@@ -44,108 +44,6 @@ module ND = Asm_targets.Asm_directives_new
44
44
module S = Asm_targets. Asm_symbol
45
45
module L = Asm_targets. Asm_label
46
46
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; fill_x86_bin_emitter } ->
81
- let data = match fill_x86_bin_emitter with Zero -> true | Nop -> false in
82
- [X86_ast. Align (data, bytes)]
83
- (* The [fill_x86_bin_emitter] field is currently ignored by GAS and MASM,
84
- but used in the binary emitter. The bytes field is only converted to the
85
- final value when printing. *)
86
- | Bytes { str; comment } -> comment_lines comment @ [X86_ast. Bytes str]
87
- | Comment s -> comment_lines (Some s)
88
- | Const { constant; comment } ->
89
- comment_lines comment @ [to_x86_constant_with_width constant]
90
- | Direct_assignment (s , c ) ->
91
- (* We use [.set s c] for direct assignments, since it evaluates [c]
92
- directly. The alternative, [s = c], is sensitive to relocations. *)
93
- [X86_ast. Set (s, to_x86_constant c)]
94
- | File { file_num = None ; _ } ->
95
- Misc. fatal_error " file directive must always carry a number on x86"
96
- | File { file_num = Some file_num ; filename } ->
97
- [X86_ast. File (file_num, filename)]
98
- | Global s -> [X86_ast. Global s]
99
- | Indirect_symbol s -> [X86_ast. Indirect_symbol s]
100
- | Loc { file_num; line; col; discriminator } ->
101
- (* Behavior differs for negative column values. x86 will not output
102
- anything, but new directives will output 0. *)
103
- [X86_ast. Loc { file_num; line; col; discriminator }]
104
- (* CR sspies: The [typ] matters only for MASM. The convention (implemented in
105
- asm directives) is that in the text section, we use Code (NONE) and in the
106
- data section, we use Machine_width_data (QWORD for amd64). The two will be
107
- emitted differently by MASM. Because some code such as the frame tables
108
- have moved from the data section to the text section (but were previously
109
- still emitted with QUAD), using the new directives below changes this
110
- behavior. *)
111
- | New_label (s , Code) -> [X86_ast. NewLabel (s, NONE )]
112
- | New_label (s , Machine_width_data) -> [X86_ast. NewLabel (s, QWORD )]
113
- | New_line -> [X86_ast. NewLine ]
114
- | Private_extern s -> [X86_ast. Private_extern s]
115
- | Section { names; flags; args } ->
116
- [X86_ast. Section (names, flags, args, false )]
117
- (* delayed for this directive is always ignored in GAS printing, and section
118
- is not supported in binary emitter. In MASM, it only supports .text and
119
- .data. *)
120
- | Size (s , c ) -> [X86_ast. Size (s, to_x86_constant c)]
121
- | Sleb128 { constant; comment } ->
122
- comment_lines comment @ [X86_ast. Sleb128 (to_x86_constant constant)]
123
- | Space { bytes } -> [Space bytes]
124
- | Type (n , st ) ->
125
- let typ = ND. symbol_type_to_string st in
126
- [Type (n, typ)]
127
- | Uleb128 { constant; comment } ->
128
- comment_lines comment @ [X86_ast. Uleb128 (to_x86_constant constant)]
129
- | Cfi_adjust_cfa_offset n -> [X86_ast. Cfi_adjust_cfa_offset n]
130
- | Cfi_def_cfa_offset n -> [X86_ast. Cfi_def_cfa_offset n]
131
- | Cfi_endproc -> [X86_ast. Cfi_endproc ]
132
- | Cfi_offset { reg; offset } -> [X86_ast. Cfi_offset (reg, offset)]
133
- | Cfi_startproc -> [X86_ast. Cfi_startproc ]
134
- | Cfi_remember_state -> [X86_ast. Cfi_remember_state ]
135
- | Cfi_restore_state -> [X86_ast. Cfi_restore_state ]
136
- | Cfi_def_cfa_register r -> [X86_ast. Cfi_def_cfa_register r]
137
- | Protected s -> [X86_ast. Protected s]
138
- | Hidden s -> [X86_ast. Hidden s]
139
- | Weak s -> [X86_ast. Weak s]
140
- | External s -> [X86_ast. External (s, NEAR )]
141
- (* All uses of [.extrn] use NEAR as the type. *)
142
- | Reloc { offset; name = R_X86_64_PLT32 ; expr } ->
143
- [ X86_ast. Reloc
144
- { offset = to_x86_constant offset;
145
- name = R_X86_64_PLT32 ;
146
- expr = to_x86_constant expr
147
- } ]
148
-
149
47
(* * Turn a Linear label into an assembly label. The section is checked against the
150
48
section tracked by [D] when emitting label definitions. *)
151
49
let label_to_asm_label (l : label ) ~(section : Asm_targets.Asm_section.t ) : L. t
@@ -348,7 +246,7 @@ let emit_named_text_section ?(suffix = "") func_name =
348
246
| _ ->
349
247
ND. switch_to_section_raw
350
248
~names: [Printf. sprintf " .text.caml.%s%s" (emit_symbol func_name) suffix]
351
- ~flags: (Some " ax" ) ~args: [" @progbits" ];
249
+ ~flags: (Some " ax" ) ~args: [" @progbits" ] ~is_delayed: false ;
352
250
(* Warning: We set the internal section ref to Text here, because it
353
251
currently does not supported named text sections. In the rest of this
354
252
file, we pretend the section is called Text rather than the function
@@ -2237,8 +2135,7 @@ let begin_assembly unix =
2237
2135
ND. initialize ~big_endian: Arch. big_endian
2238
2136
~emit_assembly_comments: ! Flambda_backend_flags. dasm_comments
2239
2137
(* As a first step, we emit by calling the corresponding x86 emit
2240
- directives. *) ~emit: (fun d ->
2241
- List. iter directive (to_x86_directive d));
2138
+ directives. *) ~emit: (fun d -> directive (Directive d));
2242
2139
let code_begin = Cmm_helpers. make_symbol " code_begin" in
2243
2140
let code_end = Cmm_helpers. make_symbol " code_end" in
2244
2141
Emitaux.Dwarf_helpers. begin_dwarf ~code_begin ~code_end ~file_emitter ;
0 commit comments