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

Go to the source code of this file.

Macros

#define EQUIV_DEBUG   8
 debugging for equivalences More...
 
#define ADD_WORD_LIST_TO_TEXT(t, l)   ADD_WORD_LIST_TO_TEXT_WITH_MARGIN(t, l, 0)
 To deal with declarations above ri-util and pipsdbm and text-util. More...
 
#define ADD_WORD_LIST_TO_TEXT_WITH_MARGIN(t, l, m)
 

Functions

static list f77_f95_style_management (list prev, string str, bool allocatable_pass_p, bool space_p)
 This handle the fact that a Fortran95 declaration use "::" as a separator between type and variable name. More...
 
static text include (const char *file)
 if the common is declared similarly in all routines, generate "include 'COMMON.h'", and the file is put in Src. More...
 
static void equiv_class_debug (list l_equiv)
 
static int equivalent_entity_compare (entity *ent1, entity *ent2)
 static int equivalent_entity_compare(entity *ent1, entity *ent2) input : two pointers on entities. More...
 
static text text_equivalence_class (list l_equiv)
 static text text_equivalence_class(list l_equiv) input : a list of entities representing an equivalence class. More...
 
static text text_equivalences (entity __attribute__((unused)) module, list ldecl, bool no_commons)
 input : the current module, and the list of declarations. More...
 
static sentence sentence_f95use_declaration (entity e)
 Create a sentence for a USE directive. More...
 
static sentence sentence_external (entity f)
 
static sentence sentence_symbolic (entity f, list *ppdl)
 
static sentence sentence_data (entity e)
 why is it assumed that the constant is an int ??? More...
 
static sentence sentence_area (entity e, entity module, bool pp_dimensions, list *ppdl)
 special management of empty commons added. More...
 
static sentence sentence_basic_declaration (entity e)
 
static sentence sentence_data_statement (statement is, list *ppdl)
 Prettyprint the initializations field of code. More...
 
static text text_of_parameters (list lp)
 
static string default_common_hook (entity __attribute__((unused)) module, entity common)
 We add this function to cope with the declaration When the user declare sth. More...
 
void reset_prettyprinter_common_hook (void)
 
static text text_area_included (entity common, entity module)
 
static text text_entity_declaration (entity module, list ldecl, bool force_common, list *ppdl)
 This function compute the list of declaration at the begining of a module. More...
 
text text_declaration (entity module)
 exported for hpfc. More...
 
text text_common_declaration (entity common, entity module)
 needed for hpfc More...
 
text text_initializations (entity m)
 
static text __attribute__ ((unused))
 returns the DATA initializations. More...
 

Variables

static string(* common_hook )(entity, entity)
 

Macro Definition Documentation

◆ ADD_WORD_LIST_TO_TEXT

#define ADD_WORD_LIST_TO_TEXT (   t,
 
)    ADD_WORD_LIST_TO_TEXT_WITH_MARGIN(t, l, 0)

To deal with declarations above ri-util and pipsdbm and text-util.

Definition at line 54 of file declarations2.c.

◆ ADD_WORD_LIST_TO_TEXT_WITH_MARGIN

#define ADD_WORD_LIST_TO_TEXT_WITH_MARGIN (   t,
  l,
 
)
Value:
make_unformatted(NULL, 0, m, l)));
unformatted make_unformatted(string a1, intptr_t a2, intptr_t a3, list a4)
Definition: text.c:149
sentence make_sentence(enum sentence_utype tag, void *val)
Definition: text.c:59
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define ADD_SENTENCE_TO_TEXT(t, p)
@ is_sentence_unformatted
Definition: text.h:58

Definition at line 55 of file declarations2.c.

◆ EQUIV_DEBUG

#define EQUIV_DEBUG   8

debugging for equivalences

Definition at line 48 of file declarations2.c.

Function Documentation

◆ __attribute__()

static text __attribute__ ( (unused)  )
static

returns the DATA initializations.

limited to integers, because I do not know where is the value for other types... of entity

of sentence

Definition at line 1273 of file declarations2.c.

1275 {
1276  list /* of sentence */ ls = NIL;
1277 
1278  FOREACH(ENTITY, e, ldecl)
1279  {
1280  value v = entity_initial(e);
1281  if(!value_undefined_p(v) &&
1283  ls = CONS(SENTENCE, sentence_data(e), ls);
1284  }
1285 
1286  return make_text(ls);
1287 }
text make_text(list a)
Definition: text.c:107
static sentence sentence_data(entity e)
why is it assumed that the constant is an int ???
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
#define value_undefined_p(x)
Definition: ri.h:3017
#define value_constant(x)
Definition: ri.h:3073
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define value_constant_p(x)
Definition: ri.h:3071
#define constant_int_p(x)
Definition: ri.h:848
#define entity_initial(x)
Definition: ri.h:2796
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define SENTENCE(x)
newgen_unformatted_domain_defined
Definition: text.h:36

References CONS, constant_int_p, ENTITY, entity_initial, FOREACH, make_text(), NIL, SENTENCE, sentence_data(), value_constant, value_constant_p, and value_undefined_p.

+ Here is the call graph for this function:

◆ default_common_hook()

static string default_common_hook ( entity __attribute__((unused))  module,
entity  common 
)
static

We add this function to cope with the declaration When the user declare sth.

there's no need to declare sth. for the user. When nothing is declared ( especially there is no way to know whether it's a SUBROUTINE or PROGRAM). We will go over the entire module to find all the variables and declare them properly. Lei ZHOU 18/10/91

the float length is now tested to generate REAL*4 or REAL*8. ??? something better could be done, printing "TYPE*%d". the problem is that you cannot mix REAL*4 and REAL*8 in the same program Fabien Coelho 12/08/93 and 15/09/93

pf4 and pf8 distinction added, FC 26/10/93

Is it really a good idea to print overloaded type variables~? FC 15/09/93 PARAMETERS added. FC 15/09/93

typed PARAMETERs FC 13/05/94 EXTERNALS are missing: added FC 13/05/94

Bug: parameters and their type should be put before other declarations since they may use them. Changed FC 08/06/94

COMMONS are also missing:-) added, FC 19/08/94

updated to fully control the list to be used. hook for commons, when not generated...

Definition at line 773 of file declarations2.c.

775 {
776  return strdup(concatenate
777  ("common to include: ", entity_local_name(common), "\n", NULL));
778 }
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
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
char * strdup()

References concatenate(), entity_local_name(), and strdup().

Referenced by reset_prettyprinter_common_hook().

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

◆ equiv_class_debug()

static void equiv_class_debug ( list  l_equiv)
static

Definition at line 101 of file declarations2.c.

102 {
103  if (ENDP(l_equiv))
104  fprintf(stderr, "<none>");
105  MAP(ENTITY, equiv_ent,
106  {
107  fprintf(stderr, " %s", entity_local_name(equiv_ent));
108  }, l_equiv);
109  fprintf(stderr, "\n");
110 }
#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
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References ENDP, ENTITY, entity_local_name(), fprintf(), and MAP.

Referenced by text_equivalence_class(), and text_equivalences().

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

◆ equivalent_entity_compare()

static int equivalent_entity_compare ( entity ent1,
entity ent2 
)
static

static int equivalent_entity_compare(entity *ent1, entity *ent2) input : two pointers on entities.

output : an integer for qsort. modifies : nothing. comment : this is a comparison function for qsort; the purpose being to order a list of equivalent variables. algorithm: If two variables have the same offset, the longest one comes first; if they have the same length, use a lexicographic ordering. author: bc.

pips_debug(1, "entities: %s %s\n", entity_local_name(*ent1), entity_local_name(*ent2));

pips_debug(1, "same offset\n");

pips_debug(1, "same size\n");

Definition at line 123 of file declarations2.c.

124 {
125  int result;
126  int offset1 = ram_offset(storage_ram(entity_storage(*ent1)));
127  int offset2 = ram_offset(storage_ram(entity_storage(*ent2)));
128  Value size1, size2;
129 
130  result = offset1 - offset2;
131 
132  /* pips_debug(1, "entities: %s %s\n", entity_local_name(*ent1),
133  entity_local_name(*ent2)); */
134 
135  if (result == 0)
136  {
137  /* pips_debug(1, "same offset\n"); */
138  size1 = ValueSizeOfArray(*ent1);
139  size2 = ValueSizeOfArray(*ent2);
140  result = value_compare(size2,size1);
141 
142  if (result == 0)
143  {
144  /* pips_debug(1, "same size\n"); */
145  result = strcmp(entity_local_name(*ent1), entity_local_name(*ent2));
146  }
147  }
148 
149  return(result);
150 }
#define value_compare(v1, v2)
int Value
Value ValueSizeOfArray(entity)
Definition: size.c:206
#define entity_storage(x)
Definition: ri.h:2794
#define storage_ram(x)
Definition: ri.h:2521
#define ram_offset(x)
Definition: ri.h:2251

