#
# This just provide a very simple pretty printing function.
# It is used for visualization.
#
# -- Allen Leung
# Compiled by:
#
src/lib/compiler/back/low/lib/visual.libstipulate
package pp = standard_prettyprinter; # standard_prettyprinter is from
src/lib/prettyprint/big/src/standard-prettyprinter.pkgherein
api Format_Instruction {
#
package mcf: Machcode_Form; # Machcode_Form is from
src/lib/compiler/back/low/code/machcode-form.api to_string
:
note::Notes
->
mcf::Machine_Op
->
String;
};
# This generic is invoked (only) in:
#
src/lib/compiler/back/low/display/machcode-controlflow-graph-viewer-g.pkg # src/lib/compiler/back/low/glue/lowhalf-glue.pkg.unused
generic package format_instruction_g (
# ====================
#
asm: Machcode_Codebuffer_Pp # Machcode_Codebuffer_Pp is from
src/lib/compiler/back/low/emit/machcode-codebuffer-pp.api )
: (weak) Format_Instruction # Format_Instruction is from
src/lib/compiler/back/low/display/lowhalf-format-instruction-g.pkg {
# Export to client packages:
#
package mcf = asm::mcf; # "mcf" == "Machcode_Form" (abstract machine code).
fun to_string an op
=
strip_nl text
where
# buffer = string_outstream::make_stream_buf();
# sss = string_outstream::open_string_out buffer;
# asm_stream::with_stream sss
# #
# (asm::make_codebuffer an).put_op
# op;
#
# text = string_outstream::get_string buffer;
text = pp::prettyprint_to_string [] {.
pp = #pp;
buf = asm::make_codebuffer pp an;
buf.put_op op;
};
fun is_space ' ' => TRUE;
is_space '\t' => TRUE;
is_space _ => FALSE;
end;
text = fold_backward
\\ (x, "") => x;
(x, y) => x + " " + y;
end
""
(string::tokens is_space text);
fun strip_nl "" => "";
#
strip_nl s
=>
f (size s - 1)
where
fun f (0) => "";
f (i) => case (string::get_byte_as_char (s, i))
#
'\n' => f (i - 1);
' ' => f (i - 1);
_ => string::extract (s, 0, THE (i+1));
esac;
end;
end;
end;
end;
};
end;