Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
gvpr.c File Reference
#include <assert.h>
#include <unistd.h>
#include "builddate.h"
#include <gvpr/gprstate.h>
#include <cgraph/agxbuf.h>
#include <cgraph/alloc.h>
#include <cgraph/cgraph.h>
#include <cgraph/gv_ctype.h>
#include <cgraph/ingraphs.h>
#include <cgraph/exit.h>
#include <cgraph/queue.h>
#include <cgraph/stack.h>
#include <cgraph/unreachable.h>
#include <common/globals.h>
#include <gvpr/compile.h>
#include <gvpr/gvpr.h>
#include <gvpr/actions.h>
#include <ast/error.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include <getopt.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 DFLT_GVPRPATH   "."
 
#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 (Expr_t *handle, Exdisc_t *discipline, 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 }
 
static jmp_buf jbuf
 

Macro Definition Documentation

◆ DFLT_GVPRPATH

#define DFLT_GVPRPATH   "."

Definition at line 44 of file gvpr.c.

◆ LISTSEP

#define LISTSEP   ':'

Definition at line 185 of file gvpr.c.

◆ MARK

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

Definition at line 502 of file gvpr.c.

◆ MARKED

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

Definition at line 501 of file gvpr.c.

◆ NUM_ARGS

#define NUM_ARGS   100

Definition at line 141 of file gvpr.c.

◆ ONSTACK

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

Definition at line 503 of file gvpr.c.

◆ PATHSEP

#define PATHSEP   '/'

Definition at line 184 of file gvpr.c.

◆ POP

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

Definition at line 505 of file gvpr.c.

◆ POST_VISIT

#define POST_VISIT   2

Definition at line 511 of file gvpr.c.

◆ PRE_VISIT

#define PRE_VISIT   1

Definition at line 510 of file gvpr.c.

◆ PUSH

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

Definition at line 504 of file gvpr.c.

Typedef Documentation

◆ fstedgefn_t

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

Definition at line 507 of file gvpr.c.

◆ nxttedgefn_t

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

Definition at line 508 of file gvpr.c.

Function Documentation

◆ addOutputGraph()

static void addOutputGraph ( Gpr_t state,
gvpropts uopts 
)
static

Definition at line 826 of file gvpr.c.

References agroot(), cloneO(), gv_recalloc(), gvpropts::ingraphs, gvpropts::n_outgraphs, gvpropts::outgraphs, and state.

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 527 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 521 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 840 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 189 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 706 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 296 of file gvpr.c.

References CLONE, error(), ERROR_ERROR, ERROR_USAGE, ERROR_WARNING, getOptarg(), INDUCE, Info, openOut(), opts, parseArgs(), resolve(), setTraceLevel(), SRCOUT, 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 435 of file gvpr.c.

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

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 457 of file gvpr.c.

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

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 356 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 264 of file gvpr.c.

References error(), ERROR_WARNING, and NULL.

Referenced by doFlags().

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

◆ gettok()

static char * gettok ( char **  sp)
static

Definition at line 99 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 871 of file gvpr.c.

References ERROR_ERROR, errorv(), graphviz_exit(), GV_USE_EXIT, GV_USE_JUMP, jbuf, state, 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 ( Expr_t handle,
Exdisc_t discipline,
int  v 
)
static

Definition at line 863 of file gvpr.c.

References jbuf.

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 1055 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

◆ ing_read()

static Agraph_t * ing_read ( void *  fp)
static

Definition at line 851 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 484 of file gvpr.c.

References agfstnode(), agnxtnode(), GV_NEXT_SET, nodestream::oldroot, nodestream::prev, and state.

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 80 of file gvpr.c.

References error(), and ERROR_ERROR.

Referenced by doFlags().

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

◆ parseArgs()

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

Definition at line 149 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 202 of file gvpr.c.

References agxbfree(), agxbprint(), agxbput(), agxbput_n(), agxbuse(), concat(), DFLT_GVPRPATH, 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 370 of file gvpr.c.

References doFlags(), error(), ERROR_ERROR, ERROR_USAGE, free(), gv_calloc(), 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 536 of file gvpr.c.

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

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 577 of file gvpr.c.

References agopp, evalEdge(), evalNode(), trav_fns::fstedge, MARK, MARKED, nData, nextNode(), Agedge_s::node, NULL, trav_fns::nxtedge, nodestream::oldroot, ONSTACK, POP, POST_VISIT, PRE_VISIT, nodestream::prev, PUSH, seed, stack_is_empty(), stack_pop(), stack_push(), stack_reset(), state, trav_fns::undirected, and trav_fns::visit.

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 668 of file gvpr.c.

References agfstnode(), agfstout(), agnxtnode(), agnxtout(), evalEdge(), and state.

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 721 of file gvpr.c.

References agsubg(), agxbfree(), agxbprint(), agxbuse(), cleanup(), DFSfns, doCleanup(), FWDfns, openSubg(), POST_VISIT, PRE_VISIT, REVfns, state, 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, 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 684 of file gvpr.c.

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

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 657 of file gvpr.c.

References agfstnode(), agnxtnode(), evalNode(), and state.

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 532 of file gvpr.c.

Referenced by traverse().

◆ FWDfns

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

Definition at line 533 of file gvpr.c.

Referenced by traverse().

◆ Info

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

Definition at line 47 of file gvpr.c.

Referenced by doFlags().

◆ jbuf

jmp_buf jbuf
static

Definition at line 856 of file gvpr.c.

Referenced by gverrorf(), gvexitf(), and gvpr_core().

◆ REVfns

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

Definition at line 534 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 53 of file gvpr.c.

Referenced by doFlags(), errexit(), gdCmd(), 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().