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. --- arm/TargetPrinter.ml | 4 +- backend/PrintAsm.ml | 136 ++++++++++++++++++++++++++------------------------ ia32/TargetPrinter.ml | 18 +++---- 3 files changed, 82 insertions(+), 76 deletions(-) diff --git a/arm/TargetPrinter.ml b/arm/TargetPrinter.ml index 73cdeae0..079d78ff 100644 --- a/arm/TargetPrinter.ml +++ b/arm/TargetPrinter.ml @@ -37,7 +37,7 @@ module type PRINTER_OPTIONS = (* Module containing the printing functions *) module Target (Opt: PRINTER_OPTIONS) : TARGET = - (struct + struct (* Code generation options. *) let literals_in_code = ref true (* to be turned into a proper option *) @@ -1119,7 +1119,7 @@ module Target (Opt: PRINTER_OPTIONS) : TARGET = let print_epilogue oc = () - end) + end let sel_target () = let module S : PRINTER_OPTIONS = struct 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 () diff --git a/ia32/TargetPrinter.ml b/ia32/TargetPrinter.ml index 2a6be734..0a14bf24 100644 --- a/ia32/TargetPrinter.ml +++ b/ia32/TargetPrinter.ml @@ -75,8 +75,8 @@ module type SYSTEM = end (* Printer functions for cygwin *) -module Cygwin_System = - (struct +module Cygwin_System : SYSTEM = + struct let raw_symbol oc s = fprintf oc "_%s" s @@ -120,11 +120,11 @@ module Cygwin_System = fprintf oc " .local %a\n" symbol name; print_comm_decl oc name sz al - end:SYSTEM) + end (* Printer functions for ELF *) -module ELF_System = - (struct +module ELF_System : SYSTEM = + struct let raw_symbol oc s = fprintf oc "%s" s @@ -167,11 +167,11 @@ module ELF_System = fprintf oc " .local %a\n" symbol name; print_comm_decl oc name sz al - end:SYSTEM) + end (* Printer functions for MacOS *) -module MacOS_System = - (struct +module MacOS_System : SYSTEM = + struct let raw_symbol oc s = fprintf oc "_%s" s @@ -235,7 +235,7 @@ module MacOS_System = fprintf oc " .lcomm %a, %s, %d\n" symbol name (Z.to_string sz) (log2 al) - end:SYSTEM) + end module Target(System: SYSTEM):TARGET = -- cgit