Graphviz 13.0.0~dev.20250210.0415
Loading...
Searching...
No Matches
gvpr.c File Reference
#include "builddate.h"
#include <assert.h>
#include <ast/error.h>
#include <cgraph/cgraph.h>
#include <cgraph/ingraphs.h>
#include <common/globals.h>
#include <getopt.h>
#include <gvpr/actions.h>
#include <gvpr/compile.h>
#include <gvpr/gprstate.h>
#include <gvpr/gvpr.h>
#include <setjmp.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <util/agxbuf.h>
#include <util/alloc.h>
#include <util/exit.h>
#include <util/gv_ctype.h>
#include <util/list.h>
#include <util/unreachable.h>
Include dependency graph for gvpr.c:

Go to the source code of this file.

Data Structures

struct  options
 
struct  nodestream
 
struct  trav_fns
 
struct  gvpr_state_t
 collective managed state used in gvpr_core More...
 

Macros

#define NUM_ARGS   100
 
#define PATHSEP   '/'
 
#define LISTSEP   ':'
 
#define MARKED(x)   (((x)->iu.integer) & 1)
 
#define MARK(x)   (((x)->iu.integer) = 1)
 
#define ONSTACK(x)   (((x)->iu.integer) & 2)
 
#define PUSH(x, e)   (((x)->iu.integer) |= 2, (x)->ine = (e))
 
#define POP(x)   (((x)->iu.integer) &= (~2))
 
#define PRE_VISIT   1
 
#define POST_VISIT   2
 

Typedefs

typedef Agedge_t *(* fstedgefn_t) (Agraph_t *, Agnode_t *)
 
typedef Agedge_t *(* nxttedgefn_t) (Agraph_t *, Agedge_t *, Agnode_t *)
 

Functions

static FILE * openOut (char *name)
 
static char * gettok (char **sp)
 
static int parseArgs (char *s, int argc, char ***argv)
 
static char * concat (char *pfx, char *sfx)
 
static char * resolve (char *arg, int verbose)
 
static char * getOptarg (int c, char **argp, int *argip, int argc, char **argv)
 
static int doFlags (char *arg, int argi, int argc, char **argv, options *opts)
 
static void freeOpts (options opts)
 
static options scanArgs (int argc, char **argv)
 
static Agobj_tevalEdge (Gpr_t *state, Expr_t *prog, comp_block *xprog, Agedge_t *e)
 
static Agobj_tevalNode (Gpr_t *state, Expr_t *prog, comp_block *xprog, Agnode_t *n)
 
static Agnode_tnextNode (Gpr_t *state, nodestream *nodes)
 
static Agedge_tagnxtout_ (Agraph_t *g, Agedge_t *e, Agnode_t *ignored)
 agnxtout wrapper to tweak calling convention
 
static Agedge_tagnxtin_ (Agraph_t *g, Agedge_t *e, Agnode_t *ignored)
 agnxtin wrapper to tweak calling convention
 
static void travBFS (Gpr_t *state, Expr_t *prog, comp_block *xprog)
 
static void travDFS (Gpr_t *state, Expr_t *prog, comp_block *xprog, trav_fns *fns)
 
static void travNodes (Gpr_t *state, Expr_t *prog, comp_block *xprog)
 
static void travEdges (Gpr_t *state, Expr_t *prog, comp_block *xprog)
 
static void travFlat (Gpr_t *state, Expr_t *prog, comp_block *xprog)
 
static void doCleanup (Agraph_t *g)
 
static bool traverse (Gpr_t *state, Expr_t *prog, comp_block *bp, bool cleanup)
 
static void addOutputGraph (Gpr_t *state, gvpropts *uopts)
 
static void chkClose (Agraph_t *g)
 
static Agraph_ting_read (void *fp)
 
static void gvexitf (void *env, int v)
 
static void gverrorf (Expr_t *handle, Exdisc_t *discipline, int level, const char *fmt,...)
 
static int gvpr_core (int argc, char *argv[], gvpropts *uopts, gvpr_state_t *gs)
 
int gvpr (int argc, char *argv[], gvpropts *uopts)
 

Variables

static char * Info []
 
static const char * usage
 
static trav_fns DFSfns = {agfstedge, agnxtedge, 1, 0}
 
static trav_fns FWDfns = {agfstout, agnxtout_, 0, 0}
 
static trav_fns REVfns = {agfstin, agnxtin_, 0, 0}
 

Macro Definition Documentation

◆ LISTSEP

#define LISTSEP   ':'

Definition at line 176 of file gvpr.c.

◆ MARK

#define MARK (   x)    (((x)->iu.integer) = 1)

Definition at line 478 of file gvpr.c.

◆ MARKED

