Skip to content

Commit 7524bbb

Browse files
authored
Remove direct assignment of the form x = e (ocaml-flambda#3906)
* remove direct assignment of the form x = e * ocamlformat
1 parent e23ff86 commit 7524bbb

File tree

7 files changed

+5
-13
lines changed

7 files changed

+5
-13
lines changed

backend/amd64/emit.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ let to_x86_directive (dir : ND.Directive.t) : X86_ast.asm_line list =
8080
| Const { constant; comment } ->
8181
comment_lines comment @ [to_x86_constant_with_width constant]
8282
| Direct_assignment (s, c) ->
83-
[X86_ast.Direct_assignment (s, to_x86_constant c)]
83+
(* We use [.set s c] for direct assignments, since it evaluates [c]
84+
directly. The alternative, [s = c], is sensitive to relocations. *)
85+
[X86_ast.Set (s, to_x86_constant c)]
8486
| File { file_num = None; _ } ->
8587
Misc.fatal_error "file directive must always carry a number on x86"
8688
| File { file_num = Some file_num; filename } ->

backend/x86_ast.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,5 @@ type asm_line =
259259
| Type of string * string
260260
| Reloc of reloc
261261

262-
(* MacOS only *)
263-
| Direct_assignment of string * constant
264262

265263
type asm_program = asm_line list

backend/x86_binary_emitter.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ let assemble_line b loc ins =
17311731
offset = ConstSub (ConstThis, Const 4L);
17321732
} when String.Tbl.mem local_labels wrap_label ->
17331733
record_local_reloc b ~offset:(-4) (RelocCall wrap_label)
1734-
| Reloc _ | Sleb128 _ | Uleb128 _ | Direct_assignment _ ->
1734+
| Reloc _ | Sleb128 _ | Uleb128 _ ->
17351735
X86_gas.generate_asm Out_channel.stderr [ins];
17361736
Misc.fatal_errorf "x86_binary_emitter: unsupported instruction"
17371737
with e ->

backend/x86_dsl.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ module D = struct
121121

122122
let data () = section [".data"] None []
123123

124-
let direct_assignment var const = directive (Direct_assignment (var, const))
125-
126124
let extrn s ptr = directive (External (s, ptr))
127125

128126
let file ~file_num ~file_name = directive (File (file_num, file_name))

backend/x86_dsl.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ module D : sig
121121

122122
val data : unit -> unit
123123

124-
val direct_assignment : string -> constant -> unit
125-
126124
val extrn : string -> data_type -> unit
127125

128126
val file : file_num:int -> file_name:string -> unit

backend/x86_gas.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,6 @@ let print_line b = function
343343
cst expr
344344
(* masm only *)
345345
| External _ | Mode386 | Model _ -> assert false
346-
(* MacOS only *)
347-
| Direct_assignment (var, c) ->
348-
assert (List.mem Config.system ["macosx"; "darwin"]);
349-
bprintf b "\t%s = %a" var cst c
350346

351347
let generate_asm oc lines =
352348
let b = Buffer.create 10000 in

backend/x86_masm.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ let print_line b = function
269269
| Cfi_def_cfa_register _ | Cfi_def_cfa_offset _ | Cfi_offset _
270270
| Cfi_remember_state | Cfi_restore_state | File _ | Indirect_symbol _ | Loc _
271271
| Private_extern _ | Set _ | Size _ | Type _ | Hidden _ | Weak _ | Reloc _
272-
| Direct_assignment _ | Protected _ ->
272+
| Protected _ ->
273273
assert false
274274

275275
let generate_asm oc lines =

0 commit comments

Comments
 (0)