PIPS
syntheses.h File Reference
#include "linear.h"
#include "genC.h"
#include "text.h"
#include "newgen.h"
#include "naming.h"
#include "ri.h"
#include "ri-util.h"
#include "pipsdbm.h"
#include "workspace-util.h"
+ Include dependency graph for syntheses.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void add_new_compilation_unit (const char *, bool, entity)
 Warning! Do not modify this file that is automatically generated! More...
 
bool add_new_module_from_text (const char *, text, bool, const char *)
 Add the new resource files associated to a module with its more-or-less correct code. More...
 
bool add_new_module (const char *, entity, statement, bool)
 Add the new resource files associated to a module with its more-or-less correct code. More...
 
void set_internal_missing_module_resolver_handler (string(*)(const char *))
 
bool fortran_initializer (const string)
 Create a module with its related file resources when there is no Fortran source for it. More...
 
bool initializer (const string)
 A phase that creates a module with its related file resources when there is no Fortran source for it. More...
 
bool c_initializer (const string)
 A phase that creates a module with its related file resources when there is no C source for it. More...
 
bool clone_on_argument (const string)
 clone.c More...
 
bool clone (const string)
 
bool clone_substitute (const string)
 
bool clone_only (const string)
 

Function Documentation

◆ add_new_compilation_unit()

void add_new_compilation_unit ( const char *  compilation_unit_name,
bool  is_fortran,
entity  module 
)

Warning! Do not modify this file that is automatically generated!

Modify src/Libs/syntheses/syntheses-local.h instead, to add your own modifications. header file built by cproto syntheses-local.h SYNTHESES Library: Passes and functions generating new modules, or removing modules, such as initializer, clone, inlining and outlining cproto-generated files initializer.c

Add the compilation unit files

Builds the compilation unit stub: it can be empty or include module_name declaration as an extern function.

Put it in the source file and link the initial file.

Parameters
compilation_unit_nameompilation_unit_name
is_fortrans_fortran
moduleodule

Definition at line 367 of file initializer.c.

367  {
368  /* Add the compilation unit files */
369  pips_assert("The compilation unit name is defined", !string_undefined_p(compilation_unit_name));
370  user_log("Registering synthesized compilation unit %s\n", compilation_unit_name);
372  const char* res = is_fortran? DBR_INITIAL_FILE : DBR_C_SOURCE_FILE;
373  if(entity_undefined_p(cu))
375 
376  char *dir_name = db_get_current_workspace_directory();
377 
378  char *file_name;
379  char* cu_real = strdup(compilation_unit_name);
380  cu_real[strlen(cu_real)-1]=0;
381  asprintf(&file_name,"%s" PP_C_ED ,cu_real);
382  free(cu_real);
383 
384  char * src_name;
385  asprintf(&src_name,WORKSPACE_TMP_SPACE "/%s",file_name);
386  char *full_name;
387  asprintf(&full_name,"%s/%s",dir_name,src_name);
388  free(src_name);
389 
390  char *init_name = db_build_file_resource_name(res, compilation_unit_name, is_fortran? FORTRAN_INITIAL_FILE_SUFFIX : C_FILE_SUFFIX);
391  char *finit_name;
392  asprintf(&finit_name,"%s/%s", dir_name, init_name);
393  free(dir_name);
394 
395  /* Builds the compilation unit stub: it can be empty or include
396  module_name declaration as an extern function.
397  */
399 
400  /* Put it in the source file and link the initial file.
401  */
403  FILE *f = safe_fopen(finit_name, "w");
404  print_text(f, stub);
405  safe_fclose(f, finit_name);
406  free_text(stub);
407 
408  if(!file_exists_p(full_name)) {
409  FILE *fake = safe_fopen(full_name,"a");
410  safe_fclose(fake, full_name);
411  }
414  DB_PUT_FILE_RESOURCE(DBR_INPUT_FILE_NAME, compilation_unit_name, strdup(""));
415 }
void user_log(const char *format,...)
Definition: message.c:234
text make_text(list a)
Definition: text.c:107
void free_text(text p)
Definition: text.c:74
string compilation_unit_name
cproto-generated files
Definition: c_parser.c:49
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
bool file_exists_p(const char *name)
Definition: file.c:321
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
void free(void *)
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#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
static text compilation_unit_text(entity cu, entity module)
Generate the text of a compilation unit for a missing C module.
Definition: initializer.c:281
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 asprintf
Definition: misc-local.h:225
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define TOP_LEVEL_MODULE_NAME
Module containing the global variables in Fortran and C.
Definition: naming-local.h:101
#define string_undefined_p(s)
Definition: newgen_types.h:41
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
static char * module
Definition: pips.c:74
#define WORKSPACE_TMP_SPACE
Definition: pipsdbm-local.h:31
#define db_make_subdirectory(n)
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
entity FindEntity(const char *package, const char *name)
Retrieve an entity from its package/module name and its local name.
Definition: entity.c:1503
entity MakeCompilationUnitEntity(const char *name)
This is useful for the C language only.
Definition: entity.c:1954
#define entity_undefined_p(x)
Definition: ri.h:2762
char * strdup()
void print_text(FILE *fd, text t)
Definition: print.c:195
static string file_name