References entity_local_name(), entity_storage, ram_offset, storage_ram, value_compare, and ValueSizeOfArray().

Referenced by text_equivalence_class().

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

◆ f77_f95_style_management()

static list f77_f95_style_management ( list  prev,
string  str,
bool  allocatable_pass_p,
bool  space_p 
)
static

This handle the fact that a Fortran95 declaration use "::" as a separator between type and variable name.

It also adds an "allocatable" modifier if requested. Finally it add a "," between each variable if there more than one to declare.

Definition at line 67 of file declarations2.c.

70  {
71  list result = prev;
72  if (prev == NIL) {
73  result = CHAIN_SWORD(result, str);
74  if(allocatable_pass_p) {
75  result = CHAIN_SWORD(result, ", ALLOCATABLE ");
76  }
78  result = CHAIN_SWORD(result, ":: ");
79  }
80  }
81  else {
82  result = CHAIN_SWORD(result, space_p? ", " : ",");
83  }
84  return result;
85 }
bool prettyprint_language_is_fortran95_p()
Definition: language.c:83
#define CHAIN_SWORD(l, s)

References CHAIN_SWORD, NIL, and prettyprint_language_is_fortran95_p().

Referenced by text_entity_declaration().

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

◆ include()

static text include ( const char *  file)
static

if the common is declared similarly in all routines, generate "include 'COMMON.h'", and the file is put in Src.

otherwise the full local declarations are generated. That's fun.

Definition at line 92 of file declarations2.c.

93 {
94  return make_text
95  (CONS(SENTENCE,
97  strdup(concatenate(" include '", file, "'\n", NULL))),
98  NIL));
99 }
@ is_sentence_formatted
Definition: text.h:57

References concatenate(), CONS, is_sentence_formatted, make_sentence(), make_text(), NIL, SENTENCE, and strdup().

Referenced by c_code_string(), and text_area_included().

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

◆ reset_prettyprinter_common_hook()

void reset_prettyprinter_common_hook ( void  )

Definition at line 787 of file declarations2.c.

788 {
790 }
static string(* common_hook)(entity, entity)
static string default_common_hook(entity __attribute__((unused)) module, entity common)
We add this function to cope with the declaration When the user declare sth.

References common_hook, and default_common_hook().

Referenced by hpfc_print_code().

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

◆ sentence_area()

static sentence sentence_area ( entity  e,
entity  module,
bool  pp_dimensions,
list ppdl 
)
static

special management of empty commons added.

this may happen in the hpfc generated code.

FI: POINTER declarations should be generated for the heap area

shouldn't get in?

the common is not output if it is empty

Definition at line 549 of file declarations2.c.

550 {
551  const char* area_name = module_local_name(e);
552  type te = entity_type(e);
553  list pc = NIL, entities = NIL;
554  bool space_p = get_bool_property("PRETTYPRINT_LISTS_WITH_SPACES");
555 
556  /* FI: POINTER declarations should be generated for the heap area */
557  if (dynamic_area_p(e) || heap_area_p(e) || stack_area_p(e) || pointer_dummy_targets_area_p(e)) /* shouldn't get in? */
558  return sentence_undefined;
559 
560  assert(type_area_p(te));
561 
562  if (!ENDP(area_layout(type_area(te))))
563  {
564  bool pp_hpfc = get_bool_property("PRETTYPRINT_HPFC");
565 
566  if (pp_hpfc)
568  else
570 
571  /* the common is not output if it is empty
572  */
573  if (!ENDP(entities))
574  {
575  bool comma = false, is_save = static_area_p(e);
576 
577  if (is_save)
578  {
579  pc = CHAIN_SWORD(pc, "SAVE ");
580  }
581  else
582  {
583  pc = CHAIN_SWORD(pc, "COMMON ");
584  if (strcmp(area_name, BLANK_COMMON_LOCAL_NAME) != 0)
585  {
586  pc = CHAIN_SWORD(pc, "/");
587  pc = CHAIN_SWORD(pc, area_name);
588  pc = CHAIN_SWORD(pc, "/ ");
589  }
590  }
591 
592  MAP(ENTITY, ee,
593  {
594  if (comma) pc = CHAIN_SWORD(pc, space_p? ", " : ",");
595  else comma = true;
596  pc = gen_nconc(pc,
597  words_declaration(ee, !is_save && pp_dimensions, ppdl));
598  },
599  entities);
600 
602  }
603  else
604  {
605  pips_user_warning("empty common %s for module %s encountered...\n",
608  strdup(concatenate("!! empty common ", entity_local_name(e),
609  " in module ", entity_local_name(module),
610  "\n", NULL)));
611  }
612  }
613 
616 }
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
list gen_copy_seq(list l)
Copy a list structure.
Definition: list.c:501
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
struct _newgen_struct_entities_ * entities
Definition: hpf_private.h:89
#define pips_user_warning
Definition: misc-local.h:146
#define BLANK_COMMON_LOCAL_NAME
Definition: naming-local.h:68
#define assert(ex)
Definition: newgen_assert.h:41
static char * module
Definition: pips.c:74
list words_declaration(entity e, bool prettyprint_common_variable_dimensions_p, list *ppdl)
some compilers don't like dimensions that are declared twice.
Definition: declarations.c:277
unsigned int get_prettyprint_indentation()
Definition: misc.c:177
bool dynamic_area_p(entity aire)
Definition: area.c:68
bool pointer_dummy_targets_area_p(entity aire)
Definition: area.c:113
bool stack_area_p(entity aire)
Definition: area.c:104
bool heap_area_p(entity aire)
Definition: area.c:86
bool static_area_p(entity aire)
Definition: area.c:77
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
list common_members_of_module(entity common, entity module, bool only_primary)
returns the list of entity to appear in the common declaration.
Definition: entity.c:1741
#define entity_name(x)
Definition: ri.h:2790
#define area_layout(x)
Definition: ri.h:546
#define type_area(x)
Definition: ri.h:2946
#define type_area_p(x)
Definition: ri.h:2944
#define entity_type(x)
Definition: ri.h:2792
#define sentence_undefined
Definition: text.h:42

References area_layout, assert, BLANK_COMMON_LOCAL_NAME, CHAIN_SWORD, common_members_of_module(), concatenate(), dynamic_area_p(), ENDP, ENTITY, entity_local_name(), entity_name, entity_type, gen_copy_seq(), gen_free_list(), gen_nconc(), get_bool_property(), get_prettyprint_indentation(), heap_area_p(), is_sentence_formatted, is_sentence_unformatted, make_sentence(), make_unformatted(), MAP, module, module_local_name(), NIL, pips_user_warning, pointer_dummy_targets_area_p(), sentence_undefined, stack_area_p(), static_area_p(), strdup(), type_area, type_area_p, and words_declaration().

Referenced by text_entity_declaration().

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

◆ sentence_basic_declaration()

static sentence sentence_basic_declaration ( entity  e)
static

Definition at line 618 of file declarations2.c.

619 {
620  list decl = NIL;
621  basic b = entity_basic(e);
622 
623  pips_assert("b is defined", !basic_undefined_p(b));
624 
625  decl = CHAIN_SWORD(decl, basic_to_string(b));
626  decl = CHAIN_SWORD(decl, " ");
627  decl = CHAIN_SWORD(decl, entity_local_name(e));
628 
630  make_unformatted(NULL, 0, get_prettyprint_indentation(), decl)));
631 }
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
string basic_to_string(basic)
Definition: type.c:87
basic entity_basic(entity e)
return the basic associated to entity e if it's a function/variable/constant basic_undefined otherwis...
Definition: entity.c:1380
#define basic_undefined_p(x)
Definition: ri.h:557

References basic_to_string(), basic_undefined_p, CHAIN_SWORD, entity_basic(), entity_local_name(), get_prettyprint_indentation(), is_sentence_unformatted, make_sentence(), make_unformatted(), NIL, and pips_assert.

Referenced by text_entity_declaration(), and text_of_parameters().

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

◆ sentence_data()

static sentence sentence_data ( entity  e)
static

why is it assumed that the constant is an int ???

Definition at line 522 of file declarations2.c.

523 {
524  list pc = NIL;
525  constant c;
526 
528  return(sentence_undefined);
529 
531 
532  if (! constant_int_p(c))
533  return(sentence_undefined);
534 
535  pc = CHAIN_SWORD(pc, "DATA ");
536  pc = CHAIN_SWORD(pc, entity_local_name(e));
537  pc = CHAIN_SWORD(pc, " /");
538  pc = CHAIN_IWORD(pc, constant_int(c));
539  pc = CHAIN_SWORD(pc, "/");
540 
543 }
#define constant_int(x)
Definition: ri.h:850
#define CHAIN_IWORD(l, i)

