asm_info_t: StrMap -> List

This commit is contained in:
Théophile Bastian 2019-09-30 09:26:06 +02:00
parent 5c83f4e1b4
commit 99adfcaa39

View file

@ -3,8 +3,6 @@
Uses `objdump -d` internally, and parses the output Uses `objdump -d` internally, and parses the output
*) *)
module StrMap = Map.Make(String)
(** A memory address *) (** A memory address *)
type addr_t = int type addr_t = int
@ -21,7 +19,7 @@ type asm_sub_t = {
sub_addr: addr_t; sub_addr: addr_t;
sub_asm: asm_t; sub_asm: asm_t;
} }
type asm_info_t = asm_sub_t StrMap.t type asm_info_t = asm_sub_t list
exception ParseError of string exception ParseError of string
@ -49,7 +47,7 @@ let pp_asm_sub ppx asm_sub =
pp_asm asm_sub.sub_asm pp_asm asm_sub.sub_asm
let pp_asm_info ppx asm_info = let pp_asm_info ppx asm_info =
StrMap.iter (fun _ asm_sub -> Format.fprintf ppx "%a" pp_asm_sub asm_sub) List.iter (fun asm_sub -> Format.fprintf ppx "%a" pp_asm_sub asm_sub)
asm_info asm_info
(** Reads the whole content of a Unix file descriptor, returning it as a Bytes (** Reads the whole content of a Unix file descriptor, returning it as a Bytes
@ -173,7 +171,7 @@ let interpret_objdump objdump_out : asm_info_t =
(* Commit in-flight *) (* Commit in-flight *)
let full_sub = { in_flight with sub_asm = List.rev asm } in let full_sub = { in_flight with sub_asm = List.rev asm } in
ObjdumpAccu( ObjdumpAccu(
StrMap.add full_sub.sub_name full_sub cur_info, full_sub::cur_info,
cur_section, cur_section,
None, None,
[] []
@ -267,10 +265,12 @@ let interpret_objdump objdump_out : asm_info_t =
String.split_on_char '\n' objdump_out String.split_on_char '\n' objdump_out
|> drop_k 2 (* Two first lines are meaningless for us *) |> drop_k 2 (* Two first lines are meaningless for us *)
|> List.fold_left aggregate_info |> List.fold_left aggregate_info
(ObjdumpAccu(StrMap.empty, "", None, [])) (ObjdumpAccu([], "", None, []))
in in
(match result with (match result with
| ObjdumpAccu(result, _, None, []) -> result | ObjdumpAccu(result, _, None, []) ->
result
|> List.rev
| _ -> raise (ParseError "Invalid end state")) | _ -> raise (ParseError "Invalid end state"))