References asprintf, compilation_unit_name, compilation_unit_text(), db_build_file_resource_name(), db_get_current_workspace_directory(), db_make_subdirectory, DB_PUT_FILE_RESOURCE, entity_undefined_p, f(), file_exists_p(), file_name, FindEntity(), free(), free_text(), full_name, make_text(), MakeCompilationUnitEntity(), module, NIL, pips_assert, print_text(), safe_fclose(), safe_fopen(), strdup(), string_undefined_p, TOP_LEVEL_MODULE_NAME, user_log(), and WORKSPACE_TMP_SPACE.

Referenced by add_new_module_from_text(), and outliner_compilation_unit().

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

◆ add_new_module()

bool add_new_module ( const char *  module_name,
entity  module,
statement  stat,
bool  is_fortran 
)

Add the new resource files associated to a module with its more-or-less correct code.

The idea is to prettyprint the module to some file resources and to parse it later in order to have a full-fledge module with all the PIPS structured up-to-date.

Useful for code generation, out-lining...

There is still some redundancy with module_name, module and stat

Get a text code for the new module

Parameters
module_nameodule_name
moduleodule
stattat
is_fortrantext heading

Definition at line 553 of file initializer.c.

557  {
558  /* Get a text code for the new module */
559  text code_text = text_module(module, stat);
561  code_text,
562  is_fortran,
564  free_text(code_text);
565 
566  return ret;
567 }
#define ret(why, what)
true if not a remapping for old.
Definition: dynamic.c:986
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
bool add_new_module_from_text(const char *module_name, text code_text, bool is_fortran, const char *compilation_unit_name)
Add the new resource files associated to a module with its more-or-less correct code.
Definition: initializer.c:431
#define string_undefined
Definition: newgen_types.h:40
text text_module(entity, statement)

References add_new_module_from_text(), free_text(), module, module_name(), ret, string_undefined, and text_module().

Referenced by create_module_with_statement().

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

◆ add_new_module_from_text()

bool add_new_module_from_text ( const char *  module_name,
text  code_text,
bool  is_fortran,
const char *  compilation_unit_name 
)

Add the new resource files associated to a module with its more-or-less correct code.

The idea is to prettyprint the module to some file resources and to parse it later in order to have a full-fledge module with all the PIPS data structures up-to-date.

Useful for code generation, out-lining, stub generation...

Should be checked with different module with the same name... Maybe a conflict in WORKSPACE_TMP_SPACE ?

relative to the current directory

For C only: compilation unit cu and compilation unit name cun

depending on output language, build compilation unit, select prettyprinter choose out file name

pips' current directory is just above the workspace

Put the code text in the temporary source file

A PIPS database may be partly incoherent after a core dump but still usable (Cathare 2, FI). So delete a previously finit_name file.

The initial file is linked to the newly generated temporary file:

Add the new generated file as a file resource with its local name... should only put a new user file, I guess?

The user file dwells in the WORKSPACE_TMP_SPACE

Parameters
module_nameodule_name
code_textode_text
is_fortrans_fortran
compilation_unit_nameompilation_unit_name

Definition at line 431 of file initializer.c.

