PIPS
lowlevel.c File Reference
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "private.h"
#include "methods.h"
#include <sys/stat.h>
#include <unistd.h>
+ Include dependency graph for lowlevel.c:

Go to the source code of this file.

Data Structures

struct  methods
 

Macros

#define no_read   (READER) abort
 
#define no_write   (WRITER) abort
 
#define DEFAULT_OWNER_NAME   WORKSPACE_PROGRAM_SPACE
 

Typedefs

typedef char *(* READER) (FILE *)
 
typedef void(* WRITER) (FILE *, void *)
 
typedef void(* FREER) (void *)
 
typedef bool(* CHECKER) (void *)
 

Functions

static void no_free (void *p)
 
static void writeln_string (FILE *f, void *p)
 
static void unexpected (void)
 
void pipsdbm_write_statement_mapping (FILE *, statement_mapping)
 Write a statement mapping. More...
 
hash_table pipsdbm_read_statement_mapping (FILE *)
 Read a statement mapping. More...
 
bool pipsdbm_check_statement_mapping (statement_mapping)
 a little bit partial, because domain are not checked. More...
 
void pipsdbm_free_statement_mapping (statement_mapping)
 
void free_static_control_mapping (statement_mapping)
 Modification Dec 11 1995: ne pas utiliser free_static_control car il libere des champs qui appartiennent a d'autres structures que celles controlees par static_controlize...(champs d'origine) Les liberation de ces champs par un autre transformer (use_def_elim) entrainait alors un core dump au niveau de cette procedure. More...
 
static methodsget_methods (const char *name)
 gcc version More...
 
int dbll_number_of_resources (void)
 
string dbll_get_ith_resource_name (int i)
 
bool dbll_very_special_resource_p (const char *rname, const char *oname)
 
void db_set_current_builder_name (const char *name)
 
void db_reset_current_builder_name (void)
 
string db_get_current_builder_name (void)
 
string db_get_directory_name_for_module (const char *name)
 returns the allocated and mkdir'ed directory for module name More...
 
string db_build_file_resource_name (const char *rname, const char *oname, const char *suffix)
 returns an allocated file name for a file resource. More...
 
string get_resource_file_name (const char *rname, const char *oname)
 allocate a full file name for the given resource. More...
 
static FILE * open_resource_file (const char *rname, const char *oname, const char *what)
 
static void close_resource_file (FILE *file, const char *rname, const char *oname)
 
void dbll_unlink_resource_file (const char *rname, const char *oname, bool erroriffailed)
 
static int dbll_stat_file (const char *file_name, bool okifnotthere)
 returns 0 on errors (say no file). More...
 
int dbll_stat_local_file (const char *file_name, bool okifnotthere)
 It is impportant that the workspace directory does not appear in the file name so as to allow workspaces to be moveable. More...
 
int dbll_stat_resource_file (const char *rname, const char *oname, bool okifnotthere)
 
void dbll_save_resource (const char *rname, const char *oname, void *p)
 save rname of oname p. More...
 
void * dbll_load_resource (const char *rname, const char *oname)
 
void dbll_free_resource (const char *rname, const char *oname, void *p)
 
bool dbll_check_resource (const char *rname, const char *oname, void *p)
 Internal consistency of the resource, not the global consistency wrt other resources and pipsmake rules which is managed by the pipsmake library at a higher level. More...
 
bool dbll_storable_p (const char *rname)
 
void dbll_save_and_free_resource (const char *rname, const char *oname, void *p, bool do_free)
 
bool displayable_file_p (const char *name)
 rather approximated. More...
 
bool dbll_database_managed_file_p (const char *name)
 returns whether the file is managed within the database. More...
 

Variables

const char * dbll_current_module = (const char*) NULL
 the current module is expected by some load/save functions... More...
 
static methods all_methods []
 sigh... More...
 
static char * current_builder = NULL
 

Macro Definition Documentation

◆ DEFAULT_OWNER_NAME

#define DEFAULT_OWNER_NAME   WORKSPACE_PROGRAM_SPACE

Definition at line 146 of file lowlevel.c.

◆ no_read

