From 20ee821830467d091984ccf9ed646de7975866a7 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Thu, 5 Feb 2015 13:02:29 +0100 Subject: Changed the ASM printer of the powerpc to the generalized backend. --- backend/PrintAsm.ml | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 backend/PrintAsm.ml (limited to 'backend/PrintAsm.ml') diff --git a/backend/PrintAsm.ml b/backend/PrintAsm.ml new file mode 100644 index 00000000..aa317a09 --- /dev/null +++ b/backend/PrintAsm.ml @@ -0,0 +1,99 @@ +(* *********************************************************************) +(* *) +(* The Compcert verified compiler *) +(* *) +(* Xavier Leroy, INRIA Paris-Rocquencourt *) +(* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *) +(* *) +(* Copyright Institut National de Recherche en Informatique et en *) +(* Automatique. All rights reserved. This file is distributed *) +(* under the terms of the INRIA Non-Commercial License Agreement. *) +(* *) +(* *********************************************************************) + +open AST +open Asm +open Camlcoq +open Datatypes +open PrintAsmaux +open Printf +open Sections +open TargetPrinter + +module Target = (val (sel_target ()):TARGET) + +let print_location oc loc = + if loc <> Cutil.no_loc then Target.print_file_line oc (fst loc) (snd loc) + +let print_function oc name fn = + Hashtbl.clear current_function_labels; + Target.reset_constants (); + let (text, lit, jmptbl) = Target.get_section_names name in + Target.section oc text; + let alignment = + match !Clflags.option_falignfunctions with Some n -> n | None -> 4 in + Target.print_align oc alignment; + if not (C2C.atom_is_static name) then + fprintf oc " .globl %a\n" symbol name; + Target.print_optional_fun_info oc; + fprintf oc "%a:\n" symbol name; + print_location oc (C2C.atom_location name); + Target.cfi_startproc oc; + Target.print_instructions oc fn.fn_code; + Target.cfi_endproc oc; + if Target.print_fun_info then + print_fun_info oc name; + Target.emit_constants oc lit; + Target.print_jumptable oc jmptbl + + +let print_init_data oc name id = + if Str.string_match PrintCsyntax.re_string_literal (extern_atom name) 0 + && List.for_all (function Init_int8 _ -> true | _ -> false) id + then + fprintf oc " .ascii \"%s\"\n" (PrintCsyntax.string_of_init id) + else + List.iter (Target.print_init oc) id + +let print_var oc name v = + match v.gvar_init with + | [] -> () + | _ -> + let sec = + match C2C.atom_sections name with + | [s] -> s + | _ -> Section_data true + and align = + match C2C.atom_alignof name with + | Some a -> a + | None -> 8 in (* 8-alignment is a safe default *) + let name_sec = Target.name_of_section sec in + if name_sec <> "COMM" then begin + fprintf oc " %s\n" name_sec; + Target.print_align oc align; + if not (C2C.atom_is_static name) then + fprintf oc " .global %a\n" symbol name; + fprintf oc "%a:\n" symbol name; + print_init_data oc name v.gvar_init; + if Target.print_var_info then + print_var_info oc name; + end else + let sz = + match v.gvar_init with [Init_space sz] -> sz | _ -> assert false in + Target.print_comm_symb oc sz name align + + +let print_globdef oc (name,gdef) = + match gdef with + | Gfun (Internal code) -> print_function oc name code + | Gfun (External ef) -> () + | Gvar v -> print_var oc name v + + +let print_program oc p = + PrintAnnot.reset_filenames (); + PrintAnnot.print_version_and_options oc Target.comment; + Target.print_prologue oc; + List.iter (print_globdef oc) p.prog_defs; + Target.print_epilogue oc; + PrintAnnot.close_filenames () -- cgit From a3c0094508f9f4985de4509380dada5f5c85e115 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Mon, 9 Feb 2015 14:54:42 +0100 Subject: Changed arm backend to the common backend printer. --- backend/PrintAsm.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backend/PrintAsm.ml') diff --git a/backend/PrintAsm.ml b/backend/PrintAsm.ml index aa317a09..0860c1d4 100644 --- a/backend/PrintAsm.ml +++ b/backend/PrintAsm.ml @@ -39,7 +39,7 @@ let print_function oc name fn = fprintf oc "%a:\n" symbol name; print_location oc (C2C.atom_location name); Target.cfi_startproc oc; - Target.print_instructions oc fn.fn_code; + Target.print_instructions oc fn; Target.cfi_endproc oc; if Target.print_fun_info then print_fun_info oc name; -- cgit From 8677f50de8515bd83221e6a3d79b0f3d6dae4cbf Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Wed, 18 Feb 2015 12:52:54 +0100 Subject: Removed some style issues. --- backend/PrintAsm.ml | 136 +++++++++++++++++++++++++++------------------------- 1 file changed, 71 insertions(+), 65 deletions(-) (limited to 'backend/PrintAsm.ml') diff --git a/backend/PrintAsm.ml b/backend/PrintAsm.ml index 0860c1d4..532de044 100644 --- a/backend/PrintAsm.ml +++ b/backend/PrintAsm.ml @@ -22,78 +22,84 @@ open TargetPrinter module Target = (val (sel_target ()):TARGET) -let print_location oc loc = - if loc <> Cutil.no_loc then Target.print_file_line oc (fst loc) (snd loc) - -let print_function oc name fn = - Hashtbl.clear current_function_labels; - Target.reset_constants (); - let (text, lit, jmptbl) = Target.get_section_names name in - Target.section oc text; - let alignment = - match !Clflags.option_falignfunctions with Some n -> n | None -> 4 in - Target.print_align oc alignment; - if not (C2C.atom_is_static name) then - fprintf oc " .globl %a\n" symbol name; - Target.print_optional_fun_info oc; - fprintf oc "%a:\n" symbol name; - print_location oc (C2C.atom_location name); - Target.cfi_startproc oc; - Target.print_instructions oc fn; - Target.cfi_endproc oc; - if Target.print_fun_info then - print_fun_info oc name; - Target.emit_constants oc lit; - Target.print_jumptable oc jmptbl - +module Printer(Target:TARGET) = + struct -let print_init_data oc name id = - if Str.string_match PrintCsyntax.re_string_literal (extern_atom name) 0 - && List.for_all (function Init_int8 _ -> true | _ -> false) id - then - fprintf oc " .ascii \"%s\"\n" (PrintCsyntax.string_of_init id) - else - List.iter (Target.print_init oc) id - -let print_var oc name v = - match v.gvar_init with - | [] -> () - | _ -> - let sec = - match C2C.atom_sections name with - | [s] -> s - | _ -> Section_data true - and align = - match C2C.atom_alignof name with - | Some a -> a - | None -> 8 in (* 8-alignment is a safe default *) - let name_sec = Target.name_of_section sec in - if name_sec <> "COMM" then begin - fprintf oc " %s\n" name_sec; - Target.print_align oc align; - if not (C2C.atom_is_static name) then - fprintf oc " .global %a\n" symbol name; - fprintf oc "%a:\n" symbol name; - print_init_data oc name v.gvar_init; - if Target.print_var_info then - print_var_info oc name; - end else - let sz = - match v.gvar_init with [Init_space sz] -> sz | _ -> assert false in - Target.print_comm_symb oc sz name align + let print_location oc loc = + if loc <> Cutil.no_loc then Target.print_file_line oc (fst loc) (snd loc) - -let print_globdef oc (name,gdef) = - match gdef with - | Gfun (Internal code) -> print_function oc name code - | Gfun (External ef) -> () - | Gvar v -> print_var oc name v + let print_function oc name fn = + Hashtbl.clear current_function_labels; + Target.reset_constants (); + let (text, lit, jmptbl) = Target.get_section_names name in + Target.section oc text; + let alignment = + match !Clflags.option_falignfunctions with Some n -> n | None -> 4 in + Target.print_align oc alignment; + if not (C2C.atom_is_static name) then + fprintf oc " .globl %a\n" symbol name; + Target.print_optional_fun_info oc; + fprintf oc "%a:\n" symbol name; + print_location oc (C2C.atom_location name); + Target.cfi_startproc oc; + Target.print_instructions oc fn; + Target.cfi_endproc oc; + if Target.print_fun_info then + print_fun_info oc name; + Target.emit_constants oc lit; + Target.print_jumptable oc jmptbl + let print_init_data oc name id = + if Str.string_match PrintCsyntax.re_string_literal (extern_atom name) 0 + && List.for_all (function Init_int8 _ -> true | _ -> false) id + then + fprintf oc " .ascii \"%s\"\n" (PrintCsyntax.string_of_init id) + else + List.iter (Target.print_init oc) id + + let print_var oc name v = + match v.gvar_init with + | [] -> () + | _ -> + let sec = + match C2C.atom_sections name with + | [s] -> s + | _ -> Section_data true + and align = + match C2C.atom_alignof name with + | Some a -> a + | None -> 8 in (* 8-alignment is a safe default *) + let name_sec = Target.name_of_section sec in + if name_sec <> "COMM" then begin + fprintf oc " %s\n" name_sec; + Target.print_align oc align; + if not (C2C.atom_is_static name) then + fprintf oc " .global %a\n" symbol name; + fprintf oc "%a:\n" symbol name; + print_init_data oc name v.gvar_init; + if Target.print_var_info then + print_var_info oc name; + end else + let sz = + match v.gvar_init with [Init_space sz] -> sz | _ -> assert false in + Target.print_comm_symb oc sz name align + + + let print_globdef oc (name,gdef) = + match gdef with + | Gfun (Internal code) -> print_function oc name code + | Gfun (External ef) -> () + | Gvar v -> print_var oc name v + + end + let print_program oc p = + let module Target = (val (sel_target ()):TARGET) in + let module Printer = Printer(Target) in PrintAnnot.reset_filenames (); PrintAnnot.print_version_and_options oc Target.comment; Target.print_prologue oc; - List.iter (print_globdef oc) p.prog_defs; + List.iter (Printer.print_globdef oc) p.prog_defs; Target.print_epilogue oc; PrintAnnot.close_filenames () -- cgit From 71260eff997f5d3c25d9ccda92b8176c893be26d Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Wed, 18 Feb 2015 13:06:58 +0100 Subject: Changed print_fun/var_info to be functions instead of booleans. --- backend/PrintAsm.ml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'backend/PrintAsm.ml') diff --git a/backend/PrintAsm.ml b/backend/PrintAsm.ml index 532de044..fb03d96b 100644 --- a/backend/PrintAsm.ml +++ b/backend/PrintAsm.ml @@ -44,8 +44,7 @@ module Printer(Target:TARGET) = Target.cfi_startproc oc; Target.print_instructions oc fn; Target.cfi_endproc oc; - if Target.print_fun_info then - print_fun_info oc name; + Target.print_fun_info oc name; Target.emit_constants oc lit; Target.print_jumptable oc jmptbl @@ -78,8 +77,7 @@ module Printer(Target:TARGET) = fprintf oc " .global %a\n" symbol name; fprintf oc "%a:\n" symbol name; print_init_data oc name v.gvar_init; - if Target.print_var_info then - print_var_info oc name; + Target.print_var_info oc name; end else let sz = match v.gvar_init with [Init_space sz] -> sz | _ -> assert false in -- cgit From fcd5ba10674f499d4e270bfb68fa40da8857fb47 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Wed, 18 Feb 2015 15:06:53 +0100 Subject: Added an elf prefix to all common elf functions in PrintAsmaux. --- backend/PrintAsm.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'backend/PrintAsm.ml') diff --git a/backend/PrintAsm.ml b/backend/PrintAsm.ml index fb03d96b..c356d7e5 100644 --- a/backend/PrintAsm.ml +++ b/backend/PrintAsm.ml @@ -37,9 +37,9 @@ module Printer(Target:TARGET) = match !Clflags.option_falignfunctions with Some n -> n | None -> 4 in Target.print_align oc alignment; if not (C2C.atom_is_static name) then - fprintf oc " .globl %a\n" symbol name; + fprintf oc " .globl %a\n" Target.symbol name; Target.print_optional_fun_info oc; - fprintf oc "%a:\n" symbol name; + fprintf oc "%a:\n" Target.symbol name; print_location oc (C2C.atom_location name); Target.cfi_startproc oc; Target.print_instructions oc fn; @@ -74,8 +74,8 @@ module Printer(Target:TARGET) = fprintf oc " %s\n" name_sec; Target.print_align oc align; if not (C2C.atom_is_static name) then - fprintf oc " .global %a\n" symbol name; - fprintf oc "%a:\n" symbol name; + fprintf oc " .global %a\n" Target.symbol name; + fprintf oc "%a:\n" Target.symbol name; print_init_data oc name v.gvar_init; Target.print_var_info oc name; end else -- cgit From cb1da9d8176ea397b833f56ee49af5c75338676f Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Thu, 19 Feb 2015 10:12:16 +0100 Subject: Removed unused sel_target, changed cygwin symbol names and changed the default function aligment to be target dependent. --- backend/PrintAsm.ml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'backend/PrintAsm.ml') diff --git a/backend/PrintAsm.ml b/backend/PrintAsm.ml index c356d7e5..a6883339 100644 --- a/backend/PrintAsm.ml +++ b/backend/PrintAsm.ml @@ -20,8 +20,6 @@ open Printf open Sections open TargetPrinter -module Target = (val (sel_target ()):TARGET) - module Printer(Target:TARGET) = struct @@ -34,7 +32,7 @@ module Printer(Target:TARGET) = let (text, lit, jmptbl) = Target.get_section_names name in Target.section oc text; let alignment = - match !Clflags.option_falignfunctions with Some n -> n | None -> 4 in + match !Clflags.option_falignfunctions with Some n -> n | None -> Target.default_falignment in Target.print_align oc alignment; if not (C2C.atom_is_static name) then fprintf oc " .globl %a\n" Target.symbol name; -- cgit