434  {
435  bool success_p = true;
437  /* relative to the current directory */
438  FILE * f;
439  const char *res = is_fortran? DBR_INITIAL_FILE : DBR_C_SOURCE_FILE;
440 
441  /* For C only: compilation unit cu and compilation unit name cun */
442  char* cun = string_undefined;
444 
445  if(entity_undefined_p(m))
446  {
448  "No entity defined for module %s although it might"
449  " have been encountered at a call site\n", module_name);
450  return false;
451  }
452 
453  /* depending on output language, build compilation unit,
454  * select prettyprinter
455  * choose out file name
456  */
457  char *file_name;
458  if(is_fortran) {
460  asprintf(&file_name,"%s" FORTRAN_FILE_SUFFIX ,module_name );
461  }
462  else {
466  }
467  else {
470  cu = MakeCompilationUnitEntity(cun);
471  }
472 
473  // Build the corresponding compilation unit for C code
474  if(string_undefined_p(cun)) {
475  char * the_cu = NULL,*iter;
476  if((iter=strchr(module_name,FILE_SEP))) {
477  the_cu = strndup(module_name,iter-module_name);
478  }
479  else the_cu = strdup(module_name);
480  asprintf(&cun, "%s" FILE_SEP_STRING, the_cu);
481  cu = MakeCompilationUnitEntity(cun);
482  free(the_cu);
483  }
484 
485  /* pips' current directory is just above the workspace
486  */
487  string cu_real = strdup(cun);
488  cu_real[strlen(cu_real)-1]=0;
489  asprintf(&file_name,"%s" PP_C_ED ,cu_real);
490  free(cu_real);
491  }
492  char *dir_name = db_get_current_workspace_directory(), *src_name;
493  asprintf(&src_name,WORKSPACE_TMP_SPACE "/%s",file_name);
494  char *full_name;
495  asprintf(&full_name,"%s/%s",dir_name,src_name);
496  char *init_name =
497  db_build_file_resource_name(res, entity_local_name(m), is_fortran? FORTRAN_INITIAL_FILE_SUFFIX : C_FILE_SUFFIX);
498  char *finit_name;
499  asprintf(&finit_name,"%s/%s" ,dir_name,init_name);
500  free(dir_name);
501 
502  /* Put the code text in the temporary source file */
504  f = safe_fopen(finit_name, "w");
505  print_text(f, code_text);
506  safe_fclose(f, finit_name);
507  /* A PIPS database may be partly incoherent after a core dump but
508  still usable (Cathare 2, FI). So delete a previously finit_name
509  file. */
512  /* The initial file is linked to the newly generated temporary file: */
513  safe_link(full_name, finit_name);
514  free(finit_name);
515 
516  /* Add the new generated file as a file resource with its local
517  * name... should only put a new user file, I guess?
518  */
519  user_log("Registering synthesized file %s\n", file_name );
520  free(file_name);
521  DB_PUT_FILE_RESOURCE(res, module_name, init_name);
522  /* The user file dwells in the WORKSPACE_TMP_SPACE */
523  DB_PUT_FILE_RESOURCE(DBR_USER_FILE, module_name, full_name);
524  if(!is_fortran) {
525  // No input file for synthesized C code
526  DB_PUT_FILE_RESOURCE(DBR_INPUT_FILE_NAME, module_name, strdup(""));
527  }
528 
529  if( !entity_undefined_p(cu) ) { // C is assumed
530  add_new_compilation_unit(cun, is_fortran, m);
531  }
532  else if(!is_fortran) {
533  if(entity_undefined_p(cu)) cu = module_name_to_entity(cun);
534  }
535 
536  if(!string_undefined_p(cun)) free(cun);
537  return success_p;
538 }
string compilation_unit_of_module(const char *)
The output is undefined if the module is referenced but not defined in the workspace,...
Definition: module.c:350
void safe_link(const char *topath, const char *frompath)
Create a hard link to topath.
Definition: file.c:878
void safe_unlink(const char *file_name)
Delete the given file.
Definition: file.c:852
void add_new_compilation_unit(const char *compilation_unit_name, bool is_fortran, entity module)
Warning! Do not modify this file that is automatically generated!
Definition: initializer.c:367
void set_prettyprint_language_tag(enum language_utype lang)
set the prettyprint language from a language_utype argument
Definition: language.c:143
#define pips_user_error
Definition: misc-local.h:147
#define FILE_SEP_STRING
Definition: naming-local.h:41
#define FILE_SEP
Definition: naming-local.h:39
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453
entity local_name_to_top_level_entity(const char *n)
This function try to find a top-level entity from a local name.
Definition: entity.c:1450
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
#define entity_undefined
Definition: ri.h:2761
@ is_language_fortran
Definition: ri.h:1566
@ is_language_c
Definition: ri.h:1567
char * strndup(char const *s, size_t n)
A replacement function, for systems that lack strndup.
Definition: strndup.c:26