#define no_read   (READER) abort

Definition at line 57 of file lowlevel.c.

◆ no_write

#define no_write   (WRITER) abort

Definition at line 58 of file lowlevel.c.

Typedef Documentation

◆ CHECKER

typedef bool(* CHECKER) (void *)

Definition at line 46 of file lowlevel.c.

◆ FREER

typedef void(* FREER) (void *)

Definition at line 45 of file lowlevel.c.

◆ READER

typedef char*(* READER) (FILE *)

Definition at line 43 of file lowlevel.c.

◆ WRITER

typedef void(* WRITER) (FILE *, void *)

Definition at line 44 of file lowlevel.c.

Function Documentation

◆ close_resource_file()

static void close_resource_file ( FILE *  file,
const char *  rname,
const char *  oname 
)
static

Definition at line 206 of file lowlevel.c.

207 {
208  string file_name = get_resource_file_name(rname, oname);
209  safe_fclose(file, file_name);
210  free(file_name);
211 }
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
void free(void *)
string get_resource_file_name(const char *rname, const char *oname)
allocate a full file name for the given resource.
Definition: lowlevel.c:187
static string file_name

References file_name, free(), get_resource_file_name(), and safe_fclose().

Referenced by dbll_load_resource(), and dbll_save_resource().

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

◆ db_build_file_resource_name()

string db_build_file_resource_name ( const char *  rname,
const char *  oname,
const char *  suffix 
)

returns an allocated file name for a file resource.

may depend on the current builder, someday. this function is to be used by all phases that generate files. it does not include the directory for movability

mkdir as a side effect.

the next name must be compatible with the Display script... it may depend on the builder function maybe (if pipsmake tells) may include the resource name? as lower letters?

Parameters
rnamename
onamename
suffixuffix

Definition at line 169 of file lowlevel.c.

170 {
171  string result;
172  if (same_string_p(oname, "")) oname = DEFAULT_OWNER_NAME;
173  free(db_get_directory_name_for_module(oname));/* mkdir as a side effect. */
174  /* the next name must be compatible with the Display script...
175  * it may depend on the builder function maybe (if pipsmake tells)
176  * may include the resource name? as lower letters?
177  */
178  result = strdup(concatenate(oname, "/", oname, suffix, NULL));
179 
180  pips_debug(8, "file name for %s[%s] with suffix '%s' is '%s'\n",
181  rname, oname, suffix, result);
182  return result;
183 }
#define DEFAULT_OWNER_NAME
Definition: lowlevel.c:146
string db_get_directory_name_for_module(const char *name)
returns the allocated and mkdir'ed directory for module name
Definition: lowlevel.c:150
#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 same_string_p(s1, s2)
char * strdup()

References concatenate(), db_get_directory_name_for_module(), DEFAULT_OWNER_NAME, free(), pips_debug, same_string_p, and strdup().

Referenced by actual_symbol_table_dump(), add_new_compilation_unit(), add_new_module_from_text(), filter_file(), flinter(), full_graph_of_calls(), generic_print_xml_application(), gpu_xml_dump(), graph_of_calls(), html_prettyprint(), html_prettyprint_symbol_table(), loop_statistics(), make_resource_from_starting_node(), make_text_resource(), module_to_callgraph(), print_c_code(), print_code_smalltalk(), print_crough(), print_dependence_or_chains_graph(), print_dot_dependence_or_chains_graph(), print_filtered_dg_or_dvdg(), print_interface(), print_loopnest_dependence_cone(), print_loops(), print_sesam_tasks_buffers_header(), print_xml_code(), print_xml_code_with_explicit_motif(), process_user_file(), step_compile(), store_new_module(), and unsplit_internal().

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

◆ db_get_current_builder_name()

string db_get_current_builder_name ( void  )

Definition at line 140 of file lowlevel.c.

141 {
142  pips_assert("some current builder", current_builder);
143  return current_builder;
144 }
static char * current_builder
Definition: lowlevel.c:126
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172

References current_builder, and pips_assert.

◆ db_get_directory_name_for_module()

string db_get_directory_name_for_module ( const char *  name)

