From 06a1a35d759dc780e389218b5f78ce3415d4b3cd Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Thu, 1 Oct 2015 09:41:06 +0200 Subject: Remove unused globals also from the debug informations. --- debug/Debug.ml | 3 +++ debug/Debug.mli | 2 ++ debug/DebugInformation.ml | 30 +++++++++++++++++++----------- debug/DebugInit.ml | 6 ++++-- debug/Dwarfgen.ml | 4 ++-- 5 files changed, 30 insertions(+), 15 deletions(-) (limited to 'debug') diff --git a/debug/Debug.ml b/debug/Debug.ml index 1d3b260e..79da3695 100644 --- a/debug/Debug.ml +++ b/debug/Debug.ml @@ -48,6 +48,7 @@ type implem = mutable add_compilation_section_start: string ->(int * int * int * string) -> unit; mutable compute_file_enum: (string -> int) -> (string-> int) -> (unit -> unit) -> unit; mutable exists_section: string -> bool; + mutable remove_unused: ident -> unit; } let implem = @@ -78,6 +79,7 @@ let implem = add_compilation_section_start = (fun _ _ -> ()); compute_file_enum = (fun _ _ _ -> ()); exists_section = (fun _ -> true); + remove_unused = (fun _ -> ()); } let init_compile_unit name = implem.init name @@ -106,3 +108,4 @@ let atom_parameter fid pid atom = implem.atom_parameter fid pid atom let add_compilation_section_start sec addr = implem.add_compilation_section_start sec addr let exists_section sec = implem.exists_section sec let compute_file_enum end_l entry_l line_e = implem.compute_file_enum end_l entry_l line_e +let remove_unused ident = implem.remove_unused ident diff --git a/debug/Debug.mli b/debug/Debug.mli index 166a6759..4677fdf8 100644 --- a/debug/Debug.mli +++ b/debug/Debug.mli @@ -46,6 +46,7 @@ type implem = mutable add_compilation_section_start: string -> (int * int * int * string) -> unit; mutable compute_file_enum: (string -> int) -> (string-> int) -> (unit -> unit) -> unit; mutable exists_section: string -> bool; + mutable remove_unused: ident -> unit; } val implem: implem @@ -76,3 +77,4 @@ val atom_parameter: ident -> ident -> atom -> unit val add_compilation_section_start: string -> (int * int * int * string) -> unit val compute_file_enum: (string -> int) -> (string-> int) -> (unit -> unit) -> unit val exists_section: string -> bool +val remove_unused: ident -> unit diff --git a/debug/DebugInformation.ml b/debug/DebugInformation.ml index 0249f20b..b14548e7 100644 --- a/debug/DebugInformation.ml +++ b/debug/DebugInformation.ml @@ -274,7 +274,7 @@ let insert_type (ty: typ) = ct_sou = Struct; ct_file_loc = None; ct_members = []; - ct_declaration = false; + ct_declaration = true; ct_sizeof = None; } in CompositeType str @@ -285,7 +285,7 @@ let insert_type (ty: typ) = ct_sou = Union; ct_file_loc = None; ct_members = []; - ct_declaration = false; + ct_declaration = true; ct_sizeof = None; } in CompositeType union @@ -484,6 +484,13 @@ let gen_comp_typ sou id at = else TUnion (id,at) +let remove_unused id = + try + let id' = Hashtbl.find stamp_to_definition id.stamp in + Hashtbl.remove definitions id'; + Hashtbl.remove stamp_to_definition id.stamp + with Not_found -> () + let insert_global_declaration env dec= add_file (fst dec.gloc); let insert d_dec stamp = @@ -513,11 +520,12 @@ let insert_global_declaration env dec= let id,var = find_gvar_stamp id.stamp in replace_var id ({var with gvar_declaration = false;}) end - end else if not (Hashtbl.mem name_to_definition id.name) then begin + end else begin (* Implict declarations need special handling *) - let id' = next_id () in - Hashtbl.add stamp_to_definition id.stamp id'; - Hashtbl.add name_to_definition id.name id' + let id' = try Hashtbl.find name_to_definition id.name with Not_found -> + let id' = next_id () in + Hashtbl.add name_to_definition id.name id';id' in + Hashtbl.add stamp_to_definition id.stamp id' end | Gfundef f -> let ret = (match f.fd_ret with @@ -547,12 +555,12 @@ let insert_global_declaration env dec= fun_high_pc = None; fun_scope = None; } in - begin try - let id' = Hashtbl.find name_to_definition f.fd_name.name in + begin + let id' = try Hashtbl.find name_to_definition f.fd_name.name with Not_found -> + let id' = next_id () in + Hashtbl.add name_to_definition f.fd_name.name id';id' in Hashtbl.add stamp_to_definition f.fd_name.stamp id'; Hashtbl.add definitions id' (Function fd) - with Not_found -> - insert (Function fd) f.fd_name.stamp end | Gcompositedecl (sou,id,at) -> ignore (insert_type (gen_comp_typ sou id at)); @@ -576,7 +584,7 @@ let insert_global_declaration env dec= }) fi in replace_composite id (fun comp -> let loc = if comp.ct_file_loc = None then Some dec.gloc else comp.ct_file_loc in - {comp with ct_file_loc = loc; ct_members = fields; ct_declaration = true;}) + {comp with ct_file_loc = loc; ct_members = fields; ct_declaration = false;}) | Gtypedef (id,t) -> let id = insert_type (TNamed (id,[])) in let tid = insert_type t in diff --git a/debug/DebugInit.ml b/debug/DebugInit.ml index 6a50b020..8c74e38e 100644 --- a/debug/DebugInit.ml +++ b/debug/DebugInit.ml @@ -44,7 +44,8 @@ let init_debug () = implem.atom_parameter <- DebugInformation.atom_parameter; implem.add_compilation_section_start <- DebugInformation.add_compilation_section_start; implem.compute_file_enum <- DebugInformation.compute_file_enum; - implem.exists_section <- DebugInformation.exists_section + implem.exists_section <- DebugInformation.exists_section; + implem.remove_unused <- DebugInformation.remove_unused let init_none () = implem.init <- (fun _ -> ()); @@ -71,7 +72,8 @@ let init_none () = implem.add_label <- (fun _ _ _ -> ()); implem.atom_parameter <- (fun _ _ _ -> ()); implem.add_compilation_section_start <- (fun _ _ -> ()); - implem.exists_section <- (fun _ -> true) + implem.exists_section <- (fun _ -> true); + implem.remove_unused <- (fun _ -> ()) let init () = if !Clflags.option_g && Configuration.advanced_debug then diff --git a/debug/Dwarfgen.ml b/debug/Dwarfgen.ml index d539f21a..aaf2d53f 100644 --- a/debug/Dwarfgen.ml +++ b/debug/Dwarfgen.ml @@ -197,7 +197,7 @@ let struct_to_entry sec id s = let tag = { structure_file_loc = translate_file_loc_opt sec s.ct_file_loc; structure_byte_size = s.ct_sizeof; - structure_declaration = Some s.ct_declaration; + structure_declaration = if s.ct_declaration then Some s.ct_declaration else None; structure_name = if s.ct_name <> "" then Some s.ct_name else None; } in let entry = new_entry id (DW_TAG_structure_type tag) in @@ -208,7 +208,7 @@ let union_to_entry sec id s = let tag = { union_file_loc = translate_file_loc_opt sec s.ct_file_loc; union_byte_size = s.ct_sizeof; - union_declaration = Some s.ct_declaration; + union_declaration = if s.ct_declaration then Some s.ct_declaration else None; union_name = if s.ct_name <> "" then Some s.ct_name else None; } in let entry = new_entry id (DW_TAG_union_type tag) in -- cgit