References CHAIN_IWORD, CHAIN_SWORD, constant_int, constant_int_p, entity_initial, entity_local_name(), get_prettyprint_indentation(), is_sentence_unformatted, make_sentence(), make_unformatted(), NIL, sentence_undefined, value_constant, and value_constant_p.

Referenced by __attribute__().

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

◆ sentence_data_statement()

static sentence sentence_data_statement ( statement  is,
list ppdl 
)
static

Prettyprint the initializations field of code.

Argument List

Reference List

reference list expression, i.e. call to DATA LIST

DATA LIST entity function

Find all initialized variables pending from DATA LIST

Move al to the first value

Print all values

print out the repeat factor if it is not one

Definition at line 635 of file declarations2.c.

636 {
637  unformatted u =
639  (NULL,
641  CONS(STRING, strdup("DATA "), NIL));
643  list wl = unformatted_words(u);
645  call ic = instruction_call(ii);
646  entity ife = entity_undefined;
647  list al = list_undefined; /* Argument List */
648  list rl = list_undefined; /* Reference List */
649  expression rle = expression_undefined; /* reference list expression, i.e. call to DATA LIST */
650  entity rlf = entity_undefined; /* DATA LIST entity function */
651  bool space_p = get_bool_property("PRETTYPRINT_LISTS_WITH_SPACES");
652 
653  pips_assert("An initialization instruction is a call", instruction_call_p(ii));
654  ife = call_function(ic);
655  pips_assert("The static initialization function is called",
657  al = call_arguments(ic);
658 
659  /* Find all initialized variables pending from DATA LIST */
660  rle = EXPRESSION(CAR(al));
661  POP(al); /* Move al to the first value */
662  pips_assert("The first argument is a call", expression_call_p(rle));
664  pips_assert("This is the DATA LIST function", ENTITY_DATA_LIST_P(rlf));
666 
667  for(; !ENDP(rl); POP(rl)){
669  list ivwl = list_undefined;
670 
672  wl = CHAIN_SWORD(wl, strdup(space_p? ", " : ","));
673  }
674 
675  ive = EXPRESSION(CAR(rl));
676  ivwl = words_expression(ive, ppdl);
677  wl = gen_nconc(wl, ivwl);
678  }
679 
680  pips_assert("The value list is not empty", !ENDP(al));
681 
682  /* Print all values */
683 
684  wl = CHAIN_SWORD(wl, " /");
685 
686  for(; !ENDP(al); POP(al)){
687  expression ve = EXPRESSION(CAR(al));
689  list iwl = list_undefined;
690 
691  pips_assert("Values are encoded as calls", expression_call_p(ve));
692 
693  if(strcmp(module_local_name(call_function(vc)), REPEAT_VALUE_NAME)==0) {
696  list rwl = list_undefined;
697 
698  pips_assert("Pseudo-intrinsic REPEAT-VALUE must have two arguments",
699  gen_length(call_arguments(vc))==2);
700 
701  rfe = binary_call_lhs(vc);
702  rve = binary_call_rhs(vc);
703 
704  if(!(integer_constant_expression_p(rfe) && expression_to_int(rfe)==1)) {
705  /* print out the repeat factor if it is not one */
706  rwl = words_expression(rfe, ppdl);
707  wl = gen_nconc(wl, rwl);
708  wl = gen_nconc(wl, CONS(STRING, strdup("*"), NIL));
709  }
710  iwl = words_expression(rve, ppdl);
711  wl = gen_nconc(wl, iwl);
712  }
713  else {
714  iwl = words_expression(ve, ppdl);
715  wl = gen_nconc(wl, iwl);
716  }
717  if(!ENDP(CDR(al))) {
718  wl = gen_nconc(wl, CONS(STRING, strdup(space_p? ", " : ","), NIL));
719  }
720  }
721 
722  wl = CHAIN_SWORD(wl, "/");
723 
724  return s;
725 }
#define STRING(x)
Definition: genC.h:87
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
size_t gen_length(const list l)
Definition: list.c:150
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69
list words_expression(expression obj, list *ppdl)
This one is exported.
Definition: misc.c:2611
#define REPEAT_VALUE_NAME
Definition: ri-util-local.h:77
#define binary_call_rhs(c)
#define STATEMENT_NUMBER_UNDEFINED
default values
#define ENTITY_STATIC_INITIALIZATION_P(e)
Fortran DATA management.
#define binary_call_lhs(c)
#define ENTITY_DATA_LIST_P(e)
bool expression_call_p(expression e)
Definition: expression.c:415
int expression_to_int(expression exp)
================================================================
Definition: expression.c:2205
bool integer_constant_expression_p(expression e)
positive integer constant expression: call to a positive constant or to a sum of positive integer con...
Definition: expression.c:903
#define call_function(x)
Definition: ri.h:709
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define entity_undefined
Definition: ri.h:2761
#define expression_undefined
Definition: ri.h:1223
#define syntax_call(x)
Definition: ri.h:2736
#define instruction_call_p(x)
Definition: ri.h:1527
#define statement_instruction(x)
Definition: ri.h:2458
#define instruction_call(x)
Definition: ri.h:1529
#define call_arguments(x)
Definition: ri.h:711
#define expression_syntax(x)
Definition: ri.h:1247
#define unformatted_words(x)
Definition: text.h:155

References binary_call_lhs, binary_call_rhs, call_arguments, call_function, CAR, CDR, CHAIN_SWORD, CONS, ENDP, ENTITY_DATA_LIST_P, ENTITY_STATIC_INITIALIZATION_P, entity_undefined, EXPRESSION, expression_call_p(), expression_syntax, expression_to_int(), expression_undefined, gen_length(), gen_nconc(), get_bool_property(), get_prettyprint_indentation(), instruction_call, instruction_call_p, integer_constant_expression_p(), is_sentence_unformatted, list_undefined, make_sentence(), make_unformatted(), module_local_name(), NIL, pips_assert, POP, REPEAT_VALUE_NAME, statement_instruction, STATEMENT_NUMBER_UNDEFINED, strdup(), STRING, syntax_call, unformatted_words, and words_expression().

Referenced by text_initializations().

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

◆ sentence_external()

static sentence sentence_external ( entity  f)
static

Definition at line 493 of file declarations2.c.

494 {
495  list pc = NIL;
496 
497  pc = CHAIN_SWORD(pc, "EXTERNAL ");
498  pc = CHAIN_SWORD(pc, entity_local_name(f));
499 
502 }
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15

References CHAIN_SWORD, entity_local_name(), f(), get_prettyprint_indentation(), is_sentence_unformatted, make_sentence(), make_unformatted(), and NIL.

Referenced by text_entity_declaration().

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

◆ sentence_f95use_declaration()

static sentence sentence_f95use_declaration ( entity  e)
static

Create a sentence for a USE directive.

@description Use directive is handled by copying the string directly in the name of the entity during the parsing. So we juste get the local name and put it in a sentence.

Returns
a sentence with correct indentation containing the whole use directive in one word.

Definition at line 482 of file declarations2.c.

482  {
483  list decl = NIL;
484 
485  decl = CHAIN_SWORD(decl, entity_local_name(e));
486 
488  0,
489  INDENTATION,
490  decl)));
491 }
#define INDENTATION

References CHAIN_SWORD, entity_local_name(), INDENTATION, is_sentence_unformatted, make_sentence(), make_unformatted(), and NIL.

Referenced by text_entity_declaration().

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

◆ sentence_symbolic()

static sentence sentence_symbolic ( entity  f,
list ppdl 
)
static

Definition at line 504 of file declarations2.c.

505 {
506  list pc = NIL;
507  value vf = entity_initial(f);
509 
510  pc = CHAIN_SWORD(pc, "PARAMETER (");
511  pc = CHAIN_SWORD(pc, entity_local_name(f));
512  pc = CHAIN_SWORD(pc, " = ");
513  pc = gen_nconc(pc, words_expression(e, ppdl));
514  pc = CHAIN_SWORD(pc, ")");
515 
518 }
#define value_symbolic(x)
Definition: ri.h:3070
#define symbolic_expression(x)
Definition: ri.h:2597

References CHAIN_SWORD, entity_initial, entity_local_name(), f(), gen_nconc(), get_prettyprint_indentation(), is_sentence_unformatted, make_sentence(), make_unformatted(), NIL, symbolic_expression, value_symbolic, and words_expression().

Referenced by text_of_parameters().

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

◆ text_area_included()

static text text_area_included ( entity  common,
entity  module 
)
static

the include was generated once before...

same declaration, generate the file!