returns the allocated and mkdir'ed directory for module name

MKDIR

Parameters
nameame

Definition at line 150 of file lowlevel.c.

151 {
152  string dir_name, ws_dir_name;
153  pips_assert("some valid name", name && !same_string_p(name, ""));
154  ws_dir_name = db_get_current_workspace_directory();
155  dir_name = strdup(concatenate(ws_dir_name, "/", name, NULL));
156  free(ws_dir_name);
157  if (!directory_exists_p(dir_name))
158  if (!create_directory(dir_name)) /* MKDIR */
160  ("cannot create directory %s\n", dir_name);
161  return dir_name;
162 }
bool create_directory(char *name)
Definition: file.c:435
bool directory_exists_p(const char *name)
Definition: file.c:314
#define pips_user_irrecoverable_error
Definition: misc-local.h:148
string db_get_current_workspace_directory(void)
Definition: workspace.c:96

References concatenate(), create_directory(), db_get_current_workspace_directory(), directory_exists_p(), free(), pips_assert, pips_user_irrecoverable_error, same_string_p, and strdup().

Referenced by dag_dot_dump(), db_build_file_resource_name(), db_get_meta_data_directory(), generate_hpf_remapping_file(), get_new_tmp_file_name(), get_opencl_file_name(), get_resource_file_name(), helper_file_name(), hpfc_init(), insert_check_alias_before_statement(), insert_flag_before_call_site(), insert_test_before_caller(), insert_test_before_statement(), process_thru_C_pp(), process_thru_fortran_pp(), push_path(), step_install(), text_area_included(), unsplit_internal(), and used_before_set().

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

◆ db_reset_current_builder_name()

void db_reset_current_builder_name ( void  )

Definition at line 134 of file lowlevel.c.

135 {
136  pips_assert("some current builder", current_builder);
138 }

References current_builder, free(), and pips_assert.

+ Here is the call graph for this function:

◆ db_set_current_builder_name()

void db_set_current_builder_name ( const char *  name)
Parameters
nameame

Definition at line 128 of file lowlevel.c.

129 {
130  pips_assert("no current builder", !current_builder);
131  current_builder = strdup(name);
132 }

References current_builder, pips_assert, and strdup().

+ Here is the call graph for this function:

◆ dbll_check_resource()

bool dbll_check_resource ( const char *  rname,
const char *  oname,
void *  p 
)

Internal consistency of the resource, not the global consistency wrt other resources and pipsmake rules which is managed by the pipsmake library at a higher level.

Know right away which resource is Newgen inconsistent

FI: I find this message I have added myself pretty useless in general as a core dump occurs in case some inconsistency is found.

Parameters
rnamename
onamename

Definition at line 324 of file lowlevel.c.

325 {
326  methods * m;
327  /* Know right away which resource is Newgen inconsistent */
328  pips_debug(9, "checking Newgen resource consistency %s[%s] (0x%p)\n",
329  rname, oname, p);
330  m = get_methods(rname);
331  bool b = m->check_function(p);
332  /* FI: I find this message I have added myself pretty useless in
333  general as a core dump occurs in case some inconsistency is
334  found. */
335  pips_debug(9, "checking Newgen resource consistency %s[%s] (0x%p): %s\n",
336  rname, oname, p,
337  bool_to_string(b));
338  return b;
339 }
static methods * get_methods(const char *name)
gcc version
Definition: lowlevel.c:88
string bool_to_string(bool)
Definition: string.c:243
CHECKER check_function
Definition: lowlevel.c:53

References bool_to_string(), methods::check_function, get_methods(), and pips_debug.

Referenced by db_get_memory_resource(), and db_put_or_update_memory_resource().

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

◆ dbll_database_managed_file_p()

bool dbll_database_managed_file_p ( const char *  name)

returns whether the file is managed within the database.

that is it is not a SOURCE_FILE. basically SOURCE_FILEs are given relative names with leading . or /, while within the database a leading "*.database/" is always appended.

Parameters
nameame

Definition at line 376 of file lowlevel.c.

377 {
378  return name[0]!='.' && name[0]!='/';
379 }

Referenced by db_check_time().