#define MARKED (   x)    (((x)->iu.integer) & 1)

Definition at line 477 of file gvpr.c.

◆ NUM_ARGS

#define NUM_ARGS   100

Definition at line 134 of file gvpr.c.

◆ ONSTACK

#define ONSTACK (   x)    (((x)->iu.integer) & 2)

Definition at line 479 of file gvpr.c.

◆ PATHSEP

#define PATHSEP   '/'

Definition at line 175 of file gvpr.c.

◆ POP

#define POP (   x)    (((x)->iu.integer) &= (~2))

Definition at line 481 of file gvpr.c.

◆ POST_VISIT

#define POST_VISIT   2

Definition at line 487 of file gvpr.c.

◆ PRE_VISIT

#define PRE_VISIT   1

Definition at line 486 of file gvpr.c.

◆ PUSH

#define PUSH (   x,
 
)    (((x)->iu.integer) |= 2, (x)->ine = (e))

Definition at line 480 of file gvpr.c.

Typedef Documentation

◆ fstedgefn_t

typedef Agedge_t *(* fstedgefn_t) (Agraph_t *, Agnode_t *)

Definition at line 483 of file gvpr.c.

◆ nxttedgefn_t

typedef Agedge_t *(* nxttedgefn_t) (Agraph_t *, Agedge_t *, Agnode_t *)

Definition at line 484 of file gvpr.c.

Function Documentation

◆ addOutputGraph()

static void addOutputGraph ( Gpr_t state,
gvpropts uopts 
)
static

Definition at line 814 of file gvpr.c.

References agroot(), cloneO(), Gpr_t::curgraph, gv_recalloc(), gvpropts::ingraphs, gvpropts::n_outgraphs, Gpr_t::outgraph, and gvpropts::outgraphs.

Referenced by gvpr_core().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ agnxtin_()

static Agedge_t * agnxtin_ ( Agraph_t g,
Agedge_t e,
Agnode_t ignored 
)
static

Definition at line 503 of file gvpr.c.

References agnxtin().

Here is the call graph for this function:

◆ agnxtout_()

static Agedge_t * agnxtout_ ( Agraph_t g,
Agedge_t e,
Agnode_t ignored 
)
static

Definition at line 497 of file gvpr.c.

References agnxtout().

Here is the call graph for this function:

◆ chkClose()

static void chkClose ( Agraph_t g)
static

Definition at line 826 of file gvpr.c.

References agclose(), and gData.

Referenced by gvpr_core().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ concat()

static char * concat ( char *  pfx,
char *  sfx 
)
static

Definition at line 179 of file gvpr.c.

References agxbdisown(), and agxbprint().

Referenced by resolve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doCleanup()

static void doCleanup ( Agraph_t g)
static

Definition at line 686 of file gvpr.c.

References agfstnode(), agnxtnode(), nData, and NULL.

Referenced by traverse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doFlags()

static int doFlags ( char *  arg,
int  argi,
int  argc,
char **  argv,
options opts 
)
static

Definition at line 279 of file gvpr.c.

References error, ERROR_ERROR, ERROR_USAGE, ERROR_WARNING, getOptarg(), Info, openOut(), opts, parseArgs(), resolve(), setTraceLevel(), and usage.

Referenced by scanArgs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ evalEdge()

static Agobj_t * evalEdge ( Gpr_t state,
Expr_t prog,
comp_block xprog,
Agedge_t e 
)
static

Definition at line 412 of file gvpr.c.

References case_stmt::action, agsubedge(), Gpr_t::curobj, comp_block::edge_stmts, exeval(), case_stmt::guard, EX_STYPE::integer, comp_block::n_estmts, and Gpr_t::target.

Referenced by travBFS(), travDFS(), travEdges(), and travFlat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ evalNode()

static Agobj_t * evalNode ( Gpr_t state,
Expr_t prog,
comp_block xprog,
Agnode_t n 
)
static

Definition at line 434 of file gvpr.c.

References case_stmt::action, agsubnode(), Gpr_t::curobj, exeval(), case_stmt::guard, EX_STYPE::integer, comp_block::n_nstmts, comp_block::node_stmts, and Gpr_t::target.

Referenced by travBFS(), travDFS(), travFlat(), and travNodes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ freeOpts()

static void freeOpts ( options  opts)
static

Definition at line 341 of file gvpr.c.

References free(), NULL, and opts.

Referenced by gvpr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getOptarg()

static char * getOptarg ( int  c,
char **  argp,
int *  argip,
int  argc,
char **  argv 
)
static

Definition at line 250 of file gvpr.c.

References error, ERROR_WARNING, and NULL.

Referenced by doFlags().

Here is the caller graph for this function:

◆ gettok()