touch the nofile to avoid the inclusion check latter on.

Parameters
commonthe common the declaration of which are of interest
modulethe module dealt with

Definition at line 792 of file declarations2.c.

795 {
796  string dir, file, local;
797  const char* name;
798  text t;
799 
801  name = module_local_name(common);
803  name = "blank";
804  local = strdup(concatenate(name, ".h", NULL));
805  file = strdup(concatenate(dir, "/", local, NULL));
806  free(dir);
807 
808  if (file_exists_p(file))
809  {
810  /* the include was generated once before... */
811  t = include(local);
812  }
813  else
814  {
815  string nofile =
816  strdup(concatenate(file, ".sorry_common_not_homogeneous", NULL));
817  t = text_common_declaration(common, module);
818  if (!file_exists_p(nofile))
819  {
820  if (check_common_inclusion(common))
821  {
822  /* same declaration, generate the file! */
823  FILE * f = safe_fopen(file, "w");
824  fprintf(f, "!!\n!! pips: include file for common %s\n!!\n",
825  name);
826  print_text(f, t);
827  safe_fclose(f, file);
828  t = include(local);
829  }
830  else
831  {
832  /* touch the nofile to avoid the inclusion check latter on. */
833  FILE * f = safe_fopen(nofile, "w");
834  fprintf(f,
835  "!!\n!! pips: sorry, cannot include common %s\n!!\n",
836  name);
837  safe_fclose(f, nofile);
838  }
839  free(nofile);
840  }
841  }
842 
843  free(local); free(file);
844  return t;
845 }
text text_common_declaration(entity common, entity module)
needed for hpfc
static text include(const char *file)
if the common is declared similarly in all routines, generate "include 'COMMON.h'",...
Definition: declarations2.c:92
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 *)
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 same_string_p(s1, s2)
#define WORKSPACE_SRC_SPACE
Definition: pipsdbm-local.h:32
bool check_common_inclusion(entity common)
check whether a common declaration can be simply included, that is it is declared with the same names...
Definition: area.c:107
void print_text(FILE *fd, text t)
Definition: print.c:195

References BLANK_COMMON_LOCAL_NAME, check_common_inclusion(), concatenate(), db_get_directory_name_for_module(), f(), file_exists_p(), fprintf(), free(), include(), module, module_local_name(), print_text(), safe_fclose(), safe_fopen(), same_string_p, strdup(), text_common_declaration(), and WORKSPACE_SRC_SPACE.

Referenced by text_entity_declaration().

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

◆ text_common_declaration()

text text_common_declaration ( entity  common,
entity  module 
)

needed for hpfc

Parameters
commonommon
moduleodule

Definition at line 1228 of file declarations2.c.

1231 {
1232  type t = entity_type(common);
1233  list l;
1234  text result;
1235  list pdl = NIL; // Assumed Fortran only
1236  pips_assert("indeed a common", type_area_p(t));
1237  l = CONS(ENTITY, common, common_members_of_module(common, module, false));
1238  result = text_entity_declaration(module, l, true, &pdl);
1239  gen_free_list(l);
1240  gen_free_list(pdl);
1241  return result;
1242 }
static text text_entity_declaration(entity module, list ldecl, bool force_common, list *ppdl)
This function compute the list of declaration at the begining of a module.

References common_members_of_module(), CONS, ENTITY, entity_type, gen_free_list(), module, NIL, pips_assert, text_entity_declaration(), and type_area_p.

Referenced by hpfc_print_common(), and text_area_included().

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

◆ text_declaration()

text text_declaration ( entity  module)

exported for hpfc.

Assume Fortran only!

Parameters
moduleodule

Definition at line 1216 of file declarations2.c.

1217 {
1218  /* Assume Fortran only! */
1219  list pdl = NIL;
1221  (module, code_declarations(entity_code(module)), false, &pdl);
1222  gen_free_list(pdl);
1223  return t;
1224 }
code entity_code(entity e)
Definition: entity.c:1098
#define code_declarations(x)
Definition: ri.h:784

References code_declarations, entity_code(), gen_free_list(), module, NIL, and text_entity_declaration().

Referenced by ensure_comment_consistency(), and init_host_and_node_entities().

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

◆ text_entity_declaration()

static text text_entity_declaration ( entity  module,
list  ldecl,
bool  force_common,
list ppdl 
)
static

This function compute the list of declaration at the begining of a module.

It's intended to be used with Fortran or Fortran95 only

Parameters
ldeclis the list of entity to be prettyprinted
force_commonwill force the prettyprint of common in include

prettyprint common in include if possible...

Declarations cannot be sorted out because Fortran standard impose at least an order on parameters. Fortunately here, PARAMETER are mostly integers, defined from other integer parameters... I assume that PIPS would fail with an ENTRY referencing an integer array dimensionned with a real parameter. But real parameters are not really well processed by PIPS anyway... Also we are in trouble if arrays or functions are used dimension other arrays

list sorted_ldecl = gen_copy_seq(ldecl);

gen_sort_list(sorted_ldecl, compare_entities);

where to put the dimension information.

subroutines won't be declared

not parsed callee

Do not declare variables used to replace formal labels

PARAMETER

EXTERNAL

AREAS: COMMONS and SAVEs

simple integers are moved ahead...

nothing! some in hpfc I guess...

usually they are sorted in order, and appended backwards, hence the reversion.

all about COMMON and SAVE declarations

and EQUIVALENCE statements... - BC

sorted_

what about DATA statements! FC

More general way with with call to text_initializations(module) in text_named_module()

gen_free_list(sorted_ldecl);

We have to do a recursive call to get the allocatable declarations

Parameters
ldeclof entity

Definition at line 856 of file declarations2.c.

860 {
861  /*
862  * allocatable_pass indicate if we want to prettyprint allocatable or non
863  * allocatable entity, this is set to true during a second recursive pass.
864  */
865  static bool allocatable_pass_p = false;
866  list allocatable_list = NULL;
867 
868  const char* how_common = get_string_property("PRETTYPRINT_COMMONS");
869  bool print_commons = !same_string_p(how_common, "none");
870  /* prettyprint common in include if possible... */
871  bool pp_cinc = same_string_p(how_common, "include") && !force_common;
872  list before = NIL, area_decl = NIL, pi1 = NIL, pi2 = NIL, pi4 = NIL, pi8 =
873  NIL, ph1 = NIL, ph2 = NIL, ph4 = NIL, ph8 = NIL, pf4 = NIL, pf8 = NIL,
874  pl = NIL, pc8 = NIL, pc16 = NIL, ps = NIL, lparam = NIL, uses = NIL;
875  list * ppi = NULL;
876  list * pph = NULL;
877  text r, t_chars = make_text(NIL), t_area = make_text(NIL);
878  const char* pp_var_dim = get_string_property("PRETTYPRINT_VARIABLE_DIMENSIONS");
879  bool pp_in_type = false, pp_in_common = false;
880  bool space_p = get_bool_property("PRETTYPRINT_LISTS_WITH_SPACES");
881  /* Declarations cannot be sorted out because Fortran standard impose
882  at least an order on parameters. Fortunately here, PARAMETER are
883  mostly integers, defined from other integer parameters... I assume
884  that PIPS would fail with an ENTRY referencing an integer array
885  dimensionned with a real parameter. But real parameters are not
886  really well processed by PIPS anyway... Also we are in trouble if
887  arrays or functions are used dimension other arrays
888 
889  list sorted_ldecl = gen_copy_seq(ldecl);
890 
891  gen_sort_list(sorted_ldecl, compare_entities); */
892 
894 
895 
896  /*
897  * Deals with indentation
898  */
899  list indentation_words = NIL;
901  for(int i=0; i<INDENTATION; i++) {
902  indentation_words = CHAIN_SWORD(indentation_words, " ");
903  }
904  }
905 
906  /* where to put the dimension information.
907  */
908  if (same_string_p(pp_var_dim, "type")) {
909  pp_in_type = true, pp_in_common = false;
910  } else if (same_string_p(pp_var_dim, "common")) {
911  pp_in_type = false, pp_in_common = true;
912  } else {
913  pips_internal_error("PRETTYPRINT_VARIABLE_DIMENSIONS=\"%s\""
914  " unexpected value\n", pp_var_dim);
915  }
916 
917 
918 
919  FOREACH(ENTITY, e,ldecl) {
920  type te = entity_type(e);
921  bool func = type_functional_p(te) && storage_rom_p(entity_storage(e));
922  value v = entity_initial(e);
923  bool param = func && value_symbolic_p(v);
924  bool external = /* subroutines won't be declared */
925  (func
926  && (value_code_p(v) || value_unknown_p(v) /* not parsed callee */)
931  bool area_p = type_area_p(te);
932  bool var = type_variable_p(te);
933  bool in_ram = storage_ram_p(entity_storage(e));
934  bool in_common = in_ram
936  bool skip_it = same_string_p(entity_local_name(e),
938 
939  pips_debug(3, "entity name is %s\n", entity_name(e));
940 
941  /* Do not declare variables used to replace formal labels */
943  && get_bool_property("PRETTYPRINT_REGENERATE_ALTERNATE_RETURNS")
945  continue;
946 
947  if (!print_commons && area_p && !entity_special_area_p(e) && !pp_cinc) {
948  area_decl = CONS(SENTENCE,
950  common_hook(module, e)),
951  area_decl);
952  }
953 
954  if (skip_it) {
955  pips_debug(5, "skipping function %s\n", entity_name(e));
956  } else if (entity_f95use_p(e)) {
957  uses = CONS(SENTENCE, sentence_f95use_declaration(e), uses);
958  } else if (!print_commons && (area_p || (var && in_common && pp_cinc))) {
959  pips_debug(5, "skipping entity %s\n", entity_name(e));
960  } else if (param) {
961  /* PARAMETER
962  */
963  pips_debug(7, "considered as a parameter\n");
964  lparam = CONS(ENTITY, e, lparam);
965  } else if (external) {
966  /* EXTERNAL
967  */
968  pips_debug(7, "considered as an external\n");
969  before = CONS(SENTENCE, sentence_basic_declaration(e), before);
970  before = CONS(SENTENCE, sentence_external(e), before);
971  } else if (area_p && !dynamic_area_p(e) && !heap_area_p(e)
973  /* AREAS: COMMONS and SAVEs
974  */
975  pips_debug(7, "considered as a regular common\n");
976  if (pp_cinc && !entity_special_area_p(e)) {
978  MERGE_TEXTS(t_area, t);
979  } else
980  area_decl = CONS(SENTENCE,
981  sentence_area(e, module, pp_in_common, ppdl),
982  area_decl);
983  } else if (var && !(in_common && pp_cinc)) {
985  bool pp_dim = pp_in_type || variable_static_p(e);
986 
987  pips_debug(7, "is a variable...\n");
988 
989  switch(basic_tag(b)) {
990  case is_basic_int:
991  /* simple integers are moved ahead... */
992 
993  pips_debug(7, "is an integer\n");
995  string s = string_undefined;
996  switch(basic_int(b)) {
997  case 4:
998  ppi = &pi4;
999  s = "INTEGER ";
1000  break;
1001  case 2:
1002  ppi = &pi2;
1003  s = "INTEGER*2 ";
1004  break;
1005  case 8:
1006  ppi = &pi8;
1007  s = "INTEGER*8 ";
1008  break;
1009  case 1:
1010  ppi = &pi1;
1011  s = "INTEGER*1 ";
1012  break;
1013 
1014  default:
1015  pips_internal_error("Unexpected integer size");
1016  }
1017 
1018  *ppi = f77_f95_style_management (*ppi, s, allocatable_pass_p, space_p);
1019  *ppi = gen_nconc(*ppi, words_declaration(e, pp_dim, ppdl));
1020  } else {
1021  string s = string_undefined;
1022 
1023  switch(basic_int(b)) {
1024  case 4:
1025  pph = &ph4;
1026  s = "INTEGER ";
1027  break;
1028  case 2:
1029  pph = &ph2;
1030  s = "INTEGER*2 ";
1031  break;
1032  case 8:
1033  pph = &ph8;
1034  s = "INTEGER*8 ";
1035  break;
1036  case 1:
1037  pph = &ph1;
1038  s = "INTEGER*1 ";
1039  break;
1040  default:
1041  pips_internal_error("Unexpected integer size");
1042  }
1043  *pph = f77_f95_style_management (*pph, s, allocatable_pass_p, space_p);
1044  *pph = gen_nconc(*pph, words_declaration(e, pp_dim, ppdl));
1045  }
1046  break;
1047  case is_basic_float:
1048  pips_debug(7, "is a float\n");
1049  switch(basic_float(b)) {
1050  case 4:
1051  pf4 = f77_f95_style_management(pf4, "REAL*4 ", allocatable_pass_p, space_p);
1052  pf4 = gen_nconc(pf4, words_declaration(e, pp_dim, ppdl));
1053  break;
1054  case 8:
1055  default:
1056  pf8 = f77_f95_style_management(pf8, "REAL*8 ", allocatable_pass_p, space_p);
1057  pf8 = gen_nconc(pf8, words_declaration(e, pp_dim, ppdl));
1058  break;
1059  }
1060  break;
1061  case is_basic_complex:
1062  pips_debug(7, "is a complex\n");
1063  switch(basic_complex(b)) {
1064  case 8:
1065  pc8 = f77_f95_style_management(pc8, "COMPLEX*8 ", allocatable_pass_p, space_p);
1066  pc8 = gen_nconc(pc8, words_declaration(e, pp_dim, ppdl));
1067  break;
1068  case 16:
1069  default:
1070  pc16 = f77_f95_style_management(pc16, "COMPLEX*16 ", allocatable_pass_p, space_p);
1071  pc16 = gen_nconc(pc16, words_declaration(e, pp_dim, ppdl));
1072  break;
1073  }
1074  break;
1075  case is_basic_logical:
1076  pips_debug(7, "is a logical\n");
1077  pl = CHAIN_SWORD(pl, pl==NIL ? "LOGICAL " : (space_p? ", " : ","));
1078  pl = gen_nconc(pl, words_declaration(e, pp_dim, ppdl));
1079  break;
1080  case is_basic_overloaded:
1081  /* nothing! some in hpfc I guess...
1082  */
1083  break;
1084  case is_basic_string: {
1085  value v = basic_string(b);
1086  pips_debug(7, "is a string\n");
1087 
1089  int i = constant_int(value_constant(v));
1090 
1091  if (i == 1) {
1092  ps = f77_f95_style_management(ps, "CHARACTER ", allocatable_pass_p, space_p);
1093  ps = gen_nconc(ps, words_declaration(e, pp_dim, ppdl));
1094  } else {
1095  list chars = NIL;
1096  chars = CHAIN_SWORD(chars, "CHARACTER*");
1097  chars = CHAIN_IWORD(chars, i);
1098  chars = CHAIN_SWORD(chars, " ");
1099  chars = gen_nconc(chars, words_declaration(e, pp_dim, ppdl));
1100  attach_declaration_size_type_to_words(chars, "CHARACTER", i);
1101  ADD_WORD_LIST_TO_TEXT_WITH_MARGIN(t_chars, chars,
1103  }
1104  } else if (value_unknown_p(v)) {
1105  list chars = NIL;
1106  chars = CHAIN_SWORD(chars, "CHARACTER*(*) ");
1107  chars = gen_nconc(chars, words_declaration(e, pp_dim, ppdl));
1108  attach_declaration_type_to_words(chars, "CHARACTER*(*)");
1109  ADD_WORD_LIST_TO_TEXT_WITH_MARGIN(t_chars, chars,
1111  } else if (value_symbolic_p(v)) {
1112  list chars = NIL;
1113  symbolic s = value_symbolic(v);
1114  chars = CHAIN_SWORD(chars, "CHARACTER*(");
1116  ppdl));
1117  chars = CHAIN_SWORD(chars, ") ");
1118  chars = gen_nconc(chars, words_declaration(e, pp_dim, ppdl));
1119 
1120  attach_declaration_type_to_words(chars, "CHARACTER*(*)");
1121  ADD_WORD_LIST_TO_TEXT(t_chars, chars);
1122  } else
1123  pips_internal_error("unexpected value");
1124  break;
1125  }
1126  case is_basic_derived: {
1127  if(allocatable_pass_p) {
1128  pips_internal_error("We got an allocatable but we are inside"
1129  "allocatable pass !! This should be impossible...\n");
1130  }
1131  // Chains the entity to be declared, aka the array inside allocatable
1132  allocatable_list = CONS(entity,get_allocatable_data_entity(e),allocatable_list);
1133  break;
1134  }
1135  default:
1136  pips_internal_error("unexpected basic tag (%d)",
1137  basic_tag(b));
1138  }
1139  }
1140  }
1141 
1142 
1143  /* usually they are sorted in order, and appended backwards,
1144  * hence the reversion.
1145  */
1146  r = make_text(uses);
1147  MERGE_TEXTS(r, make_text(gen_nreverse(before)));
1148 
1149  MERGE_TEXTS(r, text_of_parameters(lparam));
1150  gen_free_list(lparam), lparam = NIL;
1151 
1153  attach_declaration_type_to_words(ph1, "INTEGER*1");
1155  attach_declaration_type_to_words(ph2, "INTEGER*2");
1157  attach_declaration_type_to_words(ph4, "INTEGER");
1159  attach_declaration_type_to_words(ph8, "INTEGER*8");
1161  attach_declaration_type_to_words(pi1, "INTEGER*1");
1163  attach_declaration_type_to_words(pi2, "INTEGER*2");
1165  attach_declaration_type_to_words(pi4, "INTEGER");
1167  attach_declaration_type_to_words(pi8, "INTEGER*8");
1169  attach_declaration_type_to_words(pf4, "REAL*4");
1171  attach_declaration_type_to_words(pf8, "REAL*8");
1175  attach_declaration_type_to_words(pc8, "COMPLEX*8");
1177  attach_declaration_type_to_words(pc16, "COMPLEX*16");
1179  attach_declaration_type_to_words(ps, "CHARACTER");
1180  MERGE_TEXTS(r, t_chars);
1181 
1182  /* all about COMMON and SAVE declarations
1183  */
1184  MERGE_TEXTS(r, make_text(area_decl));
1185  MERGE_TEXTS(r, t_area);
1186 
1187  /* and EQUIVALENCE statements... - BC
1188  */
1189  MERGE_TEXTS(r, text_equivalences(module, /* sorted_ */ldecl,
1190  pp_cinc || !print_commons));
1191 
1192  /* what about DATA statements! FC
1193  */
1194  /* More general way with with call to text_initializations(module) in
1195  text_named_module() */
1196  /*
1197  if(get_bool_property("PRETTYPRINT_DATA_STATEMENTS")) {
1198  MERGE_TEXTS(r, text_data(module, ldecl));
1199  }
1200  */
1201 
1202  /* gen_free_list(sorted_ldecl); */
1203 
1204  if(!allocatable_pass_p && !ENDP(allocatable_list)) {
1205  /* We have to do a recursive call to get the allocatable declarations */
1206  allocatable_pass_p = true;
1207  MERGE_TEXTS(r,text_entity_declaration(module,allocatable_list,force_common,ppdl));
1208  allocatable_pass_p = false;
1209  }
1210 
1211  return r;
1212 }
void attach_declaration_type_to_words(list l, string declaration_type)
Attach a declaration type to all the words of the given list.
void attach_declaration_size_type_to_words(list l, string declaration_type, int size)
Attach a declaration type with its size to all the words of the given list.
static sentence sentence_f95use_declaration(entity e)
Create a sentence for a USE directive.
static sentence sentence_area(entity e, entity module, bool pp_dimensions, list *ppdl)
special management of empty commons added.
static text text_equivalences(entity __attribute__((unused)) module, list ldecl, bool no_commons)
input : the current module, and the list of declarations.
static list f77_f95_style_management(list prev, string str, bool allocatable_pass_p, bool space_p)
This handle the fact that a Fortran95 declaration use "::" as a separator between type and variable n...
Definition: declarations2.c:67
#define ADD_WORD_LIST_TO_TEXT(t, l)
To deal with declarations above ri-util and pipsdbm and text-util.
Definition: declarations2.c:54
static sentence sentence_external(entity f)
static text text_area_included(entity common, entity module)
#define ADD_WORD_LIST_TO_TEXT_WITH_MARGIN(t, l, m)
Definition: declarations2.c:55
static text text_of_parameters(list lp)
static sentence sentence_basic_declaration(entity e)
char * get_string_property(const char *)
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_internal_error
Definition: misc-local.h:149
#define string_undefined
Definition: newgen_types.h:40
static hash_table pl
properties are stored in this hash table (string -> property) for fast accesses.
Definition: properties.c:783
entity get_allocatable_data_entity(entity e)
Get the entity inside the struct corresponding to the array, mostly for correct prettyprint.
Definition: allocatable.c:157
bool empty_static_area_p(entity e)
Definition: area.c:201
bool entity_special_area_p(entity e)
Definition: area.c:154
void check_fortran_declaration_dependencies(list ldecl)
Regeneration of declarations from the symbol table.
Definition: declarations.c:47
bool entity_f95use_p(entity e)
Definition: entity.c:694
bool formal_label_replacement_p(entity)
Definition: variable.c:1797
bool variable_static_p(entity)
true if v appears in a SAVE statement, or in a DATA statement, or is declared static i C.
Definition: variable.c:1579
#define type_functional_p(x)
Definition: ri.h:2950
@ is_basic_derived
Definition: ri.h:579
@ is_basic_string
Definition: ri.h:576
@ is_basic_float
Definition: ri.h:572
@ is_basic_overloaded
Definition: ri.h:574
@ is_basic_int
Definition: ri.h:571
@ is_basic_logical
Definition: ri.h:573
@ is_basic_complex
Definition: ri.h:575
#define value_code_p(x)
Definition: ri.h:3065
#define functional_result(x)
Definition: ri.h:1444
#define storage_formal_p(x)
Definition: ri.h:2522
#define basic_int(x)
Definition: ri.h:616
#define type_functional(x)
Definition: ri.h:2952
#define value_unknown_p(x)
Definition: ri.h:3077
#define basic_tag(x)
Definition: ri.h:613
#define type_variable(x)
Definition: ri.h:2949
#define storage_ram_p(x)
Definition: ri.h:2519
#define ram_section(x)
Definition: ri.h:2249
#define basic_overloaded_p(x)
Definition: ri.h:623
#define value_symbolic_p(x)
Definition: ri.h:3068
#define type_void_p(x)
Definition: ri.h:2959
#define basic_float(x)
Definition: ri.h:619
#define variable_dimensions(x)
Definition: ri.h:3122
#define basic_complex(x)
Definition: ri.h:628
#define storage_rom_p(x)
Definition: ri.h:2525
#define type_variable_p(x)
Definition: ri.h:2947
#define variable_basic(x)
Definition: ri.h:3120
#define basic_string(x)
Definition: ri.h:631
Definition: replace.c:135
#define MERGE_TEXTS(r, t)

References ADD_WORD_LIST_TO_TEXT, ADD_WORD_LIST_TO_TEXT_WITH_MARGIN, attach_declaration_size_type_to_words(), attach_declaration_type_to_words(), basic_complex, basic_float, basic_int, basic_overloaded_p, basic_string, basic_tag, CHAIN_IWORD, CHAIN_SWORD, check_fortran_declaration_dependencies(), common_hook, CONS, constant_int, constant_int_p, dynamic_area_p(), empty_static_area_p(), ENDP, ENTITY, entity_f95use_p(), entity_initial, entity_local_name(), entity_name, entity_special_area_p(), entity_storage, entity_type, f77_f95_style_management(), FOREACH, formal_label_replacement_p(), functional_result, gen_free_list(), gen_nconc(), gen_nreverse(), get_allocatable_data_entity(), get_bool_property(), get_prettyprint_indentation(), get_string_property(), heap_area_p(), INDENTATION, is_basic_complex, is_basic_derived, is_basic_float, is_basic_int, is_basic_logical, is_basic_overloaded, is_basic_string, is_sentence_formatted, make_sentence(), make_text(), MERGE_TEXTS, module, NIL, pips_debug, pips_internal_error, pl, pointer_dummy_targets_area_p(), prettyprint_language_is_fortran95_p(), ram_section, same_string_p, SENTENCE, sentence_area(), sentence_basic_declaration(), sentence_external(), sentence_f95use_declaration(), stack_area_p(), storage_formal_p, storage_ram, storage_ram_p, storage_rom_p, string_undefined, symbolic_expression, text_area_included(), text_equivalences(), text_of_parameters(), type_area_p, type_functional, type_functional_p, type_variable, type_variable_p, type_void_p, value_code_p, value_constant, value_constant_p, value_symbolic, value_symbolic_p, value_unknown_p, variable_basic, variable_dimensions, variable_static_p(), words_declaration(), and words_expression().

Referenced by text_common_declaration(), and text_declaration().

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

◆ text_equivalence_class()

static text text_equivalence_class ( list  l_equiv)
static

static text text_equivalence_class(list l_equiv) input : a list of entities representing an equivalence class.

output : a text, which is the prettyprint of this class. modifies : sorts l_equiv according to equivalent_entity_compare. comment : partially associated entities are not handled. author : bc.

FIRST, sort the list by increasing offset from the beginning of the memory suite. If two variables have the same offset, the longest one comes first; if they have the same lenght, use a lexicographic ordering

THEN, prettyprint the sorted list

At each step of the next loop, we consider two entities from the equivalence class. l1 points on the first entity list, and l2 on the second one. If l2 is associated with l1, we compute the output string, and l2 becomes the next entity. If l2 is not associated with l1, l1 becomes the next entity, until it is associated with l1. In the l_equiv list, l1 is always before l2.

loop initialization