References add_new_compilation_unit(), asprintf, compilation_unit_name, compilation_unit_of_module(), db_build_file_resource_name(), db_get_current_workspace_directory(), db_make_subdirectory, DB_PUT_FILE_RESOURCE, entity_local_name(), entity_undefined, entity_undefined_p, f(), file_exists_p(), file_name, FILE_SEP, FILE_SEP_STRING, FindEntity(), free(), full_name, is_language_c, is_language_fortran, local_name_to_top_level_entity(), MakeCompilationUnitEntity(), module_name(), module_name_to_entity(), pips_user_error, print_text(), safe_fclose(), safe_fopen(), safe_link(), safe_unlink(), set_prettyprint_language_tag(), strdup(), string_undefined, string_undefined_p, strndup(), TOP_LEVEL_MODULE_NAME, user_log(), and WORKSPACE_TMP_SPACE.

Referenced by add_new_module(), create_module_with_statement(), missing_file_initializer(), outliner_file(), outliner_independent_recursively(), and simd_memory_packing().

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

◆ c_initializer()

bool c_initializer ( const  string)

A phase that creates a module with its related file resources when there is no C source for it.

Parameters
stringodule_name

Definition at line 853 of file initializer.c.

854 {
855  bool res = false;
856 
857  debug_on("INITIALIZER_DEBUG_LEVEL");
858  res = generic_initializer(module_name, false);
859  debug_off();
860 
861  return res;
862 }
static bool generic_initializer(const char *module_name, bool is_fortran)
There is no real rule to produce source or user files when there is no corresponding file; so the ini...
Definition: initializer.c:783
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160

References debug_off, debug_on, generic_initializer(), and module_name().

+ Here is the call graph for this function:

◆ clone()

bool clone ( const  string)
Parameters
stringame

Referenced by get_private_entities(), and insert_rwt().

+ Here is the caller graph for this function:

◆ clone_on_argument()

bool clone_on_argument ( const  string)

clone.c

Parameters
stringame

◆ clone_only()

bool clone_only ( const  string)
Parameters
stringod_name

◆ clone_substitute()

bool clone_substitute ( const  string)
Parameters
stringame

◆ fortran_initializer()

bool fortran_initializer ( const  string)

Create a module with its related file resources when there is no Fortran source for it.

Parameters
stringodule_name

Definition at line 831 of file initializer.c.

832 {
833  return generic_initializer(module_name, true);
834 }

References generic_initializer(), and module_name().

+ Here is the call graph for this function:

◆ initializer()

bool initializer ( const  string)

A phase that creates a module with its related file resources when there is no Fortran source for it.

Parameters
stringodule_name

Definition at line 839 of file initializer.c.

840 {
841  bool res = false;
842 
843  debug_on("INITIALIZER_DEBUG_LEVEL");
844  res = generic_initializer(module_name, true);
845  debug_off();
846 
847  return res;
848 }

References debug_off, debug_on, generic_initializer(), and module_name().

+ Here is the call graph for this function:

◆ set_internal_missing_module_resolver_handler()

void set_internal_missing_module_resolver_handler ( string(*)(const char *)  _internal_resolver)

Definition at line 612 of file initializer.c.

612  {
613  internal_resolver = _internal_resolver;
614 }
static string(* internal_resolver)(const char *)=0
Definition: initializer.c:611

References internal_resolver.

Referenced by set_python_missing_module_resolver_handler().

+ Here is the caller graph for this function: