aboutsummaryrefslogtreecommitdiffstats
path: root/debug/DwarfUtil.ml
diff options
context:
space:
mode:
authorBernhard Schommer <bernhardschommer@gmail.com>2014-10-24 15:22:06 +0200
committerBernhard Schommer <bernhardschommer@gmail.com>2014-10-24 15:22:06 +0200
commitf27d7dc78c722b068d670a5ffcb816be7b0f1166 (patch)
tree6b36d77bef33baf5847afa57c51ec06ad1c6e539 /debug/DwarfUtil.ml
parentc78b7a0562b93830f555f73e2fbe10469e1e14f0 (diff)
downloadcompcert-kvx-f27d7dc78c722b068d670a5ffcb816be7b0f1166.tar.gz
compcert-kvx-f27d7dc78c722b068d670a5ffcb816be7b0f1166.zip
Added more functionality to DwarfUtil.
Diffstat (limited to 'debug/DwarfUtil.ml')
-rw-r--r--debug/DwarfUtil.ml39
1 files changed, 39 insertions, 0 deletions
diff --git a/debug/DwarfUtil.ml b/debug/DwarfUtil.ml
index 3841caa5..ec5495c1 100644
--- a/debug/DwarfUtil.ml
+++ b/debug/DwarfUtil.ml
@@ -20,6 +20,13 @@ 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
{
@@ -28,5 +35,37 @@ let new_entry tag =
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