Skip to content

Commit b0d668b

Browse files
committed
use directives in place of emitaux
1 parent 703e1ae commit b0d668b

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

backend/arm64/emit.ml

+17-11
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,12 @@ type local_realloc_call =
538538

539539
let local_realloc_sites = ref ([] : local_realloc_call list)
540540

541+
let file_emitter ~file_num ~file_name =
542+
D.file ~file_num:(Some file_num) ~file_name
543+
544+
let emit_debug_info ?discriminator dbg =
545+
Emitaux.emit_debug_info_gen ?discriminator dbg file_emitter D.loc
546+
541547
let emit_local_realloc lr =
542548
D.define_label lr.lr_lbl;
543549
emit_debug_info lr.lr_dbg;
@@ -685,7 +691,7 @@ let emit_stack_adjustment n =
685691
let ml = m land 0xFFF and mh = m land 0xFFF_000 in
686692
if mh <> 0 then DSL.ins instr [| DSL.sp; DSL.sp; DSL.imm mh |];
687693
if ml <> 0 then DSL.ins instr [| DSL.sp; DSL.sp; DSL.imm ml |];
688-
if n <> 0 then cfi_adjust_cfa_offset (-n)
694+
if n <> 0 then D.cfi_adjust_cfa_offset ~bytes:(-n)
689695

690696
(* Deallocate the stack frame and reload the return address before a return or
691697
tail call *)
@@ -697,7 +703,7 @@ let output_epilogue f =
697703
if n > 0 then emit_stack_adjustment n;
698704
f ();
699705
(* reset CFA back because function body may continue *)
700-
if n > 0 then cfi_adjust_cfa_offset n
706+
if n > 0 then D.cfi_adjust_cfa_offset ~bytes:n
701707

702708
(* Output add-immediate / sub-immediate / cmp-immediate instructions *)
703709