If the two variables have the same offset, their first elements are equivalenced.

Else, we first check that there is an overlap

If there is no overlap, we change the reference variable

Else, we must compute the coordinates of the element of ent1 which corresponds to the first element of ent2

ATTENTION: Je n'ai pas considere le cas ou il y a association partielle. De ce fait, offset est divisiable par size_elt_1.

while

if-else: there is an overlap

if-else: not same offset

while

Parameters
l_equivof entities

Definition at line 159 of file declarations2.c.

160 {
161  text t_equiv = make_text(NIL);
162  list lw = NIL;
163  list l1, l2;
164  entity ent1, ent2;
165  int offset1, offset2;
166  Value size1, offset_end1;
167  bool first;
168  bool space_p = get_bool_property("PRETTYPRINT_LISTS_WITH_SPACES");
169 
170  if (gen_length(l_equiv)<=1) return t_equiv;
171 
172  /* FIRST, sort the list by increasing offset from the beginning of
173  the memory suite. If two variables have the same offset, the longest
174  one comes first; if they have the same lenght, use a lexicographic
175  ordering */
177  {
178  pips_debug(1, "equivalence class before sorting:\n");
179  equiv_class_debug(l_equiv);
180  }
181 
182  gen_sort_list(l_equiv,
183  (int (*)(const void *,const void *)) equivalent_entity_compare);
184 
186  {
187  pips_debug(1, "equivalence class after sorting:\n");
188  equiv_class_debug(l_equiv);
189  }
190 
191  /* THEN, prettyprint the sorted list*/
192  pips_debug(EQUIV_DEBUG,"prettyprint of the sorted list\n");
193 
194  /* At each step of the next loop, we consider two entities
195  * from the equivalence class. l1 points on the first entity list,
196  * and l2 on the second one. If l2 is associated with l1, we compute
197  * the output string, and l2 becomes the next entity. If l2 is not
198  * associated with l1, l1 becomes the next entity, until it is
199  * associated with l1. In the l_equiv list, l1 is always before l2.
200  */
201 
202  /* loop initialization */
203  l1 = l_equiv;
204  ent1 = ENTITY(CAR(l1));
205  offset1 = ram_offset(storage_ram(entity_storage(ent1)));
206  size1 = ValueSizeOfArray(ent1);
207  l2 = CDR(l_equiv);
208  first = true;
209 
210  while(!ENDP(l2))
211  {
212  ent2 = ENTITY(CAR(l2));
213  offset2 = ram_offset(storage_ram(entity_storage(ent2)));
214 
215  pips_debug(EQUIV_DEBUG, "dealing with: %s %s\n",
216  entity_local_name(ent1),
217  entity_local_name(ent2));
218 
219  /* If the two variables have the same offset, their
220  * first elements are equivalenced.
221  */
222  if (offset1 == offset2)
223  {
224  pips_debug(EQUIV_DEBUG, "easiest case: offsets are the same\n");
225 
226  if (first) lw = CHAIN_SWORD(lw, "EQUIVALENCE"), first = false;
227  else lw = CHAIN_SWORD(lw, space_p? ", " : ",");
228 
229  lw = CHAIN_SWORD(lw, " (");
230  lw = CHAIN_SWORD(lw, entity_local_name(ent1));
231  lw = CHAIN_SWORD(lw, space_p? ", " : ",");
232  lw = CHAIN_SWORD(lw, entity_local_name(ent2));
233  lw = CHAIN_SWORD(lw, ")");
234  POP(l2);
235  }
236  /* Else, we first check that there is an overlap */
237  else
238  {
239  pips_assert("the equivalence class has been sorted\n",
240  offset1 < offset2);
241 
242  offset_end1 = value_plus(offset1, size1);
243 
244  /* If there is no overlap, we change the reference variable */
245  if (value_le(offset_end1,offset2))
246  {
247  pips_debug(1, "second case: there is no overlap\n");
248  POP(l1);
249  ent1 = ENTITY(CAR(l1));
250  offset1 = ram_offset(storage_ram(entity_storage(ent1)));
251  size1 = ValueSizeOfArray(ent1);
252  if (l1 == l2) POP(l2);
253  }
254 
255  /* Else, we must compute the coordinates of the element of ent1
256  * which corresponds to the first element of ent2
257  */
258  else
259  {
260  /* ATTENTION: Je n'ai pas considere le cas
261  * ou il y a association partielle. De ce fait, offset
262  * est divisiable par size_elt_1. */
263  int offset = offset2 - offset1;
264  int rest;
265  int current_dim;
266  int dim_max = NumberOfDimension(ent1);
269  list l_tmp = variable_dimensions
270  (type_variable(entity_type(ent1)));
271  normalized nlo;
272  Pvecteur pvlo;
273 
274  pips_debug(EQUIV_DEBUG, "third case\n");
276  "offset=%d, dim_max=%d, size_elt_1=%d\n",
277  offset, dim_max,size_elt_1);
278 
279  if (first) lw = CHAIN_SWORD(lw, "EQUIVALENCE"), first = false;
280  else lw = CHAIN_SWORD(lw, space_p? ", " : ",");
281 
282  lw = CHAIN_SWORD(lw, " (");
283  lw = CHAIN_SWORD(lw, entity_local_name(ent1));
284  lw = CHAIN_SWORD(lw, "(");
285 
286  pips_assert("partial association case not implemented:\n"
287  "offset % size_elt_1 == 0",
288  (offset % size_elt_1) == 0);
289 
291  current_dim = 1;
292 
293  while (current_dim <= dim_max)
294  {
295  dimension dim = DIMENSION(CAR(l_tmp));
296  int new_decl;
297  int size;
298 
299  pips_debug(EQUIV_DEBUG, "prettyprinting dimension %d\n",
300  current_dim);
301  size = SizeOfIthDimension(ent1, current_dim);
302  rest = (offset % size);
303  offset = offset / size;
305  pvlo = normalized_linear(nlo);
306 
307  pips_assert("sg", vect_constant_p(pvlo));
309  "size=%d, rest=%d, offset=%d, lower_bound=%d\n",
310  size, rest, offset, (int)VALUE_TO_INT(val_of(pvlo)));
311 
312  new_decl = VALUE_TO_INT(val_of(pvlo)) + rest;
313  lw = CHAIN_SWORD(lw,int2a(new_decl));
314  if (current_dim < dim_max)
315  lw = CHAIN_SWORD(lw, space_p? ", " : ",");
316 
317  POP(l_tmp);
318  current_dim++;
319 
320  } /* while */
321 
322  lw = CHAIN_SWORD(lw, ")");
323  lw = CHAIN_SWORD(lw, space_p? ", " : ",");
324  lw = CHAIN_SWORD(lw, entity_local_name(ent2));
325  lw = CHAIN_SWORD(lw, ")");
326  POP(l2);
327  } /* if-else: there is an overlap */
328  } /* if-else: not same offset */
329  } /* while */
330  ADD_WORD_LIST_TO_TEXT(t_equiv, lw);
331 
332  pips_debug(EQUIV_DEBUG, "end\n");
333  return t_equiv;
334 }
#define VALUE_TO_INT(val)
#define value_le(v1, v2)
#define value_plus(v1, v2)
binary operators on values
bool vect_constant_p(Pvecteur)
bool vect_constant_p(Pvecteur v): v contains only a constant term, may be zero
Definition: predicats.c:211
static int equivalent_entity_compare(entity *ent1, entity *ent2)
static int equivalent_entity_compare(entity *ent1, entity *ent2) input : two pointers on entities.
static void equiv_class_debug(list l_equiv)
#define EQUIV_DEBUG
debugging for equivalences
Definition: declarations2.c:48
static Value size_elt_1
Definition: translation.c:285
static Value offset
Definition: translation.c:283
void gen_sort_list(list l, gen_cmp_func_t compare)
Sorts a list of gen_chunks in place, to avoid allocations...
Definition: list.c:796
#define NORMALIZE_EXPRESSION(e)
int SizeOfIthDimension(entity, int)
this function returns the size of the ith dimension of a variable e.
Definition: size.c:453
_int SizeOfElements(basic)
This function returns the length in bytes of the Fortran or C type represented by a basic,...
Definition: size.c:297
int NumberOfDimension(entity)
Definition: size.c:588
#define dimension_lower(x)
Definition: ri.h:980
#define normalized_linear(x)
Definition: ri.h:1781
#define ifdebug(n)
Definition: sg.c:47
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
char * int2a(int)
util.c
Definition: util.c:42
#define val_of(varval)

