Commit 4f9b7085 authored by POTTIER Francois's avatar POTTIER Francois

Introduce StackLangGraph.

parent 10097f7f
(******************************************************************************)
(* *)
(* Menhir *)
(* *)
(* François Pottier, Inria Paris *)
(* Yann Régis-Gianas, PPS, Université Paris Diderot *)
(* *)
(* Copyright Inria. All rights reserved. This file is distributed under the *)
(* terms of the GNU General Public License version 2, as described in the *)
(* file LICENSE. *)
(* *)
(******************************************************************************)
open Dot
open StackLang
(* [uniq] transforms an arbitrary [iter] function into one that produces each
element at most once. *)
let uniq iter =
let encountered = ref LabelSet.empty in
fun yield ->
iter begin fun label ->
if not (StringSet.mem label !encountered) then begin
encountered := StringSet.add label !encountered;
yield label
end
end
let print program =
let module P = Dot.Print(struct
type vertex = label
let name label = label
let successors (f : ?style:style -> label:string -> vertex -> unit) label =
lookup label program.cfg
|> uniq StackLangTraverse.successors (fun target -> f ~label:"" target)
let iter (f : ?shape:shape -> ?style:style -> label:string -> vertex -> unit) =
program.cfg |> LabelMap.iter begin fun label _block ->
f ~shape:Box ~label label
end
end) in
let f = open_out (Settings.base ^ ".dot") in
P.print f;
close_out f
(******************************************************************************)
(* *)
(* Menhir *)
(* *)
(* François Pottier, Inria Paris *)
(* Yann Régis-Gianas, PPS, Université Paris Diderot *)
(* *)
(* Copyright Inria. All rights reserved. This file is distributed under the *)
(* terms of the GNU General Public License version 2, as described in the *)
(* file LICENSE. *)
(* *)
(******************************************************************************)
open StackLang
(* [print program] dumps the control flow graph of the StackLang program
[program] to the file [<basename>.dot]. The vertices are the basic blocks
and the edges are the jumps between them. If there are multiple jumps from
one block to another, then only one edge is shown. *)
val print: program -> unit
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment