PIPS
util.c File Reference
#include "genC.h"
#include "misc.h"
#include "naming.h"
#include "pipsdbm.h"
+ Include dependency graph for util.c:

Go to the source code of this file.

Functions

bool some_main_entity_p (void)
 returns whether there is a main in the database More...
 
string get_main_entity_name (void)
 Return the local name of the main module if it is available, or the local name of any module by default. More...
 

Function Documentation

◆ get_main_entity_name()

string get_main_entity_name ( void  )

Return the local name of the main module if it is available, or the local name of any module by default.

Hopefully, the module names are sorted and the same module of rank 0 is always returned.

A new string is allocated.

Up to a memory leak: entity get_main_entity(void) == module_name_to_entity(get_main_entity_name())

??? some default if there is no main...

This has an impact on interprocedural analysis and especially semantics and works well if only one function is analyzed.

Definition at line 63 of file util.c.

64 {
65  string mn = string_undefined;
66  char buffer[MAXIMAL_MODULE_NAME_SIZE]; // defined in naming.h
68  "/", MAIN_FILE_NAMES, NULL));
69  FILE * fm = fopen(main_list, "r");
70  buffer[0] = 0;
71  if (fm!=NULL) {
72  // FI: we assume here that we have only one main function
74  fclose(fm);
75  // Drop the final LF
76  mn = strndup(buffer, strlen(buffer)-1);
77  }
78  else {
79  // FI: a module list is an array ?
80  gen_array_t modules = db_get_module_list();
81  int nmodules = gen_array_nitems(modules);
82 
83  pips_assert("some modules in the program", nmodules>0);
84  /* ??? some default if there is no main...
85  *
86  * This has an impact on interprocedural analysis and especially
87  * semantics and works well if only one function is analyzed.
88  */
89  pips_user_warning("No main function found, use \"%s\" instead.\n",
90  gen_array_item(modules,0));
91  mn = strdup(gen_array_item(modules, 0));
92 
93  gen_array_full_free(modules);
94  }
95  return mn;
96 }
size_t gen_array_nitems(const gen_array_t a)
Definition: array.c:131
void gen_array_full_free(gen_array_t a)
Definition: array.c:77
void * gen_array_item(const gen_array_t a, size_t i)
Definition: array.c:143
char * safe_fgets(char *s, int n, FILE *stream, char *filename)
Definition: file.c:170
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 pips_user_warning
Definition: misc-local.h:146
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define MAXIMAL_MODULE_NAME_SIZE
In C, the module name may include file names, the compilation unit name and the user name of the func...
Definition: naming-local.h:112
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
#define string_undefined
Definition: newgen_types.h:40
#define MAIN_FILE_NAMES
Name of the file containing the names of the main procedures.
Definition: pipsdbm-local.h:41
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
char * strdup()
static string buffer
Definition: string.c:113
char * strndup(char const *s, size_t n)
A replacement function, for systems that lack strndup.
Definition: strndup.c:26

References buffer, concatenate(), db_get_current_workspace_directory(), db_get_module_list(), gen_array_full_free(), gen_array_item(), gen_array_nitems(), MAIN_FILE_NAMES, MAXIMAL_MODULE_NAME_SIZE, pips_assert, pips_user_warning, safe_fgets(), strdup(), string_undefined, and strndup().

Referenced by generic_program_pointer_values(), print_program_precondition(), program_points_to(), program_postcondition(), and program_precondition().

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

◆ some_main_entity_p()

bool some_main_entity_p ( void  )

returns whether there is a main in the database

util.c

Definition at line 37 of file util.c.

38 {
39  bool some_main_p = false;
41  "/", MAIN_FILE_NAMES, NULL));
42  FILE * fm = fopen(main_list, "r");
43  if(fm!=NULL) {
44  some_main_p = true;
45  fclose(fm);
46  }
47  free(main_list);
48  return some_main_p;
49 }
void free(void *)

References concatenate(), db_get_current_workspace_directory(), free(), MAIN_FILE_NAMES, and strdup().

Referenced by ordinary_summary_precondition(), and summary_total_postcondition().

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