+ Here is the caller graph for this function:

◆ dbll_free_resource()

void dbll_free_resource ( const char *  rname,
const char *  oname,
void *  p 
)
Parameters
rnamename
onamename

Definition at line 313 of file lowlevel.c.

314 {
315  methods * m;
316  pips_debug(7, "freeing resource %s[%s] (%p)\n", rname, oname, p);
317  m = get_methods(rname);
318  m->free_function(p);
319 }
FREER free_function
Definition: lowlevel.c:52

References methods::free_function, get_methods(), and pips_debug.

Referenced by db_delete_resource(), db_save_and_free_resource(), db_set_resource_as_required(), and dbll_save_and_free_resource().

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

◆ dbll_get_ith_resource_name()

string dbll_get_ith_resource_name ( int  i)

Definition at line 113 of file lowlevel.c.

114 {
115  pips_assert("valid resource number", i>=0 && i<dbll_number_of_resources());
116  return all_methods[i].name;
117 }
int dbll_number_of_resources(void)
Definition: lowlevel.c:108
static methods all_methods[]
sigh...
Definition: lowlevel.c:78
string name
Definition: lowlevel.c:49

References all_methods, dbll_number_of_resources(), methods::name, and pips_assert.

Referenced by db_close_module(), and db_delete_all_resources().

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

◆ dbll_load_resource()

void* dbll_load_resource ( const char *  rname,
const char *  oname 
)
Parameters
rnamename
onamename

Definition at line 294 of file lowlevel.c.

295 {
296  methods * m;
297  FILE * f;
298  void * p = NULL;
299  pips_debug(7, "loading resource %s[%s]\n", rname, oname);
300 
301  dbll_current_module = oname;
302  m = get_methods(rname);
303  if (m->read_function==no_read)
304  pips_internal_error("cannot load %s of %s, no load function",
305  rname, oname);
306  f = open_resource_file(rname, oname, "r");
307  p = m->read_function(f);
308  close_resource_file(f, rname, oname);
309  dbll_current_module = (string) NULL;
310  return p;
311 }
static void close_resource_file(FILE *file, const char *rname, const char *oname)
Definition: lowlevel.c:206
static FILE * open_resource_file(const char *rname, const char *oname, const char *what)
Definition: lowlevel.c:197
#define no_read
Definition: lowlevel.c:57
const char * dbll_current_module
the current module is expected by some load/save functions...
Definition: lowlevel.c:41
#define pips_internal_error
Definition: misc-local.h:149
char * string
STRING.
Definition: newgen_types.h:39
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
READER read_function
Definition: lowlevel.c:50

References close_resource_file(), dbll_current_module, f(), get_methods(), no_read, open_resource_file(), pips_debug, pips_internal_error, and methods::read_function.

Referenced by db_load_resource().

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

◆ dbll_number_of_resources()

int dbll_number_of_resources ( void  )

I'm not sure sizeof(all_methods) is ANSI C. FC

Definition at line 108 of file lowlevel.c.

109 { /* I'm not sure sizeof(all_methods) is ANSI C. FC */
110  return sizeof(all_methods)/sizeof(methods) - 1;
111 }

References all_methods.

Referenced by db_close_module(), db_delete_all_resources(), dbll_get_ith_resource_name(), and get_methods().

+ Here is the caller graph for this function:

◆ dbll_save_and_free_resource()

void dbll_save_and_free_resource ( const char *  rname,
const char *  oname,
void *  p,
bool  do_free 
)
Parameters
rnamename
onamename
do_freeo_free

Definition at line 350 of file lowlevel.c.

352 {
353  dbll_save_resource(rname, oname, p);
354  if (do_free) dbll_free_resource(rname, oname, p);
355 }
void dbll_free_resource(const char *rname, const char *oname, void *p)
Definition: lowlevel.c:313
void dbll_save_resource(const char *rname, const char *oname, void *p)
save rname of oname p.
Definition: lowlevel.c:275

References dbll_free_resource(), and dbll_save_resource().

Referenced by db_save_and_free_resource().

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

◆ dbll_save_resource()

