From 06841a5bb7ca27bc436e87e7991d0d05dbf5267c Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Wed, 7 Jan 2015 13:53:20 +0100 Subject: In -g -S mode, annotate the generated asm file with the C source code in comments. Refactor printing of .loc debug directives in backend/PrintAnnot.ml --- ia32/PrintAsm.ml | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'ia32/PrintAsm.ml') diff --git a/ia32/PrintAsm.ml b/ia32/PrintAsm.ml index 649fd292..b0ef0180 100644 --- a/ia32/PrintAsm.ml +++ b/ia32/PrintAsm.ml @@ -264,8 +264,7 @@ let transl_label lbl = Hashtbl.add current_function_labels lbl lbl'; lbl' - -(* basic printing functions *) +(* Basic printing functions *) let comment = "#" @@ -308,6 +307,7 @@ let name_of_neg_condition = function (* Names of sections *) + let section oc sec = fprintf oc " %s\n" (name_of_section sec) @@ -338,24 +338,11 @@ let need_masks = ref false (* Emit .file / .loc debugging directives *) -let filename_num : (string, int) Hashtbl.t = Hashtbl.create 7 - let print_file_line oc file line = - if !Clflags.option_g && file <> "" then begin - let filenum = - try - Hashtbl.find filename_num file - with Not_found -> - let n = Hashtbl.length filename_num + 1 in - Hashtbl.add filename_num file n; - fprintf oc " .file %d %S\n" n file; - n - in fprintf oc " .loc %d %s\n" filenum line - end + PrintAnnot.print_file_line oc comment file line let print_location oc loc = - if loc <> Cutil.no_loc then - print_file_line oc (fst loc) (string_of_int (snd loc)) + if loc <> Cutil.no_loc then print_file_line oc (fst loc) (snd loc) (* Emit .cfi directives *) @@ -383,7 +370,8 @@ 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) (Str.matched_group 2 txt) + print_file_line oc (Str.matched_group 1 txt) + (int_of_string (Str.matched_group 2 txt)) end else begin fprintf oc "%s annotation: " comment; PrintAnnot.print_annot_stmt preg "ESP" oc txt targs args @@ -1042,7 +1030,6 @@ end) type target = ELF | MacOS | Cygwin - let print_program oc p = let target = match Configuration.system with @@ -1057,8 +1044,8 @@ let print_program oc p = | Cygwin -> (module Cygwin_System:SYSTEM)):SYSTEM) in let module Printer = AsmPrinter(Target) in PrintAnnot.print_version_and_options oc Printer.comment; + PrintAnnot.reset_filenames(); Printer.need_masks := false; - Hashtbl.clear Printer.filename_num; List.iter (Printer.print_globdef oc) p.prog_defs; if !Printer.need_masks then begin Printer.section oc (Section_const true); @@ -1073,5 +1060,5 @@ let print_program oc p = fprintf oc "%a: .long 0x7FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF\n" Target.raw_symbol "__abss_mask" end; - Target.print_epilogue oc - + Target.print_epilogue oc; + PrintAnnot.close_filenames() -- cgit From 0921a0b5bafb179f18f94561bece26a4d184fa31 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Thu, 19 Feb 2015 10:04:26 +0100 Subject: Changed the symbol function back to its old definition. --- ia32/PrintAsm.ml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'ia32/PrintAsm.ml') diff --git a/ia32/PrintAsm.ml b/ia32/PrintAsm.ml index b0ef0180..d064782e 100644 --- a/ia32/PrintAsm.ml +++ b/ia32/PrintAsm.ml @@ -60,7 +60,6 @@ let preg oc = function module type SYSTEM = sig val raw_symbol: out_channel -> string -> unit - val symbol: out_channel -> P.t -> unit val label: out_channel -> int -> unit val name_of_section: section_name -> string val stack_alignment: int @@ -80,9 +79,6 @@ module Cygwin_System = let raw_symbol oc s = fprintf oc "_%s" s - let symbol oc symb = - fprintf oc "%s" (extern_atom symb) - let label oc lbl = fprintf oc "L%d" lbl @@ -128,9 +124,6 @@ module ELF_System = let raw_symbol oc s = fprintf oc "%s" s - - let symbol oc symb = - fprintf oc "%s" (extern_atom symb) let label oc lbl = fprintf oc ".L%d" lbl @@ -182,9 +175,6 @@ module MacOS_System = let raw_symbol oc s = fprintf oc "_%s" s - let symbol oc symb = - fprintf oc "_%s" (extern_atom symb) - let label oc lbl = fprintf oc "L%d" lbl @@ -249,6 +239,9 @@ module AsmPrinter(Target: SYSTEM) = open Target (* On-the-fly label renaming *) +let symbol oc symb = + raw_symbol oc (extern_atom symb) + let next_label = ref 100 let new_label() = -- cgit From d4389977e95d3569ff0abb53e1b1fba20254b21e Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Thu, 19 Feb 2015 10:07:22 +0100 Subject: Added back symbol functions in the different printer, since they are still needed. --- ia32/PrintAsm.ml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'ia32/PrintAsm.ml') diff --git a/ia32/PrintAsm.ml b/ia32/PrintAsm.ml index d064782e..036dbda8 100644 --- a/ia32/PrintAsm.ml +++ b/ia32/PrintAsm.ml @@ -60,6 +60,7 @@ let preg oc = function module type SYSTEM = sig val raw_symbol: out_channel -> string -> unit + val symbol: out_channel -> P.t -> unit val label: out_channel -> int -> unit val name_of_section: section_name -> string val stack_alignment: int @@ -79,6 +80,9 @@ module Cygwin_System = let raw_symbol oc s = fprintf oc "_%s" s + let symbol oc s = + raw_symbol oc (extern_atom symb) + let label oc lbl = fprintf oc "L%d" lbl @@ -125,6 +129,9 @@ module ELF_System = let raw_symbol oc s = fprintf oc "%s" s + let symbol oc s = + raw_symbol oc (extern_atom symb) + let label oc lbl = fprintf oc ".L%d" lbl @@ -175,6 +182,9 @@ module MacOS_System = let raw_symbol oc s = fprintf oc "_%s" s + let symbol oc s = + raw_symbol oc (extern_atom symb) + let label oc lbl = fprintf oc "L%d" lbl @@ -239,9 +249,6 @@ module AsmPrinter(Target: SYSTEM) = open Target (* On-the-fly label renaming *) -let symbol oc symb = - raw_symbol oc (extern_atom symb) - let next_label = ref 100 let new_label() = -- cgit From b0eb1dfc9fd7b15c556c49101390d882b0f00f8a Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Thu, 19 Feb 2015 11:17:39 +0100 Subject: The parameter should also have the old name. --- ia32/PrintAsm.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ia32/PrintAsm.ml') diff --git a/ia32/PrintAsm.ml b/ia32/PrintAsm.ml index 036dbda8..2bcd8daf 100644 --- a/ia32/PrintAsm.ml +++ b/ia32/PrintAsm.ml @@ -80,7 +80,7 @@ module Cygwin_System = let raw_symbol oc s = fprintf oc "_%s" s - let symbol oc s = + let symbol oc symb = raw_symbol oc (extern_atom symb) let label oc lbl = @@ -129,7 +129,7 @@ module ELF_System = let raw_symbol oc s = fprintf oc "%s" s - let symbol oc s = + let symbol oc symb = raw_symbol oc (extern_atom symb) let label oc lbl = @@ -182,7 +182,7 @@ module MacOS_System = let raw_symbol oc s = fprintf oc "_%s" s - let symbol oc s = + let symbol oc symb = raw_symbol oc (extern_atom symb) let label oc lbl = -- cgit