blob: ec5495c1ca98ead27d42400709afdc9e02576d94 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
(* *********************************************************************)
(* *)
(* The Compcert verified compiler *)
(* *)
(* Bernhard Schommer, AbsInt Angewandte Informatik GmbH *)
(* *)
(* AbsInt Angewandte Informatik GmbH. All rights reserved. This file *)
(* is distributed under the terms of the INRIA Non-Commercial *)
(* License Agreement. *)
(* *)
(* *********************************************************************)
(* Utility functions for the dwarf debuging type *)
open DwarfTypes
let id = ref 0
let next_id () =
let nid = !id in
incr id; nid
let reset_id () =
id := 0
(* Hashtable to from type name to entry id *)
let type_table: (string, int) Hashtbl.t = Hashtbl.create 7
(* Generate a new entry from a given tag *)
let new_entry tag =
let id = next_id () in
{
tag = tag;
children = [];
id = id;
}
(* Add an entry as child to another entry *)
let add_children entry child =
{entry with children = child::entry.children;}
(* Iter over the tree in prefix order *)
let rec entry_iter f entry =
f entry.tag;
List.iter (entry_iter f) entry.children
(* Iter over the tree in prefix order with passing additional reference to next sibling *)
let entry_iter_sibling f acc entry =
f None entry.tag;
let rec aux = (function
| [] -> ()
| [last] -> f None last.tag
| a::b::rest -> f (Some b.id) a.tag; aux (b::rest)) in
aux entry.children
(* Fold over the tree in prefix order *)
let rec entry_fold f acc entry =
let acc = f acc entry.tag in
List.fold_left (entry_fold f) acc entry.children
(* Fold over the tree in prefix order with passing additional reference to next sibling *)
let entry_fold_sibling f acc entry =
let acc = f acc None entry.tag in
let rec aux acc = (function
| [] -> acc
| [last] -> f acc None last.tag
| a::b::rest -> aux (f acc (Some b.id) a.tag) (b::rest)) in
aux acc entry.children
|