void dbll_save_resource ( const char *  rname,
const char *  oname,
void *  p 
)

save rname of oname p.

get the method, then apply it.

Parameters
rnamename
onamename

Definition at line 275 of file lowlevel.c.

276 {
277  methods * m;
278  FILE * f;
279  pips_debug(7, "saving resource %s[%s] (0x%p)\n", rname, oname, p);
280 
281  dbll_current_module = oname;
282  m = get_methods(rname);
283  if (m->write_function==no_write) {
284  pips_user_warning("resource %s of %s lost, no unload function\n",
285  rname, oname);
286  } else {
287  f = open_resource_file(rname, oname, "w");
288  m->write_function(f, p);
289  close_resource_file(f, rname, oname);
290  }
291  dbll_current_module = (string) NULL;
292 }
#define no_write
Definition: lowlevel.c:58
#define pips_user_warning
Definition: misc-local.h:146
WRITER write_function
Definition: lowlevel.c:51

References close_resource_file(), dbll_current_module, f(), get_methods(), no_write, open_resource_file(), pips_debug, pips_user_warning, and methods::write_function.

Referenced by db_save_resource(), and dbll_save_and_free_resource().

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

◆ dbll_stat_file()

static int dbll_stat_file ( const char *  file_name,
bool  okifnotthere 
)
static

returns 0 on errors (say no file).

otherwise returns the modification time.

some error

humm... unsigned...

Definition at line 232 of file lowlevel.c.

233 {
234  struct stat buf;
235  int time = 0, error = stat(file_name, &buf);
236  if (error<0) { /* some error */
237  if (!okifnotthere || get_bool_property("WARNING_ON_STAT_ERROR")) {
238  perror(file_name);
239  pips_user_warning("error in stat for %s\n", file_name);
240  }
241  if (!okifnotthere) {
242  pips_internal_error("stat error not permitted here");
243  }
244  } else time = (int) buf.st_mtime; /* humm... unsigned... */
245  return time;
246 }
#define error(fun, msg)
NewGen interface with C3 type Psysteme for PIPS project.
Definition: Psc.c:78
void const char const char const int
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
static char buf[BSZ]
Definition: split_file.c:157

References buf, error, file_name, get_bool_property(), int, pips_internal_error, and pips_user_warning.

Referenced by dbll_stat_local_file(), and dbll_stat_resource_file().

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

◆ dbll_stat_local_file()

int dbll_stat_local_file ( const char *  file_name,
bool  okifnotthere 
)

It is impportant that the workspace directory does not appear in the file name so as to allow workspaces to be moveable.

Parameters
file_nameile_name
okifnottherekifnotthere

Definition at line 251 of file lowlevel.c.

252 {
253  string full_name;
254  int time;
255  if (file_name[0]!='/' && file_name[0]!='.') {
256  string dir_name = db_get_current_workspace_directory();
257  full_name = strdup(concatenate(dir_name, "/", file_name, NULL));
258  free(dir_name);
259  } else full_name = strdup(file_name);
260  time = dbll_stat_file(full_name, okifnotthere);
261  free(full_name);
262  return time;
263 }
#define full_name(dir, name)
Definition: compile.c:414
static int dbll_stat_file(const char *file_name, bool okifnotthere)
returns 0 on errors (say no file).
Definition: lowlevel.c:232

References concatenate(), db_get_current_workspace_directory(), dbll_stat_file(), file_name, free(), full_name, and strdup().

Referenced by db_check_time(), db_put_or_update_memory_resource(), and db_update_time().

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

◆ dbll_stat_resource_file()

int dbll_stat_resource_file ( const char *  rname,
const char *  oname,
bool  okifnotthere 
)
Parameters
rnamename
onamename
okifnottherekifnotthere

Definition at line 265 of file lowlevel.c.

266 {
267  string file_name = get_resource_file_name(rname, oname);
268  int time = dbll_stat_file(file_name, okifnotthere);
269  free(file_name);
270  return time;
271 }

References dbll_stat_file(), file_name, free(), and get_resource_file_name().

Referenced by db_check_time(), db_clean_db_resources(), db_save_and_free_resource(), and db_save_resource().

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