static char * gettok ( char **  sp)
static

Definition at line 93 of file gvpr.c.

References error, ERROR_WARNING, gv_isspace(), and NULL.

Referenced by parseArgs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gverrorf()

static void gverrorf ( Expr_t handle,
Exdisc_t discipline,
int  level,
const char *  fmt,
  ... 
)
static

Definition at line 857 of file gvpr.c.

References ERROR_ERROR, errorv(), Gpr_t::flags, graphviz_exit(), GV_USE_EXIT, GV_USE_JUMP, Gpr_t::jbuf, and Exdisc_s::user.

Referenced by gvpr_core().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvexitf()

static void gvexitf ( void *  env,
int  v 
)
static

Definition at line 851 of file gvpr.c.

References Gpr_t::jbuf, and gvpr_state_t::state.

Referenced by gvpr_core().

Here is the caller graph for this function:

◆ gvpr()

int gvpr ( int  argc,
char *  argv[],
gvpropts uopts 
)

main loop for gvpr

Returns
0 on success

Definition at line 1037 of file gvpr.c.

References closeGPRState(), closeIngraph(), freeCompileProg(), freeOpts(), freeParseProg(), gvpr_core(), gvpr_state_t::ing, NULL, gvpr_state_t::opts, options::outFile, gvpr_state_t::prog, gvpr_state_t::state, and gvpr_state_t::xprog.

Referenced by main(), and run_gvpr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvpr_core()

static int gvpr_core ( int  argc,
char *  argv[],
gvpropts uopts,
gvpr_state_t gs 
)
static

Definition at line 885 of file gvpr.c.

References addBindings(), addOutputGraph(), agdelete(), agnnodes(), options::argc, options::argv, Agraph_s::base, comp_block::begg_stmt, comp_prog::begin_stmt, gvpropts::bindings, comp_prog::blocks, chkClose(), cleanup(), compflags_t::clone, cloneO(), options::compflags, compileProg(), Gpr_t::curgraph, Gpr_t::curobj, comp_block::does_walk_graph, comp_prog::end_stmt, comp_prog::endg_stmt, exeval(), fileName(), Gpr_t::flags, gvpropts::flags, GV_USE_EXIT, GV_USE_JUMP, GV_USE_OUTGRAPH, gvelapsed_sec(), gverrorf(), gvexitf(), gvstart_timer(), options::inFiles, Gpr_t::infname, gvpr_state_t::ing, ing_read(), gvpropts::ingraphs, initGPRState(), Gpr_t::jbuf, comp_prog::n_blocks, gvpropts::n_outgraphs, newIng(), newIngGraphs(), nextGraph(), Gpr_t::nextgraph, NULL, openGPRState(), gvpr_state_t::opts, options::outFile, Gpr_t::outgraph, gvpropts::outgraphs, parseProg(), comp_prog::prog, gvpr_state_t::prog, options::program, options::readAhead, scanArgs(), setErrorErrors(), sfioWrite(), compflags_t::srcout, options::state, gvpr_state_t::state, Gpr_t::target, traverse(), Gpr_t::tvroot, options::useFile, comp_prog::uses_graph, options::verbose, and gvpr_state_t::xprog.

Referenced by gvpr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ing_read()

static Agraph_t * ing_read ( void *  fp)
static

Definition at line 836 of file gvpr.c.

References readG().

Referenced by gvpr_core().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nextNode()

static Agnode_t * nextNode ( Gpr_t state,
nodestream nodes 
)
static

Definition at line 461 of file gvpr.c.

References agfstnode(), agnxtnode(), Gpr_t::curgraph, Gpr_t::flags, GV_NEXT_SET, nodestream::oldroot, nodestream::prev, Gpr_t::tvnext, and Gpr_t::tvroot.

Referenced by travBFS(), and travDFS().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openOut()

static FILE * openOut ( char *  name)
static

Definition at line 74 of file gvpr.c.

References error, and ERROR_ERROR.

Referenced by doFlags().

Here is the caller graph for this function:

◆ parseArgs()

static int parseArgs ( char *  s,
int  argc,
char ***  argv 
)
static

Definition at line 142 of file gvpr.c.

References cnt(), error, ERROR_WARNING, gettok(), gv_recalloc(), gv_strdup(), and NUM_ARGS.

Referenced by doFlags().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resolve()

static char * resolve ( char *  arg,
int  verbose 
)
static

Definition at line 191 of file gvpr.c.

References agxbfree(), agxbprint(), agxbput(), agxbput_n(), agxbuse(), concat(), error, ERROR_ERROR, fname, free(), gv_strdup(), LISTSEP, NULL, PATHSEP, and verbose.

Referenced by doFlags().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scanArgs()