References ADD_WORD_LIST_TO_TEXT, CAR, CDR, CHAIN_SWORD, DIMENSION, dimension_lower, ENDP, ENTITY, entity_local_name(), entity_storage, entity_type, equiv_class_debug(), EQUIV_DEBUG, equivalent_entity_compare(), gen_length(), gen_sort_list(), get_bool_property(), ifdebug, int2a(), make_text(), NIL, NORMALIZE_EXPRESSION, normalized_linear, NumberOfDimension(), offset, pips_assert, pips_debug, POP, ram_offset, size_elt_1, SizeOfElements(), SizeOfIthDimension(), storage_ram, type_variable, val_of, value_le, value_plus, VALUE_TO_INT, ValueSizeOfArray(), variable_basic, variable_dimensions, and vect_constant_p().

Referenced by text_equivalences().

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

◆ text_equivalences()

static text text_equivalences ( entity __attribute__((unused))  module,
list  ldecl,
bool  no_commons 
)
static

input : the current module, and the list of declarations.

output : a text for all the equivalences. modifies : nothing comment :

FIRST BUILD EQUIVALENCE CLASSES

consider each entity in the declaration

but only variables which have a ram storage must be considered

If this variable is statically aliased

We first look in already found equivalence classes if there is already a class in which one of the aliased variables appears

add the entities of shared which are not already in the existing equivalence class. Useful ??

!!!

add the list of variables in l_shared; necessary because variables may appear several times in l_shared.

!!! restricted to declared...

SECOND, PRETTYPRINT THEM

AND FREE THEM

THE END

Parameters
modulethe module dealt with
ldeclthe list of declarations to consider
no_commonswhether to print common equivivalences

Definition at line 342 of file declarations2.c.

346 {
347  list equiv_classes = NIL, l_tmp;
348  text t_equiv_class;
349 
350  pips_debug(1,"begin\n");
351 
352  /* FIRST BUILD EQUIVALENCE CLASSES */
353 
354  pips_debug(EQUIV_DEBUG, "loop on declarations\n");
355  /* consider each entity in the declaration */
356  MAP(ENTITY, e,
357  {
358  storage s = entity_storage(e);
359  /* but only variables which have a ram storage must be considered
360  */
362  {
363  ram r = storage_ram(s);
364  entity common = ram_section(r);
365  list l_shared = ram_shared(r);
366 
367  if (no_commons && !entity_special_area_p(common))
368  break;
369 
371  {
372  pips_debug(1, "considering entity: %s\n",entity_local_name(e));
373  pips_debug(1, "shared variables:\n");
374  equiv_class_debug(l_shared);
375  }
376 
377  /* If this variable is statically aliased */
378  if (!ENDP(l_shared))
379  {
380  bool found = false;
381  list found_equiv_class = NIL;
382 
383  /* We first look in already found equivalence classes
384  * if there is already a class in which one of the
385  * aliased variables appears
386  */
387  MAP(LIST, equiv_class,
388  {
390  {
391  pips_debug(1, "considering equivalence class:\n");
392  equiv_class_debug(equiv_class);
393  }
394 
395  MAP(ENTITY, ent,
396  {
397  if (variable_in_list_p(ent, equiv_class))
398  {
399  found = true;
400  found_equiv_class = equiv_class;
401  break;
402  }
403  }, l_shared);
404 
405  if (found) break;
406  },
407  equiv_classes);
408 
409  if (found)
410  {
411  pips_debug(EQUIV_DEBUG, "already there\n");
412  /* add the entities of shared which are not already in
413  * the existing equivalence class. Useful ??
414  */
415  MAP(ENTITY, ent,
416  {
417  if(!variable_in_list_p(ent, found_equiv_class) &&
418  variable_in_list_p(ent, ldecl)) /* !!! */
419  found_equiv_class =
420  CONS(ENTITY, ent, found_equiv_class);
421  }, l_shared)
422  }
423  else
424  {
425  list l_tmp = NIL;
426  pips_debug(EQUIV_DEBUG, "not found\n");
427  /* add the list of variables in l_shared; necessary
428  * because variables may appear several times in
429  * l_shared. */
430  MAP(ENTITY, shared_ent,
431  {
432  if (!variable_in_list_p(shared_ent, l_tmp) &&
433  variable_in_list_p(shared_ent, ldecl))
434  /* !!! restricted to declared... */
435  l_tmp = CONS(ENTITY, shared_ent, l_tmp);
436  },
437  l_shared);
438  equiv_classes = CONS(LIST, l_tmp, equiv_classes);
439  }
440  }
441  }
442  },
443  ldecl);
444 
446  {
447  pips_debug(1, "final equivalence classes:\n");
448  MAP(LIST, equiv_class, equiv_class_debug(equiv_class), equiv_classes);
449  }
450 
451  /* SECOND, PRETTYPRINT THEM */
452  t_equiv_class = make_text(NIL);
453  MAP(LIST, equiv_class,
454  {
455  MERGE_TEXTS(t_equiv_class, text_equivalence_class(equiv_class));
456  }, equiv_classes);
457 
458  /* AND FREE THEM */
459  for(l_tmp = equiv_classes; !ENDP(l_tmp); POP(l_tmp))
460  {
461  list equiv_class = LIST(CAR(l_tmp));
462  gen_free_list(equiv_class);
463  LIST(CAR(l_tmp)) = NIL;
464  }
465  gen_free_list(equiv_classes);
466 
467  /* THE END */
468  pips_debug(EQUIV_DEBUG, "end\n");
469  return(t_equiv_class);
470 }
static text text_equivalence_class(list l_equiv)
static text text_equivalence_class(list l_equiv) input : a list of entities representing an equivale...
#define LIST(x)
Definition: genC.h:93
bool variable_in_list_p(entity, list)
Definition: variable.c:1623
#define ram_shared(x)
Definition: ri.h:2253

References CAR, CONS, ENDP, ENTITY, entity_local_name(), entity_special_area_p(), entity_storage, entity_type, equiv_class_debug(), EQUIV_DEBUG, gen_free_list(), ifdebug, LIST, make_text(), MAP, MERGE_TEXTS, NIL, pips_debug, POP, ram_section, ram_shared, storage_ram, storage_ram_p, text_equivalence_class(), type_variable_p, and variable_in_list_p().

Referenced by text_entity_declaration().

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

◆ text_initializations()

text text_initializations ( entity  m)

The previous declaration list is useless in Fortran, but the signature of functions designed for C or Fortran must be respected.

Definition at line 1244 of file declarations2.c.

1245 {
1246  text t = make_text(NIL);
1247  list il = list_undefined;
1248 
1249  pips_assert("m is a module", entity_module_p(m));
1250 
1252 
1253  FOREACH(STATEMENT, is, il) {
1254  /* The previous declaration list is useless in Fortran, but the
1255  signature of functions designed for C or Fortran must be
1256  respected. */
1257  list pdl = NIL;
1260  strdup(statement_comments(is))));
1261  }
1263  gen_free_list(pdl);
1264  }
1265 
1266  return t;
1267 }
static sentence sentence_data_statement(statement is, list *ppdl)
Prettyprint the initializations field of code.
bool empty_comments_p(const char *)
Definition: statement.c:107
bool entity_module_p(entity e)
Definition: entity.c:683
#define code_initializations(x)
Definition: ri.h:788
#define sequence_statements(x)
Definition: ri.h:2360
#define value_code(x)
Definition: ri.h:3067
#define statement_comments(x)
Definition: ri.h:2456
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413

References ADD_SENTENCE_TO_TEXT, code_initializations, empty_comments_p(), entity_initial, entity_module_p(), FOREACH, gen_free_list(), is_sentence_formatted, list_undefined, make_sentence(), make_text(), NIL, pips_assert, sentence_data_statement(), sequence_statements, STATEMENT, statement_comments, strdup(), and value_code.

Referenced by ensure_comment_consistency().

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

◆ text_of_parameters()

static text text_of_parameters ( list  lp)
static

of sentence

generate the sentences

Parameters
lpof entity that are parameters

Definition at line 729 of file declarations2.c.

730 {
731  list /* of sentence */ ls = NIL;
732 
733  /* generate the sentences
734  */
735  FOREACH(ENTITY, e, lp) {
736  list pdl = NIL; // Assumed to be Fortran only
738  CONS(SENTENCE, sentence_symbolic(e, &pdl), ls));
739  }
740 
741  return make_text(ls);
742 }
static sentence sentence_symbolic(entity f, list *ppdl)

References CONS, ENTITY, FOREACH, make_text(), NIL, SENTENCE, sentence_basic_declaration(), and sentence_symbolic().

Referenced by text_entity_declaration().

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

Variable Documentation

◆ common_hook

string(* common_hook) (entity, entity) ( entity  ,
entity   
)
staticdefault

Definition at line 780 of file declarations2.c.

783 {
784  common_hook=f;
785 }

Referenced by reset_prettyprinter_common_hook(), and text_entity_declaration().