Collapse irrelevant subroutines

This commit is contained in:
Théophile Bastian 2019-11-20 15:56:56 +01:00
parent b87020a5cd
commit d738314490
2 changed files with 57 additions and 1 deletions

View File

@ -3,6 +3,22 @@
Renders the output of computations on a given program as an HTML webpage.
*)
(** Generates a fresh unique identifier *)
let fresh_uuid =
let next = ref 0 in
fun () ->
let out = !next in
incr next ; out
(** Checks whether a submethod is relevant to show, or whether it should be
hidden by default. *)
let is_sub_relevant sub = Renderer.AnnotAsm.(
List.exists
(fun instr -> instr.instr_annot.Renderer.events <> [])
sub.sub_asm
)
(** Box `AnnotAsm.asm_info_t` as a Jingoo tvalue *)
let render_prog_box annotated_prog = Jingoo.Jg_types.(Renderer.AnnotAsm.(
let render_addr addr = (Format.sprintf "%04x" addr) in
@ -11,6 +27,10 @@ let render_prog_box annotated_prog = Jingoo.Jg_types.(Renderer.AnnotAsm.(
("sub_section", box_string render_sub.sub_section);
("sub_name", box_string render_sub.sub_name);
("sub_addr", box_string (Format.sprintf "%016x" render_sub.sub_addr));
("sub_uuid", box_int @@ fresh_uuid ());
("sub_relevant", box_int @@ (match is_sub_relevant render_sub with
| true -> 1
| false -> 0));
("sub_asm", List.map (fun row -> [
("instr_addr", box_string (render_addr row.instr_addr));
("instr_bytes", box_string (

View File

@ -28,6 +28,17 @@
.subroutine {
margin: 20px 0;
}
.sub_collapser {
background-color: #8c8c8c;
color: white;
font-weight: bold;
border-radius: 50%;
text-align: center;
display: inline-block;
width: 1em;
}
.sub_body {
margin-left: 4ex;
}
@ -70,6 +81,22 @@
}
}
</script>
<script>
function toggle_visibility(id) {
var e = document.getElementById(id);
var label = document.getElementById(id + "_collapser");
if(e.style.display == 'none') {
label.innerHTML = label.innerHTML.replace("+","-");
e.style.display = 'block';
}
else {
label.innerHTML = label.innerHTML.replace("-","+");
e.style.display = 'none';
}
}
</script>
</head>
<body>
<div class="prog_container">
@ -79,11 +106,17 @@
{% for subroutine in prog.prog %}
<div class="subroutine">
<div class="sub_headline">
<span class="sub_collapser"
id="sub_body_{{subroutine.sub_uuid}}_collapser"
onclick="toggle_visibility('sub_body_{{ subroutine.sub_uuid }}')"
>
-
</span>
<span class="addr">{{ subroutine.sub_addr }}</span>
<span class="sub_section">[{{ subroutine.sub_section }}]</span>
<span class="sub_name">&lt;{{ subroutine.sub_name }}&gt;</span>:
</div>
<div class="sub_body">
<div class="sub_body" id="sub_body_{{ subroutine.sub_uuid }}">
{% for row in subroutine.sub_asm %}
{% for event in row.instr_events %}
{% if event.typ == "start" %}
@ -106,6 +139,9 @@
{% endfor %}
</div>
</div>
{% if not subroutine.sub_relevant %}
<script>toggle_visibility('sub_body_{{ subroutine.sub_uuid }}');</script>
{% endif %}
{% endfor %}
</div>
{% endfor %}