PIPS
graph.c File Reference
#include <stdio.h>
#include <string.h>
#include "linear.h"
#include "genC.h"
#include "misc.h"
#include "pipsdbm.h"
#include "ri.h"
#include "ri-util.h"
+ Include dependency graph for graph.c:

Go to the source code of this file.

Macros

#define DV_SUFFIX   ".daVinci"
 

Functions

static void node (FILE *out, string name)
 Build for module name a node and link to its successors. More...
 
static void init_seen (void)
 
static void close_seen (void)
 
static void set_as_seen (string m)
 
static bool seen_p (string m)
 
static void recursive_append (FILE *out, string name)
 generates into "out" a davinci node for module "name", and recurse to its not yet seen callees. More...
 
bool graph_of_calls (const string name)
 to be called by pipsmake. More...
 
bool full_graph_of_calls (string name)
 To be called by pipsmake. More...
 

Variables

static hash_table seen = hash_table_undefined
 static function to store whether a module has been seen during the recursive generation of the daVinci file. More...
 
static bool first_seen = false
 

Macro Definition Documentation

◆ DV_SUFFIX

#define DV_SUFFIX   ".daVinci"

Definition at line 48 of file graph.c.

Function Documentation

◆ close_seen()

static void close_seen ( void  )
static

Definition at line 89 of file graph.c.