◆ dbll_storable_p()

bool dbll_storable_p ( const char *  rname)
Parameters
rnamename

Definition at line 341 of file lowlevel.c.

342 {
343  methods * m = get_methods(rname);
344  return m->write_function!=no_write;
345 }

References get_methods(), no_write, and methods::write_function.

Referenced by db_get_memory_resource(), db_save_and_free_resource(), and db_save_resource().

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

◆ dbll_unlink_resource_file()

void dbll_unlink_resource_file ( const char *  rname,
const char *  oname,
bool  erroriffailed 
)
Parameters
rnamename
onamename
erroriffailedrroriffailed

Definition at line 219 of file lowlevel.c.

220 {
221  string full_name = get_resource_file_name(rname, oname);
222  if (unlink(full_name) && erroriffailed) {
223  perror(full_name);
224  pips_internal_error("cannot unlink resource %s of %s", rname, oname);
225  }
226  free(full_name);
227 }

References free(), full_name, get_resource_file_name(), and pips_internal_error.

Referenced by db_delete_obsolete_resources(), and db_unput_resources().

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

◆ dbll_very_special_resource_p()

bool dbll_very_special_resource_p ( const char *  rname,
const char *  oname 
)
Parameters
rnamename
onamename

Definition at line 119 of file lowlevel.c.

120 {
121  return same_string_p(rname, DBR_ENTITIES) && same_string_p(oname, "");
122 }

References same_string_p.

Referenced by db_load_resource(), and db_save_and_free_resource().

+ Here is the caller graph for this function:

◆ displayable_file_p()

bool displayable_file_p ( const char *  name)

rather approximated.

beware that this function is used to check whether a resource is a file, and also to check its current time on pipsmake dependencies.

Parameters
nameame

Definition at line 361 of file lowlevel.c.

362 {
363  methods * m = get_methods(name);
364  return
365  // the resource itself is a string
367  // and the resource names ends with "_FILE"
368  find_suffix((string) name, "_FILE");
369 }
static void writeln_string(FILE *f, void *p)
Definition: lowlevel.c:60
string find_suffix(const string, const string)
Find if a string s end with a suffix.
Definition: string.c:273

References find_suffix(), get_methods(), methods::write_function, and writeln_string().

Referenced by db_check_time(), db_put_or_update_memory_resource(), db_save_resource(), db_time_of_resource(), db_update_time(), get_view_file(), just_show(), and show().

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

◆ free_static_control_mapping()

void free_static_control_mapping ( statement_mapping  map)

Modification Dec 11 1995: ne pas utiliser free_static_control car il libere des champs qui appartiennent a d'autres structures que celles controlees par static_controlize...(champs d'origine) Les liberation de ces champs par un autre transformer (use_def_elim) entrainait alors un core dump au niveau de cette procedure.

On fait a la place des gen_free_list en detail –DB ]

Definition at line 318 of file externals.c.

319 {
320  STATEMENT_MAPPING_MAP(s, val, {
326  gen_free( (void*) val );
327  }, map);
328 
330 }
void gen_free(gen_chunk *obj)
version without shared_pointers.
Definition: genClib.c:992
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define FREE_STATEMENT_MAPPING(map)
Definition: newgen-local.h:45
#define STATEMENT_MAPPING_MAP(s, v, code, h)
Definition: newgen-local.h:53
#define static_control_loops(x)
Definition: paf_ri.h:757
#define static_control_params(x)
Definition: paf_ri.h:755
#define static_control_tests(x)
Definition: paf_ri.h:759

◆ get_methods()

static methods* get_methods ( const char *  name)
static

gcc version

return the methods for resource name

we use a local cache for fast retrieval.

initialize at first call.

get the methods!

last is unexpected

Definition at line 88 of file lowlevel.c.

