aboutsummaryrefslogtreecommitdiffstats
path: root/arm/PrintAsm.ml
diff options
context:
space:
mode:
Diffstat (limited to 'arm/PrintAsm.ml')
-rw-r--r--arm/PrintAsm.ml108
1 files changed, 24 insertions, 84 deletions
diff --git a/arm/PrintAsm.ml b/arm/PrintAsm.ml
index 7f511912..9558348a 100644
--- a/arm/PrintAsm.ml
+++ b/arm/PrintAsm.ml
@@ -19,6 +19,7 @@ open Sections
open AST
open Memdata
open Asm
+open PrintAsmaux
(* Type for the ABI versions *)
type float_abi_type =
@@ -31,10 +32,6 @@ module type PRINTER_OPTIONS =
val float_abi: float_abi_type
val vfpv3: bool
val hardware_idiv: bool
- val cfi_startproc: out_channel -> unit
- val cfi_endproc: out_channel -> unit
- val cfi_adjust: out_channel -> int32 -> unit
- val cfi_rel_offset: out_channel -> string -> int32 -> unit
end
(* Module containing the printing functions *)
@@ -45,38 +42,14 @@ module AsmPrinter (Opt: PRINTER_OPTIONS) =
let literals_in_code = ref true (* to be turned into a proper option *)
-(* On-the-fly label renaming *)
-
-let next_label = ref 100
-
-let new_label() =
- let lbl = !next_label in incr next_label; lbl
-
-let current_function_labels = (Hashtbl.create 39 : (label, int) Hashtbl.t)
-
-let label_for_label lbl =
- try
- Hashtbl.find current_function_labels lbl
- with Not_found ->
- let lbl' = new_label() in
- Hashtbl.add current_function_labels lbl lbl';
- lbl'
-
(* Basic printing functions *)
-let print_symb oc symb =
- fprintf oc "%s" (extern_atom symb)
-
-let print_label oc lbl =
- fprintf oc ".L%d" (label_for_label lbl)
-
-let coqint oc n =
- fprintf oc "%ld" (camlint_of_coqint n)
+let print_label oc lbl = label oc (transl_label lbl)
let comment = "@"
-let print_symb_ofs oc (symb, ofs) =
- print_symb oc symb;
+let symbol_offset oc (symb, ofs) =
+ symbol oc symb;
let ofs = camlint_of_coqint ofs in
if ofs <> 0l then fprintf oc " + %ld" ofs
@@ -254,7 +227,7 @@ let emit_constants oc =
Hashtbl.iter
(fun (id, ofs) lbl ->
fprintf oc ".L%d: .word %a\n"
- lbl print_symb_ofs (id, ofs))
+ lbl symbol_offset (id, ofs))
symbol_labels;
reset_constants ()
@@ -263,13 +236,13 @@ let emit_constants oc =
let loadsymbol oc r id ofs =
if !Clflags.option_mthumb then begin
fprintf oc " movw %a, #:lower16:%a\n"
- ireg r print_symb_ofs (id, ofs);
+ ireg r symbol_offset (id, ofs);
fprintf oc " movt %a, #:upper16:%a\n"
- ireg r print_symb_ofs (id, ofs); 2
+ ireg r symbol_offset (id, ofs); 2
end else begin
let lbl = label_symbol id ofs in
fprintf oc " ldr %a, .L%d @ %a\n"
- ireg r lbl print_symb_ofs (id, ofs); 1
+ ireg r lbl symbol_offset (id, ofs); 1
end
(* Emit instruction sequences that set or offset a register by a constant. *)
@@ -336,8 +309,6 @@ let print_location oc loc =
(* Handling of annotations *)
-let re_file_line = Str.regexp "#line:\\(.*\\):\\([1-9][0-9]*\\)$"
-
let print_annot_stmt oc txt targs args =
if Str.string_match re_file_line txt 0 then begin
print_file_line oc (Str.matched_group 1 txt)
@@ -483,10 +454,6 @@ let print_builtin_vstore_global oc chunk id ofs args =
(* Handling of varargs *)
-let current_function_stacksize = ref 0l
-let current_function_sig =
- ref { sig_args = []; sig_res = None; sig_cc = cc_default }
-
let align n a = (n + a - 1) land (-a)
let rec next_arg_location ir ofs = function
@@ -761,7 +728,7 @@ let print_instruction oc = function
fprintf oc " b%s %a\n" (condition_name bit) print_label lbl; 1
| Pbsymb(id, sg) ->
let n = fixup_arguments oc Outgoing sg in
- fprintf oc " b %a\n" print_symb id;
+ fprintf oc " b %a\n" symbol id;
n + 1
| Pbreg(r, sg) ->
let n =
@@ -772,7 +739,7 @@ let print_instruction oc = function
n + 1
| Pblsymb(id, sg) ->
let n1 = fixup_arguments oc Outgoing sg in
- fprintf oc " bl %a\n" print_symb id;
+ fprintf oc " bl %a\n" symbol id;
let n2 = fixup_result oc Incoming sg in
n1 + 1 + n2
| Pblreg(r, sg) ->
@@ -825,7 +792,7 @@ let print_instruction oc = function
| Pstr(r1, r2, sa) | Pstr_a(r1, r2, sa) ->
fprintf oc " str %a, [%a, %a]\n" ireg r1 ireg r2 shift_op sa;
begin match r1, r2, sa with
- | IR14, IR13, SOimm n -> Opt.cfi_rel_offset oc "lr" (camlint_of_coqint n)
+ | IR14, IR13, SOimm n -> cfi_rel_offset oc "lr" (camlint_of_coqint n)
| _ -> ()
end;
1
@@ -969,11 +936,11 @@ let print_instruction oc = function
fprintf oc " mov r12, sp\n";
if (!current_function_sig).sig_cc.cc_vararg then begin
fprintf oc " push {r0, r1, r2, r3}\n";
- Opt.cfi_adjust oc 16l
+ cfi_adjust oc 16l
end;
let sz' = camlint_of_coqint sz in
let ninstr = subimm oc "sp" "sp" sz in
- Opt.cfi_adjust oc sz';
+ cfi_adjust oc sz';
fprintf oc " str r12, [sp, #%a]\n" coqint ofs;
current_function_stacksize := sz';
ninstr + (if (!current_function_sig).sig_cc.cc_vararg then 3 else 2)
@@ -1084,18 +1051,17 @@ let print_function oc name fn =
match !Clflags.option_falignfunctions with Some n -> n | None -> 4 in
fprintf oc " .balign %d\n" alignment;
if not (C2C.atom_is_static name) then
- fprintf oc " .global %a\n" print_symb name;
+ fprintf oc " .global %a\n" symbol name;
if !Clflags.option_mthumb then
fprintf oc " .thumb_func\n";
- fprintf oc "%a:\n" print_symb name;
+ fprintf oc "%a:\n" symbol name;
print_location oc (C2C.atom_location name);
- Opt.cfi_startproc oc;
+ cfi_startproc oc;
ignore (fixup_arguments oc Incoming fn.fn_sig);
print_instructions oc fn.fn_code;
if !literals_in_code then emit_constants oc;
- Opt.cfi_endproc oc;
- fprintf oc " .type %a, %%function\n" print_symb name;
- fprintf oc " .size %a, . - %a\n" print_symb name print_symb name;
+ cfi_endproc oc;
+ print_fun_info oc name;
if not !literals_in_code && !size_constants > 0 then begin
section oc lit;
emit_constants oc
@@ -1122,7 +1088,7 @@ let print_init oc = function
if Z.gt n Z.zero then
fprintf oc " .space %s\n" (Z.to_string n)
| Init_addrof(symb, ofs) ->
- fprintf oc " .word %a\n" print_symb_ofs (symb, ofs)
+ fprintf oc " .word %a\n" symbol_offset (symb, ofs)
let print_init_data oc name id =
if Str.string_match PrintCsyntax.re_string_literal (extern_atom name) 0
@@ -1151,18 +1117,17 @@ let print_var oc name v =
fprintf oc " %s\n" name_sec;
fprintf oc " .balign %d\n" align;
if not (C2C.atom_is_static name) then
- fprintf oc " .global %a\n" print_symb name;
- fprintf oc "%a:\n" print_symb name;
+ fprintf oc " .global %a\n" symbol name;
+ fprintf oc "%a:\n" symbol name;
print_init_data oc name v.gvar_init;
- fprintf oc " .type %a, %%object\n" print_symb name;
- fprintf oc " .size %a, . - %a\n" print_symb name print_symb name
+ print_var_info oc name
end else begin
let sz =
match v.gvar_init with [Init_space sz] -> sz | _ -> assert false in
if C2C.atom_is_static name then
- fprintf oc " .local %a\n" print_symb name;
+ fprintf oc " .local %a\n" symbol name;
fprintf oc " .comm %a, %s, %d\n"
- print_symb name
+ symbol name
(Z.to_string sz)
align
end
@@ -1190,31 +1155,6 @@ let print_program oc p =
| "armv7r" | "armv7m" -> !Clflags.option_mthumb
| _ -> false
-
- (* Emit .cfi directives *)
- let cfi_startproc =
- if Configuration.asm_supports_cfi then
- (fun oc -> fprintf oc " .cfi_startproc\n")
- else
- (fun _ -> ())
-
- let cfi_endproc =
- if Configuration.asm_supports_cfi then
- (fun oc ->fprintf oc " .cfi_endproc\n")
- else
- (fun _ -> ())
-
- let cfi_adjust =
- if Configuration.asm_supports_cfi then
- (fun oc delta -> fprintf oc " .cfi_adjust_cfa_offset %ld\n" delta)
- else
- (fun _ _ -> ())
-
- let cfi_rel_offset =
- if Configuration.asm_supports_cfi then
- (fun oc reg ofs -> fprintf oc " .cfi_rel_offset %s, %ld\n" reg ofs)
- else
- (fun _ _ _ -> ())
end in
let module Printer = AsmPrinter(Opt) in