@@ -1390,7 +1396,7 @@ let emit_instr i =
13901396
if n > 0 then emit_stack_adjustment (-n);
13911397
if !contains_calls
13921398
then (
1393-
cfi_offset ~reg:30 (* return address *) ~offset:(-8);
1399+
D.cfi_offset ~reg:30 (* return address *) ~offset:(-8);
13941400
DSL.ins I.STR [| DSL.reg_x_30; DSL.emit_mem_sp_offset (n - 8) |])
13951401
| Lop (Intop_atomic _) ->
13961402
(* Never generated; builtins are not yet translated to atomics *)
@@ -1489,8 +1495,8 @@ let emit_instr i =
14891495
if Config.runtime5
14901496
then (
14911497
DSL.ins I.MOV [| DSL.reg_x_29; DSL.sp |];
1492-
cfi_remember_state ();
1493-
cfi_def_cfa_register ~reg:29;
1498+
D.cfi_remember_state ();
1499+
D.cfi_def_cfa_register ~reg:(Int.to_string 29);
14941500
let offset = Domainstate.(idx_of_field Domain_c_stack) * 8 in
14951501
DSL.ins I.LDR
14961502
[| DSL.emit_reg reg_tmp1;
@@ -1499,7 +1505,7 @@ let emit_instr i =
14991505
DSL.ins I.MOV [| DSL.sp; DSL.emit_reg reg_tmp1 |]);
15001506
DSL.ins I.BL [| DSL.emit_symbol (S.create func) |];
15011507
if Config.runtime5 then DSL.ins I.MOV [| DSL.sp; DSL.reg_x_29 |];
1502-
cfi_restore_state ())
1508+
D.cfi_restore_state ())
15031509
| Lop (Stackoffset n) ->
15041510
assert (n mod 16 = 0);
15051511
emit_stack_adjustment (-n);
@@ -1959,7 +1965,7 @@ let emit_instr i =
19591965
*)
19601966
| Lentertrap -> ()
19611967
| Ladjust_stack_offset { delta_bytes } ->
1962-
cfi_adjust_cfa_offset delta_bytes;
1968+
D.cfi_adjust_cfa_offset ~bytes:delta_bytes;
19631969
stack_offset := !stack_offset + delta_bytes
19641970
| Lpushtrap { lbl_handler } ->
19651971
let lbl_handler = label_to_asm_label ~section:Text lbl_handler in
@@ -1970,14 +1976,14 @@ let emit_instr i =
19701976
DSL.emit_reg reg_tmp1;
19711977
DSL.mem_pre ~base:Arm64_ast.Reg.sp ~offset:(-16)
19721978
|];
1973-
cfi_adjust_cfa_offset 16;
1979+
D.cfi_adjust_cfa_offset ~bytes:16;
19741980
DSL.ins I.MOV [| DSL.emit_reg reg_trap_ptr; DSL.sp |]
19751981
| Lpoptrap ->
19761982
DSL.ins I.LDR
19771983
[| DSL.emit_reg reg_trap_ptr;
19781984
DSL.mem_post ~base:Arm64_ast.Reg.sp ~offset:16
19791985
|];
1980-
cfi_adjust_cfa_offset (-16);
1986+
D.cfi_adjust_cfa_offset ~bytes:(-16);
19811987
stack_offset := !stack_offset - 16
19821988
| Lraise k -> (
19831989
match k with
@@ -2067,7 +2073,7 @@ let fundecl fundecl =
20672073
D.type_symbol ~ty:Function fun_sym;
20682074
D.define_symbol_label ~section:Text fun_sym;
20692075
emit_debug_info fundecl.fun_dbg;
2070-
cfi_startproc ();
2076+
D.cfi_startproc ();
20712077
let num_call_gc = num_call_gc_points fundecl.fun_body in
20722078
let max_out_of_line_code_offset = max_out_of_line_code_offset ~num_call_gc in
20732079
BR.relax fundecl.fun_body ~max_out_of_line_code_offset;
@@ -2081,7 +2087,7 @@ let fundecl fundecl =
20812087
| Some fun_end_label ->
20822088
let fun_end_label = label_to_asm_label ~section:Text fun_end_label in
20832089
D.define_label fun_end_label);
2084-
cfi_endproc ();
2090+
D.cfi_endproc ();
20852091
(* The type symbol and the size are system specific. They are not output on
20862092
macOS. The asm directives take care of correctly handling this distinction.
20872093
For the size, they automatically emit the size [. - symbol], meaning "this

backend/asm_targets/asm_directives_new.ml

+17
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ module Directive = struct
166166
offset : int
167167
}
168168
| Cfi_startproc
169+
| Cfi_remember_state
170+
| Cfi_restore_state
171+
| Cfi_def_cfa_register of string
169172
| Comment of comment
170173
| Const of
171174
{ constant : Constant_with_width.t;
@@ -333,6 +336,9 @@ module Directive = struct
333336
| Cfi_offset { reg; offset } ->
334337
bprintf buf "\t.cfi_offset %d, %d" reg offset
335338
| Cfi_startproc -> bprintf buf "\t.cfi_startproc"
339+
| Cfi_remember_state -> bprintf buf "\t.cfi_remember_state"
340+
| Cfi_restore_state -> bprintf buf "\t.cfi_restore_state"
341+
| Cfi_def_cfa_register reg -> bprintf buf "\t.cfi_def_cfa_register %%%s" reg
336342
| File { file_num = None; filename } ->
337343
bprintf buf "\t.file\t\"%s\"" filename
338344
| File { file_num = Some file_num; filename } ->
@@ -422,6 +428,9 @@ module Directive = struct
422428
| Cfi_endproc -> unsupported "Cfi_endproc"
423429
| Cfi_offset _ -> unsupported "Cfi_offset"
424430
| Cfi_startproc -> unsupported "Cfi_startproc"
431+
| Cfi_remember_state -> unsupported "Cfi_remember_state"
432+
| Cfi_restore_state -> unsupported "Cfi_restore_state"
433+
| Cfi_def_cfa_register _ -> unsupported "Cfi_def_cfa_register"
425434
| File _ -> unsupported "File"
426435
| Indirect_symbol _ -> unsupported "Indirect_symbol"
427436
| Loc _ -> unsupported "Loc"
@@ -512,6 +521,14 @@ let cfi_offset ~reg ~offset =
512521

513522
let cfi_startproc () = if should_generate_cfi () then emit Cfi_startproc
514523

524+
let cfi_remember_state () =
525+
if should_generate_cfi () then emit Cfi_remember_state
526+
527+
let cfi_restore_state () = if should_generate_cfi () then emit Cfi_restore_state
528+
529+
let cfi_def_cfa_register ~reg =
530+
if should_generate_cfi () then emit (Cfi_def_cfa_register reg)
531+
515532
let comment text = if emit_comments () then emit (Comment text)
516533

517534
let loc ~file_num ~line ~col ?discriminator () =

backend/asm_targets/asm_directives_new.mli

+12
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ val cfi_startproc : unit -> unit
145145
(** Mark the end of a function, for CFI purposes. *)
146146
val cfi_endproc : unit -> unit
147147

148+
(** Remember the current state for CFI purposes. *)
149+
val cfi_remember_state : unit -> unit
150+
151+
(** Restore the state for CFI purposes. *)
152+
val cfi_restore_state : unit -> unit
153+
154+
(** Define a CFA register, for CFI purposes. *)
155+
val cfi_def_cfa_register : reg:string -> unit
156+
148157
(** Mark that the call stack is not to be executable at runtime. Not
149158
supported on all platforms. *)
150159
val mark_stack_non_executable : unit -> unit
@@ -367,6 +376,9 @@ module Directive : sig
367376
offset : int
368377
}
369378
| Cfi_startproc
379+
| Cfi_remember_state
380+
| Cfi_restore_state
381+
| Cfi_def_cfa_register of string
370382
| Comment of comment
371383
| Const of
372384
{ constant : Constant_with_width.t;

0 commit comments

Comments
 (0)