89 {
90  /* we use a local cache for fast retrieval.
91  */
92  static hash_table cache = hash_table_undefined;
93  methods * m;
94 
95  if (hash_table_undefined_p(cache)) { /* initialize at first call. */
97  for (m = all_methods; m->name; m++)
98  hash_put(cache, m->name, (void *) m);
99  }
100 
101  /* get the methods! */
102  m = (methods*) hash_get(cache, name);
103  if (m==(methods*)HASH_UNDEFINED_VALUE)
104  m = &all_methods[dbll_number_of_resources()]; /* last is unexpected */
105  return m;
106 }
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:449
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
@ hash_string
Definition: newgen_hash.h:32
#define HASH_UNDEFINED_VALUE
value returned by hash_get() when the key is not found; could also be called HASH_KEY_NOT_FOUND,...
Definition: newgen_hash.h:56
#define hash_table_undefined_p(h)
Definition: newgen_hash.h:50
#define hash_table_undefined
Value of an undefined hash_table.
Definition: newgen_hash.h:49

References all_methods, dbll_number_of_resources(), hash_get(), hash_put(), hash_string, hash_table_make(), hash_table_undefined, hash_table_undefined_p, HASH_UNDEFINED_VALUE, and methods::name.

Referenced by dbll_check_resource(), dbll_free_resource(), dbll_load_resource(), dbll_save_resource(), dbll_storable_p(), and displayable_file_p().

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

◆ get_resource_file_name()

string get_resource_file_name ( const char *  rname,
const char *  oname 
)

allocate a full file name for the given resource.

Parameters
rnamename
onamename

Definition at line 187 of file lowlevel.c.

188 {
189  string dir_name, file_name;
190  if (same_string_p(oname, "")) oname = DEFAULT_OWNER_NAME;
191  dir_name = db_get_directory_name_for_module(oname);
192  file_name = strdup(concatenate(dir_name, "/", rname, NULL));
193  free(dir_name);
194  return file_name;
195 }

References concatenate(), db_get_directory_name_for_module(), DEFAULT_OWNER_NAME, file_name, free(), same_string_p, and strdup().

Referenced by close_resource_file(), dbll_stat_resource_file(), dbll_unlink_resource_file(), f95split(), open_resource_file(), and process_user_file().

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

◆ no_free()

static void no_free ( void *  p)
static

Definition at line 59 of file lowlevel.c.

59 { pips_debug(2, "memory leak (%p)\n", p); }

References pips_debug.

◆ open_resource_file()

static FILE* open_resource_file ( const char *  rname,
const char *  oname,
const char *  what 
)
static

Definition at line 197 of file lowlevel.c.

198 {
199  FILE * file;
200  string file_name = get_resource_file_name(rname, oname);
201  file = safe_fopen(file_name, what);
202  free(file_name);
203  return file;
204 }
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67

References file_name, free(), get_resource_file_name(), and safe_fopen().

Referenced by dbll_load_resource(), and dbll_save_resource().

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

◆ pipsdbm_check_statement_mapping()

bool pipsdbm_check_statement_mapping ( statement_mapping  h)

a little bit partial, because domain are not checked.

Definition at line 178 of file externals.c.

