Better AST html dump

This commit is contained in:
Dmitry Boulytchev 2020-02-18 13:28:12 +03:00
parent a6a72a9313
commit c1b8f5e630
2 changed files with 12 additions and 3 deletions

View file

@ -36,8 +36,8 @@ Additionally, the following options can be given to the driver:
\begin{itemize}
\item "\texttt{-I $path$}"~--- specifies a path to look for external units. Multiples instances of this option can be given in driver's
invocation, and the paths are looked up in that order.
\item "\texttt{-dp}"~--- forces the driver to dump the AST of compiled unit. The dump is written in the file with the same
basename as the source one, with the extension replaced with "\texttt{.ast}".
\item "\texttt{-dp}"~--- forces the driver to dump the AST of compiled unit in \textsc{html} representation. The dump is written in the file with the same
basename as the source one, with the extension replaced with "\texttt{.html}".
\item "\texttt{-ds}"~--- forces the driver to sump stack machine code. The option is only in effect in stack interpreter on
native mode. The dump is written in the file "\texttt{.sm}".
\item "\texttt{-v}"~--- makes the driver to print the version of the compiler.

View file

@ -134,7 +134,16 @@ class options args =
close_out outf
method dump_AST ast =
if (!dump land dump_ast) > 0
then self#dump_file "ast" (GT.show(Language.Expr.t) ast)
then (
let buf = Buffer.create 1024 in
Buffer.add_string buf "<html>";
Buffer.add_string buf (Printf.sprintf "<title> %s </title>" self#get_infile);
Buffer.add_string buf "<body><li>";
GT.html(Language.Expr.t) ast buf;
Buffer.add_string buf "</li></body>";
Buffer.add_string buf "</html>";
self#dump_file "html" (Buffer.contents buf)
)
else ()
method dump_SM sm =
if (!dump land dump_sm) > 0