89  {
static hash_table seen
static function to store whether a module has been seen during the recursive generation of the daVinc...
Definition: graph.c:85
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
#define hash_table_undefined
Value of an undefined hash_table.
Definition: newgen_hash.h:49

References hash_table_free(), hash_table_undefined, and seen.

Referenced by graph_of_calls().

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

◆ full_graph_of_calls()

bool full_graph_of_calls ( string  name)

To be called by pipsmake.

Generate a global resource, hence name is ignored.

build file name... and open it.

prolog, per module stuff, epilog.

close and clean...

put resulting resource into pipsdbm.

Parameters
nameame

Definition at line 147 of file graph.c.

148 {
149  gen_array_t modules = db_get_module_list();
150  int n = gen_array_nitems(modules), i;
151  FILE * out;
152  bool first = true;
153  string dir_name, file_name, full_name;
154 
155  pips_debug(7, "global call graph requested for %s (PROGRAM)\n", name);
156 
157  /* build file name... and open it. */
159 
161  (DBR_DVCG_FILE, PROGRAM_RESOURCE_OWNER, DV_SUFFIX);
162 
163  full_name = strdup(concatenate(dir_name, "/", file_name, NULL));
164 
165  out = safe_fopen(full_name, "w");
166 
167  /* prolog, per module stuff, epilog. */
168  fprintf(out, "[\n");
169 
170  for (i=0; i<n; i++)
171  {
172  if (!first) fprintf(out, ",\n");
173  first=false;
174  node(out, gen_array_item(modules, i));
175  }
176 
177  fprintf(out, "]\n");
178 
179  /* close and clean... */
181  gen_array_free(modules);
182  free(dir_name), dir_name=NULL;
183  free(full_name), full_name=NULL;
184 
185  /* put resulting resource into pipsdbm. */
187 
188  return true;
189 }
#define DV_SUFFIX
Definition: graph.c:48
static void node(FILE *out, string name)
Build for module name a node and link to its successors.
Definition: graph.c:56
static FILE * out
Definition: alias_check.c:128
size_t gen_array_nitems(const gen_array_t a)
Definition: array.c:131
void * gen_array_item(const gen_array_t a, size_t i)
Definition: array.c:143
void gen_array_free(gen_array_t a)
Definition: array.c:70
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
void free(void *)
gen_array_t db_get_module_list(void)
Get an array of all the modules (functions, procedures and compilation units) of a workspace.
Definition: database.c:1266
#define DB_PUT_FILE_RESOURCE
Put a file resource into the current workspace database.
Definition: pipsdbm-local.h:85
#define full_name(dir, name)
Definition: compile.c:414
string db_build_file_resource_name(const char *rname, const char *oname, const char *suffix)
returns an allocated file name for a file resource.
Definition: lowlevel.c:169
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define PROGRAM_RESOURCE_OWNER
Definition: pipsdbm-local.h:29
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()
static string file_name

References concatenate(), db_build_file_resource_name(), db_get_current_workspace_directory(), db_get_module_list(), DB_PUT_FILE_RESOURCE, DV_SUFFIX, file_name, fprintf(), free(), full_name, gen_array_free(), gen_array_item(), gen_array_nitems(), node(), out, pips_debug, PROGRAM_RESOURCE_OWNER, safe_fclose(), safe_fopen(), and strdup().

+ Here is the call graph for this function:

◆ graph_of_calls()

bool graph_of_calls ( const string  name)

to be called by pipsmake.

graph.c

builds the daVinci file for module "name".

do the job here.

Parameters
nameame

Definition at line 120 of file graph.c.

121 {
122  FILE * out;
123  string dir_name, file_name, full_name;
125  file_name = db_build_file_resource_name(DBR_DVCG_FILE, name, DV_SUFFIX);
126  full_name = strdup(concatenate(dir_name, "/", file_name, NULL));
127  free(dir_name), dir_name = NULL;
128  out = safe_fopen(full_name, "w");
129  init_seen();
130 
131  /* do the job here. */
132  fprintf(out, "[\n");
133  recursive_append(out, name);
134  fprintf(out, "]\n");
135 
136  close_seen();
138  free(full_name), full_name = NULL;
139  DB_PUT_FILE_RESOURCE(DBR_DVCG_FILE, name, file_name);
140 
141  return true;
142 }
static void init_seen(void)
Definition: graph.c:87
static void close_seen(void)
Definition: graph.c:89
static void recursive_append(FILE *out, string name)
generates into "out" a davinci node for module "name", and recurse to its not yet seen callees.
Definition: graph.c:98

References close_seen(), concatenate(), db_build_file_resource_name(), db_get_current_workspace_directory(), DB_PUT_FILE_RESOURCE, DV_SUFFIX, file_name, fprintf(), free(), full_name, init_seen(), out, recursive_append(), safe_fclose(), safe_fopen(), and strdup().

+ Here is the call graph for this function:

◆ init_seen()

static void init_seen ( void  )
static

Definition at line 87 of file graph.c.

87  { first_seen = false;
static bool first_seen
Definition: graph.c:86
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
@ hash_string
Definition: newgen_hash.h:32

References first_seen, hash_string, hash_table_make(), and seen.

Referenced by graph_of_calls().

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

◆ node()

static void node ( FILE *  out,
string  name 
)
static

Build for module name a node and link to its successors.

It could be a per module resource, however the callgraph is not expected to change often, and we can avoid to manipulate the many small files.

lazy callees.

daVinci node prolog.

one edge per callee

node epilog

Definition at line 56 of file graph.c.

57 {
58  bool first=true;
59  list lcallees = NIL;
60 
61  if (db_resource_p(DBR_CALLEES, name)) /* lazy callees. */
62  lcallees = callees_callees
63  ((callees) db_get_memory_resource(DBR_CALLEES, name, true));
64 
65  /* daVinci node prolog. */
66  fprintf(out, "l(\"%s\",n(\"\",[a(\"OBJECT\",\"%s\")],[", name, name);
67 
68  /* one edge per callee */
69  MAP(STRING, module_called,
70  {
71  if (!first) fprintf(out, ",\n");
72  else { fprintf(out, "\n"); first=false; }
73  fprintf(out, " l(\"%s->%s\",e(\"\",[],r(\"%s\")))",
74  name, module_called, module_called);
75  },
76  lcallees);
77 
78  /* node epilog */
79  fprintf(out, "]))");
80 }
bool db_resource_p(const char *rname, const char *oname)
true if exists and in loaded or stored state.
Definition: database.c:524
#define STRING(x)
Definition: genC.h:87
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755
#define callees_callees(x)
Definition: ri.h:675
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References callees_callees, db_get_memory_resource(), db_resource_p(), fprintf(), MAP, NIL, out, and STRING.

Referenced by __attribute__(), add_node_to_interval(), automatic_translation(), build_bdt_null(), build_creductions_of_statement(), build_reduction_of_variable(), display_interval_graph(), full_graph_of_calls(), interval_graph(), list_of_reduced_variables(), make_host_and_node_modules(), recursive_append(), and write_resulting_bdt().

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

◆ recursive_append()

static void recursive_append ( FILE *  out,
string  name 
)
static

generates into "out" a davinci node for module "name", and recurse to its not yet seen callees.

else

the resource may not have been defined, for instance if the code was not parsed, because the ALL dependence is limited.

Definition at line 98 of file graph.c.

99 {
100  if (seen_p(name)) return;
101  /* else */
102  if (first_seen) fprintf(out, ",\n");
103  else first_seen = true;
104  node(out, name);
105  set_as_seen(name);
106 
107  /* the resource may not have been defined, for instance if the
108  * code was not parsed, because the %ALL dependence is limited.
109  */
110  if (db_resource_p(DBR_CALLEES, name))
111  {
112  callees l = (callees) db_get_memory_resource(DBR_CALLEES, name, true);
114  }
115 }
static bool seen_p(string m)
Definition: graph.c:92
static void set_as_seen(string m)
Definition: graph.c:91
struct _newgen_struct_callees_ * callees
Definition: ri.h:55

References callees_callees, db_get_memory_resource(), db_resource_p(), first_seen, fprintf(), MAP, node(), out, seen_p(), set_as_seen(), and STRING.

Referenced by graph_of_calls().

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

◆ seen_p()

static bool seen_p ( string  m)
static

Definition at line 92 of file graph.c.

92 { return hash_defined_p(seen, (char*)m); }
bool hash_defined_p(const hash_table htp, const void *key)
true if key has e value in htp.
Definition: hash.c:484

References hash_defined_p(), and seen.

Referenced by recursive_append().

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

◆ set_as_seen()

static void set_as_seen ( string  m)
static

Definition at line 91 of file graph.c.

91 { hash_put(seen, (char*) m, (char*) 1); }
void hash_put(hash_table htp, const void *key, const void *val)
This functions stores a couple (key,val) in the hash table pointed to by htp.
Definition: hash.c:364

References hash_put(), and seen.

Referenced by recursive_append().

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

Variable Documentation

◆ first_seen

bool first_seen = false
static

Definition at line 86 of file graph.c.

Referenced by init_seen(), and recursive_append().

◆ seen