179 {
180  STATEMENT_MAPPING_MAP(k, v, {
181  pips_assert("consistent statement",
183  pips_assert("consistent val", gen_consistent_p((void*) v));
184  },
185  h);
186  return true;
187 }
bool statement_consistent_p(statement p)
Definition: ri.c:2195
int gen_consistent_p(gen_chunk *obj)
GEN_CONSISTENT_P dynamically checks the type correctness of OBJ.
Definition: genClib.c:2398

◆ pipsdbm_free_statement_mapping()

void pipsdbm_free_statement_mapping ( statement_mapping  h)

Definition at line 190 of file externals.c.

191 {
192  STATEMENT_MAPPING_MAP(k, v, gen_free((void*) v), h);
194 }

◆ pipsdbm_read_statement_mapping()

hash_table pipsdbm_read_statement_mapping ( FILE *  fd)

Read a statement mapping.

This function is quite too low level... It mixes raw getc() from a FILE with gen_read. To survive other NewGen backend (XML), fprintf could be replaced with a gen_getc() that could peek in a CDATA for example in the case of XML.

But in this case it should be a call to something like so = gen_read_int(fd) instead to do even simpler and read an int value (in textual form or in <int>...</int> in the case of XML.

get meta data.

Definition at line 147 of file externals.c.

148 {
149  statement stat;
151  int n;
152 
153  pips_assert("some current module name", dbll_current_module);
154  pips_debug(3, "statement -> ??? for %s\n", dbll_current_module);
155  stat = (statement)
157 
159 
160  /* get meta data.
161  */
162  n = lire_int(fd);
163 
164  while (n-->0) {
165  int so = lire_int(fd);
166  pips_assert("valid ordering", so!=STATEMENT_ORDERING_UNDEFINED);
167  hash_put(result,(void*)ordering_to_statement(so),(void*)gen_read(fd));
168  }
169 
171 
172  return result;
173 }
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
static int lire_int(FILE *fd)
reads an int while sharing file and buffers with newgen...
Definition: externals.c:40
gen_chunk * gen_read(FILE *file)
GEN_READ reads any object from the FILE stream.
Definition: genClib.c:2323
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 STATEMENT_ORDERING_UNDEFINED
mapping.h inclusion
Definition: newgen-local.h:35
@ hash_pointer
Definition: newgen_hash.h:32
hash_table set_ordering_to_statement(statement s)
To be used instead of initialize_ordering_to_statement() to make sure that the hash table ots is in s...
Definition: ordering.c:172
statement ordering_to_statement(int o)
Get the statement associated to a given ordering.
Definition: ordering.c:111
void reset_ordering_to_statement(void)
Reset the mapping from ordering to statement.
Definition: ordering.c:185

◆ pipsdbm_write_statement_mapping()

void pipsdbm_write_statement_mapping ( FILE *  fd,
statement_mapping  h 
)

Write a statement mapping.

This function is quite too low level... It mixes raw printf in a FILE with gen_write. To survive other NewGen backend (XML), fprintf could be replaced with a gen_fprintf() that could encapsulate the output in a CDATA for example in the case of XML.

But in this case it should be a call to something like gen_write_int(fd, order) instead to do even simpler.

save it!

Parameters
fdfile to write to
hhash table to dump

Definition at line 115 of file externals.c.

118 {
119  fprintf(fd, "%d\n", statement_mapping_count(h));
121  {
122  statement key = (statement) s;
123  gen_chunkp val = (gen_chunkp) v;
124  int order = statement_ordering(key);
125  if (order!=STATEMENT_ORDERING_UNDEFINED) { /* save it! */
126  fprintf(fd, "%d\n", order);
127  gen_write(fd, (gen_chunkp) val);
128  }
129  else pips_user_warning("statement with illegal ordering\n");
130  },
131  h);
132 }
static int statement_mapping_count(statement_mapping h)
The old statement_mapping is an hash_table managed directly.
Definition: externals.c:94
union gen_chunk * gen_chunkp
void gen_write(FILE *fd, gen_chunk *obj)
GEN_WRITE writes the OBJect on the stream FD.
Definition: genClib.c:1745
#define statement_ordering(x)
Definition: ri.h:2454
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
A gen_chunk is used to store every object.
Definition: genC.h:58

◆ unexpected()

static void unexpected ( void  )
static

Definition at line 61 of file lowlevel.c.

62 { pips_internal_error("unexpected pipsdbm method");}

References pips_internal_error.

◆ writeln_string()

static void writeln_string ( FILE *  f,
void *  p 
)
static

Definition at line 60 of file lowlevel.c.

60 {fprintf(f, "%s\n", (char*)p);}

References f(), and fprintf().

Referenced by displayable_file_p().

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

Variable Documentation

◆ all_methods

methods all_methods[]
static
Initial value:
= {
}

sigh...

gcc version

Definition at line 78 of file lowlevel.c.

Referenced by dbll_get_ith_resource_name(), dbll_number_of_resources(), and get_methods().

◆ current_builder

char* current_builder = NULL
static

◆ dbll_current_module

const char* dbll_current_module = (const char*) NULL

the current module is expected by some load/save functions...

lowlevel.c

Definition at line 41 of file lowlevel.c.

Referenced by dbll_load_resource(), dbll_save_resource(), pipsdbm_read_statement_function(), and pipsdbm_read_statement_mapping().