static options scanArgs ( int  argc,
char **  argv 
)
static

Definition at line 357 of file gvpr.c.

References doFlags(), error, ERROR_ERROR, ERROR_USAGE, NULL, opts, setErrorId(), and usage.

Referenced by gvpr_core().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ travBFS()

static void travBFS ( Gpr_t state,
Expr_t prog,
comp_block xprog 
)
static

Definition at line 514 of file gvpr.c.

References agfstedge(), agnxtedge(), evalEdge(), evalNode(), MARK, MARKED, nData, nextNode(), Agedge_s::node, nodestream::oldroot, ONSTACK, POP, nodestream::prev, and PUSH.

Referenced by traverse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ travDFS()

static void travDFS ( Gpr_t state,
Expr_t prog,
comp_block xprog,
trav_fns fns 
)
static

Definition at line 559 of file gvpr.c.

References agopp, evalEdge(), evalNode(), MARK, MARKED, nData, nextNode(), Agedge_s::node, NULL, nodestream::oldroot, ONSTACK, POP, POST_VISIT, PRE_VISIT, nodestream::prev, PUSH, and seed.

Referenced by traverse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ travEdges()

static void travEdges ( Gpr_t state,
Expr_t prog,
comp_block xprog 
)
static

Definition at line 649 of file gvpr.c.

References agfstnode(), agfstout(), agnxtnode(), agnxtout(), Gpr_t::curgraph, and evalEdge().

Referenced by traverse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ traverse()

static bool traverse ( Gpr_t state,
Expr_t prog,
comp_block bp,
bool  cleanup 
)
static

Definition at line 700 of file gvpr.c.

References agsubg(), agxbfree(), agxbprint(), agxbuse(), cleanup(), Gpr_t::curgraph, DFSfns, doCleanup(), FWDfns, Gpr_t::name_used, openSubg(), Gpr_t::outgraph, POST_VISIT, PRE_VISIT, REVfns, Gpr_t::target, Gpr_t::tgtname, travBFS(), travDFS(), travEdges(), travFlat(), travNodes(), TV_bfs, TV_dfs, TV_en, TV_flat, TV_fwd, TV_ne, TV_postdfs, TV_postfwd, TV_postrev, TV_prepostdfs, TV_prepostfwd, TV_prepostrev, TV_rev, Gpr_t::tvt, UNREACHABLE, and trav_fns::visit.

Referenced by gvpr_core().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ travFlat()

static void travFlat ( Gpr_t state,
Expr_t prog,
comp_block xprog 
)
static

Definition at line 664 of file gvpr.c.

References agfstnode(), agfstout(), agnxtnode(), agnxtout(), Gpr_t::curgraph, evalEdge(), evalNode(), and comp_block::n_estmts.

Referenced by traverse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ travNodes()

static void travNodes ( Gpr_t state,
Expr_t prog,
comp_block xprog 
)
static

Definition at line 639 of file gvpr.c.

References agfstnode(), agnxtnode(), Gpr_t::curgraph, and evalNode().

Referenced by traverse().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ DFSfns

trav_fns DFSfns = {agfstedge, agnxtedge, 1, 0}
static

Definition at line 508 of file gvpr.c.

Referenced by traverse().

◆ FWDfns

trav_fns FWDfns = {agfstout, agnxtout_, 0, 0}
static

Definition at line 509 of file gvpr.c.

Referenced by traverse().

◆ Info

char* Info[]
static
Initial value:
= {
"gvpr",
PACKAGE_VERSION,
BUILDDATE
}

Definition at line 41 of file gvpr.c.

Referenced by doFlags().

◆ REVfns

trav_fns REVfns = {agfstin, agnxtin_, 0, 0}
static

Definition at line 510 of file gvpr.c.

Referenced by traverse().

◆ usage

const char* usage
static
Initial value:
=
" [-o <ofile>] [-a <args>] ([-f <prog>] | 'prog') [files]\n\
-c - use source graph for output\n\
-f <pfile> - find program in file <pfile>\n\
-i - create node induced subgraph\n\
-a <args> - string arguments available as ARGV[0..]\n\
-o <ofile> - write output to <ofile>; stdout by default\n\
-n - no read-ahead of input graphs\n\
-q - turn off warning messages\n\
-V - print version info\n\
-? - print usage info\n\
If no files are specified, stdin is used\n"

Definition at line 47 of file gvpr.c.

Referenced by doFlags(), errexit(), gdCmd(), init(), init(), init(), init(), init(), init(), init(), init(), init(), init(), init(), init(), init(), init(), init(), initargs(), initargs(), initargs(), main(), parseArgs(), scanArgs(), scanArgs(), scanargs(), setAction(), and tclGdColorCmd().