PreviousUpNext

15.4.236  src/lib/compiler/back/low/display/graph-viewer-g.pkg

## graph-viewer-g.pkg
#
# This module starts a graph viewer.
#
# -- Allen Leung 

# Compiled by:
#     src/lib/compiler/back/low/lib/visual.lib


stipulate
    package fil =  file__premicrothread;                                # file__premicrothread          is from   src/lib/std/src/posix/file--premicrothread.pkg
#   package gl  =  graph_layout;                                        # graph_layout                  is from   src/lib/compiler/back/low/display/graph-layout.pkg
    package odg =  oop_digraph;                                         # oop_digraph                   is from   src/lib/graph/oop-digraph.pkg
    package fs  =  winix__premicrothread::file;                         # winix__premicrothread         is from   src/lib/std/winix--premicrothread.pkg
herein

    # This generic is invoked various places, most notably:
    #
    #     src/lib/compiler/back/low/main/main/backend-lowhalf-g.pkg
    #
    generic package   graph_viewer_g   (
        #             ==============
        #
        gd:  Graph_Display                                              # Graph_Display         is from   src/lib/compiler/back/low/display/graph-display.api
    )
    : (weak)  Graph_Viewer                                              # Graph_Viewer          is from   src/lib/compiler/back/low/display/graph-viewer.api
    {
        tmp_name =  lowhalf_control::get_string  "tmp_name";
        #
        fun display exec (layout as odg::DIGRAPH l) filename
            = 
            {   filename  =  filename  +  gd::suffix();
                #
                print("[ " + l.name + ": " + 
                                  gd::program() + " " + filename + 
                                  " " + int::to_string (l.order ()) + " nodes"  + 
                                  " " + int::to_string (l.size ()) + " edges");

                file  =  fil::open_for_write filename;
                out   =  \\ s = fil::write (file, s);
                gd::visualize out layout;
                fil::close_output file;
                print(" ]\n");

                exec filename;

                ();
            }
            except
                e = {   print("[Uncaught exception in " + exception_name e + " graph viewer]\n");
                        raise exception e;
                    };

        fun system filename
            =
            {   winix__premicrothread::process::bin_sh' ((gd::program()) + " " + filename);
                fs::remove_file filename;
            };

        fun fork filename
            =
            winix__premicrothread::process::bin_sh'
              ( "("
              +  (gd::program())
              +  " "
              +  filename
              +  "; /bin/rm "
              + filename
              + ") &"
              );

       fun get_tmp_name ()
           =
           if (*tmp_name == "")   fs::tmp_name ();
           else                   *tmp_name;
           fi;

       fun view layout
           =
           display system layout (get_tmp_name());
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext