PIPS
xml_prettyprinter.c
Go to the documentation of this file.
1 /*
2 
3  $Id: xml_prettyprinter.c 23491 2018-10-23 06:20:51Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 
25 
26 #ifdef HAVE_CONFIG_H
27 #include "pips_config.h"
28 #endif
29 
30 #define DEBUG_XML 1
31 
32 #include <stdio.h>
33 #include <ctype.h>
34 
35 #include "genC.h"
36 #include "linear.h"
37 
38 #include "pipsdbm.h"
39 #include "misc.h"
40 
41 #include "properties.h"
42 #include "text.h"
43 
44 #include "effects.h"
45 #include "ri.h"
46 #include "ri-util.h"
47 #include "text-util.h"
48 #include "control.h" // load_ctrl_graph
49 #include "effects-util.h"
50 
51 #include "transformer.h"
52 #include "prettyprint.h" // for print_statement, words_expression...
53 #include "dg.h"
56 #include "graph.h"
57 #include "rice.h"
58 #include "ricedg.h"
59 
60 #include "effects-convex.h" // used
61 #include "effects-generic.h" // used
62 #include "effects-simple.h" // used
63 #include "complexity_ri.h" // for next include
64 #include "complexity.h" // used
65 #include "semantics.h" // used
66 #include "modeling.h"
67 
68 #define COMMA ","
69 #define EMPTY ""
70 #define NL "\n"
71 #define TAB " "
72 #define SEMICOLON ";" NL
73 #define SPACE " "
74 
75 #define OPENBRACKET "["
76 #define CLOSEBRACKET "]"
77 
78 #define OPENPAREN "("
79 #define CLOSEPAREN ")"
80 
81 #define OPENBRACE "{"
82 #define CLOSEBRACE "}"
83 
84 #define OPENANGLE "<"
85 #define CLOSEANGLE ">"
86 #define SLASH "/"
87 
88 #define SHARPDEF "#define"
89 #define COMMENT "//" SPACE
90 #define QUOTE "\""
91 
92 
93 #define XML_TASK_PREFIX "T_"
94 #define XML_MOTIF_PREFIX "M_"
95 #define XML_ARRAY_PREFIX "A_"
96 
97 #define XML_RL NL,TAB,TAB
98 
99 #define code_is_a_box 0
100 #define code_is_a_te 1
101 #define code_is_a_main 2
102 #define USER_MAIN "main"
103 
104 /* array containing extern loop indices names */
106 /* array containing intern loop indices (name : "M_") */
108 /* array containing extern upperbounds */
110 /* array containing intern upperbounds */
112 /* array containing the tasks names*/
114 
115 static const char* global_module_name;
116 #define BL " "
117 #define TB1 "\t"
118 
119 // entity [var] -> Pcallst
121 
122 static const char* global_module_name;
123 static int global_margin =0;
124 
125 static bool fortran_appli = true;
126 static bool box_in_statement_p = false;
127 static bool motif_in_statement_p = false;
128 static bool statement_in_truebranch_p = false;
133 #define MEM_PREFIX "-MEM:"
134 static string array_location_string;
135 static string array_mem_string;
138 
139 /******************************************************** DEF TO TASK MAPPING */
140 
141 // entity [var] -> entity [func]
142 // static hash_table hash_entity_def_to_task = hash_table_undefined;
143 
144 // global
146 
147 static void def_to_task_init(void)
148 {
149  pips_assert("def_to_task_mapping is undefined",
152 }
153 
154 static void def_to_task_set(entity_to_entity mapping)
155 {
156  pips_assert("def_to_task_mapping is undefined",
158  def_to_task_mapping = mapping;
159 }
160 
161 static void def_to_task_reset(void)
162 {
163  pips_assert("def_to_task_mapping is defined",
166 }
167 
168 static void def_to_task_store(entity var, entity fun)
169 {
172  else
174 }
175 
177 {
180 }
181 
182 /**************************************************************** MISC UTILS */
183 
184 #define current_module_is_a_function() \
185  (entity_function_p(get_current_module_entity()))
186 
187 static bool variable_p(entity e)
188 {
189  storage s = entity_storage(e);
190  return type_variable_p(entity_type(e)) &&
191  (storage_ram_p(s) || storage_return_p(s));
192 }
193 
194 
195 #define RESULT_NAME "result"
196 static string xml_entity_local_name(entity var)
197 {
198  const char* name;
199 
201  var != get_current_module_entity() &&
204  name = RESULT_NAME;
205  else
206  {
207  name = entity_local_name(var);
208 
209  /* Delete all the prefixes */
210 
211  if (strstr(name,STRUCT_PREFIX) != NULL)
212  name = strstr(name,STRUCT_PREFIX) + 1;
213  if (strstr(name,UNION_PREFIX) != NULL)
214  name = strstr(name,UNION_PREFIX) + 1;
215  if (strstr(name,ENUM_PREFIX) != NULL)
216  name = strstr(name,ENUM_PREFIX) + 1;
217  if (strstr(name,TYPEDEF_PREFIX) != NULL)
218  name = strstr(name,TYPEDEF_PREFIX) + 1;
219  if (strstr(name,MEMBER_SEP_STRING) != NULL)
220  name = strstr(name,MEMBER_SEP_STRING) + 1;
221  }
222 
223  /* switch to upper cases... */
224  char *rname=strupper(strdup(name),name);
225  return rname;
226 }
227 
228 
229 /************************************************************** DECLARATIONS */
230 
231 /*
232  integer a(n,m) -> int a[m][n];
233  parameter (n=4) -> #define n 4
234 */
235 
236 
237 
238 /* forward declaration */
239 static string xml_expression(expression);
240 
241 /* Attention with Fortran: the indices are reversed. */
243 {
244  string result = strdup(EMPTY), old, svar;
245  MAP(EXPRESSION, e,
246  {
247  string s = strdup(xml_expression(e));
248  old = result;
249  result = strdup(concatenate(old, OPENBRACKET, s, CLOSEBRACKET, NULL));
250  free(old);
251  free(s);
252  }, reference_indices(r));
253 
254  old = result;
256  result = strdup(concatenate(svar, old, NULL));
257  free(old);
258  free(svar);
259  return result;
260 }
261 
262 static string xml_expression(expression e)
263 {
264  string result = string_undefined;
265  syntax s = expression_syntax(e);
266 
267  switch (syntax_tag(s))
268  {
269  case is_syntax_reference:
271  break;
272  case is_syntax_call: {
273  value ev = EvalExpression(e);
274  constant ec = value_constant(ev);
275  int eiv = 0;
276 
277  if(!value_constant_p(ev)) {
278  pips_user_error("Constant expected for XML loop bounds.\n");
279  }
280  if(!constant_int_p(ec)) {
281  pips_user_error("Integer constant expected for XML loop bounds.\n");
282  }
283  eiv = constant_int(ec);
284  result = strdup(i2a(eiv));
285  break;
286  }
287  default:
288  pips_internal_error("unexpected syntax tag");
289  }
290  return result;
291 }
292 
295 
296 #define ITEM_NOT_IN_ARRAY -1
297 
298 static int gen_array_index(gen_array_t ar, string item){
299  int i;
300 
301  for(i = 0; i<(int) gen_array_nitems(ar); i++){
302  if(gen_array_item(ar, i) != NULL){
303  if(same_string_p(item, *((string *)(gen_array_item(ar, i))))){
304  return i;
305  }
306  }
307  }
308  return ITEM_NOT_IN_ARRAY;
309 }
310 
311 static string xml_dim_string(list ldim, string name)
312 {
313  string result = "";
314  int nbdim = 0;
315  string origins = "origins = list<integer>(";
316  string dimensions = "dimSizes = list<integer>(";
317  string deuxpoints = " :: ";
318  string data_array = "DATA_ARRAY(";
319  string data_decl = "name = symbol!(";
320  string dimstring = "dim = ";
321  string datatype = "dataType = INTEGER)";
322  string name4p = name;
323  string * namep = malloc(sizeof(string));
324  int * nbdimptr = malloc(sizeof(int));
325  *namep = name4p;
326  if (ldim)
327  {
328  result = strdup(concatenate(name, deuxpoints, data_array, data_decl, QUOTE, name, QUOTE, CLOSEPAREN, COMMA, NL, NULL));
329  result = strdup(concatenate(result, TAB, dimstring, NULL));
330  MAP(DIMENSION, dim, {
331  expression elow = dimension_lower(dim);
332  expression eup = dimension_upper(dim);
333 
334  intptr_t low;
335  intptr_t up;
336  nbdim++;
337  if (expression_integer_value(elow, &low)){
338  if(nbdim != 1)
339  origins = strdup(concatenate(origins, COMMA ,int2a(low), NULL));
340  else
341  origins = strdup(concatenate(origins, int2a(low), NULL));
342  }
343  else pips_user_error("Array origins must be integer\n");
344 
345  if (expression_integer_value(eup, &up)){
346  if(nbdim != 1)
347  dimensions = strdup(concatenate(dimensions, COMMA ,int2a(up-low+1), NULL));
348  else
349  dimensions = strdup(concatenate(dimensions, int2a(up-low+1), NULL));
350  }
351  else pips_user_error("Array dimensions must be integer\n");
352  }, ldim);
353  *nbdimptr = nbdim;
354  gen_array_append(array_dims, nbdimptr);
356  result = strdup(concatenate(result, int2a(nbdim), COMMA, NL, NULL));
357  result = strdup(concatenate(result, TAB, origins, CLOSEPAREN, COMMA, NL, NULL));
358  result = strdup(concatenate(result, TAB, dimensions, CLOSEPAREN, COMMA, NL, NULL));
359  result = strdup(concatenate(result, TAB, datatype, NL, NL, NULL));
360  }
361  return result;
362 }
363 
365 {
366  string result = strdup("");
367  string name = strdup(concatenate("A_", entity_local_name(var), NULL));
368  type t = entity_type(var);
369  pips_debug(2,"Entity name : %s\n",entity_name(var));
370  /* Many possible combinations */
371 
372  if (strstr(name,TYPEDEF_PREFIX) != NULL)
373  pips_user_error("Structs not supported\n");
374 
375  switch (type_tag(t)) {
376  case is_type_variable:
377  {
378  variable v = type_variable(t);
379  string sd;
380  sd = strdup(xml_dim_string(variable_dimensions(v), name));
381  result = strdup(concatenate(result, sd, NULL));
382  break;
383  }
384  case is_type_struct:
385  {
386  pips_user_error("Struct not allowed\n");
387  break;
388  }
389  case is_type_union:
390  {
391  pips_user_error("Union not allowed\n");
392  break;
393  }
394  case is_type_enum:
395  {
396  pips_user_error("Enum not allowed\n");
397  break;
398  }
399  default:
400  pips_user_error("Something not allowed here\n");
401  }
402 
403  return result;
404 }
405 
406 static string
408  bool (*consider_this_entity)(entity),
409  string separator,
410  bool lastsep)
411 {
412  string result = strdup("");
413  code c;
414  bool first = true;
415 
416  pips_assert("it is a code", value_code_p(entity_initial(module)));
417 
419  MAP(ENTITY, var,
420  {
421  debug(2, "\n Prettyprinter declaration for variable :",xml_entity_local_name(var));
422  if (consider_this_entity(var))
423  {
424  string old = strdup(result);
425  string svar = strdup(this_entity_xmldeclaration(var));
426  result = strdup(concatenate(old, !first && !lastsep? separator: "",
427  svar, lastsep? separator: "", NULL));
428  free(old);
429  free(svar);
430  first = false;
431  }
432  },code_declarations(c));
433  return result;
434 }
435 
436 static string xml_array_in_task(reference r, bool first, int task_number);
437 
438 static string xml_call_from_assignation(call c, int task_number, bool * input_provided){
439  /* All arguments of this call are in Rmode (inputs of the task) */
440  /* This function is called recursively */
442  syntax syn;
443  string result = "";
444 
445  MAP(EXPRESSION, expr, {
446  syn = expression_syntax(expr);
447  switch(syntax_tag(syn)){
448  case is_syntax_call:{
449  result = strdup(concatenate(result, xml_call_from_assignation(syntax_call(syn), task_number, input_provided), NULL));
450  break;
451  }
452  case is_syntax_reference:{
455  string varname = strdup(concatenate("A_", svar, NULL));
456  free(svar);
458  result = strdup(concatenate(result, xml_array_in_task(ref, false, task_number), NULL));
459  *input_provided = true;
460  }
461  break;
462  }
463  default:{
464  pips_user_error("only call and references allowed here\n");
465  }
466  }
467  }, arguments);
468  return result;
469 }
470 
471 static void xml_call_from_indice(call c, string * offset_array, string paving_array[], string fitting_array[]){
472  entity called = call_function(c);
473  string funname = xml_entity_local_name(called);
475  syntax args[2];
476  int i = 0;
477  int iterator_nr;
478  if(gen_length(arguments)==2){
479  if(same_string_p(funname, "+") || same_string_p(funname, "-") || same_string_p(funname, "*")){
480  MAP(EXPRESSION, arg, {
481  args[i] = expression_syntax(arg);
482  i++;
483  }, arguments);
484  if(same_string_p(funname, "+")){
485  if(syntax_tag(args[0]) == is_syntax_call){
486  xml_call_from_indice(syntax_call(args[0]), offset_array, paving_array, fitting_array);
487  }
488  if(syntax_tag(args[1]) == is_syntax_call){
489  xml_call_from_indice(syntax_call(args[1]), offset_array, paving_array, fitting_array);
490  }
491  if(syntax_tag(args[0]) == is_syntax_reference){
492  reference ref = syntax_reference(args[0]);
494  paving_array[iterator_nr] = strdup("1");
495  }
497  fitting_array[iterator_nr] = strdup("1");
498  }
499  }
500  if(syntax_tag(args[1]) == is_syntax_reference){
501  reference ref = syntax_reference(args[1]);
503  paving_array[iterator_nr] = strdup("1");
504  }
506  fitting_array[iterator_nr] = strdup("1");
507  }
508  }
509  }
510  else if(same_string_p(funname, "-")){
511  if(syntax_tag(args[1]) == is_syntax_call && gen_length(call_arguments(syntax_call(args[1])))==0){
512  if(syntax_tag(args[0]) == is_syntax_reference){
513  reference ref = syntax_reference(args[0]);
515  paving_array[iterator_nr] = strdup("1");
516  }
518  fitting_array[iterator_nr] = strdup("1");
519  }
520  }
521  if(syntax_tag(args[0]) == is_syntax_call){
522  xml_call_from_indice(syntax_call(args[0]), offset_array, paving_array, fitting_array);
523  }
524  xml_call_from_indice(syntax_call(args[1]), offset_array, paving_array, fitting_array);
525  }
526  else {
527  pips_user_error("APOTRES doesn't allow negative coefficients in paving and fitting matrices\n");
528  }
529  }
530  else if(same_string_p(funname, "*")){
531  if(syntax_tag(args[0]) != is_syntax_call || syntax_tag(args[1]) != is_syntax_reference || gen_length(call_arguments(syntax_call(args[0])))!=0 ){
532  pips_user_error("Only scalar * reference are allowed here. Please develop expressions.\n");
533  }
534  else {
537  string mult = strdup(xml_entity_local_name(call_function(syntax_call(args[0]))));
538  if(extern_nr != ITEM_NOT_IN_ARRAY){
539  paving_array[extern_nr] = mult;
540  }
541  else if(intern_nr != ITEM_NOT_IN_ARRAY){
542  fitting_array[intern_nr] = strdup(mult);
543  }
544  }
545  }
546  }
547  else{
548  pips_user_error("only linear expression of indices allowed\n");
549  }
550  }
551  else if(gen_length(arguments) == 0){
552  *offset_array = funname;
553  }
554  else{
555  pips_user_error("only +, -, * and constants allowed\n");
556  }
557 }
558 
559 #define XML_ARRAY_PREFIX "A_"
560 
561 static string xml_array_in_task(reference r, bool first, int task_number){
562  /* XML name of the referenced array */
563  string varname = strdup(concatenate(XML_ARRAY_PREFIX,
565  NULL));
566  /* iterator for dimensions of array */
567  int indice_nr = 0;
569  string result = "";
570  /* number of external loops*/
571  int extern_nb = gen_array_nitems(extern_indices_array);
572 
573  /* number of dimensions of referenced array */
574  int index_of_array = gen_length(indices); /*((int *) (gen_array_item(array_dims, gen_array_index(array_names, varname))));*/
575 
576  /* number of internal loops*/
577  int intern_nb = gen_array_nitems(intern_indices_array);
578 
579  /* list of offsets for XML code */
580  string offset_array[index_of_array];
581  /* paving matrix for XML code
582  1st coeff: array dimension (row index)
583  2nd coeff: iteration dimension (column index) */
584  string paving_array[index_of_array][extern_nb];
585 
586  /* fitting matrix for XML code
587  1st coeff: array dimension
588  2nd coeff: iteration dimension*/
589  string fitting_array[index_of_array][intern_nb];
590  int i;
591  int j;
592  int depth = 0;
593 
594  bool null_fitting_p = true;
595  string internal_index_declarations = strdup("");
596  string fitting_declaration = strdup("");
597  string fitting_declaration2 = strdup("");
598 
599  /* initialization of the arrays */
600  for (i=0; i<index_of_array; i++)
601  offset_array[i] = "0";
602 
603  for (i=0; i<index_of_array ; i++)
604  for (j=0; j<extern_nb; j++)
605  paving_array[i][j] = "0";
606 
607  for (i=0; i<index_of_array ; i++)
608  for (j=0; j<intern_nb; j++)
609  fitting_array[i][j] = "0";
610 
611  /* XML reference header */
612  result = strdup(concatenate(result, "DATA(name = symbol!(\"", "T_", int2a(task_number),
613  "\" /+ \"", varname, "\"),", NL, TAB, TAB, NULL));
614 
615  result = strdup(concatenate(result, "darray = ", varname, "," NL, TAB, TAB, "accessMode = ", (first?"Wmode,":"Rmode,"),
616  NL, TAB, TAB, "offset = list<VARTYPE>(", NULL));
617 
618  /* Fill in paving, fitting and offset matrices from index expressions. */
619  MAP(EXPRESSION, ind, {
620  syntax sind = expression_syntax(ind);
621  int iterator_nr;
622  switch(syntax_tag(sind)){
623  case is_syntax_reference:{
626  paving_array[indice_nr][iterator_nr] = strdup("1");
627  }
629  fitting_array[indice_nr][iterator_nr] = strdup("1");
630  }
631 
632  break;
633  }
634  case is_syntax_call:{
635  call c = syntax_call(sind);
636  xml_call_from_indice(c, &(offset_array[indice_nr]), paving_array[indice_nr], fitting_array[indice_nr]);
637  break;
638  }
639  default:{
640  pips_user_error("Only call and reference allowed in indices.\n");
641  break;
642  }
643  }
644  indice_nr++;
645  }, indices);
646 
647 
648  /* generate offset list in XML code */
649  for(i=0; i<index_of_array - 1; i++){
650  result=strdup(concatenate(result, "vartype!(", offset_array[i],"), ", NULL));
651  }
652  result = strdup(concatenate(result, "vartype!(", offset_array[i], "))," NL, NULL));
653 
654  /* fitting header */
655  result = strdup(concatenate(result, TAB, TAB, "fitting = list<list[VARTYPE]>(", NULL));
656 
657  /* XML column-major storage of fitting matrix */
658  for(i=0;i<intern_nb; i++){
659  bool is_null_p = true;
660  for(j = 0; j<index_of_array; j++){
661  is_null_p = is_null_p && (same_string_p(fitting_array[j][i], "0"));
662  }
663  if(!is_null_p){
664  null_fitting_p = false;
665  fitting_declaration = strdup(concatenate(fitting_declaration, "list(", NULL));
666  for(j = 0; j<index_of_array-1; j++){
667  fitting_declaration = strdup(concatenate(fitting_declaration, "vartype!(", fitting_array[j][i], "), ", NULL));
668  }
669  fitting_declaration = strdup(concatenate(fitting_declaration,
670  "vartype!(",
671  fitting_array[j][i],
672  ")), ",
673  NULL));
674  }
675  }
676 
677  if(!null_fitting_p){
678  fitting_declaration2 =
679  strdup(concatenate(gen_strndup0(fitting_declaration,
680  strlen(fitting_declaration) - 2),
681  "),", NL, TAB, TAB, TAB, NULL));
682  result = strdup(concatenate(result, fitting_declaration2, NULL));
683  }
684 
685  if(null_fitting_p){
686  result = strdup(concatenate(result, "list()),", NL, TAB, TAB, NULL));
687  }
688 
689  null_fitting_p = true;
690  /* Generation of paving XML code*/
691  result = strdup(concatenate(result, TAB, TAB, "paving = list<list[VARTYPE]>(", NULL));
692 
693  for(i=0;i<extern_nb-1; i++){
694  result = strdup(concatenate(result, "list(", NULL));
695  for(j = 0; j<index_of_array-1; j++){
696  result = strdup(concatenate(result, "vartype!(", paving_array[j][i], "), ", NULL));
697  }
698  result = strdup(concatenate(result, "vartype!(", paving_array[j][i], ")),", NL, TAB, TAB, TAB, NULL));
699  }
700  result = strdup(concatenate(result, "list(", NULL));
701  for(j = 0; j<index_of_array-1; j++){
702  result = strdup(concatenate(result, "vartype!(", paving_array[j][i], "), ", NULL));
703  }
704  result = strdup(concatenate(result, "vartype!(", paving_array[j][i], "))),", NL, TAB, TAB, NULL));
705 
706 #define MONMAX(a, b) ((a<b)?b:a)
707 
708  /* Definition of the inner loop nest */
709  /* FI->IH: if some columns are removed, the effective depth is unkown and must be computed here */
710  /* result = strdup(concatenate(result, "inLoopNest = LOOPNEST(deep = ", int2a(MONMAX(gen_array_nitems(intern_indices_array), 1)), ",", NL, TAB, TAB, TAB, NULL)); */
711 
712  for (j = 0; j<intern_nb; j++){
713  bool is_null_p = true;
714  for(i = 0; i < index_of_array; i++){
715  is_null_p = is_null_p && (same_string_p(fitting_array[i][j], "0"));
716  }
717  if(!is_null_p){
718  depth++;
719  }
720  }
721  if(depth==0) depth = 1; /* see comment just below about null fitting matrices. */
722  result = strdup(concatenate(result, "inLoopNest = LOOPNEST(deep = ", i2a(depth), ",", NL, TAB, TAB, TAB, NULL));
723  result = strdup(concatenate(result, "upperBound = list<VARTYPE>(", NULL));
724 
725  /* 3 cases :
726  - the fitting matrix is null : must generate a (0,0) loop with dummy index
727  - some fitting matrix column is null : do not generate anything
728  - some fitting matrix column is not null : generate the corresponding loop bound and index name
729  */
730 
731  for (j = 0; j<intern_nb; j++){
732  bool is_null_p = true;
733  for(i = 0; i < index_of_array; i++){
734  is_null_p = is_null_p && (same_string_p(fitting_array[i][j], "0"));
735  }
736  if(!is_null_p){
737  null_fitting_p = false;
738  result = strdup(concatenate(result,
739  "vartype!(",
740  *((string *)(gen_array_item(intern_upperbounds_array, j))),
741  "), ",
742  NULL));
743  internal_index_declarations =
744  strdup(concatenate(internal_index_declarations,
745  QUOTE,
746  *((string *)(gen_array_item(intern_indices_array, j))),
747  QUOTE,
748  ", ",
749  NULL));
750  }
751  }
752  if(!null_fitting_p)
753  {
754  result = strdup(concatenate(gen_strndup0(result, strlen(result) - 2),
755  "),", NULL));
756  internal_index_declarations =
757  strdup(concatenate(gen_strndup0(internal_index_declarations,
758  strlen(internal_index_declarations) -2),
759  ")", NULL));
760  }
761 
762 
763 
764  if(null_fitting_p){
765  result = strdup(concatenate(result, "vartype!(1)),", NL, TAB, TAB, TAB, "names = list<string>(\"M_I\")", NULL));
766  }
767  else{
768  result = strdup(concatenate(result, NL, TAB, "names = list<string>(", internal_index_declarations, NULL));
769  }
770 
771  /* Complete XML reference */
772  result = strdup(concatenate(result, "))", (first?")":","), NL, NULL));
773  return result;
774 }
775 
776 static string xml_call_from_loopnest(call c, int task_number){
777  entity called = call_function(c);
779  syntax s;
780  string result = "";
781  string first_result = "";
782  bool first = true;
783  bool input_provided = false, output_provided = false;
784  string name = strdup(xml_entity_local_name(called));
785 
786  if(!same_string_p(name, "="))
787  pips_user_error("Only assignation allowed here.\n");
788 
790  s = expression_syntax(e);
791  switch(syntax_tag(s)){
792  case is_syntax_call:{
793  if(first)
794  pips_user_error("Call not allowed in left-hand side argument of assignation.\n");
795  else
796  result = strdup(concatenate(result, xml_call_from_assignation(syntax_call(s), task_number, &input_provided), NULL));
797  break;
798  }
799  case is_syntax_reference:
800  {
802  string varname = strdup(concatenate("A_",
805  {
806  if(first){
807  first_result = xml_array_in_task(r, first, task_number);
808  output_provided = true;
809  }
810  else{
811  result = strdup(concatenate(result,
812  xml_array_in_task(r, first, task_number), NULL));
813  input_provided = true;
814  }
815  }
816  break;
817  }
818  default:
819  pips_internal_error("unhandled case");
820  }
821  first = false;
822  }
823 
824  if(!input_provided){
825  result = strdup(concatenate("data = list<DATA>(dummyDATA, ", result, first_result, NULL));
826  }
827  else{
828  result = strdup(concatenate("data = list<DATA>(", result, first_result, NULL));
829  }
830  if(!output_provided){
831  result = strdup(concatenate(result, " dummyDATA)", NULL));
832  }
833  result = strdup(concatenate(result, TAB, ")", NL, NULL));
834  return result;
835 }
836 
837 
839 {
840  call mc = call_undefined; /* meaningful call */
841  int nc = 0; /* number of calls */
842 
843  MAP(STATEMENT, s, {
844  if(continue_statement_p(s))
845  ;
846  else if(statement_call_p(s)) {
848  nc++;
849  }
850  else {
851  nc = 0;
852  break;
853  }
854  }, sequence_statements(seq));
855 
856  if(nc!=1)
857  mc = call_undefined;
858 
859  return mc;
860 }
861 
863 {
864  loop ml = loop_undefined; /* meaningful loop */
865  int nl = 0; /* number of loops */
866 
867  MAP(STATEMENT, s, {
868  if(continue_statement_p(s))
869  ;
870  else if(statement_loop_p(s)) {
872  nl++;
873  }
874  else {
875  nl = 0;
876  break;
877  }
878  }, sequence_statements(seq));
879 
880  if(nl!=1)
881  ml = loop_undefined;
882 
883  return ml;
884 }
885 
886 static call xml_loop_from_loop(loop l, string * result, int task_number){
887 
888  string * up = malloc(sizeof(string));
889  string * xml_name = malloc(sizeof(string));
890  statement s = loop_body(l);
892  int u, low;
894  syntax incr_s = expression_syntax(incr_e);
895 
896  if(!syntax_call_p(incr_s) ||
897  strcmp( entity_local_name(call_function(syntax_call(incr_s))), "1") != 0 ) {
898  pips_user_error("Loop increments must be constant \"1\".\n");
899  }
900 
901  u = atoi(xml_expression(range_upper(loop_range(l))));
902  low = atoi(xml_expression(range_lower(loop_range(l))));
903  /* printf("%i %i\n", u, low); */
904  *up = strdup(int2a(u - low+1));
905  //*up = xml_expression(range_upper(loop_range(l)) - range_lower(loop_range(l)) + 1);
906  *xml_name = xml_entity_local_name(loop_index(l));
907  if( (*xml_name)[0] == 'M'){
910  }
911  else{
914  }
915 
916  switch(instruction_tag(i)){
917  case is_instruction_loop:{
918  loop l = instruction_loop(i);
919  return xml_loop_from_loop(l, result, task_number);
920  break;
921  }
922  case is_instruction_call: {
923  call c = instruction_call(i);
924  return c;
925  }
927  {
930  if (!call_undefined_p(c))
931  return c;
932  if (!loop_undefined_p(l))
933  return xml_loop_from_loop(l, result, task_number);
934  pips_user_error("A sequence should only contain a call or a loop");
935  }
936  default:
937  pips_user_error("Only loops and calls allowed in a loop.");
938  }
939  return call_undefined;
940 }
941 
942 
943 /* We enter a loop nest. The first loop must be an extern loop. */
944 static string xml_loop_from_sequence(loop l, int task_number){
945  statement s = loop_body(l);
946  call c= call_undefined;
947  int i;
948  string * taskname = (string *)(malloc(sizeof(string)));
950  syntax incr_s = expression_syntax(incr_e);
951 
952 
953  /* Initialize result string with the declaration of the task */
954  string result;
955 
957  string * name = malloc(sizeof(string));
958  string * up = malloc(sizeof(string));
959  int u, low;
960  if(!syntax_call_p(incr_s) ||
961  strcmp( entity_local_name(call_function(syntax_call(incr_s))), "1") != 0 ) {
962  pips_user_error("Loop increments must be constant \"1\".\n");
963  }
964 
965 
966  *taskname = strdup(concatenate("T_", int2a(task_number), NULL));
967  result = strdup(concatenate(*taskname,
968  " :: TASK(unitSpentTime = vartype!(1),"
969  NL, TAB, "exLoopNest = LOOPNEST(deep = ", NULL));
970  gen_array_append(tasks_names, taskname);
971  /* (re-)initialize task-scoped arrays*/
976 
977  *name = xml_entity_local_name(loop_index(l));
978  u = atoi(xml_expression(range_upper(loop_range(l))));
979  low = atoi(xml_expression(range_lower(loop_range(l))));
980  *up = strdup(int2a(u - low+1));
981  //*up = xml_expression(range_upper(loop_range(l)) - range_lower(loop_range(l)) + 1);
982 
983  if((*name)[0] == 'M'){
984  pips_user_error("At least one extern loop is needed.\n");
985  }
986  else{
989  }
990 
991 
992  switch(instruction_tag(ins)){
993  case is_instruction_loop:{
994  loop l = instruction_loop(ins);
995  c = xml_loop_from_loop(l, &result, task_number);
996  break;
997  }
998  case is_instruction_call:
999  {
1000  c = instruction_call(ins);
1001  }
1002  break;
1004  /* The sequence should contain only one meaningful call */
1006  break;
1008  c = xml_loop_from_loop(l, &result, task_number);
1009  break;
1010  }
1011  pips_user_error("Sequence should contain one loop or one call");
1012  break;
1013  default:
1014  pips_user_error("Only loops and one significant call allowed in a loop.");
1015  }
1016 
1017  /* External loop nest depth */
1018  result = strdup(concatenate(result, int2a(gen_array_nitems(extern_upperbounds_array)), ",", NL, TAB, TAB, NULL));
1019 
1020  /* add external upperbounds */
1021  result = strdup(concatenate(result, "upperBound = list<VARTYPE>(", NULL));
1022 
1023  for(i=0; i< ((int) gen_array_nitems(extern_upperbounds_array)) - 1; i++){
1024  result = strdup(concatenate(result, "vartype!(", *((string *)(gen_array_item(extern_upperbounds_array, i))), "), ", NULL));
1025  }
1026  result = strdup(concatenate(result, "vartype!(",*((string *)(gen_array_item(extern_upperbounds_array, i))), ")),",NL, TAB, TAB, NULL));
1027 
1028  /* add external indices names*/
1029  result = strdup(concatenate(result, "names = list<string>(", NULL));
1030  for(i=0; i<((int) gen_array_nitems(extern_indices_array)) - 1; i++){
1031  result = strdup(concatenate(result, QUOTE, *((string *)(gen_array_item(extern_indices_array, i))), QUOTE ", ", NULL));
1032  }
1033  result = strdup(concatenate(result, QUOTE, *((string *)(gen_array_item(extern_indices_array, i))), QUOTE, ")),", NL, TAB, NULL));
1034 
1035  result = strdup(concatenate(result, xml_call_from_loopnest(c, task_number), NULL));
1036 
1041  result = strdup(concatenate(result, NL, NULL));
1042  return result;
1043 }
1044 
1045 /* We are here at the highest level of statements. The statements are either
1046  loopnests or a RETURN instruction. Any other possibility pips_user_errors
1047  the prettyprinter.*/
1048 static string xml_statement_from_sequence(statement s, int task_number){
1049  string result = "";
1051 
1052  switch(instruction_tag(i)){
1053  case is_instruction_loop:{
1054  loop l = instruction_loop(i);
1055  result = xml_loop_from_sequence(l, task_number);
1056  break;
1057  }
1058  case is_instruction_call:{
1059  /* RETURN should only be allowed as the last statement in the sequence */
1061  pips_user_error("Only RETURN and CONTINUE allowed here.\n");
1062  break;
1063  }
1064  default:{
1065  pips_user_error("Only loops and calls allowed here.\n");
1066  }
1067  }
1068 
1069  return result;
1070 }
1071 
1072 /* Concatentates each task to the final result.
1073  The validity of the task is not checked in this function but
1074  it is into xml_statementement_from_sequence and subsequent
1075  functions.*/
1077  string result = "";
1078  int task_number = 0;
1079  MAP(STATEMENT, s,
1080  {
1081  string oldresult = strdup(result);
1082  string current = strdup(xml_statement_from_sequence(s, task_number));
1083 
1084  if(strlen(current)==0) {
1085  free(current);
1086  result = oldresult;
1087  }
1088  else {
1089  result = strdup(concatenate(oldresult, current, NULL));
1090  free(current);
1091  free(oldresult);
1092  task_number++;
1093  }
1094  }, sequence_statements(seq));
1095  return result;
1096 }
1097 
1098 /* Manages tasks. The code is very defensive and hangs if sth not
1099  predicted happens. Here basically we begin the code in itself
1100  and thus $stat is obligatory a sequence. */
1101 static string xml_tasks_with_motif(statement stat){
1102  int j;
1103  instruction i;
1104  string result = "tasks\n";
1105  if(statement_undefined_p(stat))
1106  {
1107  pips_internal_error("statement error");
1108  }
1109  i = statement_instruction(stat);
1111  switch(instruction_tag(i)){
1113  sequence seq = instruction_sequence(i);
1114  result = xml_sequence_from_task(seq);
1115  break;
1116  }
1117  default:{
1118  pips_user_error("Only a sequence can be here");
1119  }
1120  }
1121  result = strdup(concatenate(result, NL, NL, "PRES:APPLICATION := APPLICATION(name = symbol!(", QUOTE, global_module_name, QUOTE, "), ", NL, TAB,NULL));
1122  result = strdup(concatenate(result, "tasks = list<TASK>(", NULL));
1123  for(j = 0; j<(int) gen_array_nitems(tasks_names) - 1; j++){
1124  result = strdup(concatenate(result, *((string *)(gen_array_item(tasks_names, j))), ", ", NULL));
1125  }
1126  result = strdup(concatenate(result, *((string *)(gen_array_item(tasks_names, j))), "))", NULL));
1127 
1128  return result;
1129 }
1130 
1131 /* Creates string for xml pretty printer.
1132  This string divides in declarations (array decl.) and
1133  tasks which are loopnest with an instruction at the core.
1134 */
1136 {
1137  string decls="", tasks="", result="";
1138 
1139  ifdebug(2)
1140  {
1141  printf("Module statement: \n");
1142  print_statement(stat);
1143  printf("and declarations: \n");
1145  }
1146 
1148  tasks = xml_tasks_with_motif(stat);
1149  result = strdup(concatenate(decls, NL, tasks, NL, NULL));
1150  ifdebug(2)
1151  {
1152  printf("%s", result);
1153  }
1154  return result;
1155 }
1156 
1157 
1158 /******************************************************** PIPSMAKE INTERFACE */
1159 
1160 /* Initiates xml pretty print modules
1161  */
1163 {
1164  FILE * out;
1165  string ppt, xml, dir, filename;
1166  entity module;
1167  statement stat;
1170  xml = db_build_file_resource_name(DBR_XML_PRINTED_FILE, module_name, ".xml");
1171 
1175  filename = strdup(concatenate(dir, "/", xml, NULL));
1176  stat = (statement) db_get_memory_resource(DBR_CODE, module_name, true);
1177 
1178  if(statement_undefined_p(stat))
1179  {
1180  pips_internal_error("No statement for module %s", module_name);
1181  }
1184 
1185  debug_on("XMLPRETTYPRINTER_DEBUG_LEVEL");
1186  pips_debug(1, "Begin Claire prettyprinter for %s\n", entity_name(module));
1187  ppt = xml_code_string(module, stat);
1188  pips_debug(1, "end\n");
1189  debug_off();
1190 
1191  /* save to file */
1192  out = safe_fopen(filename, "w");
1193  fprintf(out, "%s", ppt);
1194  safe_fclose(out, filename);
1195 
1196  free(ppt);
1197  free(dir);
1198  free(filename);
1199 
1200  DB_PUT_FILE_RESOURCE(DBR_XML_PRINTED_FILE, module_name, xml);
1201 
1204 
1205  return true;
1206 }
1207 
1208 
1209 /* ======================================================= */
1210 
1211 
1212 // If false prettyprint the full name of entities - used in Arguments, Parameters
1213 // If true prettyprint the first level of the entity name (no struct field,...)
1214 static bool print_full_name_p()
1215 {
1216  return false;
1217 }
1218 
1219 // If false prettyprint the full name of entities - used in the Chain_graph
1220 // If true prettyprint the first level of the entity name (no struct field,...)
1222 {
1223  return true;
1224 }
1225 
1226 static void
1228 {
1229  list dim;
1231  list ld;
1232 
1233  entity var = entity_undefined;
1234  for(ld = ldecl; !ENDP(ld); ld = CDR(ld)){
1235 
1236  //printf("inside for");
1237  var = ENTITY(CAR(ld));
1238  //printf("Entity Name in the List : %s ",entity_name(var));
1239 
1240  if (variable_p(var) && ( variable_entity_dimension(var) > 0))
1241  {
1242  // int nb_dim = variable_entity_dimension(var);
1243  //printf("inside p, %d",nb_dim);
1244 
1245  string_buffer_append(result,
1247  " dataType = ", QUOTE,
1248  "INTEGER", QUOTE,CLOSEANGLE
1249  , XML_RL, NULL));
1250  string_buffer_append(result,
1251  concatenate(OPENANGLE,"dimensions",CLOSEANGLE
1252  , XML_RL,NULL));
1253 
1254  for (dim = variable_dimensions(type_variable(entity_type(var))); !ENDP(dim); dim = CDR(dim)) {
1255 
1256  intptr_t low;
1257  intptr_t up;
1258  expression elow = dimension_lower(DIMENSION(CAR(dim)));
1259  expression eup = dimension_upper(DIMENSION(CAR(dim)));
1260  if (expression_integer_value(elow, &low) && expression_integer_value(eup, &up)){
1261  string_buffer_append(result,
1262  concatenate( TAB,OPENANGLE, "range min =", QUOTE, int2a(low), QUOTE, NULL));
1263  string_buffer_append(result,
1264  concatenate(" max =", QUOTE, int2a(up-low+1),QUOTE, SLASH, CLOSEANGLE, XML_RL, NULL));
1265  }
1266  else pips_user_error("Array dimensions must be integer\n");
1267 
1268  }
1269 
1270  string_buffer_append(result,
1271  concatenate(OPENANGLE, SLASH, "dimensions", CLOSEANGLE,NL ,NULL));
1272  string_buffer_append(result,
1273  concatenate(TAB, OPENANGLE, SLASH, "array", CLOSEANGLE, NL, NULL));
1274 
1275  }
1276  }
1277 }
1278 
1279 
1280 static void
1282 {
1283  stack_push(s , nest->current_stat);
1284 }
1285 
1286 static void
1288  nest_context_p nest)
1289 {
1290  /* if (debug) print_statement(s);*/
1291  stack_pop(nest->current_stat);
1292 }
1293 
1294 static void
1296 {
1297  /* on sauve le statement associe a la boucle courante */
1299  stack_push(sl , nest->loops_for_call);
1300  stack_push(loop_index(l) , nest->loop_indices);
1301 }
1302 
1303 static void
1305 {
1306  stack_pop(nest->loops_for_call);
1307  stack_pop(nest->loop_indices);
1308 }
1309 
1310 static void
1312 {
1313  /* on sauve le statement associe au test */
1315  stack_push(sl , nest->testif);
1316 }
1317 
1318 static void
1320  nest_context_p nest)
1321 {
1322  stack_pop(nest->testif);
1323 
1324 }
1325 typedef struct {
1328 } expression_ctxt;
1329 
1331 {
1332  entity f = call_function(c);
1335  encapsulated_call =c;
1336 }
1337 
1338 static bool call_selection(call c, nest_context_p nest __attribute__ ((unused)))
1339 {
1340  /* CA il faut implemeter un choix judicieux ... distribution ou encapsulation*/
1341  /* pour le moment distribution systematique de tout call */
1342  /* il faut recuperer les appels de fonction value_code_p(entity_initial(f)*/
1343  entity f = call_function(c);
1345  return true;
1346  else return false;
1347 }
1348 
1349 static void store_call_context(call c __attribute__((unused)),
1350  nest_context_p nest) {
1351  /* on sauve le statement associe au call */
1352  statement statc = (statement)stack_head(nest->current_stat);
1353  // if (instruction_call_p(statement_instruction(statc))) {
1354  stack sl = stack_copy(nest->loops_for_call);
1355  stack si = stack_copy(nest->loop_indices);
1356  stack statif = stack_copy(nest->testif);
1358  gen_array_append(nest->nested_loops, sl);
1359  gen_array_append(nest->nested_call, statc);
1360  gen_array_append(nest->nested_if, statif);
1361  // }
1362 }
1363 
1364 
1365 // gen_true ?
1366 static bool push_test(test t __attribute__ ((unused)),
1367  nest_context_p nest __attribute__ ((unused)))
1368 {
1369  /* encapsulation de l'ensemble des instructions appartenant au test*/
1370  return true;
1371 }
1372 
1373 // gen_null
1374 static void pop_test(test t __attribute__ ((unused)),
1375  nest_context_p nest __attribute__ ((unused)))
1376 {
1377  /* encapsulation de l'ensemble des instructions appartenant au test*/
1378 }
1379 
1380 
1381 
1382 static void
1384 {
1389  NULL);
1390 }
1391 
1392 static void __attribute__ ((unused)) print_call_selection(nest_context_p nest)
1393 {
1394  int j;
1395  int numberOfTasks=(int) gen_array_nitems(nest->nested_call);
1396  for (j = 0; j<numberOfTasks; j++)
1397  {
1398  //statement s = gen_array_item(nest->nested_call,j);
1399  //stack st = gen_array_item(nest->nested_loops,j);
1400  /* print_statement(s);
1401  stack_map( st, print_statement);*/
1402  }
1403 }
1404 
1405 
1407 {
1408  expression new_e;
1409  if (expression_constant_p(e)) {
1410  new_e = int_to_expression(1+ expression_to_int(e));
1411  }
1412  else {
1414  new_e = make_call_expression(add_ent,
1416  }
1417  return new_e;
1418 }
1419 
1420 static void xml_loop(stack st, string_buffer result)
1421 {
1422  string_buffer_append(result,concatenate(TAB,SPACE, OPENANGLE, "outLoop", CLOSEANGLE, NL, NULL));
1423  string_buffer_append(result,concatenate(TAB,SPACE, SPACE, OPENANGLE, "loopNest", CLOSEANGLE, NL, NULL));
1424  string_buffer_append(result,concatenate(TAB,SPACE, SPACE, SPACE, OPENANGLE, "bounds", CLOSEANGLE, NL, NULL));
1425 
1427  {
1431  expression new_eu= expression_plusplus(eu);
1432 
1433  string_buffer_append(result,
1435  string_buffer_append(result,
1436  concatenate(SPACE, "lower =",QUOTE,expression_to_string(el),QUOTE,NULL));
1437  string_buffer_append(result,
1438  concatenate(SPACE, "upper =", QUOTE, expression_to_string(new_eu),QUOTE, SLASH, CLOSEANGLE,NL,NULL));
1439  },
1440  st, 0);
1441 
1443  string_buffer_append(result,concatenate(TAB,SPACE, SPACE, OPENANGLE,SLASH, "loopNest", CLOSEANGLE, NL, NULL));
1444  string_buffer_append(result,concatenate(TAB,SPACE, OPENANGLE, SLASH, "openLoop", CLOSEANGLE, NL, NULL));
1445 }
1446 
1447 
1448 
1449 static void xml_reference(int taskNumber __attribute__ ((unused)), reference r, bool wmode,
1450  string_buffer result)
1451 {
1452 
1453  const char* varname = entity_user_name(reference_variable(r));
1455  (result,
1456  concatenate(SPACE, QUOTE, XML_ARRAY_PREFIX, varname, QUOTE, SPACE, "accessMode =", QUOTE,
1457  (wmode?"W":"R"),QUOTE, CLOSEANGLE,NL,
1458  NULL));
1459 }
1460 
1461 static void find_motif(Psysteme ps, Pvecteur nested_indices, int dim, int nb_dim __attribute__ ((unused)), Pcontrainte *bound_inf, Pcontrainte *bound_sup, Pcontrainte *iterator, int *motif_up_bound, int *lowerbound, int *upperbound)
1462 {
1463  Variable phi;
1464  Value v;
1465  Pvecteur pi;
1466  Pcontrainte c, next, cl, cu, cl_dup, cu_dup,lind, lind_dup,
1467  list_cl=NULL,
1468  list_cu=NULL,
1469  list_ind=NULL;
1470  int lower =1;
1471  int upper =2;
1472  int ind =3;
1473  Pcontrainte bounds[4][4];
1474  int nb_bounds =0;
1475  int nb_lower = 0;
1476  int nb_upper = 0;
1477  int nb_indices=0;
1478  int i,j;
1479  Pbase vars_to_eliminate = BASE_NULLE;
1480 
1481  for (i=1; i<=3;i++)
1482  for (j=1; j<=3;j++)
1483  bounds[i][j]=CONTRAINTE_UNDEFINED;
1484 
1485  phi = (Variable) make_phi_entity(dim);
1486  /* elimination des variables autres de les phi et les indices de boucles englobants
1487  copie de la base + mise a zero des indices englobants + projection selon les elem de ce vecteur*/
1488 
1489  if (!SC_EMPTY_P(ps)) {
1490  vars_to_eliminate = vect_copy(ps->base);
1491  /* printf("Base des variables :\n");
1492  vect_print(vars_to_eliminate, entity_local_name);
1493  */
1494  vect_erase_var(&vars_to_eliminate, phi);
1495  for (pi = nested_indices; !VECTEUR_NUL_P(pi); pi = pi->succ)
1496  vect_erase_var(&vars_to_eliminate, var_of(pi));
1497 
1498  /* printf("Elimination des variables :\n");
1499  vect_print(vars_to_eliminate, entity_local_name);
1500  */
1501 
1502  sc_projection_along_variables_ofl_ctrl(&ps,vars_to_eliminate , NO_OFL_CTRL);
1503 
1504  for(c = sc_inegalites(ps), next=(c==NULL ? NULL : c->succ);
1505  c!=NULL;
1506  c=next, next=(c==NULL ? NULL : c->succ))
1507  {
1508  Pvecteur indices_in_vecteur = VECTEUR_NUL;
1509  /* printf("Tri de la contrainte :\n");
1510  vect_print(c->vecteur, entity_local_name);
1511  */
1512  v = vect_coeff(phi, c->vecteur);
1513  for (pi = nested_indices; !VECTEUR_NUL_P(pi); pi = pi->succ)
1514  {
1515  int coeff_index = vect_coeff(var_of(pi),c->vecteur);
1516  if (coeff_index)
1517  vect_add_elem(&indices_in_vecteur,var_of(pi), coeff_index);
1518  }
1519 
1520  nb_indices=vect_size(indices_in_vecteur);
1521  nb_indices = (nb_indices >2) ? 2 : nb_indices;
1522 
1523  if (value_pos_p(v)) {
1524  c->succ = bounds[upper][nb_indices+1];
1525  bounds[upper][nb_indices+1] = c;
1526  /* printf(" bornes inf avec indices de boucles englobants :\n");
1527  vect_print(bounds[upper][nb_indices+1]->vecteur, entity_local_name); */
1528  nb_upper ++;
1529  }
1530  else if (value_neg_p(v)) {
1531  c->succ = bounds[lower][nb_indices+1];
1532  bounds[lower][nb_indices+1] = c;
1533  /* printf(" bornes inf avec indices de boucles englobants :\n");
1534  vect_print(bounds[lower][nb_indices+1]->vecteur, entity_local_name);*/
1535  lind = contrainte_make(indices_in_vecteur);
1536  lind->succ = bounds[ind][nb_indices+1];
1537  bounds[ind][nb_indices+1] = lind;
1538  /* printf(" indices contenus dans la contrainte :\n");
1539  vect_print(bounds[ind][nb_indices+1]->vecteur, entity_local_name); */
1540  nb_lower ++;
1541  }
1542  }
1543  /* printf("Nb borne inf = %d, Nb borne sup = %d ;\n",nb_lower,nb_upper); */
1544 
1545  if (!CONTRAINTE_UNDEFINED_P(bounds[lower][2])) {
1546  /* case with 1 loop index in the loop bound constraints */
1547  for(cl = bounds[lower][2], lind= bounds[ind][2]; cl !=NULL; cl=cl->succ,lind=lind->succ) {
1548  for(cu = bounds[upper][2]; cu !=NULL; cu =cu->succ) {
1549  /* printf("Tests de la negation des contraintes :\n");
1550  vect_print(cl->vecteur, entity_local_name);
1551  vect_print(cu->vecteur, entity_local_name); */
1552  if (vect_opposite_except(cl->vecteur,cu->vecteur,TCST)){
1553  cl_dup = contrainte_dup(cl);
1554  cl_dup->succ = list_cl, list_cl=cl_dup;
1555  cu_dup = contrainte_dup(cu);
1556  cu_dup->succ = list_cu, list_cu=cu_dup;
1557  lind_dup = contrainte_dup(lind);
1558  lind_dup->succ = list_ind, list_ind = lind_dup;
1559  nb_bounds ++;
1560  }
1561  }
1562  }
1563  *bound_inf= list_cl;
1564  *bound_sup = list_cu;
1565  *iterator = list_ind;
1566  *motif_up_bound =- vect_coeff(TCST,list_cl->vecteur) - vect_coeff(TCST,list_cu->vecteur) +1;
1567  *lowerbound = vect_coeff(TCST,list_cl->vecteur);
1568  *upperbound = vect_coeff(TCST,list_cu->vecteur)+1;
1569  }
1570  else if (!CONTRAINTE_UNDEFINED_P(bounds[lower][1]) && !CONTRAINTE_UNDEFINED_P(bounds[upper][1])) {
1571  /* case where loop bounds are numeric */
1572  *bound_inf= bounds[lower][1];
1573  *bound_sup = bounds[upper][1];
1574  *iterator = bounds[ind][1];
1575  *motif_up_bound = - vect_coeff(TCST,bounds[lower][1]->vecteur)
1576  - vect_coeff(TCST,bounds[upper][1]->vecteur)+1;
1577  *upperbound = vect_coeff(TCST,bounds[upper][1]->vecteur)+1;
1578  *lowerbound = vect_coeff(TCST,bounds[lower][1]->vecteur);
1579  } else {
1580  /* Only bounds with several loop indices */
1581  /* printf("PB - Only bounds with several loop indices\n"); */
1582  *bound_inf= CONTRAINTE_UNDEFINED;
1583  *bound_sup = CONTRAINTE_UNDEFINED;
1584  *iterator = CONTRAINTE_UNDEFINED;
1585  *motif_up_bound = 1;
1586  *upperbound = 1;
1587  *lowerbound = 0;
1588  }
1589  }
1590  vect_rm( vars_to_eliminate);
1591 }
1592 
1593 
1594 static void xml_tiling(int taskNumber, reference ref, region reg, stack indices, string_buffer result)
1595 {
1596  fprintf(stderr,"XML");
1597  Psysteme ps_reg = sc_dup(region_system(reg));
1598  entity var = reference_variable(ref);
1600  int i, j ;
1601  string_buffer buffer_bound = string_buffer_make(true);
1602  string_buffer buffer_offset = string_buffer_make(true);
1603  string_buffer buffer_fitting = string_buffer_make(true);
1604  string_buffer buffer_paving = string_buffer_make(true);
1605  string string_bound = "";
1606  string string_offset = "";
1607  string string_paving = "";
1608  string string_fitting = "";
1609  Pvecteur iterat, pi= VECTEUR_NUL;
1610  Pcontrainte bound_inf = CONTRAINTE_UNDEFINED;
1611  Pcontrainte bound_up = CONTRAINTE_UNDEFINED;
1612  Pcontrainte iterator = CONTRAINTE_UNDEFINED;
1613  int motif_up_bound =0;
1614  int lowerbound = 0;
1615  int upperbound = 0;
1616  int dim_indices= stack_size(indices);
1617  int pav_matrix[10][10], fit_matrix[10][10];
1618 
1619  for (i=1; i<=9;i++)
1620  for (j=1;j<=9;j++)
1621  pav_matrix[i][j]=0, fit_matrix[i][j]=0;
1622 
1623  STACK_MAP_X(index,entity,
1624  {
1625  vect_add_elem (&pi,(Variable) index ,VALUE_ONE);
1626  }, indices,1);
1627 
1628  for(i=1; i<=dim ; i++) {
1629  Psysteme ps = sc_dup(ps_reg);
1631 
1632  find_motif(ps, pi, i, dim, &bound_inf, &bound_up, &iterator,
1633  &motif_up_bound, &lowerbound, &upperbound);
1634  string_buffer_append(buffer_offset,
1635  concatenate(TAB,TAB,OPENANGLE,"offset val =", QUOTE,
1636  (CONTRAINTE_UNDEFINED_P(bound_inf))? "0" :
1637  int2a(vect_coeff(TCST,bound_inf->vecteur)),
1638  QUOTE, SLASH, CLOSEANGLE,NL,NULL));
1639  if (!CONTRAINTE_UNDEFINED_P(iterator)) {
1640  for (iterat = pi, j=1; !VECTEUR_NUL_P(iterat); iterat = iterat->succ, j++)
1641  pav_matrix[i][j]= vect_coeff(var_of(iterat),iterator->vecteur);
1642  }
1643  if (!CONTRAINTE_UNDEFINED_P(bound_inf))
1644  fit_matrix[i][i]= (motif_up_bound >1) ? 1:0;
1645 
1646  string_buffer_append(buffer_bound,
1647  concatenate(TAB,TAB, OPENANGLE, "bound idx=",
1648  QUOTE, XML_MOTIF_PREFIX, int2a(taskNumber),"_",
1649  entity_user_name(var), "_",int2a(i),QUOTE, SPACE,
1650  "lower =" QUOTE,int2a(lowerbound),QUOTE,
1651  SPACE, "upper =", QUOTE, int2a(upperbound),
1653  NL,NULL));
1654  }
1655 
1656  for (j=1; j<=dim_indices ; j++){
1657  string_buffer_append(buffer_paving,concatenate(TAB,TAB, OPENANGLE,"row",
1658  CLOSEANGLE,NULL));
1659  for(i=1; i<=dim ; i++)
1660  string_buffer_append(buffer_paving,
1661  concatenate(OPENANGLE, "cell val =", QUOTE,
1662  int2a( pav_matrix[i][j]),QUOTE, SLASH,
1663  CLOSEANGLE,NULL));
1664  string_buffer_append(buffer_paving,concatenate(OPENANGLE,SLASH, "row",
1665  CLOSEANGLE,NL,NULL));
1666  }
1667  for(i=1; i<=dim ; i++) {
1668  string_buffer_append(buffer_fitting,concatenate(TAB, TAB,OPENANGLE,"row",
1669  CLOSEANGLE,NULL));
1670  for(j=1; j<=dim ; j++)
1671  string_buffer_append(buffer_fitting, concatenate(OPENANGLE, "cell val =", QUOTE,
1672  int2a( fit_matrix[i][j]),
1673  QUOTE, SLASH,
1674  CLOSEANGLE,NULL));
1675 
1676  string_buffer_append(buffer_fitting,concatenate(OPENANGLE,SLASH, "row",
1677  CLOSEANGLE,NL,NULL));
1678  }
1680  CLOSEANGLE,NL,NULL));
1681  string_offset =string_buffer_to_string(buffer_offset);
1682  string_buffer_append(result,string_offset);
1683  free(string_offset);
1684  string_offset=NULL;
1686  CLOSEANGLE,NL,NULL));
1687 
1689  CLOSEANGLE,NL,NULL));
1690  string_fitting =string_buffer_to_string(buffer_fitting);
1691  string_buffer_append(result,string_fitting);
1692  free(string_fitting);
1693  string_fitting=NULL;
1695  CLOSEANGLE,NL,NULL));
1697  CLOSEANGLE,NL,NULL));
1698  string_paving =string_buffer_to_string(buffer_paving);
1699  string_buffer_append(result,string_paving);
1700  free(string_paving);
1701  string_paving=NULL;
1703  CLOSEANGLE,NL,NULL));
1705  CLOSEANGLE, NL, NULL));
1707  CLOSEANGLE, NL, NULL));
1709  CLOSEANGLE, NL, NULL));
1710  string_bound =string_buffer_to_string(buffer_bound);
1711  string_buffer_append(result,string_bound);
1712  free(string_bound);
1713  string_bound=NULL;
1714 
1716  SLASH "bounds", CLOSEANGLE, NL, NULL));
1718  CLOSEANGLE, NL, NULL));
1720  CLOSEANGLE, NL, NULL));
1721 
1722 
1723 }
1724 
1725 static void xml_references(int taskNumber, list l_regions, stack indices, string_buffer result)
1726 {
1727  list lr;
1728  bool atleast_one_read_ref = false;
1729  bool atleast_one_written_ref = false;
1730  /* Read array references first */
1731  for ( lr = l_regions; !ENDP(lr); lr = CDR(lr))
1732  {
1733  region re = REGION(CAR(lr));
1736  atleast_one_read_ref = true;
1737  string_buffer_append(result,concatenate(TAB, SPACE, SPACE, OPENANGLE, "data darray=",NULL));
1738  xml_reference(taskNumber, ref, region_write_p(re), result);
1739  xml_tiling(taskNumber, ref,re, indices, result);
1740  }
1741  }
1742  if (!atleast_one_read_ref)
1743  string_buffer_append(result,concatenate(TAB,SPACE, SPACE, "dummyDATA",
1744  NL,NULL));
1745  for ( lr = l_regions; !ENDP(lr); lr = CDR(lr))
1746  {
1747  region re = REGION(CAR(lr));
1750  atleast_one_written_ref = true;
1751  string_buffer_append(result,concatenate(TAB, SPACE, SPACE, OPENANGLE, "data darray=",NULL));
1752  xml_reference(taskNumber, ref, region_write_p(re), result);
1753  xml_tiling(taskNumber, ref,re, indices, result);
1754  }
1755  }
1756  if (!atleast_one_written_ref)
1757  string_buffer_append(result,concatenate(TAB,SPACE, SPACE,"dummyDATA",NL,NULL));
1758 }
1759 
1760 static void xml_data(int taskNumber,statement s, stack indices, string_buffer result )
1761 {
1762 
1764  string_buffer_append(result,concatenate(TAB,SPACE, OPENANGLE, "dataList", CLOSEANGLE, NL,NULL));
1765  /*
1766  ifdebug(2) {
1767  fprintf(stderr, "\n list of regions ");
1768  print_regions(l_regions);
1769  fprintf(stderr, "\n for the statement");
1770  print_statement(s);
1771  }
1772  */
1773  xml_references(taskNumber, l_regions, indices, result);
1774  string_buffer_append(result,concatenate(TAB,SPACE,OPENANGLE, SLASH, "dataList", CLOSEANGLE,NL,NULL));
1775  regions_free(l_regions);
1776 }
1777 
1778 static string task_complexity(statement s)
1779 {
1780  complexity stat_comp = load_statement_complexity(s);
1781  string r;
1782  if(stat_comp != (complexity) HASH_UNDEFINED_VALUE && !complexity_zero_p(stat_comp)) {
1783  cons *pc = CHAIN_SWORD(NIL, complexity_sprint(stat_comp, false,
1784  true));
1785  r = words_to_string(pc);
1786  }
1787  else r = int2a(1);
1788  return (r);
1789 }
1790 static void xml_task( int taskNumber, nest_context_p nest, string_buffer result)
1791 {
1792 
1793  statement s = gen_array_item(nest->nested_call,taskNumber);
1794  stack st = gen_array_item(nest->nested_loops,taskNumber);
1795  stack sindices = gen_array_item(nest->nested_loop_indices,taskNumber);
1796 
1797  string_buffer_append(result, concatenate(NL,TAB,OPENANGLE,"task name =", QUOTE, XML_TASK_PREFIX,int2a(taskNumber),QUOTE, CLOSEANGLE, NL, NULL));
1798  string_buffer_append(result, concatenate(TAB, SPACE, OPENANGLE, "unitSpentTime", CLOSEANGLE,task_complexity(s),NULL));
1799  string_buffer_append(result, concatenate(OPENANGLE,SLASH,"unitSpentTime",CLOSEANGLE,NL,NULL));
1800 
1801  xml_loop(st, result);
1802  xml_data (taskNumber, s,sindices, result);
1804 }
1805 
1806 static void xml_tasks(statement stat, string_buffer result){
1807 
1808  const char* module_name = get_current_module_name();
1809  nest_context_t nest;
1810  int taskNumber =0;
1814  nest.nested_loops= gen_array_make(0);
1816  nest.nested_call= gen_array_make(0);
1817 
1819 
1820  if(statement_undefined_p(stat)) {
1821  pips_internal_error("statement error");
1822  }
1823 
1824  search_nested_loops_and_calls(stat,&nest);
1825  /* ifdebug(2) print_call_selection(&nest); */
1826 
1827  for (taskNumber = 0; taskNumber<(int) gen_array_nitems(nest.nested_call); taskNumber++)
1828 
1829  xml_task(taskNumber, &nest,result);
1831  string_buffer_append(result,
1833  "application name = ",
1835  NL, NULL));
1836 
1837  for(taskNumber = 0; taskNumber<(int) gen_array_nitems(nest.nested_call)-1; taskNumber++)
1838  string_buffer_append(result,concatenate(TAB, OPENANGLE, "taskref ref = ", QUOTE, XML_TASK_PREFIX,
1839  int2a(taskNumber),QUOTE, SLASH, CLOSEANGLE, NL, NULL));
1840 
1841  string_buffer_append(result,concatenate(TAB, OPENANGLE, "taskref ref = ", QUOTE, XML_TASK_PREFIX,
1842  int2a(taskNumber),QUOTE, SLASH, CLOSEANGLE, NL, NULL));
1843 
1844  string_buffer_append(result,concatenate(SPACE, OPENANGLE, SLASH, "application",CLOSEANGLE, NL, NULL));
1845 
1849  stack_free(&(nest.loops_for_call));
1850  stack_free(&(nest.loop_indices));
1851  stack_free(&(nest.current_stat));
1852 
1853 }
1854 
1855 /* Creates string for xml pretty printer.
1856  This string divides in declarations (array decl.) and
1857  tasks which are loopnests with an instruction at the core.
1858 */
1859 
1860 static string xml_code(entity module, statement stat)
1861 {
1862  string_buffer result=string_buffer_make(true);
1863  string result2;
1864 
1866  xml_declarations(module,result);
1867  xml_tasks(stat,result);
1868 
1869  string_buffer_append(result,concatenate(OPENANGLE, SLASH, "module", CLOSEANGLE, NL, NULL ));
1870  result2=string_buffer_to_string(result);
1871  /* ifdebug(2)
1872  {
1873  printf("%s", result2);
1874  } */
1875  return result2;
1876 }
1877 
1879  statement stat __attribute__ ((unused)))
1880 { return true;
1881 }
1882 
1883 /******************************************************** PIPSMAKE INTERFACE */
1884 
1885 /* Initiates xml pretty print modules
1886  */
1887 
1888 bool print_xml_code(const char* module_name)
1889 {
1890  FILE * out;
1891  string ppt;
1893  string xml = db_build_file_resource_name(DBR_XML_PRINTED_FILE,
1894  module_name, ".xml");
1895  string dir = db_get_current_workspace_directory();
1896  string filename = strdup(concatenate(dir, "/", xml, NULL));
1897  statement stat=(statement) db_get_memory_resource(DBR_CODE,
1898  module_name, true);
1899 
1900  init_cost_table();
1901  /* Get the READ and WRITE regions of the module */
1903  db_get_memory_resource(DBR_REGIONS, module_name, true));
1904 
1906  db_get_memory_resource(DBR_COMPLEXITIES, module_name, true));
1907 
1908  if(statement_undefined_p(stat))
1909  {
1910  pips_internal_error("No statement for module %s", module_name);
1911  }
1914 
1915  debug_on("XMLPRETTYPRINTER_DEBUG_LEVEL");
1916  pips_debug(1, "Spec validation before xml prettyprinter for %s\n",
1917  entity_name(module));
1918  if (valid_specification_p(module,stat)){
1919  pips_debug(1, "Spec is valid\n");
1920  pips_debug(1, "Begin XML prettyprinter for %s\n", entity_name(module));
1921  ppt = xml_code(module, stat);
1922  pips_debug(1, "end\n");
1923  debug_off();
1924  /* save to file */
1925  out = safe_fopen(filename, "w");
1926  fprintf(out,"%s",ppt);
1927  safe_fclose(out, filename);
1928  free(ppt);
1929  }
1930 
1931  free(dir);
1932  free(filename);
1933 
1934  DB_PUT_FILE_RESOURCE(DBR_XML_PRINTED_FILE, module_name, xml);
1935 
1939  reset_rw_effects();
1940  return true;
1941 }
1942 
1943 
1944 
1945 //================== PRETTYPRINT TERAOPT DTD ============================
1946 
1947 
1948 static string vect_to_string(Pvecteur pv) {
1950 }
1951 
1952 /* UNUSED
1953 static bool vect_one_p(Pvecteur v) {
1954  return (!VECTEUR_NUL_P(v) && vect_size(v) == 1 && vect_coeff(TCST, v) ==1);
1955 }
1956 */
1957 
1958 /* UNUSED
1959 static bool vect_zero_p(Pvecteur v) {
1960  return (VECTEUR_NUL_P(v) ||
1961  (!VECTEUR_NUL_P(v) && vect_size(v) == 1 && value_zero_p(vect_coeff(TCST, v))));
1962 }
1963 */
1964 
1965 static void type_and_size_of_var(entity var, const char ** datatype, int *size)
1966 {
1967  // type t = ultimate_type(entity_type(var));
1968  type t = entity_type(var);
1969  if (type_variable_p(t)) {
1971  int e = SizeOfElements(b);
1972  if (e==-1)
1973  *size = 9999;
1974  else
1975  *size = e;
1976  *datatype =basic_to_string(b);
1977  }
1978 }
1979 
1980 
1981 static void add_margin(int gm, string_buffer sb_result) {
1982  int i;
1983  for (i=1;i<=gm;i++)
1984  string_buffer_append(sb_result, " ");
1985 }
1986 
1987 static void string_buffer_append_word(string str, string_buffer sb_result)
1988 {
1989  add_margin(global_margin,sb_result);
1990  string_buffer_append(sb_result,
1991  concatenate(OPENANGLE,NULL));
1992  string_buffer_append_xml_text(sb_result, str, false);
1993  string_buffer_append(sb_result,
1994  concatenate(CLOSEANGLE, NL, NULL));
1995 }
1996 
1997 static void string_buffer_append_symbolic(string str, string_buffer sb_result){
1998  add_margin(global_margin,sb_result);
1999  string_buffer_append(sb_result,
2000  concatenate(OPENANGLE, "Symbolic", CLOSEANGLE, NULL));
2001  string_buffer_append_xml_text(sb_result, str, false);
2002  string_buffer_append(sb_result,
2003  concatenate(OPENANGLE,"/Symbolic",CLOSEANGLE,
2004  NL, NULL));
2005 }
2006 
2007 static void two_string_buffer_append_symbolic(string str1, string str2, string_buffer sb_result){
2008  add_margin(global_margin,sb_result);
2009  string_buffer_append(sb_result,
2010  concatenate(OPENANGLE,"Symbolic",CLOSEANGLE, NULL));
2011  string_buffer_append_xml_text(sb_result,str1,false);
2012  string_buffer_append_xml_text(sb_result,str2,false);
2013  string_buffer_append(sb_result,
2014  concatenate(OPENANGLE,"/Symbolic",CLOSEANGLE,
2015  NL, NULL));
2016 }
2017 
2018 static void string_buffer_append_numeric(string str, string_buffer sb_result){
2019  add_margin(global_margin,sb_result);
2020  string_buffer_append(sb_result,
2021  concatenate(OPENANGLE,"Numeric",CLOSEANGLE,
2022  str,
2023  OPENANGLE,"/Numeric",CLOSEANGLE,
2024  NL, NULL));
2025 }
2026 
2027 
2028 
2029 static void
2031 {
2036  NULL);
2037 }
2038 
2039 // A completer
2040 static void xml_Library(string_buffer sb_result)
2041 {
2042  string_buffer_append_word("Library",sb_result);
2043  string_buffer_append_word("/Library",sb_result);
2044 }
2045 // A completer
2046 static void xml_Returns(string_buffer sb_result __attribute__ ((unused)))
2047 {
2048  //string_buffer_append_word("Returns",sb_result);
2049  //string_buffer_append_word("/Returns",sb_result);
2050 }
2051 // A completer
2052 static void xml_Timecosts(string_buffer sb_result __attribute__ ((unused)))
2053 {
2054  //string_buffer_append_word("Timecosts",sb_result);
2055  // string_buffer_append_word("/Timecosts",sb_result);
2056 }
2057 
2058 // A completer
2059 static void xml_AccessFunction(string_buffer sb_result __attribute__ ((unused)))
2060 {
2061  //string_buffer_append_word("AccessFunction",sb_result);
2062  //string_buffer_append_word("/AccessFunction",sb_result);
2063 }
2064 // A completer
2065 static void xml_Regions(string_buffer sb_result __attribute__ ((unused)))
2066 {
2067  // string_buffer_append_word("Regions",sb_result);
2068  // string_buffer_append_word("/Regions",sb_result);
2069 }
2070 // A completer
2071 static void xml_CodeSize(string_buffer sb_result)
2072 {
2073  string_buffer_append_word("CodeSize",sb_result);
2074  string_buffer_append_word("/CodeSize",sb_result);
2075 }
2076 
2077 // A changer par une fonction qui detectera si la variable a ete definie
2078 // dans un fichier de parametres ...
2080 {
2081  const char* s = entity_local_name(e);
2082  bool b=false;
2083  if (strstr(s,"PARAM")!=NULL || strstr(s,"param")!=NULL) b = true;
2084  return (b);
2085 }
2086 
2087 typedef struct Spattern {
2093  bool unitp;
2094  struct Spattern *next;
2096 
2097 /*
2098 Pour traiter les cas ou il y a des patterns symboliques, sans preconditions
2099 interprocedurales permettant d'evaluer un min sur les bornes:
2100 Choix selon ordre de priorite:
2101  - borne numerique
2102  - borne symbolique avec un seul parametre et coeff ==1
2103  - borne symbolique avec un seul parametre
2104  - la premiere borne symbolique avec plusieurs parametres
2105 */
2106 
2107 static void choose_pattern(Ppattern *patt)
2108 {
2109  Ppattern patt1= NULL,
2110  pattn= NULL,
2111  pattc1= NULL,
2112  pattcx= NULL,
2113  pattcp= NULL;
2114  Pvecteur pv;
2115  for(patt1 = *patt; patt1 !=NULL; patt1=patt1->next) {
2116  if (vect_size(patt1->diff) ==1) {
2117  if (vect_dimension(patt1->diff)==0) // borne constante numerique
2118  pattn = patt1;
2119  else { // borne constante symbolique
2120  for (pv = patt1->diff;pv!=NULL;pv=pv->succ) {
2121  if (pv->var!= TCST) {
2122  if (pv->val ==1)
2123  pattc1=patt1;
2124  else pattcx = patt1;
2125  }
2126  }
2127  }
2128  }
2129  else pattcp = patt1;
2130  }
2131  if (pattn!=NULL ) *patt=pattn;
2132  else if (pattc1!= NULL) *patt=pattc1;
2133  else if (pattcx!=NULL ) *patt=pattcx;
2134  else *patt=pattcp;
2135 }
2136 
2137 
2138 //static void find_pattern(Psysteme ps, Pvecteur paving_indices, Pvecteur formal_parameters, int dim, Pcontrainte *bound_inf, Pcontrainte *bound_sup, Pcontrainte *pattern_up_bound , Pcontrainte *iterator, int *mult)
2139 static void find_pattern(Psysteme ps, Pvecteur paving_indices, Pvecteur formal_parameters, int dim, Ppattern *patt)
2140 {
2141  Variable phi;
2142  Value v;
2143  Pvecteur pi;
2144  Pcontrainte c, next, cl, cu, lind;
2145  *patt = NULL;
2146  int lower =1;
2147  int upper =2;
2148  int ind =3;
2149  Pcontrainte bounds[4][4];
2150  int nb_bounds =0;
2151  int nb_lower = 0;
2152  int nb_upper = 0;
2153  int nb_indices=0;
2154  int i,j;
2155  Pbase vars_to_eliminate = BASE_NULLE;
2156  Pvecteur vdiff = VECTEUR_NUL,
2157  diff2 = VECTEUR_NUL;
2158  // DEBUG Ppattern pt= NULL;
2159  Ppattern patt1=NULL;
2160  int mult=1;
2161  for (i=1; i<=3;i++)
2162  for (j=1; j<=3;j++)
2163  bounds[i][j]=CONTRAINTE_UNDEFINED;
2164 
2165  phi = (Variable) make_phi_entity(dim);
2166 
2167  /* Liste des variables a eliminer autres de les phi et les indices de boucles englobants
2168  et les parametres formels de la fonction.
2169  copie de la base + mise a zero des indices englobants
2170  + projection selon les elem de ce vecteur
2171  */
2172  if (!SC_EMPTY_P(ps)) {
2173 
2174  Psysteme ps_dup=sc_dup(ps);
2175  vars_to_eliminate = vect_copy(ps->base);
2176  vect_erase_var(&vars_to_eliminate, phi);
2177 
2178  //printf("paving_indices:\n");
2179  //vect_fprint(stdout,paving_indices,(char * (*)(Variable)) entity_local_name);
2180 
2181  for (pi = paving_indices; !VECTEUR_NUL_P(pi); pi = pi->succ)
2182  vect_erase_var(&vars_to_eliminate, var_of(pi));
2183  //printf("formal_parameters:\n");
2184  // vect_fprint(stdout,formal_parameters,(char * (*)(Variable)) entity_local_name);
2185 
2186  for (pi = formal_parameters; !VECTEUR_NUL_P(pi); pi = pi->succ)
2187  vect_erase_var(&vars_to_eliminate, var_of(pi));
2188  //printf("vars_to_eliminate:\n");
2189  //vect_fprint(stdout,vars_to_eliminate,(char * (*)(Variable)) entity_local_name);
2190 
2191  sc_projection_along_variables_ofl_ctrl(&ps_dup,vars_to_eliminate , NO_OFL_CTRL);
2192 
2193  //printf("Systeme a partir duquel on genere les contraintes du motif:\n");
2194  //sc_fprint(stdout,ps,entity_local_name);
2195 
2196  for(c = sc_inegalites(ps_dup), next=(c==NULL ? NULL : c->succ);
2197  c!=NULL;
2198  c=next, next=(c==NULL ? NULL : c->succ))
2199  {
2200  Pvecteur indices_in_vecteur = VECTEUR_NUL;
2201  vdiff = VECTEUR_NUL;
2202  v = vect_coeff(phi, c->vecteur);
2203  for (pi = paving_indices; !VECTEUR_NUL_P(pi); pi = pi->succ)
2204  {
2205  int coeff_index = vect_coeff(var_of(pi),c->vecteur);
2206  if (coeff_index)
2207  vect_add_elem(&indices_in_vecteur,var_of(pi), coeff_index);
2208  }
2209  /* on classe toutes les contraintes ayant plus de 2 indices de boucles
2210  externes ensemble */
2211  nb_indices=vect_size(indices_in_vecteur);
2212  nb_indices = (nb_indices >2) ? 2 : nb_indices;
2213 
2214  if (value_pos_p(v)) {
2215  c->succ = bounds[upper][nb_indices+1];
2216  bounds[upper][nb_indices+1] = c;
2217 
2218  // printf(" bornes sup avec indices de boucles englobants :\n");
2219  // vect_print(bounds[upper][nb_indices+1]->vecteur, (char * (*)(Variable)) entity_local_name);
2220  nb_upper ++;
2221  }
2222  else if (value_neg_p(v)) {
2223  c->succ = bounds[lower][nb_indices+1];
2224  bounds[lower][nb_indices+1] = c;
2225  // printf(" bornes inf avec indices de boucles englobants :\n");
2226  // vect_print(bounds[lower][nb_indices+1]->vecteur, (char * (*)(Variable)) entity_local_name);
2227  lind = contrainte_make(indices_in_vecteur);
2228  lind->succ = bounds[ind][nb_indices+1];
2229  bounds[ind][nb_indices+1] = lind;
2230  // printf(" indices contenus dans la contrainte :\n");
2231  // vect_print(bounds[ind][nb_indices+1]->vecteur, (char * (*)(Variable)) entity_local_name);
2232  nb_lower ++;
2233  }
2234  }
2235  // printf("Nb borne inf = %d, Nb borne sup = %d pour dimension %d;\n",nb_lower,nb_upper,dim);
2236 
2237 
2238  for (int nb_ind=2; nb_ind>=1; nb_ind--){
2239  /* case with 1 loop index in the loop bound constraints than 0 */
2240  if (!CONTRAINTE_UNDEFINED_P(bounds[lower][nb_ind])) {
2241  for(cl = bounds[lower][nb_ind], lind= bounds[ind][nb_ind]; cl !=NULL; cl=cl->succ,lind=lind->succ) {
2242  for(cu = bounds[upper][nb_ind]; cu !=NULL; cu =cu->succ) {
2243  Value cv1 = vect_coeff(phi, cl->vecteur);
2244  Value cv2 = vect_coeff(phi, cu->vecteur);
2245  if (value_abs(cv1)==value_abs(cv2)) {
2246  vdiff = vect_add(cu->vecteur,cl->vecteur);
2247  mult=value_abs(cv1);
2248  }
2249  else {
2250  vdiff = vect_cl2(value_abs(cv1),cu->vecteur,value_abs(cv2),cl->vecteur);
2251  mult=(int) value_abs(cv1 * cv2);
2252  }
2253  vect_chg_sgn(vdiff);
2254 
2255  // le +1 est ajoute dans l'expression apres division lorsque mult!=1
2256  if (mult==1)
2257  vect_add_elem(&vdiff,TCST,1);
2258  // pattern = contrainte_make(vect_dup(vdiff));
2259 
2260  diff2=vect_dup(vdiff);
2261  for (pi = formal_parameters; !VECTEUR_NUL_P(pi); pi = pi->succ)
2262  vect_erase_var(&vdiff, var_of(pi));
2263 
2264  if (vect_dimension(vdiff)==0) {
2265  patt1= (Ppattern) malloc(sizeof(Spattern));
2266  patt1->diff = vect_dup(diff2);
2267  patt1->lower = vect_dup(cl->vecteur);
2268  patt1->upper = vect_dup(cu->vecteur);
2269  patt1->lind = vect_dup(lind->vecteur);
2270  patt1->cl_coeff=mult;
2271  patt1->unitp=(vect_dimension(diff2)==0 && vect_coeff(TCST, diff2)==1)?true:false;
2272 
2273  vect_chg_sgn(patt1->upper);
2274  for (pi = lind->vecteur; !VECTEUR_NUL_P(pi); pi = pi->succ) {
2275  vect_erase_var(&(patt1->lower), var_of(pi));
2276  vect_erase_var(&(patt1->upper), var_of(pi));
2277  }
2278  vect_erase_var(&(patt1->lower), phi);
2279  vect_erase_var(&(patt1->upper),phi);
2280  patt1->next = *patt, *patt=patt1;
2281  nb_bounds ++;
2282  }
2283  vect_rm(vdiff);
2284  vect_rm(diff2);
2285  }
2286  }
2287  }
2288  }
2289  /* DEBUG
2290  printf("Liste des contraintes ajoutees PHI-%d: \n",dim);
2291  for (pt=*patt; pt != NULL; pt=pt->next) {
2292  vect_fprint(stdout, pt->diff, (char * (*)(Variable)) entity_local_name);
2293  vect_fprint(stdout, pt->lower, (char * (*)(Variable)) entity_local_name);
2294  vect_fprint(stdout, pt->upper, (char * (*)(Variable)) entity_local_name);
2295  vect_fprint(stdout, pt->lind, (char * (*)(Variable)) entity_local_name);
2296  fprintf(stdout,"mult = %d\n", pt->cl_coeff);
2297  } */
2298 
2299  choose_pattern(patt);
2300  /* DEBUG
2301  pt =*patt;
2302  if (patt != NULL && pt != NULL) {
2303  printf("Pattern choisi : \n");
2304  vect_fprint(stdout, pt->diff, (char * (*)(Variable)) entity_local_name);
2305  vect_fprint(stdout, pt->lower, (char * (*)(Variable)) entity_local_name);
2306  vect_fprint(stdout, pt->upper, (char * (*)(Variable)) entity_local_name);
2307  vect_fprint(stdout, pt->lind, (char * (*)(Variable)) entity_local_name);
2308  fprintf(stdout,"mult = %d\n", pt->cl_coeff);
2309  } */
2310 
2311  base_rm( vars_to_eliminate);
2312  sc_rm(ps_dup);
2313  }
2314 }
2315 
2316 static void xml_Pattern_Paving( region reg,entity var, bool effet_read, Pvecteur formal_parameters, Pvecteur paving_indices, string_buffer sb_result)
2317 {
2318  string_buffer buffer_pattern = string_buffer_make(true);
2319  string_buffer buffer_paving = string_buffer_make(true);
2320  string string_paving = "";
2321  string string_pattern = "";
2322  Pvecteur voffset;
2323 
2324  if(reg != region_undefined) {
2326  entity vreg = reference_variable(ref);
2327  if ( array_entity_p(reference_variable(ref)) && same_entity_p(vreg,var) && region_read_p(reg)== effet_read) {
2328  Psysteme ps_reg = sc_dup(region_system(reg));
2329  Pvecteur iterat= VECTEUR_NUL;
2330  Pvecteur iterator = VECTEUR_NUL;
2331  Ppattern patt=NULL;
2332  Pvecteur vpattern=VECTEUR_NUL;
2334  int i ;
2335  int val =0;
2336  int inc =0;
2337  dimension vreg_dim = dimension_undefined;
2338  int mult=1;
2339  if (!SC_UNDEFINED_P(ps_reg))
2340  sc_transform_eg_in_ineg(ps_reg);
2341  add_margin(global_margin,buffer_pattern);
2342  string_buffer_append(buffer_pattern,
2344  "Pattern AccessMode=",
2345  QUOTE,(effet_read)? "USE":"DEF",QUOTE,CLOSEANGLE,NL,NULL));
2346  add_margin(global_margin,buffer_paving);
2347  string_buffer_append(buffer_paving,
2349  "Pavage AccessMode=",
2350  QUOTE,(effet_read)? "USE":"DEF",QUOTE,CLOSEANGLE,NL,NULL));
2351  global_margin++;
2352  // pour chaque dimension : generer en meme temps le pattern et le pavage
2353  for(i=1; i<=dim; i++) {
2354  int uniqp=0;
2355  voffset =vect_new(TCST,0);
2356  patt = NULL;
2357  // printf("find pattern for entity %s [dim=%d]\n",entity_local_name(var),i);
2358  // sc_fprint(stdout,ps_reg,(char * (*)(Variable)) entity_local_name);
2359  // printf("paving_indices:\n");
2360  // vect_fprint(stdout,paving_indices,(char * (*)(Variable)) entity_local_name);
2361 
2362  //find_pattern(ps_reg, paving_indices, formal_parameters, i, &bound_inf, &bound_up, &pattern_up_bound, &iterator, &mult);
2363  find_pattern(ps_reg, paving_indices, formal_parameters, i, &patt);
2364  if (patt !=NULL) {
2365  vpattern=patt->diff;
2366  iterator= patt->lind;
2367  mult = patt->cl_coeff;
2368  uniqp=patt->unitp;
2369  voffset = patt->lower;
2370  }
2371  else
2372  {
2373  vpattern=VECTEUR_NUL;
2374  iterator = VECTEUR_NUL;
2375  }
2376 
2377  // printf("pattern_bound:\n");
2378  //if (!VECTEUR_NUL_P(vpattern))
2379  // vect_fprint(stdout,vpattern,(char * (*)(Variable)) entity_local_name);
2380  /* phi = (Variable) make_phi_entity(i);
2381  if(!SC_UNDEFINED_P(ps_reg) && base_contains_variable_p(sc_base(ps_reg),phi)) {
2382  ps1 = sc_dup(ps_reg);
2383  feasible = sc_minmax_of_variable(ps1, (Variable)phi, &min, &max);
2384  if (feasible){
2385  if (min!=VALUE_MIN)
2386  voffset = vect_new(TCST,min);
2387  // if (min==max)
2388  // uniqp=1;
2389  }
2390  }
2391  */
2392 
2393  if (!uniqp) {
2394  if (VECTEUR_NUL_P(vpattern)) { // if we cannot deduce pattern length from region, array dim size is taken
2396  vreg_dim = find_ith_dimension(ldim,i);
2398  vpattern = vect_dup((Pvecteur) normalized_linear(ndim));
2399  if (vpattern != VECTEUR_NUL)
2400  vect_add_elem(&vpattern,TCST,1);
2401  }
2402  }
2403  /* PRINT PATTERN and PAVING */
2404  // if ((vect_zero_p(voffset) && (!VECTEUR_NUL_P(vpattern) && vect_one_p(vpattern)))
2405  // || (uniqp && vect_zero_p(voffset)))
2406  if (!VECTEUR_NUL_P(vpattern) && uniqp && vect_dimension(voffset)==0 && vect_coeff(TCST,voffset)==0)
2407  string_buffer_append_word("DimUnitPattern/",buffer_pattern);
2408  else {
2409  add_margin(global_margin,buffer_pattern);
2410  // A completer - choisir un indice pour le motif ?
2411  string_buffer_append(buffer_pattern,
2413  "DimPattern Index=",QUOTE, QUOTE,CLOSEANGLE,NL,NULL));
2414 
2415  global_margin++;
2416  string_buffer_append_word("Offset",buffer_pattern);
2418  buffer_pattern);
2419  if (vect_dimension(voffset)==0)
2421  buffer_pattern);
2422  string_buffer_append_word("/Offset",buffer_pattern);
2423 
2424  string_buffer_append_word("Length",buffer_pattern);
2425 
2426  // The upper bound is not a complex expression
2427  if (uniqp) {
2428  string_buffer_append_symbolic(int2a(1),buffer_pattern);
2429  string_buffer_append_numeric(int2a(1),buffer_pattern);
2430  }
2431  else {
2432  if (vpattern != VECTEUR_NUL) {
2433  if (mult==1)
2434  string_buffer_append_symbolic(vect_to_string(vpattern),buffer_pattern);
2435  else {
2436  add_margin(global_margin,buffer_pattern);
2437  string_buffer_append(buffer_pattern,
2438  concatenate(OPENANGLE,"Symbolic",CLOSEANGLE,
2439  "(",NULL));
2440  string_buffer_append_xml_text(buffer_pattern,vect_to_string(vpattern),false);
2441  string_buffer_append(buffer_pattern,
2442  concatenate(")",
2443  "/",i2a(mult),"+1",
2444  OPENANGLE,"/Symbolic",CLOSEANGLE,
2445  NL, NULL));
2446  }
2447 
2448  }
2449  else //vpattern == VECTEUR_NUL
2451  buffer_pattern);
2452  if ((vpattern != VECTEUR_NUL) && vect_dimension(vpattern)==0)
2454  buffer_pattern);
2455  }
2456  string_buffer_append_word("/Length",buffer_pattern);
2457 
2458  string_buffer_append_word("Stride",buffer_pattern);
2459  val =1;
2460  string_buffer_append_symbolic(int2a(val),buffer_pattern);
2461  string_buffer_append_numeric(int2a(val),buffer_pattern);
2462  string_buffer_append_word("/Stride",buffer_pattern);
2463  global_margin--;
2464  string_buffer_append_word("/DimPattern",buffer_pattern);
2465  }
2466  if (!VECTEUR_UNDEFINED_P(iterator) &&!VECTEUR_NUL_P(iterator)) {
2467  string_buffer_append_word("DimPavage",buffer_paving);
2468  for (iterat = paving_indices; !VECTEUR_NUL_P(iterat); iterat = iterat->succ) {
2469  if ((inc = vect_coeff(var_of(iterat),iterator)) !=0) {
2470  add_margin(global_margin,buffer_paving);
2471  string_buffer_append(buffer_paving,
2473  "RefLoopIndex Name=",
2474  QUOTE,entity_user_name(var_of(iterat)),QUOTE, BL,
2475  "Inc=", QUOTE,
2476  int2a(inc),QUOTE,"/", CLOSEANGLE,NL,NULL));
2477  }
2478  }
2479  string_buffer_append_word("/DimPavage",buffer_paving);
2480  }
2481  else
2482  string_buffer_append_word("DimPavage/",buffer_paving);
2483  }
2484  global_margin--;
2485  string_buffer_append_word("/Pattern",buffer_pattern);
2486  string_buffer_append_word("/Pavage",buffer_paving);
2487  string_pattern = string_buffer_to_string(buffer_pattern);
2488  string_paving = string_buffer_to_string(buffer_paving);
2489  string_buffer_append(sb_result, string_pattern);
2490  free(string_pattern);
2491  string_pattern=NULL;
2492  string_buffer_append(sb_result, string_paving);
2493  free(string_paving);
2494  string_paving=NULL;
2495  xml_AccessFunction(sb_result);
2496  sc_free(ps_reg);
2497  }
2498  }
2499 }
2500 
2501 /* UNUSED
2502 static void array_vars_read_or_written(list effects_list, Pvecteur *vl)
2503 {
2504  Pvecteur vin=VECTEUR_NUL;
2505  Pvecteur vout = VECTEUR_NUL;
2506  list pc;
2507  for (pc= effects_list;pc != NIL; pc = CDR(pc)){
2508  effect e = EFFECT(CAR(pc));
2509  reference r = effect_any_reference(e);
2510  if (store_effect_p(e) && array_entity_p(reference_variable(r))) {
2511  entity v = reference_variable(r);
2512  if (effect_read_p(e))
2513  vect_add_elem(&vin,v,1);
2514  else vect_add_elem(&vout,v,1);
2515  }
2516  }
2517  vin = base_normalize(vin);
2518  vout = base_normalize(vout);
2519  *vl = vect_substract(vin,vout);
2520  *vl= base_normalize(*vl);
2521  vect_rm(vin);
2522  vect_rm(vout);
2523 }
2524 */
2525 
2526 static void vars_read_and_written(list effects_list, Pvecteur *vr, Pvecteur *vw)
2527 {
2528  list pc;
2529  for (pc= effects_list;pc != NIL; pc = CDR(pc)){
2530  effect e = EFFECT(CAR(pc));
2531  if (e!=(effect) 0 && effect_cell(e)!=0 && !effect_undefined_p(e) && store_effect_p(e)) {
2533  entity v = reference_variable(r);
2534  if (effect_read_p(e))
2535  vect_add_elem(vr,v,1);
2536  else vect_add_elem(vw,v,1);
2537  }
2538  }
2539  *vr = base_normalize(*vr);
2540  *vw = base_normalize(*vw);
2541 }
2542 
2543 static void xml_Region_Range(region reg, string_buffer sb_result)
2544 {
2545  Variable phi;
2546  int i;
2547  Pcontrainte pc;
2548  if(reg != region_undefined) {
2550  entity vreg = reference_variable(ref);
2553  Psysteme ps_reg = sc_dup(region_system(reg));
2554  /* on peut ameliorer les resultats en projetant
2555  les egalites portant sur les variables autres que les PHI */
2556  /*
2557  Pvecteur vva = VECTEUR_NUL;
2558  Variable va;
2559  for(pc = sc_egalites(ps_reg); pc!=NULL;pc= pc->succ)
2560  {
2561  va = vect_one_coeff_if_any(pc->vecteur);
2562  if (va!= NULL && strcmp(variable_name(va),"PHI")==0 ) vect_add_elem(&vva,va,1);
2563  }
2564  sc_projection_along_variables_ofl_ctrl(&ps_reg,vva , NO_OFL_CTRL);
2565  */
2566  if (!SC_UNDEFINED_P(ps_reg)) {
2567  sc_transform_eg_in_ineg(ps_reg);
2568  for (i=1;i<=dim;i++) {
2569  string_buffer sbi_result=string_buffer_make(true);
2570  string_buffer sbu_result=string_buffer_make(true);
2571  string string_sbi, string_sbu;
2572  int fub = 0;
2573  int fib = 0;
2574  phi = (Variable) make_phi_entity(i);
2575  string_buffer_append(sbi_result,
2576  concatenate("[", NULL));
2577  string_buffer_append(sbu_result,
2578  concatenate(";",NULL));
2579  for(pc = sc_inegalites(ps_reg); pc!=NULL;pc= pc->succ)
2580  {
2581  int vc = vect_coeff(phi, pc->vecteur);
2582  Pvecteur vvc = vect_dup(pc->vecteur);
2583  string sb= NULL;
2584  string scst;
2585  if (value_pos_p(vc)) { // borne sup
2586  vect_erase_var(&vvc,phi);
2587  vect_chg_sgn(vvc);
2588  sb = vect_to_string(vvc);
2589  if (vc-1)
2590  scst =strdup(i2a(vc));
2591  if (fub++)
2592  if (vc-1)
2593  string_buffer_append(sbu_result,
2594  concatenate(",(",sb, NULL));
2595  else string_buffer_append(sbu_result,
2596  concatenate(",",sb, NULL));
2597  else
2598  if (vc-1)
2599  string_buffer_append(sbu_result,
2600  concatenate("(",sb, NULL));
2601  else string_buffer_append(sbu_result,
2602  concatenate(sb, NULL));
2603  if (vc-1)
2604  string_buffer_append(sbu_result,
2605  concatenate(")/",scst, NULL));
2606  }
2607  else if (value_neg_p(vc)) {
2608  vect_erase_var(&vvc,phi);
2609  sb = vect_to_string(vvc);
2610  if (vc+1) scst =strdup(i2a(-1*vc));
2611  if (fib++)
2612  if (vc+1)
2613  string_buffer_append(sbi_result,
2614  concatenate(",(",sb, NULL));
2615  else string_buffer_append(sbi_result,
2616  concatenate(",",sb, NULL));
2617  else
2618  if (vc+1)
2619  string_buffer_append(sbi_result,
2620  concatenate("(",sb, NULL));
2621  else string_buffer_append(sbi_result,
2622  concatenate(sb, NULL));
2623  if (vc+1)
2624  string_buffer_append(sbi_result,
2625  concatenate(")/",scst, NULL));
2626  }
2627  }
2628  string_buffer_append(sbu_result,
2629  concatenate("]",NULL));
2630  string_sbi = string_buffer_to_string(sbi_result);
2631  string_sbu = string_buffer_to_string(sbu_result);
2632  string_buffer_append(sb_result,string_sbi);
2633  string_buffer_append(sb_result,string_sbu);
2634  }
2635  sc_rm(ps_reg);
2636  }
2637  }
2638  }
2639 }
2640 
2641 /*static bool string_in_list_p(string ts,list lr){
2642  bool trouve=false;
2643  MAPL(tt,
2644  {trouve= trouve || strcmp(STRING(CAR(tt)),ts) == 0;},
2645  lr);
2646  return trouve;
2647 }
2648 */
2649 
2650 static bool region_range_nul_p(region reg,Variable phi)
2651 {
2652  Pcontrainte pc;
2653  bool result=false;
2654  if(reg != region_undefined) {
2656  entity vreg = reference_variable(ref);
2659  Psysteme ps_reg = sc_dup(region_system(reg));
2660  if (!SC_UNDEFINED_P(ps_reg)) {
2661  for(pc = sc_egalites(ps_reg); pc!=NULL;pc= pc->succ) {
2662  if (vect_coeff(phi, pc->vecteur) && (vect_size(pc->vecteur)==1 ))
2663  result=true;
2664  }
2665  }
2666  }
2667  }
2668  }
2669  return result;
2670 }
2671 
2672 
2673 char *str_sub (const char *s, int start, int end)
2674 {
2675  char *new_s = NULL;
2676  if (s != NULL && start <= end)
2677  {
2678  new_s = malloc (sizeof (*new_s) * (end - start + 2));
2679  if (new_s != NULL) {
2680  int i;
2681  for (i = start; i <= end; i++) {
2682  new_s[i-start] = s[i];
2683  }
2684  new_s[i-start] = '\0';
2685  }
2686  }
2687  return new_s;
2688 }
2689 
2690 char * pointer_to_initial_name(char *ts, _UNUSED_ char * ste)
2691 {
2692  string ts_tmp = ts;
2693  string initial_ts =ts;
2694  /* Prefix extraction
2695  int nbpref= strcspn(ste, ts);
2696  string pref_ts= malloc (sizeof (char) * (nbpref+1));
2697  pref_ts = strncpy(pref_ts,ste,(int)nbpref);
2698  pref_ts[nbpref]='\0';
2699  fprintf(stdout,"Prefix for %s in %s is %s\n",ts, ste,pref_ts );
2700  */
2701  bool reduction_p=true;
2702  // Remove "_" on either side of intial entity name ts in case of pointer
2703  while (reduction_p && strchr(ts_tmp,'_')==ts_tmp)
2704  {
2705  string end_ts=strrchr(ts,'_');
2706  if (strlen(ts_tmp)-strlen(end_ts)-1>0)
2707  initial_ts = str_sub (ts,1,strlen(ts_tmp)-strlen(end_ts)-1);
2708  else reduction_p=false;
2709  ts_tmp=initial_ts;
2710  }
2711 
2712  /* Search entity to determine its type
2713  string newst = malloc (sizeof (char) * (nbpref+strlen(initial_ts)));
2714  newst = strcat(pref_ts,initial_ts);
2715  entity newent=gen_find_entity(newst);
2716  */
2717  return(initial_ts);
2718 }
2719 
2720 static const char * words_points_to_reference(reference rv, bool suffix_only_p, region reg)
2721 {
2722  list pc = NIL;
2723  list pc1=NIL;
2724  int i;
2725  bool bp=false;
2726  entity vv = reference_variable(rv);
2728  list lr=reference_indices(rv);
2729 
2730  if (!suffix_only_p) {
2731  // Translate temporary constant entity name into user entity name
2732  string full_name= (string) entity_user_name(vv);
2733  string initial_name = pointer_to_initial_name(full_name,(string)entity_name(vv));
2734  pc = CHAIN_SWORD(pc, initial_name);
2735  }
2736  while(lr != NIL) {
2737  switch (type_tag(ct)) {
2738  case is_type_variable: {
2739 
2740  variable vt = type_variable(ct);
2741  basic bt = variable_basic(vt);
2742  list lt = variable_dimensions(vt);
2743 
2744  if (array_type_p(ct)) {
2745  expression ll = EXPRESSION(CAR(lr));
2749  if (gen_length(lt) ==1 && !region_undefined_p(reg) && !entity_undefined_p(re) && region_range_nul_p(reg,(Variable)re)) {
2750  if (CDR(lr)!=NIL) {
2751  pc = CHAIN_SWORD(pc,"->");
2752  bp=true;
2753  }
2754  else {
2755  pc1=NIL;
2756  pc1 = CHAIN_SWORD(pc1,"*");
2757  gen_nconc(pc1,pc);
2758  pc=pc1;
2759  }
2760  lr=CDR(lr);
2761  }
2762  else {
2763  for (i= 1; i<= (int) gen_length(lt) && lr!=NIL; i++) {
2764  pc = CHAIN_SWORD(pc,"[*]");
2765  lr=CDR(lr);
2766  }
2767  }
2768  }
2769 
2770  if (lr!=NIL) {
2771  if(basic_typedef_p(bt)) {
2772  entity e = basic_typedef(bt);
2774  }
2775  else if(basic_pointer_p(bt)) {
2776  pc = CHAIN_SWORD(pc, "->");
2777  lr=CDR(lr); // equivalent to [0]
2779  bp=true;
2780  }
2781  else if(basic_derived_p(bt)) {
2783  }
2784  else { // int, float, logical, overload, complex, string, bit ==> nothing to do
2785  if (lr ==NIL)
2786  printf(" additional basic type, PB \n");
2787  else {
2788  lr=CDR(lr);
2789  }
2790  }
2791  }
2792  break;
2793  }
2794 
2795  case is_type_struct: {
2796  if (!bp) pc = CHAIN_SWORD(pc, ".");
2797  bp=false;
2798  list fe = type_struct(ct); // list of type entities in struct
2799  expression exp= EXPRESSION(CAR(lr));
2801  if (syntax_reference_p(se)) {
2803  FOREACH(ENTITY, fee, fe){
2804  if (same_entity_p(fee,re))
2806  }
2808  lr = CDR(lr);
2809  }
2810  else printf("pb avec le STRUCT\n");
2811  break;
2812  }
2813  case is_type_union: {
2814  if (!bp) pc = CHAIN_SWORD(pc, ".");
2815  bp=false;
2816  list fe = type_union(ct); // list of type entities in union
2817  expression exp= EXPRESSION(CAR(lr));
2819  if (syntax_reference_p(se)) {
2821  FOREACH(ENTITY, fee, fe){
2822  if (same_entity_p(fee,re))
2824  }
2825  pc = CHAIN_SWORD(pc, "{");
2827  pc = CHAIN_SWORD(pc, "}");
2828  lr = CDR(lr);
2829  }
2830  else printf("pb avec le UNION\n");
2831  break;
2832  }
2833  case is_type_enum: {
2834  if (!bp) pc = CHAIN_SWORD(pc, ".");
2835  bp=false;
2836  list fe = type_enum(ct); // list of type entities in union
2837  expression exp= EXPRESSION(CAR(lr));
2839  if (syntax_reference_p(se)) {
2841  FOREACH(ENTITY, fee, fe){
2842  if (same_entity_p(fee,re))
2844  }
2845  pc = CHAIN_SWORD(pc, "{");
2847  pc = CHAIN_SWORD(pc, "}");
2848  lr = CDR(lr);
2849  }
2850  else printf("pb avec le ENUM\n");
2851  break;
2852  }
2853  default: // void(not here), unknown(not here), varargs (to be added?), functional (not here), statement(not here), area (not here)
2854  {
2855  printf("Not implemented\n");
2857  lr = CDR(lr);
2858  }
2859  }
2860  }
2861  return(strdup(list_to_string(pc)));
2862 }
2863 
2864 
2865 
2866 static void xml_Full_Type(type pt, int max_step, string_buffer type_result)
2867 {
2868  if (max_step>=0) {
2869  switch (type_tag(pt)) {
2870  case is_type_variable: {
2871  variable vt1 = type_variable(pt);
2872  basic bt1 = variable_basic(vt1);
2873  list lt1 = variable_dimensions(vt1);
2874  //DEBUG- if ((int)gen_length(lt1)>0) printf("ARRAY_DIMENSION= %d ", (int)gen_length(lt1));
2875 
2876  global_margin++;
2877 
2878  if ((int)gen_length(lt1)>0) {
2879  add_margin(global_margin,type_result);
2880  string_buffer_append(type_result,
2882  "ArrayType Dimension = ",QUOTE,i2a((int)gen_length(lt1)),QUOTE,
2883  CLOSEANGLE,NL,NULL));
2884  }
2885  if(basic_typedef_p(bt1)) {
2886  entity e1 = basic_typedef(bt1);
2887  //DEBUG- printf("TYPEDEF %s \n",basic_to_string(bt1));
2888  add_margin(global_margin,type_result);
2889  string_buffer_append(type_result,
2891  "Typedef Name= ",QUOTE,basic_to_string(bt1),QUOTE,CLOSEANGLE,NL,NULL));
2892  xml_Full_Type(entity_type(e1),max_step-1,type_result);
2893  string_buffer_append_word("/Typedef",type_result);
2894  }
2895  else if(basic_pointer_p(bt1)) {
2896  type pt1 = basic_pointer(bt1);
2897  //DEBUG- printf("POINTER %s\n",basic_to_string(bt1));
2898  add_margin(global_margin,type_result);
2899  string_buffer_append(type_result, concatenate(
2900  OPENANGLE, "Pointer Name = ", QUOTE, basic_to_string(bt1), QUOTE,
2901  CLOSEANGLE,NL,NULL));
2902  xml_Full_Type(pt1,max_step-1,type_result);
2903  string_buffer_append_word("/Pointer",type_result);
2904  }
2905  else if(basic_derived_p(bt1)) {
2906  entity e1 = basic_derived(bt1);
2907  //DEBUG- printf("DERIVED %s \n", basic_to_string(bt1));
2908  add_margin(global_margin,type_result);
2910  "Derived Name= ",QUOTE,basic_to_string(bt1),QUOTE,CLOSEANGLE,NL, NULL));
2911  xml_Full_Type(entity_type(e1),max_step-1,type_result);
2912  string_buffer_append_word("/Derived",type_result);
2913  }
2914  else { // int, float, logical, overload, complex, string, bit ==> nothing to do
2915  add_margin(global_margin,type_result);
2916  string_buffer_append(type_result,
2918  basic_to_string(bt1),
2919  OPENANGLE,"/Basic",CLOSEANGLE,NL, NULL));
2920  //DEBUG- printf("BASIC %s \n", basic_to_string(bt1));
2921  }
2922  if ((int)gen_length(lt1)>0)
2923  string_buffer_append_word("/ArrayType",type_result);
2924  global_margin--;
2925  break;
2926  }
2927 
2928  case is_type_struct: {
2929  list fe1 = type_struct(pt);
2930  global_margin++;
2931  string_buffer_append_word("Struct",type_result);
2932  FOREACH(ENTITY, fee1, fe1){
2933  global_margin++;
2934  //DEBUG- printf("field %s \n",entity_user_name(fee1));
2935  add_margin(global_margin,type_result);
2936  string_buffer_append(type_result, concatenate(
2937  OPENANGLE, "Field Name= ",QUOTE,entity_user_name(fee1),QUOTE,BL,
2938  CLOSEANGLE,NL,NULL));
2939  xml_Full_Type(entity_type(fee1),max_step-1,type_result);
2940  string_buffer_append_word("/Field",type_result);
2941  global_margin--;
2942  }
2943  string_buffer_append_word("/Struct",type_result);
2944  global_margin--;
2945  break;
2946  }
2947  case is_type_union: {
2948  list fe1 = type_union(pt);
2949  global_margin++;
2950  string_buffer_append_word("Union",type_result);
2951  FOREACH(ENTITY, fee1, fe1){
2952  global_margin++;
2953  //DEBUG- printf("field %s \n",entity_user_name(fee1));
2954  add_margin(global_margin,type_result);
2955  string_buffer_append(type_result,
2956  concatenate(OPENANGLE,"Field Name= ",QUOTE,entity_user_name(fee1),QUOTE,BL,CLOSEANGLE,NL,NULL));
2957  xml_Full_Type(entity_type(fee1),max_step-1,type_result);
2958  string_buffer_append_word("/Field",type_result);
2959  global_margin--;
2960  }
2961  string_buffer_append_word("/Union",type_result);
2962  global_margin--;
2963  break;
2964  }
2965  case is_type_enum: {
2966  list fe1 = type_enum(pt);
2967  global_margin++;
2968  string_buffer_append_word("Enum",type_result);
2969  FOREACH(ENTITY, fee1, fe1){
2970  global_margin++;
2971  //DEBUG- printf("field %s \n",entity_user_name(fee1));
2972  add_margin(global_margin,type_result);
2973  string_buffer_append(type_result,
2974  concatenate(OPENANGLE,"Field Name= ",QUOTE,entity_user_name(fee1),QUOTE,BL,CLOSEANGLE,NL,NULL));
2975  xml_Full_Type(entity_type(fee1),max_step-1,type_result);
2976  string_buffer_append_word("/Field",type_result);
2977  global_margin--;
2978  }
2979  string_buffer_append_word("/Enum",type_result);
2980  global_margin--;
2981  break;
2982  }
2983  default: // void(not here), unknown(not here), varargs (to be added?), functional (not here), statement(not here), area (not here)
2984  { //printf("Not implemented\n");
2985  max_step=-1;
2986  }
2987  return;
2988  }
2989  }
2990 }
2991 
2992 static void xml_Type_Entity(entity vv,string_buffer type_buffer)
2993 {
2994  int max_step = (int) maximal_type_depth(entity_type(vv));
2995  if (max_step <=30) {
2996  // if (!io_entity_p(vv) && !ENTITY_STDOUT_P(vv) && !ENTITY_STDIN_P(vv) && !ENTITY_STDERR_P(vv)) {
2997  if (!effects_package_entity_p(vv) && !std_file_entity_p(vv) && !variable_heap_p(vv)) {
2998  type ct = entity_type(vv);
2999  global_margin++;
3000  add_margin(global_margin,type_buffer);
3001  string_buffer_append(type_buffer,
3003  "Reference Name= ",QUOTE,NULL));
3004  string_buffer_append_xml_text(type_buffer, (string) entity_user_name(vv),false);
3005  string_buffer_append(type_buffer, concatenate(QUOTE,CLOSEANGLE,NL,NULL));
3006  xml_Full_Type(ct,max_step,type_buffer);
3007  string_buffer_append_word("/Reference",type_buffer);
3008  global_margin--;
3009  }
3010  }
3011 }
3012 
3013 static void xml_Region_Parameter(list pattern_region, string_buffer sb_result)
3014 {
3015  list lr;
3016  list lrr = NIL, lrw=NIL;
3017  bool effet_read = true;
3018  reference ref;
3019  region reg;
3020  entity v;
3021 
3022  string_buffer_append_word("ReferencedParameters",sb_result);
3023  global_margin++;
3024 
3025  for ( lr = pattern_region; !ENDP(lr); lr = CDR(lr))
3026  {
3027  reg = REGION(CAR(lr));
3028  ref = effect_any_reference(reg);
3029  v = reference_variable(ref);
3031  && !(entity_static_variable_p(v) && !top_level_entity_p(v))) {
3032  string ts = strdup(entity_user_name(v));
3033 
3034  // string temp2 = pointer_to_initial_name(ts);
3035 
3036  effet_read = region_read_p(reg);
3037  // if ((effet_read && !string_in_list_p(ts,lrr)) || (!effet_read && !string_in_list_p(ts,lrw))) {
3038  if (effet_read)
3039  lrr = gen_nconc(lrr,CONS(STRING,ts,NIL));
3040  else lrw = gen_nconc(lrw,CONS(STRING,ts,NIL));
3041  add_margin(global_margin,sb_result);
3042  string_buffer_append(sb_result,
3044  "ReferencedParameter"," Name=",
3045  QUOTE,NULL));
3048  false);
3049  string_buffer_append(sb_result,
3050  concatenate(QUOTE, BL,"Range=",QUOTE,NULL));
3051  xml_Region_Range(reg, sb_result);
3052 
3053  string_buffer_append(sb_result,
3054  concatenate(QUOTE, BL,
3055  "Type=", QUOTE,(entity_xml_parameter_p(v))? "CONTROL":"DATA",QUOTE,BL,
3056  "AccessMode=", QUOTE, (effet_read)? "USE":"DEF",QUOTE,BL,
3057  "ArrayP=", QUOTE, (array_entity_p(v))?"TRUE":"FALSE",QUOTE, BL,
3058  "Kind=", QUOTE, "VARIABLE",QUOTE,"/",
3059  CLOSEANGLE
3060  NL, NULL));
3061 
3062  // }
3063  }
3064  }
3065  global_margin--;
3066  string_buffer_append_word("/ReferencedParameters",sb_result);
3067  gen_free_list(lrr);
3068  gen_free_list(lrw);
3069 }
3070 
3072  list leff, effect *effr, effect *effw, entity e)
3073 {
3074  // return effet_rwb = 1 for Read, 2 for Write, 3 for Read/Write
3075  int effet_rwb=0;
3076  list lr = NIL;
3077  bool er = false;
3078  bool ew = false;
3079  //fprintf(stdout,"DEBUG - Effects for var =%s\n",entity_user_name(e));
3080  //print_effects(leff);
3081  for ( lr = leff; !ENDP(lr); lr = CDR(lr)) {
3082  effect eff= EFFECT(CAR(lr));
3085  if (store_effect_p(eff) && same_entity_p(v,e) && !environment_effect_p(eff)) {
3086  if (action_read_p(effect_action(eff)))
3087  er = true, *effr =eff;
3088  else ew = true, *effw=eff;
3089  }
3090  }
3091  effet_rwb = (er?1:0) +(ew?2:0);
3092  return (effet_rwb);
3093 }
3094 
3096 {
3097  if (same_entity_p(reference_variable(r),ctxt->e))
3098  ctxt->entity_in_p = true;
3099 }
3100 
3102 {
3103 
3104  expression_ctxt ctxt = { e, false };
3106  return ctxt.entity_in_p;
3107 }
3108 
3110 {
3111  string sdim;
3112  entity FormalArrayName, mod = get_current_module_entity();
3113  int ith, FormalParameterNumber = (int) gen_length(module_formal_parameters(mod));
3114  global_margin++;
3115  for (ith=1;ith<=FormalParameterNumber;ith++) {
3116  FormalArrayName = find_ith_formal_parameter(mod,ith);
3117  if (type_variable_p(entity_type(FormalArrayName))
3118  && ( variable_entity_dimension(FormalArrayName)>0)) {
3119  list ld, ldim = variable_dimensions(type_variable(entity_type(FormalArrayName)));
3120  int dim;
3121  for (ld = ldim, dim =1 ; !ENDP(ld); ld = CDR(ld), dim++) {
3122  expression elow = dimension_lower(DIMENSION(CAR(ld)));
3124  //const char * low= words_to_string(words_syntax(expression_syntax(elow),NIL));
3125  //const char * up = words_to_string(words_syntax(expression_syntax(eup),NIL));
3126  //const char * sv = entity_local_name(var);
3127  //if ((strstr(low,sv)!=NULL) || (strstr(up,sv)!=NULL)) {
3128  if (entity_in_expression_p(elow,var) || entity_in_expression_p(eup,var)) {
3129  sdim= strdup(i2a(variable_entity_dimension(FormalArrayName)-dim+1));
3130  add_margin(global_margin,sb_result);
3131  string_buffer_append(sb_result,
3133  "TaskParameterUsedFor"," ArrayName=", QUOTE, NULL));
3134  string_buffer_append_xml_text(sb_result, (string) entity_user_name(FormalArrayName),false);
3135  string_buffer_append(sb_result,
3136  concatenate(QUOTE, BL,
3137  //QUOTE,words_points_to_reference(FormalArrayName),QUOTE, BL,
3138  "Dim=", QUOTE,sdim,QUOTE,"/", CLOSEANGLE, NL, NULL));
3139  }
3140  }
3141  }
3142  }
3143  global_margin--;
3144 }
3145 
3146 
3147 typedef struct callst
3148 {
3150  int stat_nb;
3151  struct callst *succ;
3153 
3154 static bool same_callst_p(Pcallst c1,Pcallst c2)
3155 {
3156  return(same_entity_p(c1->func,c2->func) && (c1->stat_nb ==c2->stat_nb));
3157 }
3158 
3160 {
3161  Pcallst ll= NULL,lc2;
3162  bool found=false;
3163  Pcallst ldef = (Pcallst) hash_get(hash_entity_def_into_tasks,(char *) v);
3164  if (ldef != (Pcallst) HASH_UNDEFINED_VALUE) {
3165  for(lc2=ldef;lc2 !=(Pcallst) HASH_UNDEFINED_VALUE && lc2 !=(Pcallst) NULL && !found; lc2=lc2->succ)
3166  {
3167  if (same_callst_p(c1,lc2))
3168  found=true;
3169  }
3170  if (!found)
3171  c1->succ=ldef, ll=c1;
3172  else ll =ldef;
3173  }
3174  else ll=c1;
3176  hash_put(hash_entity_def_into_tasks,(char *) v,(char *)ll);
3177 }
3179 {
3180  Pcallst ldef = (Pcallst) hash_get(hash_entity_def_into_tasks,(char *) v);
3181  if (ldef == (Pcallst) HASH_UNDEFINED_VALUE) {
3182  hash_put(hash_entity_def_into_tasks,(char *) v,(char *)c1);
3183  }
3184 }
3185 
3186 static void xml_TaskReturnParameter(entity function, _UNUSED_ int statnb, string_buffer sb_result)
3187 {
3188  const char* datatype ="";
3189 
3190  if (type_functional_p(entity_type(function))) {
3192  if (type_variable_p(tp)) {
3193  variable v=type_variable(tp);
3194  basic b = variable_basic(v);
3195  //int e = SizeOfElements(b);
3196  // int size = (e==-1) ? 9999:e;
3197  datatype =basic_to_string(b);
3198 
3199  add_margin(global_margin,sb_result);
3200  string_buffer_append(sb_result,
3202  "AssignParameter",
3203  " Name= ",QUOTE, "RETURN",QUOTE,BL,
3204  "DataType=",QUOTE,datatype,QUOTE,BL,
3205  "AccessMode=", QUOTE,"DEF",QUOTE,BL,
3206  "ArrayP=", QUOTE, (variable_dimensions(v) != NIL)?"TRUE":"FALSE",QUOTE, BL,
3207  "Kind=", QUOTE, "VARIABLE",QUOTE,
3208  CLOSEANGLE,
3209  NL, NULL));
3210  string_buffer_append_word("/AssignParameter",sb_result);
3211 
3212  }
3213  }
3214 }
3215 
3216 
3217 static void xml_TaskParameter(bool assign_function, _UNUSED_ entity function, int statnb, bool is_not_main_p, entity var, Pvecteur formal_parameters, list pattern_region, Pvecteur paving_indices, string_buffer sb_result, string_buffer buffer_assign)
3218 {
3219  bool effet_read = true;
3220  region rwr = region_undefined;
3221  region rre = region_undefined;
3222  const char* datatype ="";
3223  int size=0, rw_ef=0, prems=0;
3225  region reg = region_undefined;
3227  list pc = list_undefined;
3228  bool pavp=true, RW_effet=false;
3229 
3230  // rappel : les regions contiennent les effects sur les scalaires
3231  // - Pour les fonctions, on ecrit les parametres formels dans l'ordre.
3232  // - Pour le MAIN, ordre des regions:
3233  if (assign_function){
3234  reg = REGION(CAR(pattern_region));
3235  ref = effect_any_reference(reg);
3236  v = reference_variable(ref);
3237  pavp = true;
3238  effet_read = region_read_p(reg);
3239  rw_ef=(!effet_read)?2:1;
3240  }
3241  else {
3242  if (!is_not_main_p) {
3243  reg = REGION(CAR(pattern_region));
3244  ref = effect_any_reference(reg);
3245  v = reference_variable(ref);
3246  pavp =(vect_coeff(v,paving_indices) == 0);
3247  effet_read = region_read_p(reg);
3248  }
3249  else { // c'est une fonction --> impression selon l'ordre des parametres formels
3250  // recherche des regions du parametre formel
3251  rw_ef= find_effect_actions_for_entity(pattern_region,&rre, &rwr,var);
3252  // choix de l'affichage des regions write en premier lorsque R&W existent
3253  if (rwr != region_undefined)
3254  reg=rwr, effet_read=false;
3255  else reg= rre, effet_read=true;
3256  if (reg != region_undefined) {
3257  ref = effect_any_reference(reg);
3258  v = reference_variable(ref);
3259  }
3260  else // cas ou il n'y a pas d'effet sur le parametre formel,
3261  // mais il fait partie de la liste des parametres de la fonction
3262  v = var, effet_read = true;
3263 
3264  // La liste des effects de la fonction a ete completee dans le TaskParameters
3265  // On recherche le premier effect sur la variable pour en deduire l'info Use OU Def dans la fonction
3266  if((rw_ef>=3) && (int)gen_length(cumulated_list) >0) {
3267  for (pc= cumulated_list;pc != NIL && prems ==0; pc = CDR(pc)){
3268  effect e = EFFECT(CAR(pc));
3271  prems=(effect_read_p(e)) ? 1:2;
3272  }
3273  }
3274  // printf("DEBUG - DEF_USE detection %s \n",(prems)? ((prems==1)?"USE":"DEF"):"Erreur pas d'effets sur cette variable");
3275  }
3276  }
3277  }
3278 
3279  RW_effet=((!is_not_main_p || assign_function) && !effet_read) || (is_not_main_p && (rw_ef==2 || prems==2));
3280  if (pavp) {
3281  type_and_size_of_var(v, &datatype,&size);
3282 
3283  if (assign_function && RW_effet && same_entity_p(var,v)) {
3284  add_margin(global_margin,buffer_assign);
3285  string_buffer_append(buffer_assign,
3287  "AssignParameter"," Name=",
3288  QUOTE, NULL));
3289  string_buffer_append_xml_text(buffer_assign,
3290  (string) ((print_full_name_p() || reference_undefined_p(ref)) ?
3292  false);
3293  string_buffer_append(buffer_assign,
3294  concatenate(QUOTE, BL,
3295  "Type=", QUOTE,(entity_xml_parameter_p(v))? "CONTROL":"DATA",QUOTE,BL,
3296  "DataType=",QUOTE,datatype,QUOTE,BL,
3297  "AccessMode=", QUOTE, RW_effet ? "DEF":"USE",QUOTE,BL,
3298  "ArrayP=", QUOTE, (array_entity_p(v))?"TRUE":"FALSE",QUOTE, BL,
3299  "Kind=", QUOTE, "VARIABLE",QUOTE,
3300  CLOSEANGLE,
3301  NL, NULL));
3302 
3303  global_margin++;
3304  xml_Pattern_Paving(reg,v, effet_read, formal_parameters,
3305  paving_indices, buffer_assign);
3306  if (rw_ef>=3)
3307  xml_Pattern_Paving(rre,v, true, formal_parameters,
3308  paving_indices, buffer_assign);
3309  global_margin--;
3310  string_buffer_append_word("/AssignParameter",buffer_assign);
3311 
3312  }
3313  else {
3314  add_margin(global_margin,sb_result);
3315  string_buffer_append(sb_result,
3317  "TaskParameter",
3318  // " Name=", QUOTE,entity_user_name(v),QUOTE, BL,
3319  " Name=", QUOTE, NULL));
3320  // For the task/function parameter, only one region is taken to represent all the struct fields if any.
3322  (string) ((print_full_name_p() || reference_undefined_p(ref) || is_not_main_p)?
3324  false);
3325  string_buffer_append(sb_result,
3326  concatenate(QUOTE, BL,
3327  "Type=", QUOTE,(entity_xml_parameter_p(v))? "CONTROL":"DATA",QUOTE,BL,
3328  "DataType=",QUOTE,datatype,QUOTE,BL,
3329  "AccessMode=", QUOTE, RW_effet ? "DEF":"USE",QUOTE,BL,
3330  "ArrayP=", QUOTE, (array_entity_p(v))?"TRUE":"FALSE",QUOTE, BL,
3331  "Kind=", QUOTE, "VARIABLE",QUOTE,
3332  CLOSEANGLE,
3333  NL, NULL));
3334  xml_ParameterUseToArrayBound(var,sb_result);
3335  global_margin++;
3336  xml_Pattern_Paving(reg,v, effet_read, formal_parameters,
3337  paving_indices, sb_result);
3338  if (rw_ef>=3)
3339  xml_Pattern_Paving(rre,v, true, formal_parameters,
3340  paving_indices, sb_result);
3341  global_margin--;
3342  string_buffer_append_word("/TaskParameter",sb_result);
3343  }
3344  if (assign_function && rw_ef>=2 && statnb>0) {
3345  Pcallst cst1=(callst *) malloc(sizeof(callst));
3348  entity_domain);
3349  cst1->func = assign_ent;
3350  cst1->stat_nb= statnb;
3351  cst1->succ = (Pcallst)NULL;
3352  update_def_into_tasks_table(v ,cst1);
3353  }
3354  }
3355 }
3356 
3359  if (!ENDP(l) && !list_undefined_p(l)) {
3361 
3362  for (list pc = l; pc != NIL; pc = CDR(pc)) {
3363  effect e = EFFECT(CAR(pc));
3365  action ac = effect_action(e);
3366  entity v = reference_variable(r);
3367  if (store_effect_p(e)
3368  && !effects_package_entity_p(v) && !std_file_entity_p(v) //&& !variable_heap_p(v)
3369  && action_write_p(ac) &&
3371  {
3372  Pcallst cst1 = (callst *)malloc(sizeof(callst));
3373  cst1->func = entity_undefined;
3374  cst1->stat_nb = statement_number(s);
3375  cst1->succ = (Pcallst)NULL;
3376  add_def_into_tasks_table(v, cst1);
3377  }
3378  }
3379  }
3380  }
3381 }
3382 
3384 {
3386  if (!ENDP(l) && !list_undefined_p(l))
3388 
3389 }
3390 
3391 static void xml_TaskParameters(statement stat, bool assign_function, int code_tag, entity module, list pattern_region, Pvecteur paving_indices, string_buffer sb_result)
3392 {
3393  string_buffer buffer_assign = string_buffer_make(true);
3394  string string_temp = "";
3395  list lr=NIL;
3396  call c=call_undefined;
3397  int ith;
3398  entity FormalName = entity_undefined;
3399  Pvecteur formal_parameters = VECTEUR_NUL;
3400  int FormalParameterNumber = (int) gen_length(module_formal_parameters(module));
3401 
3402  string_buffer_append_word("TaskParameters",sb_result);
3403  global_margin++;
3404 
3405  if (assign_function){
3408  }
3409  else {
3412  c =encapsulated_call;
3413  }
3414  if (c==call_undefined)
3415  pips_internal_error("Unexpected call in statement number %d \n",(int) statement_number(stat));
3416 
3417  expression lhs_exp=EXPRESSION(CAR(call_arguments(c)));
3418  syntax lhs_syn= expression_syntax(lhs_exp);
3419  if (syntax_reference_p(lhs_syn))
3420  FormalName = reference_variable(syntax_reference(lhs_syn));
3421  else FormalName = entity_undefined;
3422 
3423  for (lr = pattern_region; !ENDP(lr); lr = CDR(lr)) {
3424  effect efs = REGION(CAR(lr));
3425  reference rs = effect_any_reference(efs);
3426  entity vs = reference_variable(rs);
3427 
3428  if (store_effect_p(efs) &&
3430  xml_TaskParameter(assign_function,module, statement_number(stat),false,FormalName,
3431  formal_parameters,lr,paving_indices,sb_result, buffer_assign);
3432  }
3433  }
3434  else {
3435  // Formal parameters list
3436  for (ith=1;ith<=FormalParameterNumber;ith++) {
3437  FormalName = find_ith_formal_parameter(module,ith);
3438  vect_add_elem (&formal_parameters,(Variable) FormalName,VALUE_ONE);
3439  }
3440 
3441  if (code_tag != code_is_a_main) {
3442  // Formal parameters of functions are printed in the function argument order
3443  for (ith=1;ith<=FormalParameterNumber;ith++) {
3444  FormalName = find_ith_formal_parameter(module,ith);
3445 
3446  xml_TaskParameter(assign_function,module, statement_number(stat),true,FormalName,
3447  formal_parameters,pattern_region,paving_indices,sb_result, buffer_assign);
3448  }
3449  }
3450  else {
3451  for (lr = pattern_region; !ENDP(lr); lr = CDR(lr)) {
3452  if (store_effect_p(REGION(CAR(lr))))
3453  xml_TaskParameter(assign_function,module, statement_number(stat), false,FormalName,
3454  formal_parameters,lr,paving_indices,sb_result, buffer_assign);
3455  }
3456  }
3458  }
3459 
3460  if (assign_function && !string_buffer_empty_p(buffer_assign)) {
3461  string_temp =string_buffer_to_string(buffer_assign);
3462  string_buffer_append(sb_result,string_temp);
3463  }
3464  string_temp=NULL;
3465  global_margin--;
3466  string_buffer_append_word("/TaskParameters",sb_result);
3467 }
3468 
3470  expression exp, transformer ps, int *val, int *min, int *max)
3471 {
3472  bool result=true;
3473  *val = 0;
3474  *min=0;
3475  *max=0;
3476  /* printf("Eval expression :\n");
3477  print_expression(exp);
3478  Psysteme prec = sc_dup((Psysteme) predicate_system(transformer_relation(ps)));
3479  printf("In context :\n");
3480  sc_print(prec, (get_variable_name_t) entity_local_name);
3481  */
3482 
3483  if (!transformer_undefined_p(ps) && transformer_is_rn_p(ps)) {
3484  *min=INT_MIN,*max =INT_MAX;
3485  return(false);
3486  }
3487 
3488  // Should be part of semantics/utils.c FI
3492  if (integer_type_p(et)) {
3494  // DEBUG - printf("Min = %d, Max = %d \n", *min,*max);
3495  }
3496  else result = false;
3497  free_transformer(psr);
3499  if (*max<*min) {
3500  *min=INT_MIN,*max =INT_MAX;
3501  result= false;
3502  }
3503  else if (*max==*min && result) {
3504  *val = *min;
3505  }
3506  return (result);
3507 }
3508 
3509 /* UNUSED
3510 static bool eval_linear_expression2(
3511  expression exp, Psysteme ps, int *val, int *min, int *max)
3512 {
3513  normalized norm= normalized_undefined;
3514  Pvecteur vexp,pv;
3515  bool result = true,result_exact = true,min_exact=true,max_exact=true;
3516  *val = 0;
3517  *min=0;
3518  *max=0;
3519 
3520  // fprintf(stdout,"Expression a evaluer : %s",words_to_string(words_expression(exp,NIL)));
3521 
3522  if (expression_normalized(exp) == normalized_undefined)
3523  expression_normalized(exp)= NormalizeExpression(exp);
3524  norm = expression_normalized(exp);
3525  if (normalized_linear_p(norm) && !SC_UNDEFINED_P(ps)) {
3526  vexp = (Pvecteur)normalized_linear(norm);
3527  for (pv= vexp; pv != VECTEUR_NUL; pv=pv->succ) {
3528  Variable v = var_of(pv);
3529  if (v==TCST) {
3530  *val += vect_coeff(TCST,vexp);
3531  *min += vect_coeff(TCST,vexp);
3532  *max += vect_coeff(TCST,vexp);
3533  }
3534  else {
3535  if(base_contains_variable_p(sc_base(ps), v)) {
3536  Value min1, max1;
3537  Psysteme ps1 = sc_dup(ps);
3538  bool feasible = sc_minmax_of_variable2(ps1, (Variable)v, &min1, &max1);
3539  if (feasible) {
3540  if (value_eq(min1,max1)) {
3541  *val += vect_coeff(v,vexp) *min1;
3542  *min+= vect_coeff(v,vexp) *min1;
3543  *max+= vect_coeff(v,vexp) *max1;
3544  }
3545  else {
3546  result_exact=false;
3547  bool pb = (vect_coeff(v,vexp)>0);
3548  if (pb) {
3549  if (*min!=INT_MIN && min1!=INT_MIN && min1!=VALUE_MIN)
3550  *min+= vect_coeff(v,vexp) *min1;
3551  else min_exact=false;
3552  if (*max!=INT_MAX && max1!=INT_MAX && max1!=VALUE_MAX)
3553  *max+= vect_coeff(v,vexp) *max1;
3554  else max_exact=false;
3555  }
3556  else {
3557  if (*max!=INT_MIN && min1!=INT_MIN && min1!=VALUE_MIN)
3558  *max+= vect_coeff(v,vexp) *min1;
3559  else max_exact=false;
3560  if (*min!=INT_MAX && max1!=INT_MAX && max1!=VALUE_MAX)
3561  *min+= vect_coeff(v,vexp) *max1;
3562  else min_exact=false;
3563  }
3564  }
3565  }
3566  else // fprintf(stdout,"le systeme est non faisable\n");
3567  result = false,min_exact=false,max_exact=false;
3568  } // sc_free(ps1); le systeme est desalloue par sc_minmax_of_variable
3569  else
3570  result = false,min_exact=false,max_exact=false;
3571  }
3572  }
3573  }
3574  else // fprintf(stdout,"Ce n'est pas une expression lineaire\n");
3575  result = false,min_exact=false,max_exact=false;
3576  if (!result) *min=INT_MIN,*max =INT_MAX;
3577  if (!min_exact) *min=INT_MIN;
3578  if (!max_exact) *max=INT_MAX;
3579  if (!result_exact) result=false;
3580  //fprintf(stdout,"Valeur trouvee : %d \n",*val);
3581  return result;
3582 }
3583 */
3584 
3585 static void xml_Bounds(expression elow, expression eup, transformer t,
3586  _UNUSED_ Psysteme prec, bool formal_p, string_buffer sb_result) {
3587  intptr_t low, up;
3588  int valr = 0;
3589  int min = 0, max = 0;
3590  bool tb = true;
3591  /* Print XML Array LOWER BOUND */
3592  string_buffer_append_word("LowerBound", sb_result);
3593  global_margin++;
3595  if (expression_integer_value(elow, &low))
3596  string_buffer_append_numeric(int2a(low), sb_result);
3597  else if (!formal_p && (tb = eval_linear_expression(elow, t, &valr, &min, &max)) == true) {
3598  if (valr == min && valr == max)
3599  string_buffer_append_numeric(int2a(valr), sb_result);
3600  else {
3601  if (min != INT_MIN) {
3602  add_margin(global_margin, sb_result);
3603  string_buffer_append(sb_result,
3605  "MinNumeric", CLOSEANGLE, int2a(min), OPENANGLE,
3606  "/MinNumeric",
3607  CLOSEANGLE, NL, NULL));
3608  }
3609  if (max != INT_MAX) {
3610  add_margin(global_margin, sb_result);
3611  string_buffer_append(sb_result,
3613  "MaxNumeric", CLOSEANGLE, int2a(max), OPENANGLE,
3614  "/MaxNumeric",
3615  CLOSEANGLE, NL, NULL));
3616  }
3617  }
3618  }
3619  global_margin--;
3620  string_buffer_append_word("/LowerBound", sb_result);
3621 
3622  /* Print XML Array UPPER BOUND */
3623  string_buffer_append_word("UpperBound", sb_result);
3624  global_margin++;
3626  if (expression_integer_value(eup, &up))
3627  string_buffer_append_numeric(int2a(up), sb_result);
3628  else if (!formal_p && (tb = eval_linear_expression(eup, t, &valr, &min, &max)) == true) {
3629  if (valr == min && valr == max)
3630  string_buffer_append_numeric(int2a(valr), sb_result);
3631  else {
3632  if (min != INT_MIN) {
3633  add_margin(global_margin, sb_result);
3634  string_buffer_append(sb_result,
3636  "MinNumeric", CLOSEANGLE, int2a(min), OPENANGLE,
3637  "/MinNumeric",
3638  CLOSEANGLE, NL, NULL));
3639  }
3640  if (max != INT_MAX) {
3641  add_margin(global_margin, sb_result);
3642  string_buffer_append(sb_result,
3644  "MaxNumeric", CLOSEANGLE, int2a(max), OPENANGLE,
3645  "/MaxNumeric",
3646  CLOSEANGLE, NL, NULL));
3647  }
3648  }
3649  }
3650  global_margin--;
3651  string_buffer_append_word("/UpperBound", sb_result);
3652 }
3654  transformer t, Psysteme prec, bool formal_p, string_buffer sb_result)
3655 {
3656  intptr_t inc;
3657  int valr =0,min=0,max=0;
3658  xml_Bounds(elow, eup,t,prec,formal_p, sb_result);
3659  string_buffer_append_word("Stride",sb_result);
3660  global_margin++;
3662  sb_result);
3663  if (expression_integer_value(stride, &inc))
3664  string_buffer_append_numeric(int2a(inc),sb_result);
3665  else if (eval_linear_expression(stride,t,&valr,&min,&max)) {
3666  if (valr==min && valr==max)
3667  string_buffer_append_numeric(int2a(valr),sb_result);
3668  }
3669  global_margin--;
3670  string_buffer_append_word("/Stride",sb_result);
3671 
3672 }
3673 
3675 {
3676  string comm = statement_comments(s);
3677  string result = NULL;
3678 
3679  if (!string_undefined_p(comm)
3680  && (result=strstr(comm,array_mem_string))!=NULL)
3681  array_location_string = result;
3682 }
3683 
3684 static string memory_location_for_array_p(const char* sa)
3685 {
3687  string result=NULL;
3688  int n=0;
3689 
3690  array_location_string = NULL;
3691  array_mem_string = (char *)malloc(strlen(sa)+5+1);
3692  (void) strcpy(array_mem_string, sa);
3693  (void) strcat(array_mem_string,MEM_PREFIX);
3695  if (array_location_string != NULL) {
3696  n= strcspn(array_location_string+strlen(sa)+5,":\n");
3697  result=(char *)malloc(n+1);
3698  strncpy(result,array_location_string+strlen(sa)+5,n);
3699  result[n]=(char) 0;
3700  }
3702  return (result);
3703 }
3704 
3705 
3706 static void xml_Array(entity var,transformer t,Psysteme prec, bool formal_p, string_buffer sb_result)
3707 {
3708  const char* datatype ="";
3710  int i,j, size =0;
3711  int nb_dim = (int) gen_length(ldim);
3712  char* layout_up[nb_dim];
3713  char *layout_low[nb_dim];
3714  int no_dim=0;
3715 
3716  string spec_location = memory_location_for_array_p(entity_user_name(var));
3717 
3718  add_margin(global_margin,sb_result);
3719  string_buffer_append(sb_result,
3720  concatenate(OPENANGLE, "Array Name=",QUOTE,NULL));
3721  string_buffer_append_xml_text(sb_result,(string) entity_user_name(var),false);
3722  string_buffer_append(sb_result,
3723  concatenate(QUOTE, BL,
3724  "Type=", QUOTE,(entity_xml_parameter_p(var))? "CONTROL":"DATA",QUOTE,BL,
3725  "Allocation=", QUOTE,
3726  (heap_area_p(var) || stack_area_p(var)) ? "DYNAMIC": "STATIC", QUOTE,BL,
3727  "Kind=", QUOTE, "VARIABLE",QUOTE,
3728  CLOSEANGLE,NL, NULL));
3729 
3730  /* Print XML Array DATA TYPE and DATA SIZE */
3731  type_and_size_of_var(var, &datatype,&size);
3732  add_margin(global_margin,sb_result);
3733  string_buffer_append(sb_result,
3735  "DataType Type=",QUOTE,datatype,QUOTE, BL,
3736  "Size=",QUOTE, int2a(size), QUOTE, "/"
3737  CLOSEANGLE,NL,NULL));
3738  /* Print XML Array Memory Location */
3739  if (spec_location!=NULL) {
3740  add_margin(global_margin,sb_result);
3741  string_buffer_append(sb_result,
3743  "ArrayLocation",CLOSEANGLE, spec_location,OPENANGLE,
3744  "/ArrayLocation",CLOSEANGLE,
3745  NL, NULL));
3746  }
3747  /* Print XML Array DIMENSION */
3748 
3749  if((int) gen_length(ldim) >0) {
3750  string_buffer_append_word("Dimensions",sb_result);
3751 
3752  for (ld = ldim ; !ENDP(ld); ld = CDR(ld)) {
3753  expression elow = dimension_lower(DIMENSION(CAR(ld)));
3755  global_margin++;
3756  string_buffer_append_word("Dimension",sb_result);
3757  /* Print XML Array Bound */
3758  global_margin++;
3759  xml_Bounds(elow,eup,t,prec, formal_p, sb_result);
3760  global_margin--;
3761  string_buffer_append_word("/Dimension",sb_result);
3762  global_margin--;
3763  layout_low[no_dim] = expression_to_string(elow);
3764  layout_up[no_dim] = expression_to_string(eup);
3765  no_dim++;
3766  }
3767  }
3768 
3769  string_buffer_append_word("/Dimensions",sb_result);
3770 
3771  /* Print XML Array LAYOUT */
3772  string_buffer_append_word("Layout",sb_result);
3773  global_margin++;
3774  for (i =0; i<= no_dim-1; i++) {
3775  string_buffer_append_word("DimLayout",sb_result);
3776  global_margin++;
3777  string_buffer_append_word("Symbolic",sb_result);
3778  if (i==no_dim-1) {
3779  add_margin(global_margin,sb_result);
3780  string_buffer_append(sb_result,concatenate("1",NL,NULL));
3781  }
3782  else {
3783  add_margin(global_margin,sb_result);
3784  for (j=no_dim-1; j>=i+1; j--)
3785  {
3786  if (strcmp(layout_low[j],"0")==0)
3787  string_buffer_append(sb_result,
3788  concatenate("(",layout_up[j],"+1)",NULL));
3789  else
3790  string_buffer_append(sb_result,
3791  concatenate("(",layout_up[j],"-",
3792  layout_low[j],"+1)",NULL));
3793  if (j==i+1)
3794  string_buffer_append(sb_result,NL);
3795  }
3796  }
3797  string_buffer_append_word("/Symbolic",sb_result);
3798  global_margin--;
3799  string_buffer_append_word("/DimLayout",sb_result);
3800  }
3801  global_margin--;
3802  string_buffer_append_word("/Layout",sb_result);
3803  string_buffer_append_word("/Array",sb_result);
3804 }
3805 
3806 static void xml_Scalar(entity var, _UNUSED_ Psysteme prec,string_buffer sb_result)
3807 {
3808  const char* datatype ="";
3809  int size =0;
3810 
3811  add_margin(global_margin,sb_result);
3812  string_buffer_append(sb_result,
3813  concatenate(OPENANGLE, "Scalar Name=", QUOTE,NULL));
3814  string_buffer_append_xml_text(sb_result, (string) entity_user_name(var),false);
3815  string_buffer_append(sb_result,
3816  concatenate(QUOTE, BL,
3817  "Type=", QUOTE,(entity_xml_parameter_p(var))? "CONTROL":"DATA",QUOTE,BL,
3818  "Allocation=", QUOTE,
3819  (heap_area_p(var) || stack_area_p(var)) ? "DYNAMIC": "STATIC", QUOTE,BL,
3820  "Kind=", QUOTE,"VARIABLE",QUOTE, NULL));
3821  /* Print XML Array DATA TYPE and DATA SIZE */
3822  type_and_size_of_var(var, &datatype,&size);
3823  //add_margin(global_margin,sb_result);
3824  string_buffer_append(sb_result,
3825  concatenate(BL,
3826  "DataType=",QUOTE,datatype,QUOTE, BL,
3827  "Size=",QUOTE, int2a(size), QUOTE, "/"
3828  CLOSEANGLE,NL,NULL));
3829 }
3830 
3831 static void xml_GlobalVariables(transformer t,Psysteme prec, bool printp, string_buffer sb_result)
3832 {
3833  list ldecl;
3834  int nb_dim=0;
3835 
3836  Pvecteur v_already_seen=VECTEUR_NUL;
3838  cumulated_list = NIL;
3840 
3841  ldecl = statement_declarations(s);
3842  MAP(ENTITY,var, {
3843  vect_add_elem(&v_already_seen,var,1);
3844  },ldecl);
3845  if((int) gen_length( cumulated_list) >0) {
3846  string_buffer_append_word("GlobalVariables",sb_result);
3847  global_margin++;
3848  MAP(EFFECT,ef, {
3853  && (storage_ram_p(entity_storage(v)))
3854  && top_level_entity_p(v)
3856  && !vect_coeff(v,v_already_seen)) {
3857  vect_add_elem(&v_already_seen,v,1);
3858  if (printp) {
3859  if ((nb_dim = variable_entity_dimension(v))>0)
3860  xml_Array(v,t,prec,false,sb_result);
3861  else xml_Scalar(v,prec,sb_result);
3862  }
3863  }
3864  }, cumulated_list);
3865  global_application_variables=vect_copy(v_already_seen);
3866  vect_rm(v_already_seen);
3867  global_margin--;
3868  string_buffer_append_word("/GlobalVariables",sb_result);
3869  }
3870  else
3871  string_buffer_append_word("GlobalVariables/",sb_result);
3872 }
3873 
3875 {
3876  list ls;
3877  if (declaration_statement_p(s)) {
3878  ls=statement_declarations(s);
3880  }
3881 }
3883 {
3884  list ldecl;
3885  int nb_dim=0;
3886  Pvecteur pv_dec= vect_new(TCST,1);
3888  if (fortran_appli)
3890  else
3891  ldecl = statement_declarations(s);
3892 
3893  if((int) gen_length(ldecl) >0) {
3894  string_buffer_append_word("LocalVariables",sb_result);
3895  global_margin++;
3896  MAP(ENTITY,var, {
3897  if (type_variable_p(entity_type(var))
3898  //&& ((nb_dim = variable_entity_dimension(var))>0)
3899  && !(storage_formal_p(entity_storage(var)))) {
3900  if ((nb_dim = variable_entity_dimension(var))>0)
3901  xml_Array(var,t, prec,false,sb_result);
3902  else xml_Scalar(var,prec,sb_result);
3903  vect_add_elem(&pv_dec,(Variable)var,1);
3904  }
3905  },ldecl);
3908  // printf("list tableaux locaux pour module %s\n",entity_user_name(module));
3909  // MAP(ENTITY,var, {
3910  // printf("Entity = %s\n",entity_user_name(var));
3911  // },local_declaration_list);
3912 
3913  MAP(ENTITY,var, {
3914  if (type_variable_p(entity_type(var))
3915  // && (variable_entity_dimension(var)>0)
3916  && !(storage_formal_p(entity_storage(var)))
3917  && !vect_coeff(var,pv_dec)) {
3918  if ((nb_dim = variable_entity_dimension(var))>0)
3919  xml_Array(var,t, prec,false,sb_result);
3920  else xml_Scalar(var,prec,sb_result);
3921  vect_add_elem(&pv_dec,(Variable)var,1);
3922  }
3924 
3925  global_margin--;
3926  string_buffer_append_word("/LocalVariables",sb_result);
3928  }
3929  else
3930  string_buffer_append_word("LocalVariables/",sb_result);
3931  vect_rm(pv_dec);
3932 }
3933 
3935 {
3936  // gen_length(functional_results(type_functional(entity_type(module))))
3937  int FormalParameterNumber = (int) gen_length(module_formal_parameters(module));
3938  entity FormalArrayName = entity_undefined;
3939  int ith ;
3940  if(FormalParameterNumber >=1) {
3941  string_buffer_append_word("FormalVariables",sb_result);
3942  global_margin++;
3943 
3944  for (ith=1;ith<=FormalParameterNumber;ith++) {
3945  FormalArrayName = find_ith_formal_parameter(module,ith);
3946  if (type_variable_p(entity_type(FormalArrayName))
3947  && (storage_formal_p(entity_storage(FormalArrayName)))) {
3948  if (variable_entity_dimension(FormalArrayName)>0)
3949  xml_Array(FormalArrayName,t, prec, true, sb_result);
3950  else xml_Scalar(FormalArrayName,prec,sb_result);
3951  }
3952  }
3953  global_margin--;
3954  string_buffer_append_word("/FormalVariables",sb_result);
3955  }
3956  else string_buffer_append_word("FormalVariables/",sb_result);
3957 }
3958 
3960 {
3962  list exl=extensions_extension(es);
3963  string name="MOTIF";
3964  bool result=false;
3965  FOREACH(EXTENSION, ex, exl){
3966  if (extension_pragma_p(ex)) {
3967  pragma p = extension_pragma(ex);
3968  if(pragma_string_p(p)) {
3969  if(same_string_p(pragma_string(p),name))
3970  result= true;
3971  }
3972  }
3973  }
3974  return result;
3975 }
3976 
3978 {
3979  if (pragma_motif_p(s)) motif_in_statement_p= true;
3980 }
3981 /* currently unused
3982  static void motif_in_statement2(statement s)
3983  {
3984  string comm = statement_comments(s);
3985  if (!string_undefined_p(comm) && strstr(comm,"MOTIF")!=NULL)
3986  motif_in_statement_p= true;
3987  }
3988 */
3990 {
3991  string comm = statement_comments(s);
3992  if (!string_undefined_p(comm) && strstr(comm,"BOX")!=NULL)
3993  box_in_statement_p= true;
3994 }
3995 
3997 {
3998  const char * comm = entity_user_name(e);
3999  if (!string_undefined_p(comm) && strstr(comm,"\"")!=NULL)
4000  return (true);
4001  else return (false);
4002 }
4003 
4004 static void xml_Loop(statement s, string_buffer sb_result)
4005 {
4011  expression stride = range_increment(loop_range(l));
4012  entity index =loop_index(l);
4013 
4015  add_margin(global_margin,sb_result);
4016  string_buffer_append(sb_result,
4018  "Loop Index=",QUOTE, NULL));
4019  string_buffer_append_xml_text(sb_result, (string) entity_user_name(index),false);
4020  string_buffer_append(sb_result,
4021  concatenate(QUOTE, BL,
4022  "ExecutionMode=",QUOTE,
4023  (execution_parallel_p(loop_execution(l)))? "PARALLEL":"SEQUENTIAL", QUOTE,
4024  CLOSEANGLE,NL,NULL));
4025  xml_Bounds_and_Stride(el,eu,stride,t,prec, false,sb_result);
4026  string_buffer_append_word("/Loop",sb_result);
4028  sc_free(prec);
4029 }
4030 
4031 static void xml_Loops(stack st,bool call_external_loop_p, list *pattern_region, Pvecteur *paving_indices, Pvecteur *pattern_indices, bool motif_in_te_p, string_buffer sb_result)
4032 {
4033  bool in_motif_p=!call_external_loop_p && !motif_in_te_p;
4034  bool motif_on_loop_p=false;
4035  // Boucles externes a la TE
4036  if (call_external_loop_p)
4037  string_buffer_append_word("ExternalLoops",sb_result);
4038  else
4039  // Boucles externes au motif dans la TE
4040  string_buffer_append_word("Loops",sb_result);
4041 
4042  // if comment MOTIF is on the loop, the pattern_region is the loop region
4043  // if comment MOTIF is on a statement inside the sequence of the loop body
4044  // the cumulated regions of the loop body are taken
4045  // if comment MOTIF is outside the loop nest, the pattern_region is the call region
4046  global_margin++;
4047  if (st != STACK_NULL) {
4049  {
4051  //string comm = statement_comments(s);
4052  entity index =loop_index(l);
4054  if (!in_motif_p) {
4055  // Test : Motif is in the loop body or not
4056  motif_in_statement_p=false;
4058  //motif_on_loop_p = !string_undefined_p(comm) && strstr(comm,"MOTIF")!=NULL;
4059  motif_on_loop_p = pragma_motif_p(s);
4060 
4061  if (motif_on_loop_p) { // comment MOTIF is on the Loop
4062  *pattern_region = regions_dup(load_statement_local_regions(s));
4064  }
4065  else if (motif_in_statement_p) {
4066  // cumulated regions on the sequence of the loop body instructions are needed
4067  *pattern_region = regions_dup(load_statement_local_regions(loop_body(l)));
4068  }
4069  in_motif_p = (!call_external_loop_p && !motif_in_te_p) //Par default on englobe si TE
4070  || in_motif_p // on etait deja dans le motif
4071  || motif_on_loop_p // on vient de trouver un Motif sur la boucle
4072  || (motif_in_te_p && !motif_on_loop_p && !motif_in_statement_p);
4073  // motif externe au nid de boucles (cas des motif au milieu d'une sequence)
4074  }
4075  if (!in_motif_p) {
4076  vect_add_elem (paving_indices,(Variable) index ,VALUE_ONE);
4077  xml_Loop(s, sb_result);
4078  }
4079  (void) pop_statement_global_stack();
4080  },
4081  st, 0);
4082  }
4083  global_margin--;
4084  if (call_external_loop_p)
4085  string_buffer_append_word("/ExternalLoops",sb_result);
4086  else
4087  string_buffer_append_word("/Loops",sb_result);
4088 }
4089 
4091 {
4094  instruction inst = statement_instruction(st1);
4096  *ps= SC_UNDEFINED;
4097  switch instruction_tag(inst)
4098  {
4101  if (sts !=NULL)
4102  fst = STATEMENT(CAR(sts));
4103  break;
4104  }
4105 
4106  default:
4107  fst = st1;
4108  }
4109  if ( fst!= statement_undefined) {
4112  }
4113  return t;
4114 }
4115 
4116 // ??? reset? zero?
4117 static void matrix_init(Pmatrix mat, int n, int m)
4118 {
4119  int i,j;
4120  for (i=1;i<=n;i++) {
4121  for (j=1;j<=m;j++) {
4122  MATRIX_ELEM(mat,i,j)=0;
4123  }
4124  }
4125 }
4126 
4127 static void xml_Matrix(Pmatrix mat, int n, int m, string_buffer sb_result)
4128 {
4129  string srow, scolumn;
4130  int i,j;
4131  // cas des nids de boucles vides
4132  if (n==0 && m!=0) m=0;
4133  if (m==0 && n!=0) n=0;
4134  srow =strdup(i2a(n));
4135  scolumn=strdup(i2a(m));
4136 
4137  add_margin(global_margin,sb_result);
4138  string_buffer_append(sb_result,
4140  "Matrix NbRows=", QUOTE,srow,QUOTE,BL,
4141  "NbColumns=", QUOTE, scolumn,QUOTE, BL,
4142  CLOSEANGLE,NL, NULL));
4143  for (i=1;i<=n;i++) {
4144  add_margin(global_margin,sb_result);
4145  string_buffer_append(sb_result,
4147  "Row", CLOSEANGLE,BL, NULL));
4148  for (j=1;j<=m;j++) {
4149  string_buffer_append(sb_result,
4151  i2a(MATRIX_ELEM(mat,i,j)),
4152  OPENANGLE, "/c", CLOSEANGLE,
4153  BL, NULL));
4154  }
4155  string_buffer_append(sb_result,
4157  "/Row", CLOSEANGLE, NL, NULL));
4158  }
4159  string_buffer_append_word("/Matrix",sb_result);
4160 }
4161 
4162 static int int_compare(void const *a, void const *b)
4163 {
4164  int const*pa=a;
4165  int const*pb=b;
4166  return(*pb-*pa);
4167 }
4168 
4169 static void tri_abc(int a[12], int dim, int result[12])
4170 {
4171  int a_copy[12];
4172  int i;
4173  memcpy(a_copy,a,(2*dim+1)*sizeof(int));
4174  qsort(&a_copy[1],dim,sizeof(int), int_compare);
4175  qsort(&a_copy[1+dim],dim,sizeof(int), int_compare);
4176  for (int k=0;k<=1;k++)
4177  for ( i=1; i<=dim; i++) {
4178  for (int j=1; j<=dim; j++)
4179  if (a_copy[i+dim*k]==a[j+dim*k])
4180  result[i+dim*k]=j;
4181  }
4182 }
4183 
4184 
4186 {
4187  MATRIX_ELEM(mat,1,1)=0;
4188  MATRIX_ELEM(mat,1,2)=1;
4189  MATRIX_ELEM(mat,2,1)=1;
4190  MATRIX_ELEM(mat,2,2)=0;
4191 }
4192 
4194  Pmatrix mat
4195  ,int a[12], int ArrayDim1, _UNUSED_ int ArrayDim2)
4196 {
4197 
4198  int i,j,n;
4199  int result[]={0,0,0,0,0,0,0,0,0,0,0,0};
4200  tri_abc(a,ArrayDim1,result);
4201  for (i=1; i<= ArrayDim1; i++) {
4202  n = result[i+ArrayDim1];
4203  for (j=1;j<=ArrayDim1;j++) {
4204  if (result[j]==n)
4205  MATRIX_ELEM(mat,i,j)=1;
4206  }
4207  }
4208 }
4209 
4211 {
4212  expression exp1=exp;
4215  return exp1;
4216 }
4217 
4219 {
4220  expression exp1=exp;
4221  if (expression_field_p(exp))
4223  if (syntax_cast_p(expression_syntax(exp1)))
4225  return exp1;
4226 }
4227 
4229 {
4230  expression exp1=exp;
4233  if (syntax_call_p(expression_syntax(exp1))) {
4234  call cl = syntax_call(expression_syntax(exp1));
4235  const char *fun = entity_local_name(call_function(cl));
4236  if (strcmp(fun, ADDRESS_OF_OPERATOR_NAME) == 0) {
4237  exp1 = EXPRESSION(CAR(call_arguments(cl)));
4238  }
4239  }
4240  return exp1;
4241 }
4242 
4243 /*
4244 static expression skip_field_and_cast_and_addop_expression(expression exp)
4245 {
4246  expression exp1=exp;
4247  if (expression_field_p(exp))
4248  exp1= EXPRESSION(CAR(call_arguments(expression_call(exp))));
4249  if (syntax_cast_p(expression_syntax(exp1)))
4250  exp1 = cast_expression(syntax_cast(expression_syntax(exp1)));
4251  if (syntax_call_p(expression_syntax(exp1))) {
4252  call cl = syntax_call(expression_syntax(exp1));
4253  const char *fun = entity_local_name(call_function(cl));
4254  if (strcmp(fun, ADDRESS_OF_OPERATOR_NAME) == 0) {
4255  exp1 = EXPRESSION(CAR(call_arguments(cl)));
4256  }
4257  }
4258  return exp1;
4259 }
4260 */
4261 
4262 // Only to deal with Opengpu cornerturns
4263 // version =0 generates the transposition matrix for cornerturn_xd functions
4264 // version =1 generates the transposition matrix for transpose_xd functions
4265 
4266 static void xml_Transposition(statement s, call c,int d,string_buffer sb_result, int version)
4267 {
4268  int tab[]={0,0,0,0,0,0,0,0,0,0,0,0};
4269  int i;
4271  value v;
4272  list args = call_arguments(c);
4273  Pmatrix mat = NULL;
4274 
4275  if ((version==0) && (int) gen_length(args)==3+3*d) {
4276  for (i=1; i<=d; i++) {
4277  arg1= EXPRESSION(CAR(args));
4278  POP(args);
4279  }
4280  for (i=1;i<=2*d;i++){
4281  arg2= EXPRESSION(CAR(args));
4282  v = EvalExpression(arg2);
4284  tab[i] = constant_int(value_constant(v));
4285  }
4286  POP(args);
4287  }
4288  POP(args);
4289  arg1= EXPRESSION(CAR(args));
4290  POP(args);
4291  arg2= EXPRESSION(CAR(args));
4292 
4293  if (d>2 && d<=5) {
4294  mat = matrix_new(d,d);
4297  }
4298  else if (d==2) {
4299  mat = matrix_new(2,2);
4302  }
4303  }
4304  else if ((version==1) && (int) gen_length(args)==3+2*d) {
4305  int j;
4306  mat = matrix_new(d,d);
4308  for (i=1; i<= d; i++) {
4309  arg1= EXPRESSION(CAR(args));
4310  v = EvalExpression(arg1);
4313  if (0<=j && j<=d-1)
4314  MATRIX_ELEM(mat,i,j+1)=1;
4315  }
4316  POP(args);
4317  }
4318  for (i=1; i<= d; i++)
4319  POP(args); // strides
4320  POP(args); // size
4321  arg1= EXPRESSION(CAR(args));
4322  POP(args);
4323  arg2= EXPRESSION(CAR(args));
4324  }
4325  else {
4326  spear_warning(s, "Change the arguments to be consistent with the prototype ",
4327  "The prototype of the function %s is not correct ",
4329  }
4330  // case with array field reference
4331  if (arg1 != expression_undefined && arg2 != expression_undefined) {
4332  arg1 = skip_field_and_cast_expression(arg1);
4333  arg2 = skip_field_and_cast_expression(arg2);
4334  if (array_argument_p(arg1) && array_argument_p(arg2)) {
4337  string_buffer_append_word("Transposition",sb_result);
4338  global_margin++;
4339  add_margin(global_margin,sb_result);
4340  string_buffer_append(sb_result,
4341  concatenate(OPENANGLE,"TransposParameters ", "OUT=", QUOTE,NULL));
4342  string_buffer_append_xml_text(sb_result, (string) entity_user_name(reference_variable(r1)),false);
4343  string_buffer_append(sb_result,
4346  CLOSEANGLE,NL,NULL));
4347  xml_Matrix(mat,mat->number_of_lines,mat->number_of_columns,sb_result);
4348  matrix_free(mat);
4349  global_margin--;
4350  string_buffer_append_word("/Transposition",sb_result);
4351  }
4352  }
4353 }
4354 
4355 static void xml_Task(const char* module_name, int code_tag, string_buffer sb_result)
4356 {
4357  nest_context_t task_loopnest;
4358  task_loopnest.loops_for_call = stack_make(statement_domain,0,0);
4359  task_loopnest.loop_indices = stack_make(entity_domain,0,0);
4360  task_loopnest.current_stat = stack_make(statement_domain,0,0);
4361  task_loopnest.testif = stack_make(statement_domain,0,0);
4362  task_loopnest.nested_loops= gen_array_make(0);
4363  task_loopnest.nested_loop_indices = gen_array_make(0);
4364  task_loopnest.nested_call= gen_array_make(0);
4365  task_loopnest.nested_if= gen_array_make(0);
4366  stack nested_loops;
4367  list pattern_region =NIL;
4368  Pvecteur paving_indices = VECTEUR_NUL;
4370  bool motif_in_te_p = false;
4372  Psysteme prec;
4373  transformer t;
4374  statement stat_module=(statement) db_get_memory_resource(DBR_CODE,
4375  module_name, true);
4377  reset_rw_effects();
4380  db_get_memory_resource(DBR_REGIONS, module_name, true));
4381 
4382  push_current_module_statement(stat_module);
4384  global_margin++;
4385  add_margin(global_margin,sb_result);
4386  string_buffer_append(sb_result,
4388  "Task Name=",QUOTE,
4389  module_name,QUOTE,CLOSEANGLE,NL, NULL));
4390  global_margin++;
4391 
4392  find_loops_and_calls_in_box(stat_module,&task_loopnest);
4393  pattern_region = regions_dup(load_statement_local_regions(stat_module));
4394 
4395  xml_Library(sb_result);
4396  xml_Returns(sb_result);
4397  xml_Timecosts(sb_result);
4398  xml_GlobalVariables(t,prec,true,sb_result);
4399  xml_LocalVariables(module,t, prec,sb_result);
4400  xml_FormalVariables(module,t,prec,sb_result);
4401  /* On ne traite qu'une TE : un seul nid de boucles */
4402  nested_loops = gen_array_item(task_loopnest.nested_loops,0);
4403  xml_Region_Parameter(pattern_region, sb_result);
4405  motif_in_te_p = motif_in_statement_p;
4406  xml_Loops(nested_loops,false,&pattern_region,&paving_indices, &pattern_indices, motif_in_te_p, sb_result);
4407  xml_TaskParameters(stat_module, false,code_tag, module,pattern_region,paving_indices,sb_result);
4408  xml_Regions(sb_result);
4409  xml_CodeSize(sb_result);
4410  global_margin--;
4411  string_buffer_append_word("/Task",sb_result);
4412  global_margin--;
4413 
4415  gen_array_free(task_loopnest.nested_loops);
4416  gen_array_free(task_loopnest.nested_loop_indices);
4417  gen_array_free(task_loopnest.nested_call);
4418  gen_array_free(task_loopnest.nested_if);
4419  stack_free(&(task_loopnest.testif));
4420  stack_free(&(task_loopnest.loops_for_call));
4421  stack_free(&(task_loopnest.loop_indices));
4422  stack_free(&(task_loopnest.current_stat));
4424  regions_free(pattern_region);
4425  sc_rm(prec);
4426 }
4427 
4428 // A completer
4429 // ne traite que les cas ou tout est correctement aligne
4430 // A traiter aussi le cas ActualArrayDim = NIL
4431 //
4432 static void xml_Connection(list ActualArrayInd,int ActualArrayDim, int FormalArrayDim, string_buffer sb_result)
4433 {
4434  Pmatrix mat;
4435  int i,j;
4436  Pvecteur pv;
4437  string_buffer_append_word("Connection",sb_result);
4438  mat = matrix_new(ActualArrayDim,FormalArrayDim);
4439  matrix_init(mat,ActualArrayDim,FormalArrayDim);
4440  if (fortran_appli) {
4441  for (i=1;i<=ActualArrayDim && i<= FormalArrayDim;i++)
4442  MATRIX_ELEM(mat,i,i)=1;
4443  }
4444  else
4445  for (i=ActualArrayDim, j=FormalArrayDim;i>=1 && j>=1;i=i-1,j=j-1)
4446  MATRIX_ELEM(mat,i,j)=1;
4447  // Normalise les expressions lors du premier parcours
4448  // Utile aussi a xml_LoopOffset
4449  MAP(EXPRESSION, e , {
4453  pv = pv;
4454  },
4455  ActualArrayInd);
4456 
4457  xml_Matrix(mat,ActualArrayDim,FormalArrayDim,sb_result);
4458  string_buffer_append_word("/Connection",sb_result);
4459 }
4460 
4461 static void xml_LoopOffset(list ActualArrayInd,int ActualArrayDim, Pvecteur loop_indices,string_buffer sb_result)
4462 {
4463  Pmatrix mat;
4464  Pvecteur loop_indices2 = vect_reversal(loop_indices);
4465  int nestloop_dim = vect_size(loop_indices2);
4466  Pvecteur pv, pv2;
4467  int i,j;
4468 
4469  string_buffer_append_word("LoopOffset",sb_result);
4470  mat = matrix_new(ActualArrayDim,nestloop_dim);
4471  matrix_init(mat,ActualArrayDim,nestloop_dim);
4472  i=1;
4473  MAP(EXPRESSION, e , {
4475  for (pv2 = loop_indices2, j=1; !VECTEUR_NUL_P(pv2);pv2=pv2->succ,j++)
4476  MATRIX_ELEM(mat,i,j)=vect_coeff(pv2->var,pv);
4477  i++;
4478  },
4479  ActualArrayInd);
4480 
4481  xml_Matrix(mat,ActualArrayDim,nestloop_dim,sb_result);
4482  string_buffer_append_word("/LoopOffset",sb_result);
4483 }
4484 
4485 
4486 static void xml_ConstOffset(list ActualArrayInd, int ActualArrayDim, string_buffer sb_result)
4487 {
4488  Pmatrix mat;
4489  Pvecteur pv;
4490  int i=1;
4491  string_buffer_append_word("ConstOffset",sb_result);
4492  mat = matrix_new(ActualArrayDim,1);
4493  matrix_init(mat,ActualArrayDim,1);
4494  MAP(EXPRESSION, e , {
4498  MATRIX_ELEM(mat,i,1)=vect_coeff(TCST,pv);
4499  i++;
4500  },
4501  ActualArrayInd);
4502 
4503  xml_Matrix(mat,ActualArrayDim,1,sb_result);
4504  string_buffer_append_word("/ConstOffset",sb_result);
4505 }
4506 
4507 
4508 typedef struct {
4511 } alias_in_args;
4512 
4514 {
4515  p->alias_arg_p +=(reference_equal_p(r,p->rf))? 1:0;
4516  return p->alias_arg_p;
4517 }
4518 
4519 static bool aliasing_p(call c, reference refname)
4520 {
4521  alias_in_args p = { refname, 0 };
4522  list largs = call_arguments(c);
4523  FOREACH(EXPRESSION, exp, largs) {
4525  }
4526  return p.alias_arg_p > 1;
4527 }
4528 
4529 static void xml_Argument(
4530  statement s, entity function, int statnb, bool assign_func,
4531  expression exp0, entity FormalName, Pvecteur loop_indices,
4532  transformer t, _UNUSED_ Psysteme prec, string_buffer sb_result)
4533 {
4534  list call_effect = load_proper_rw_effects_list(s);
4535  entity ActualName = entity_undefined;
4536  reference ActualRef = reference_undefined;
4537  syntax sr;
4539  ;
4540  intptr_t iexp;
4541  int rw_ef = 0;
4542  string aan = "";
4543  // string quote_p = "";
4544  int valr = 0, min = 0, max = 0;
4545 
4547  //skip field, cast and address operator
4548  //expression exp2 = skip_field_and_cast_and_addop_expression(exp0);
4549  expression exp2 = skip_cast_expression(exp0);
4550  expression exp=exp1;
4552  sr = expression_syntax(exp);
4553  if (syntax_reference_p(sr)) {
4554  ActualRef = syntax_reference(sr);
4555  ActualName = reference_variable(ActualRef);
4556  //aan = strdup(entity_user_name(ActualName));
4557  aan = expression_to_string(exp2);
4558  rw_ef = find_effect_actions_for_entity(call_effect, &efr, &efw, ActualName);
4559 
4560  if (rw_ef == 3) { // Aliasing checking
4561  // First, search the Call
4562  call c = call_undefined;
4565  } else {
4568  c = encapsulated_call;
4569  }
4570  if (c == call_undefined)
4571  pips_internal_error("Unexpected call in statement number %d \n",(int) statement_number(s));
4572 
4573  if (aliasing_p(c, ActualRef))
4574  spear_warning(s, "Check the IN PLACE condition",
4575  "Array %s is read and written into the same function and "
4576  "appears twice as actual argument in the Call",
4577  entity_user_name(ActualName));
4578  }
4579  } else {
4580  // Actual Parameter could be an expression
4581  aan = words_to_string(Words_Syntax(sr));
4582  rw_ef = 1;
4583  }
4584  string_buffer_append_word("Argument", sb_result);
4585  if (!array_argument_p(exp)) { /* Scalar Argument */
4586  bool tb = true;
4587  global_margin++;
4588  add_margin(global_margin, sb_result);
4589  /* if (strncmp(aan, "\"", 1) == 0)
4590  quote_p = "";
4591  else
4592  quote_p = QUOTE;*/
4593 
4594  if (!assign_func) {
4595  string_buffer_append( sb_result,
4597  "ScalarArgument ActualName=", QUOTE, NULL));
4598  string_buffer_append_xml_text(sb_result,aan,false);
4599  string_buffer_append( sb_result,
4600  concatenate(QUOTE, BL,
4601  "FormalName=", QUOTE,
4602  (!entity_undefined_p(FormalName)) ? entity_user_name(FormalName) : "LocalExpression",
4603  QUOTE, BL,
4604  "AccessMode=", QUOTE,
4605  (rw_ef >= 2) ? ((rw_ef == 2) ? "DEF" : "DEF_USE") : "USE",
4606  QUOTE, CLOSEANGLE, NL, NULL));
4607  }
4608 
4609  else {
4610  string_buffer_append(sb_result,
4612  "ScalarArgument ActualName=", QUOTE, NULL));
4613  string_buffer_append_xml_text(sb_result,aan,false);
4614  string_buffer_append(sb_result,
4615  concatenate(QUOTE, BL,
4616  "AccessMode=", QUOTE,
4617  (rw_ef >= 2) ? ((rw_ef == 2) ? "DEF" : "DEF_USE") : "USE",
4618  QUOTE, CLOSEANGLE, NL, NULL));
4619  }
4620  if (expression_integer_value(exp, &iexp))
4621  string_buffer_append_numeric(int2a(iexp), sb_result);
4622  else if (value_constant_p(EvalExpression(exp))) {
4623  string exps = expression_to_string(exp);
4624  string_buffer_append_numeric(exps, sb_result);
4625  }
4626  else if ((tb = eval_linear_expression(exp1,t, &valr, &min, &max)) == true) {
4627  if (valr==min && valr==max)
4628  string_buffer_append_numeric(int2a(valr), sb_result);
4629  else {
4630  if (min != INT_MIN) {
4631  add_margin(global_margin, sb_result);
4632  string_buffer_append(sb_result,
4634  "MinNumeric", CLOSEANGLE, int2a(min), OPENANGLE,
4635  "/MinNumeric",
4636  CLOSEANGLE, NL, NULL));
4637  }
4638  if (max != INT_MAX) {
4639  add_margin(global_margin, sb_result);
4640  string_buffer_append(sb_result,
4642  "MaxNumeric", CLOSEANGLE, int2a(max), OPENANGLE,
4643  "/MaxNumeric",
4644  CLOSEANGLE, NL, NULL));
4645  }
4646  }
4647  }
4648  string_buffer_append_word("/ScalarArgument", sb_result);
4649  global_margin--;
4650  if (rw_ef >= 2) {
4651  Pcallst cst1 = (callst *)malloc(sizeof(callst));
4652  cst1->func = function;
4653  cst1->stat_nb = statnb;
4654  cst1->succ = (Pcallst)NULL;
4655  update_def_into_tasks_table(ActualName, cst1);
4656  }
4657  } else { /* Array Argument */
4658  int ActualArrayDim = variable_entity_dimension(ActualName);
4659  char *SActualArrayDim = strdup(i2a(ActualArrayDim));
4660  int FormalArrayDim = (entity_undefined_p(FormalName))
4661  ? 0
4662  : variable_entity_dimension(FormalName);
4663  list ActualArrayInd = reference_indices(ActualRef);
4664 
4665  global_margin++;
4666  add_margin(global_margin, sb_result);
4667  if (!assign_func) {
4668  string_buffer_append(sb_result,
4670  "ArrayArgument ActualName=", QUOTE,NULL));
4671  string_buffer_append_xml_text(sb_result, (string) entity_user_name(ActualName),false);
4672  string_buffer_append(sb_result,
4673  concatenate(QUOTE, BL,
4674  //Give Array access function indices "ArrayArgument ActualName=", QUOTE, expression_to_string(exp2), QUOTE, BL,
4675  "ActualDim=", QUOTE, SActualArrayDim, QUOTE, BL,
4676  "FormalName=", QUOTE,
4677  (!entity_undefined_p(FormalName)) ? entity_user_name(FormalName) : "LocalExpression",
4678  QUOTE, BL,
4679  "FormalDim=", QUOTE, i2a(FormalArrayDim), QUOTE, BL,
4680  "AccessMode=", QUOTE,
4681  (rw_ef >= 2) ? ((rw_ef == 2) ? "DEF" : "DEF_USE") : "USE",
4682  QUOTE, CLOSEANGLE, NL, NULL));
4683  }
4684  else {
4685  string_buffer_append(sb_result,
4687  "ArrayArgument ActualName=", QUOTE, NULL));
4688  string_buffer_append_xml_text(sb_result, (string) entity_user_name(ActualName),false);
4689  string_buffer_append(sb_result,
4690  concatenate(QUOTE, BL,
4691  // Give Array access function indices "ArrayArgument ActualName=", QUOTE, expression_to_string(exp2), QUOTE, BL,
4692  "ActualDim=", QUOTE, SActualArrayDim, QUOTE, BL,
4693  "AccessMode=", QUOTE, (rw_ef >= 2) ? ((rw_ef == 2) ? "DEF" : "DEF_USE") : "USE",
4694  QUOTE, CLOSEANGLE, NL, NULL));
4695  }
4696  /* Save information to generate Task Graph */
4697  if (rw_ef >= 2) {
4698  Pcallst cst1 = (callst *)malloc(sizeof(callst));
4699  cst1->func = function;
4700  cst1->stat_nb = statnb;
4701  cst1->succ = (Pcallst)NULL;
4702  update_def_into_tasks_table(ActualName, cst1);
4703  }
4704  free(SActualArrayDim);
4705  xml_Connection(ActualArrayInd, ActualArrayDim, FormalArrayDim, sb_result);
4706  xml_LoopOffset(ActualArrayInd, ActualArrayDim, loop_indices, sb_result);
4707  xml_ConstOffset(ActualArrayInd, ActualArrayDim, sb_result);
4708  global_margin--;
4709  string_buffer_append_word("/ArrayArgument", sb_result);
4710  }
4711  string_buffer_append_word("/Argument", sb_result);
4712  (void) pop_statement_global_stack();
4713 }
4714 
4715 static void xml_AssignArgument(_UNUSED_ statement s, entity function, int statnb,
4716  bool assign_func, expression exp, entity FormalName,
4717  Pvecteur loop_indices, transformer t,
4718  _UNUSED_ Psysteme prec, string_buffer sb_result)
4719 {
4720  entity ActualName = entity_undefined;
4721  reference ActualRef = reference_undefined;
4722  syntax sr;
4723  intptr_t iexp;
4724  int rw_ef = 0;
4725  string aan = "";
4726  // string quote_p = "";
4727  int valr = 0, min = 0, max = 0;
4728 
4729  sr = expression_syntax(exp);
4730  if (syntax_reference_p(sr)) {
4731  ActualRef = syntax_reference(sr);
4732  ActualName = reference_variable(ActualRef);
4733  aan = strdup(entity_user_name(ActualName));
4734  rw_ef = 2;
4735  } else
4736  printf("PB traduction AssignParameter\n");
4737  string_buffer_append_word("AssignArgument", sb_result);
4738  if (!array_argument_p(exp)) { /* Scalar Argument */
4739  global_margin++;
4740  add_margin(global_margin, sb_result);
4741  /* if (strncmp(aan, "\"", 1) == 0)
4742  quote_p = "";
4743  else
4744  quote_p = QUOTE;
4745  */
4746  string_buffer_append(sb_result,
4748  "ScalarArgument ActualName=", QUOTE, NULL));
4749  string_buffer_append_xml_text(sb_result, aan, false);
4750  string_buffer_append(sb_result,
4751  concatenate(QUOTE, BL,
4752  "AccessMode=", QUOTE, "DEF", QUOTE,
4753  CLOSEANGLE, NL, NULL));
4754  if (expression_integer_value(exp, &iexp))
4755  string_buffer_append_numeric(int2a(iexp), sb_result);
4756  else if (value_constant_p(EvalExpression(exp))) {
4757  string exps = expression_to_string(exp);
4758  string_buffer_append_numeric(exps, sb_result);
4759  } else if (eval_linear_expression(exp, t, &valr, &min, &max)) {
4760  if (valr==min && valr==max)
4761  string_buffer_append_numeric(int2a(valr), sb_result);
4762  }
4763  string_buffer_append_word("/ScalarArgument", sb_result);
4764  global_margin--;
4765  Pcallst cst1 = (callst *)malloc(sizeof(callst));
4766  cst1->func = function;
4767  cst1->stat_nb = statnb;
4768  cst1->succ = (Pcallst)NULL;
4769  update_def_into_tasks_table(ActualName, cst1);
4770  } else { /* Array Argument */
4771  int ActualArrayDim = variable_entity_dimension(ActualName);
4772  char *SActualArrayDim = strdup(i2a(ActualArrayDim));
4773  int FormalArrayDim = (entity_undefined_p(FormalName))
4774  ? 0
4775  : variable_entity_dimension(FormalName);
4776  list ActualArrayInd = reference_indices(ActualRef);
4777  global_margin++;
4778  add_margin(global_margin, sb_result);
4779  string_buffer_append( sb_result,
4781  "ArrayArgument ActualName=", QUOTE, NULL));
4782  string_buffer_append_xml_text( sb_result, (string) entity_user_name(ActualName), false);
4783  string_buffer_append( sb_result,
4784  concatenate(QUOTE, BL,
4785  "ActualDim=", QUOTE, SActualArrayDim, QUOTE, BL,
4786  "AccessMode=", QUOTE, (rw_ef >= 2) ? ((rw_ef == 2) ? "DEF" : "DEF_USE") : "USE", QUOTE,
4787  CLOSEANGLE, NL, NULL));
4788 
4789  /* Save information to generate Task Graph */
4790  Pcallst cst1 = (callst *)malloc(sizeof(callst));
4791  cst1->func = function;
4792  cst1->stat_nb = statnb;
4793  cst1->succ = (Pcallst)NULL;
4794  update_def_into_tasks_table(ActualName, cst1);
4795  free(SActualArrayDim);
4796  if (!assign_func)
4797  xml_Connection(ActualArrayInd, ActualArrayDim, FormalArrayDim, sb_result);
4798  xml_LoopOffset(ActualArrayInd, ActualArrayDim, loop_indices, sb_result);
4799  xml_ConstOffset(ActualArrayInd, ActualArrayDim, sb_result);
4800  global_margin--;
4801  string_buffer_append_word("/ArrayArgument", sb_result);
4802  }
4803  string_buffer_append_word("/AssignArgument", sb_result);
4804 }
4805 
4806 static void xml_Arguments(statement s, entity function, int statnb, bool assign_func, Pvecteur loop_indices, transformer t, Psysteme prec, string_buffer sb_result )
4807 {
4808  entity FormalName= entity_undefined;
4809  intptr_t ith=0;
4810  call c = call_undefined, rhs_call= call_undefined;
4811  entity rhs_func=entity_undefined;
4812  expression lhs_exp;
4813  bool func_as_rhs_of_assign =false;
4814 
4817  }
4818  else {
4821  c =encapsulated_call;
4822  }
4823  if (c==call_undefined)
4824  pips_internal_error("Unexpected call in statement number %d \n",(int) statement_number(s));
4825 
4826  if (ENTITY_ASSIGN_P(function)) {
4827  list largs = call_arguments(c);
4828  if(gen_length(largs)==2) {
4829  POP(largs);
4830  expression rhs_exp = EXPRESSION(CAR(largs));
4831  syntax sr = expression_syntax(rhs_exp);
4832  if(syntax_call_p(sr)) {
4833  rhs_call = syntax_call(sr);
4834  rhs_func=call_function(rhs_call);
4835  func_as_rhs_of_assign = (entity_subroutine_p(rhs_func)|| entity_function_p(rhs_func)|| (io_intrinsic_p(rhs_func)));
4836  }
4837  }
4838  }
4839  string_buffer_append_word("Arguments",sb_result);
4840  global_margin++;
4841  call final_call = (func_as_rhs_of_assign)? rhs_call:c;
4842  entity final_func = (func_as_rhs_of_assign)? rhs_func:function;
4843  bool asb = (!assign_func || (assign_func && func_as_rhs_of_assign && !io_intrinsic_p(rhs_func)));
4844  FOREACH(EXPRESSION,exp,call_arguments(final_call)){
4845  ith ++;
4846  if (asb)
4847  FormalName = find_ith_formal_parameter(call_function(final_call),ith);
4848  else FormalName = entity_undefined;
4849  xml_Argument(s,final_func,statnb, (assign_func && !func_as_rhs_of_assign),exp,FormalName, loop_indices,t,prec,sb_result);
4850  }
4851  if (func_as_rhs_of_assign) {
4852  lhs_exp=EXPRESSION(CAR(call_arguments(c)));
4853  FormalName = reference_variable(syntax_reference(expression_syntax(lhs_exp)));
4854  xml_AssignArgument(s,final_func,statnb, assign_func,lhs_exp,FormalName, loop_indices,t, prec,sb_result);
4855  }
4856  global_margin--;
4857  string_buffer_append_word("/Arguments",sb_result);
4858 }
4859 
4861 {
4864 }
4865 
4866 
4868 {
4874  *cond=call_function(oper);
4876  list largs_oper= call_arguments(oper);
4877  if (gen_length(largs_oper)>=2) {
4878  *lhs = EXPRESSION(CAR(largs_oper));
4879  *rhs = EXPRESSION(CAR(CDR(largs_oper)));
4880  return true;
4881  }
4882  else
4883  spear_warning(s1,"Change the test or Encapsulate it into a function",
4884  "NON BINARY OPERATORS in conditional are not accepted outside task");
4885  }
4886  else spear_warning(s1,"Change the test or Encapsulate it into a function",
4887  "NON LOGICAL OPERATORS in conditional are not accepted outside task");
4888  }
4889  else
4890  spear_warning(s1,"Change the test or Encapsulate it into a function",
4891  "The conditional is not a LOGICAL TEST");
4892  }
4893  return false;
4894 }
4895 
4896 
4898 {
4899  entity func1=entity_undefined;
4900  instruction inst;
4901  // Filtering function call and another function call or a declaration or a conditional
4903  *k1=2;
4904  else {
4905  inst = statement_instruction(s1);
4906  switch(instruction_tag(inst)) {
4907  case is_instruction_call : {
4909  // call_func_p1=((ENTITY_ASSIGN_P(func1)) ||entity_subroutine_p(func1)|| entity_function_p(func1));
4910  *k1= ENTITY_ASSIGN_P(func1)? 0 : 1;
4911  break;
4912  }
4913  case is_instruction_test : {
4914  *k1=3;
4915  break;
4916  }
4917  default:break;
4918  }
4919  }
4920 }
4921 
4922 static bool indice_p(stack indices, entity v)
4923 {
4924  bool result=false;
4925  STACK_MAP_X(index,entity,
4926  {
4927  if (same_entity_p(index ,v)) result=true;
4928  }, indices,1);
4929  return result;
4930 }
4931 
4933  graph mod_graph,nest_context_p nest, string_buffer sb_result)
4934 {
4935  cons *pv1, *ps, *pc;
4936  string_buffer buff_computed_by_func1 = string_buffer_make(true);
4937  string_buffer buff_needed_from_func1 = string_buffer_make(true);
4938  string_buffer buff_cumul_needed = string_buffer_make(true);
4939  string_buffer buffer_cond = string_buffer_make(true);
4940  string string_temp, stn1="", stn2="";
4941  bool new_temp=false, empty_buff_computed_by_func1=true,new_cond=false;
4942  bool new_temp2=false, empty_buff_needed_from_func1=true;
4943  bool empty_buff_cumul_needed=true;
4944  int taskNumber=0;
4945  stack statif=STACK_NULL;
4946  entity func1=entity_undefined;
4947  entity func2=entity_undefined;
4948  entity cond;
4949  expression lhs,rhs;
4950  statement sc;
4951  int nb_cond=0;
4952  int stat_kind1=-1,stat_kind2=-1;
4954  list cumulated_effects_list=NIL, local_effects=NIL;
4955  string st_nb1, st_nb2;
4956  add_margin(global_margin,sb_result);
4957  string_buffer_append(sb_result,
4959  "BoxGraph Name=", QUOTE,entity_user_name(module), QUOTE,
4960  CLOSEANGLE,NL, NULL));
4961  global_margin++;
4962 
4963  // COMPUTATION of the cumulated proper effects for the 2 following lists of NEEDS and COMPUTES
4964  cumulated_list = NIL;
4966  cumulated_effects_list= cumulated_list;
4967  vars_read_and_written(cumulated_effects_list,&vr,&vw);
4968 
4969  ifdebug(8) {
4971  }
4973  for ( pv1 = graph_vertices(mod_graph); !ENDP(pv1); pv1 = CDR(pv1) ) {
4974  vertex v1 = VERTEX(CAR(pv1));
4976  Pvecteur vread_func1= vect_new(TCST,1);
4977  Pvecteur vwritten_func1 = vect_new(TCST,1); // only 1 "xml COMPUTES information" per reference for each call statement S1
4978  Pvecteur vread_in_condition= vect_new(TCST,1);
4979  buffer_cond = string_buffer_make(true);
4980  buff_computed_by_func1 = string_buffer_make(true);
4982  new_temp=false;
4983  taskNumber=-1;
4984  new_cond=false;
4985  func1=entity_undefined;
4986  statif = STACK_NULL;
4988  // Recovery of conditions on/in statement s1, if any
4989  for (int callnumber = 0; callnumber<(int)gen_array_nitems(nest->nested_call); callnumber++) {
4990  statement s3 = gen_array_item(nest->nested_call,callnumber);
4991  if (statement_number(s3) == statement_number(s1))
4992  taskNumber=callnumber;
4993  }
4994  if (taskNumber>=0) {
4995  sc = gen_array_item(nest->nested_call,taskNumber);
4996  indices = gen_array_item(nest->nested_loop_indices,taskNumber);
4997  local_effects=regions_dup(load_statement_local_regions(sc));
4998  statif = gen_array_item(nest->nested_if,taskNumber);
4999  }
5000  // Conditional information around the dependencies
5001  if (statif != STACK_NULL) {
5003  nb_cond=0; // to restore alignment
5004  global_margin++;
5005  STACK_MAP_X(sx, statement,
5006  { if (logic_condition_filter(s1,sx,&cond,&lhs,&rhs)) {
5012  add_margin(global_margin,buffer_cond);
5013  //DEBUG - printf("Condition Branch=%s Test=\n", (statement_in_truebranch_p ? "TRUE":"FALSE"),(string)entity_user_name(cond));
5014  string_buffer_append(buffer_cond,
5016  "Condition Branch=",
5017  QUOTE, (statement_in_truebranch_p ? "TRUE":"FALSE"),
5018  QUOTE, BL,
5019  "Test=", QUOTE, NULL));
5020  string_buffer_append_xml_text(buffer_cond,(string)entity_user_name(cond),false);
5021  string_buffer_append(buffer_cond,
5022  concatenate(QUOTE, BL,
5023  "LHS=",QUOTE, expression_to_string(lhs), QUOTE, BL,
5024  "RHS=",QUOTE, expression_to_string(rhs), QUOTE, BL,
5025  "StNumber=",QUOTE,int2a(statement_number(sx)),QUOTE,
5026  CLOSEANGLE,NL, NULL));
5027  // For special character : string_buffer_append_xml_text(buffer_cond,exps,false);
5028  global_margin++;nb_cond++;
5029 
5030  { // usefull to add the READ effects on variables referenced into condition
5032  if (!ENDP(l) && !list_undefined_p(l)) {
5033 
5034  for (list pc = l; pc != NIL; pc = CDR(pc)) {
5035  effect e = EFFECT(CAR(pc));
5037  action ac = effect_action(e);
5038  entity v = reference_variable(r);
5039  if (store_effect_p(e)
5041  // local effect = read and no written effect in the function
5042  && action_read_p(ac) && vect_coeff(v,vw)==0 &&
5044  vect_add_elem(&vread_in_condition,(Variable)v,statement_number(sx));
5045  }
5046  }
5047  }
5048  }
5049 
5050  (void) pop_statement_global_stack();
5051  }
5052  },
5053  statif, 0);
5054  global_margin--;
5055  if (nb_cond>0) new_cond=true;
5056  }
5057 
5058  // Scan dependences from Call statement S1 to all Call Statement S2
5059  for ( ps = vertex_successors(v1); !ENDP(ps); ps = CDR(ps) ) {
5060  successor su = SUCCESSOR(CAR(ps));
5061  vertex v2 = successor_vertex(su);
5062  statement s2 = vertex_to_statement( v2 );
5064  list cl = dg_arc_label_conflicts(dal);
5065  int nb_conflicts = gen_length(cl);
5066  vread_func1 = vect_new(TCST,1);
5067  buff_needed_from_func1 = string_buffer_make(true);
5068  new_temp2=false;
5069  empty_buff_needed_from_func1=true;
5070  if(get_bool_property("PRETTYPRINT_MEMORY_EFFECTS_ONLY")) {
5071  FOREACH(CONFLICT, c, cl) {
5072  effect efsrc = conflict_source(c);
5073  if(!store_effect_p(efsrc))
5074  nb_conflicts--;
5075  }
5076  }
5077  if(nb_conflicts==0)
5078  continue;
5079  if ( nb_conflicts > 1 ) { //SORT
5080  gen_array_t conflicts_array = gen_array_make( 20 );
5081  list_to_array( dg_arc_label_conflicts(dal), conflicts_array );
5082  qsort( gen_array_pointer( conflicts_array ),
5083  gen_array_nitems( conflicts_array ),
5084  sizeof(void *),
5086  list conflicts_list = NIL;
5087  GEN_ARRAY_FOREACH(conflict, s, conflicts_array)
5088  conflicts_list = CONS(conflict, s, conflicts_list);
5089  gen_array_free(conflicts_array);
5090  dg_arc_label_conflicts(dal)=conflicts_list;
5091  }
5092 
5093  stat_kind1=-1, stat_kind2=-1;
5094  dependencies_filter(s1,&stat_kind1);
5095  dependencies_filter(s2,&stat_kind2);
5096  if ((( 0<=stat_kind1 && stat_kind1 <=1)
5097  && ( 0<=stat_kind2 && stat_kind2 <=1) && !(statement_number(s2) == statement_number(s1)))
5098  || ((stat_kind1==2 || stat_kind1==3) && ( 0<=stat_kind2 && stat_kind2 <=1) )
5099  || ((stat_kind2==2 || stat_kind2==3) && ( 0<=stat_kind1 && stat_kind1 <=1))) {
5100  st_nb1=int2a(statement_number(s1));
5101  st_nb2=int2a(statement_number(s2));
5102  // DEBUG - printf( "\t\tdependence %s - %s between %s and %s \n",stn1,stn2, st_nb1,st_nb2 );
5103  switch(stat_kind1) {
5104  case 1: {
5106  stn1 = strdup(entity_user_name(func1));
5107  break;
5108  }
5109  case 2: {
5110  stn1 = strdup("DeclarationInstruction");
5111  break;
5112  }
5113  case 0: {
5115  syntax sr = expression_syntax(rhs_exp);
5116  if(syntax_call_p(sr)) {
5117  call rhs_call = syntax_call(sr);
5118  func2=call_function(rhs_call);
5119  if ((entity_subroutine_p(func2)|| entity_function_p(func2)))
5120  stn1= (string) entity_local_name(call_function(rhs_call));
5121  else
5122  stn1 = strdup("LocalAssignment");
5123  }
5124  else
5125  stn1 = strdup("LocalAssignment");
5126  break;
5127  }
5128  case 3: {
5129  stn1 = strdup("TestInstruction");
5130  break;
5131  }
5132  default:
5133  break;
5134  }
5135  switch(stat_kind2) {
5136  case 1: {
5138  stn2 = strdup(entity_user_name(func2));
5139  break;
5140  }
5141  case 2: {
5142  stn2 = strdup("DeclarationInstruction");
5143  break;
5144  }
5145  case 0: {
5147  syntax sr = expression_syntax(rhs_exp);
5148  if(syntax_call_p(sr)) {
5149  call rhs_call = syntax_call(sr);
5150  func2=call_function(rhs_call);
5151  if ((entity_subroutine_p(func2)|| entity_function_p(func2)))
5152  stn2= (string) entity_local_name(call_function(rhs_call));
5153  else
5154  stn2 = strdup("LocalAssignment");
5155  }
5156  else
5157  stn2 = strdup("LocalAssignment");
5158  break;
5159  break;
5160  }
5161  case 3: {
5162  stn2 = strdup("TestInstruction");
5163  break;
5164  }
5165  default:
5166  break;
5167  }
5168  // Create the header for dependencies for TASKREF func1
5169  if (!new_temp){
5170  global_margin ++;
5171  add_margin(global_margin,buff_computed_by_func1);
5172  string_buffer_append(buff_computed_by_func1,
5174  (stat_kind1>=0 && stat_kind1<=1)?"TaskRef Name=" :"Instruction Name=",QUOTE,stn1,QUOTE, BL,
5175  "StNumber=",QUOTE,st_nb1,QUOTE,
5176  CLOSEANGLE,NL,
5177  NULL));
5178  new_temp=true;
5179  empty_buff_computed_by_func1=true;
5180  }
5181  if (!new_temp2){
5182  add_margin(global_margin,buff_needed_from_func1);
5183  string_buffer_append(buff_needed_from_func1,
5185  (stat_kind2>=0 && stat_kind2<=1)?"TaskRef Name=" :"Instruction Name=",QUOTE,stn2,QUOTE, BL,
5186  "StNumber=",QUOTE,st_nb2,QUOTE,
5187  CLOSEANGLE,NL,
5188  NULL));
5189  new_temp2=true;
5190  empty_buff_needed_from_func1=true;
5191  }
5192  // Scan all dependences from Call statement S1 to Call Statement S2
5193  for ( pc = dg_arc_label_conflicts(dal); !ENDP(pc); pc = CDR(pc) ) {
5194  conflict c = CONFLICT(CAR(pc));
5195  effect efsrc = conflict_source(c);
5196  effect efsrs = conflict_sink(c);
5197  action acc = effect_action(efsrc);
5198  action acs = effect_action(efsrs);
5199  reference rc = effect_any_reference(efsrc);
5200  reference rs = effect_any_reference(efsrs);
5201  entity vc = reference_variable(rc);
5202  entity vs = reference_variable(rs);
5203 
5204  // DEBUG-
5205  // if (( 0<=stat_kind1 && stat_kind1 <=3) && ( 0<=stat_kind2 && stat_kind2 <=3))
5206  // printf( "\t\tdependence %s (%s)- %s(%s) for %s - %s \n",stn1,st_nb1,stn2,st_nb2, entity_user_name(vc), entity_user_name(vs) );
5207 
5208  if (store_effect_p(efsrc)
5211  && !string_parameter_p(vs) && !string_parameter_p(vc)
5212  // && !variable_heap_p(vc) && !variable_heap_p(vs)
5213  ) {
5214 
5215  if (action_write_p(acc) && action_read_p(acs) && vect_coeff(vc,vwritten_func1)==0
5216  ) {
5217  //DEBUG- printf( "\t\t%s COMPUTES %s read by %s(%s)\n",stn1, entity_user_name(vc),stn2,st_nb2 );
5218  global_margin++;
5219  add_margin(global_margin,buff_computed_by_func1);
5220  string_buffer_append(buff_computed_by_func1,
5222  "Computes ",(array_entity_p(vc))?"ArrayName=": "ScalarName=",
5223  QUOTE,NULL));
5224  string_buffer_append_xml_text(buff_computed_by_func1,
5225  (string) ((print_name_1_level_p() || reference_undefined_p(rc))?
5227  false);
5228  string_buffer_append(buff_computed_by_func1,
5229  concatenate(QUOTE, BL,
5230  "ReadBy=",QUOTE,stn2,QUOTE, BL,
5231  "StNumber=",QUOTE,st_nb2,QUOTE,
5232  "/",CLOSEANGLE,NL,
5233  NULL));
5234  global_margin--;
5235  empty_buff_computed_by_func1=false;
5236  vect_add_elem(&vwritten_func1,(Variable)vc,1);
5237  vect_add_elem(&written_cumul,(Variable)vc,1);
5238  }
5239  if (action_write_p(acc) && action_read_p(acs)) {
5240  if (vect_coeff(vc,vread_func1)==0 ) {
5241  //DEBUG- printf( "\t\t%s NEEDS %s DefinedBy by %s (%s)\n",stn2, entity_user_name(vc),stn1, st_nb1);
5242 
5243  global_margin++;
5244  add_margin(global_margin,buff_needed_from_func1);
5245  string_buffer_append(buff_needed_from_func1,
5247  "Needs ",(array_entity_p(vc))?"ArrayName=": "ScalarName=",
5248  QUOTE, NULL));
5249  string_buffer_append_xml_text(buff_needed_from_func1,
5250  (string) ((print_name_1_level_p() || reference_undefined_p(rc)) ?
5252  false);
5253  string_buffer_append(buff_needed_from_func1,
5254  concatenate(QUOTE, BL,
5255  "DefinedBy=",QUOTE,stn1,QUOTE,BL,
5256  "StNumber=",QUOTE,st_nb1,QUOTE,
5257  "/",CLOSEANGLE,NL,NULL));
5258  global_margin--;
5259  empty_buff_needed_from_func1=false;
5260  if (!entity_undefined_p(func1))
5261  def_to_task_store(vc, func1);
5262  vect_add_elem(&vread_func1,(Variable)vc,1);
5263  }
5264  }
5265 
5266  if (action_write_p(acc) && action_write_p(acs) && !same_string_p(stn1,stn2))
5267  spear_warning(s1,"Check the dependencies before mapping",
5268  "Elements of Array %s written into two different functions %s and %s",
5271 
5272  // ADD R-W Dependances
5273  if (action_write_p(acs) && action_read_p(acc)) {
5274  //DEBUG- printf( "\t\t%s COMPUTES %s read by %s(%s)\n",stn1, entity_user_name(vc),stn2,st_nb2 );
5275  global_margin++;
5276  add_margin(global_margin,buff_computed_by_func1);
5277  string_buffer_append(buff_computed_by_func1,
5279  "Reads ",(array_entity_p(vc))?"ArrayName=": "ScalarName=",
5280  QUOTE,NULL));
5281  string_buffer_append_xml_text(buff_computed_by_func1,
5282  (string) ((print_name_1_level_p() || reference_undefined_p(rc))?
5284  false);
5285  string_buffer_append(buff_computed_by_func1,
5286  concatenate(QUOTE, BL,
5287  "WrittenAfterBy=",QUOTE,stn2,QUOTE, BL,
5288  "StNumber=",QUOTE,st_nb2,QUOTE,
5289  "/",CLOSEANGLE,NL,
5290  NULL));
5291  global_margin--;
5292  empty_buff_computed_by_func1=false;
5293  }
5294  }
5295  } // end scanning dependencies
5296  } // end dependency filter
5297 
5298  if (new_temp2) {
5299  string_buffer_append_word((stat_kind2>=0 && stat_kind2<=1)?"/TaskRef":"/Instruction",buff_needed_from_func1);
5300  if (!empty_buff_needed_from_func1) {
5301  string_temp =string_buffer_to_string(buff_needed_from_func1);
5302  string_buffer_append(buff_cumul_needed,string_temp);
5303  empty_buff_cumul_needed=false;
5304  string_buffer_free(&buff_needed_from_func1);
5305  }
5306  new_temp2=false;
5307  empty_buff_needed_from_func1=true;
5308  }
5309  } // end scan func2
5310 
5311  if (new_temp) {
5312  string_buffer_append_word((stat_kind1>=0 && stat_kind1<=1)?"/TaskRef":"/Instruction",buff_computed_by_func1);
5313  global_margin--;
5314  }
5315  if (new_cond && !new_temp) {
5316  global_margin--;
5317  }
5318  if (!empty_buff_computed_by_func1) {
5319  if (statif != STACK_NULL) {
5320  for (int tp=1;tp<=nb_cond;tp++) {
5321  string_buffer_append_word("/Condition",buff_computed_by_func1);
5322  global_margin--;
5323  }
5324  string_temp =string_buffer_to_string(buffer_cond);
5325  string_buffer_append(sb_result,string_temp);
5326  }
5327  string_temp =string_buffer_to_string(buff_computed_by_func1);
5328  string_buffer_append(sb_result,string_temp);
5329 
5330  string_temp=NULL;
5331  new_temp=false;
5332  empty_buff_computed_by_func1=true;
5333  }
5334  else {
5335  string_buffer_free(&buff_computed_by_func1);
5336  // string_buffer_free(&buffer_cond);
5337  }
5338 
5339  // Add Read effects on variable written outside the function and Read by the local statement (in local_effects=local regions)
5340  if (taskNumber>=0) {
5341  call c1=call_undefined;
5344  }
5345  else { // The call is encapsulated
5348  c1 =encapsulated_call;
5349  }
5350  if (c1!=call_undefined) {
5351  // pips_internal_error("Unexpected call in statement number %d \n",(int) statement_number(s1));
5352 
5353  sc = gen_array_item(nest->nested_call,taskNumber);
5354  indices = gen_array_item(nest->nested_loop_indices,taskNumber);
5355  statif = gen_array_item(nest->nested_if,taskNumber);
5356 
5357 
5358  func1 = call_function(c1);
5359  const char *temp = (ENTITY_ASSIGN_P(func1))?"LocalAssignment":entity_user_name(func1);
5360  stn1 = strdup(temp);
5361  st_nb1=int2a(statement_number(s1));
5362  for (pc= local_effects;!ENDP(pc); pc = CDR(pc)){
5363  effect e2 = EFFECT(CAR(pc));
5365  action ac2 = effect_action(e2);
5366  entity v2 = reference_variable(r2);
5368  bool b=(t!=(Pcallst) HASH_UNDEFINED_VALUE);
5369 
5370  if ( store_effect_p(e2) && action_read_p(ac2)
5372  // variable written outside the function
5373  && (vect_coeff(v2,vwritten_func1)==0 || (vect_coeff(v2,vwritten_func1)!=0 &&b ))
5374  // only if not yet mentioned in the dependencies list or in the local_effects list
5375  && vect_coeff(v2,vread_func1)==0
5377  && vect_coeff(v2,written_cumul)==0 && !(indice_p(indices,v2))
5378  && !string_parameter_p(v2)// && (b && t->stat_nb<statement_number(s1))
5379  ) {
5380 
5381  // Conditional information around the dependencies
5382  string_temp =string_buffer_to_string(buffer_cond);
5383  string_buffer_append(sb_result,string_temp);
5384 
5385 
5386  global_margin++;
5387  add_margin(global_margin,sb_result);
5388  string_buffer_append(sb_result,
5390  "TaskRef Name=",QUOTE, stn1,QUOTE, BL,
5391  "StNumber=",QUOTE,st_nb1,QUOTE,
5392  CLOSEANGLE,NL,
5393  NULL));
5394  global_margin++;
5395  add_margin(global_margin,sb_result);
5396  string_buffer_append(sb_result,
5398  "Needs ",(array_entity_p(v2))?"ArrayName=": "ScalarName=",
5399  QUOTE, NULL));
5401  (string) ((print_name_1_level_p() || reference_undefined_p(r2))?
5403  false);
5404  string_buffer_append(sb_result,
5405  concatenate(QUOTE, BL,
5406  "DefinedBy=",QUOTE,
5407  //(b && t->stat_nb<statement_number(s1))?
5408  // - v2 has been updated into a non-call instruction or into a call nested into other instructions.
5409  // - v2 has been updated IN_PLACE
5410  // - v2 has been updated into a callee
5411  // ((t->stat_nb<statement_number(s1)) ? entity_user_name(t->func):"IN_PLACE"):
5412  //((t->stat_nb==statement_number(s1)) ?"IN_PLACE":
5413  //(!(entity_undefined_p(t->func)) ? entity_user_name(t->func) : "NestedCall")
5414  //)
5415  //:
5416  "IN_VALUE",QUOTE,BL,
5417  "StNumber=",QUOTE,(b)?int2a(t->stat_nb):int2a(0),QUOTE,
5418  "/",CLOSEANGLE,NL,NULL));
5419 
5420  vect_add_elem(&vread_func1,(Variable)v2,1);
5421  global_margin--;
5422  string_buffer_append_word("/TaskRef",sb_result);
5423  global_margin--;
5424 
5425  if (statif != STACK_NULL) {
5426  for (int tp=1;tp<=nb_cond;tp++) {
5427  string_buffer_append_word("/Condition",sb_result);
5428  global_margin--;
5429  }
5430  }
5431  }
5432  }
5433  }
5434  {//begin
5435  vect_chg_coeff(&vread_in_condition, TCST,0);
5436  for (Pvecteur pv= vread_in_condition;!VECTEUR_UNDEFINED_P(pv); pv = pv->succ){
5437  entity ent = (entity)pv->var;
5438  global_margin++;
5439  add_margin(global_margin,sb_result);
5440  string_buffer_append(sb_result,
5442  "Instruction Name=",QUOTE, "TestInstruction",QUOTE, BL,
5443  "StNumber=",QUOTE,int2a(pv->val),QUOTE,
5444  CLOSEANGLE,NL,
5445  NULL));
5446  global_margin++;
5447  add_margin(global_margin,sb_result);
5448  string_buffer_append(sb_result,
5450  "Needs ","ScalarName=",
5451  QUOTE, NULL));
5453  (string) entity_user_name(ent),
5454  false);
5455  string_buffer_append(sb_result,
5456  concatenate(QUOTE, BL,
5457  "DefinedBy=",QUOTE,
5458  "IN_VALUE",QUOTE,
5459  //BL, "StNumber=",QUOTE,int2a(0),QUOTE,
5460  "/",CLOSEANGLE,NL,NULL));
5461 
5462  global_margin--;
5463  string_buffer_append_word("/Instruction",sb_result);
5464  global_margin--;
5465 
5466 
5467  }
5468  }//end
5469  vect_rm(vread_func1);
5470  vect_rm(vwritten_func1);
5471  vect_rm(vread_in_condition);
5472  string_buffer_free(&buffer_cond);
5473  }
5474  } // end toutes les func1
5475  if (!empty_buff_cumul_needed) {
5476  string_temp =string_buffer_to_string(buff_cumul_needed);
5477  string_buffer_append(sb_result,string_temp);
5478  string_buffer_free(&buff_cumul_needed);
5479  }
5480  // ADD Write effects on variables that are not used in the function
5481  //printf("ADD Write effects on variables that are not used in the function\n");
5482 
5483  for (pc= cumulated_effects_list;pc != NIL; pc = CDR(pc)){
5484  effect e = EFFECT(CAR(pc));
5486  action ac = effect_action(e);
5487  entity v = reference_variable(r);
5488  if ( store_effect_p(e)
5490  &&!action_read_p(ac) && vect_coeff(v,vw) // Write effects in the cumulated effects list
5492  && vect_coeff(v,written_cumul)==0) {
5493  Pcallst ct2,ct1=hash_get(hash_entity_def_into_tasks,(char *) v);
5494  for(ct2=ct1;ct2 !=(Pcallst) HASH_UNDEFINED_VALUE && ct2 !=(Pcallst) NULL; ct2=ct2->succ)
5495  {
5496  print_reference(r);
5497  string temp =strdup(int2a(ct2->stat_nb));
5498 
5499  {
5500  taskNumber=-1;
5501  statif = STACK_NULL;
5502  for (int callnumber = 0; callnumber<(int)gen_array_nitems(nest->nested_call); callnumber++) {
5503  statement s3 = gen_array_item(nest->nested_call,callnumber);
5504  if (statement_number(s3) == ct2->stat_nb)
5505  taskNumber=callnumber;
5506  }
5507  if (taskNumber>=0) {
5508  sc = gen_array_item(nest->nested_call,taskNumber);
5509  statif = gen_array_item(nest->nested_if,taskNumber);
5510  }
5511  // Conditional information around the dependencies
5512  if (statif != STACK_NULL) {
5514  nb_cond=0; // to restore alignment
5515  global_margin++;
5516  STACK_MAP_X(sx, statement,
5517  { if (logic_condition_filter(sc,sx,&cond,&lhs,&rhs)) {
5523  add_margin(global_margin,sb_result);
5524  //DEBUG - printf("Condition Branch=%s Test=\n", (statement_in_truebranch_p ? "TRUE":"FALSE"),(string)entity_user_name(cond));
5525  string_buffer_append(sb_result,
5527  "Condition Branch=",
5528  QUOTE, (statement_in_truebranch_p ? "TRUE":"FALSE"),
5529  QUOTE, BL,
5530  "Test=", QUOTE, NULL));
5531  string_buffer_append_xml_text(sb_result,(string)entity_user_name(cond),false);
5532  string_buffer_append(sb_result,
5533  concatenate(QUOTE, BL, "LHS=",QUOTE, NULL));
5534  string_buffer_append_xml_text(sb_result,expression_to_string(lhs), false);
5535  string_buffer_append(sb_result,
5536  concatenate(QUOTE, BL, "RHS=",QUOTE, NULL));
5537  string_buffer_append_xml_text(sb_result,expression_to_string(rhs), false);
5538  string_buffer_append(sb_result,
5539  concatenate(QUOTE, BL,
5540  "StNumber=",QUOTE,int2a(statement_number(sx)),QUOTE,
5541  CLOSEANGLE,NL, NULL));
5542  // For special character : string_buffer_append_xml_text(buffer_cond,exps,false);
5543  global_margin++;nb_cond++;
5544  (void) pop_statement_global_stack();
5545  }
5546  },
5547  statif, 0);
5548  global_margin--;
5549  if (nb_cond>0) new_cond=true;
5550  }
5551 
5552  {
5553  global_margin++;
5554  add_margin(global_margin,sb_result);
5555  string_buffer_append(sb_result,
5556  concatenate(OPENANGLE,"TaskRef Name=",QUOTE,
5557  (!entity_undefined_p(ct2->func)) ?
5558  (ENTITY_ASSIGN_P(ct2->func)?"LocalAssignment":entity_user_name(ct2->func)):
5559  // Variable assigned in an instruction that is not a Call; in a loop, a nested call,...
5560  "NestedCall", QUOTE,
5561  BL,"StNumber=",QUOTE,temp,QUOTE,
5562  CLOSEANGLE,NL,
5563  NULL));
5564  global_margin++;
5565  add_margin(global_margin,sb_result);
5566  string_buffer_append(sb_result,
5568  "Computes ",(array_entity_p(v))?"ArrayName=": "ScalarName=",
5569  QUOTE,NULL));
5571  (string) ((print_name_1_level_p() || reference_undefined_p(r))?
5573  false);
5574  string_buffer_append(sb_result,
5575  concatenate(QUOTE,"/", CLOSEANGLE,NL, NULL));
5576  vect_add_elem(&written_cumul,(Variable)v,1);
5577  global_margin--;
5578  string_buffer_append_word("/TaskRef",sb_result);
5579  global_margin--;
5580  }
5581  if (statif != STACK_NULL) {
5582  for (int tp=1;tp<=nb_cond;tp++) {
5583  string_buffer_append_word("/Condition",sb_result);
5584  global_margin--;
5585  }
5586  }
5587  }
5588  }
5589  }
5590  }
5591  global_margin--;
5592  string_buffer_append_word("/BoxGraph",sb_result);
5593  vect_rm(written_cumul);
5594  vect_rm(vr);
5595  vect_rm(vw);
5596 }
5597 
5598 static void xml_Chains(entity module,const char* mod_name, statement mod_stat, nest_context_p nest,string_buffer sb_result)
5599 {
5601  dg = (graph) db_get_memory_resource(DBR_DG, mod_name, true);
5602  xml_Chain_Graph(module,mod_stat,dg,nest,sb_result);
5603  // reset_current_module_statement();
5604  // reset_current_module_entity();
5606 }
5607 
5608 
5609 static void print_call_precondition(Psysteme prec, string_buffer sb_result)
5610 {
5611  // fprintf(stdout,"DEBUG - preconditions\n");
5612  // sc_fprint(stdout,prec, (get_variable_name_t) entity_local_name);
5613 
5614  Pcontrainte pc;
5615  Pvecteur pv;
5616 
5617  string_buffer_append_word("CallPreconditions", sb_result);
5618  global_margin++;
5619  for (pc = prec->egalites; pc!=NULL; pc=pc->succ) {
5620  pv = contrainte_vecteur(pc);
5621  if (vect_size(pv)<=2 && vect_dimension(pv)==1){
5622  Pvecteur pv2=vect_copy(pv);
5623  int coeff = - vect_coeff(TCST,pv2);
5624  vect_chg_coeff(&pv2,TCST,0);
5625  if (!VECTEUR_UNDEFINED_P(pv2) && !VECTEUR_NUL_P(pv2)) {
5626  entity etmp = (entity) pv2->var;
5627  if (!old_value_entity_p(etmp)) {
5628  entity ve=(entity) pv2->var;
5631  entity v = reference_variable(r);
5632  region reg = region_undefined;
5633  add_margin(global_margin, sb_result);
5634  string_buffer_append(sb_result,
5636  "Precondition Param=", QUOTE,entity_user_name(v), QUOTE,
5637  " Field=", QUOTE, words_points_to_reference(r,true,reg), QUOTE,
5638  " Numeric=", QUOTE, int2a(coeff), QUOTE, SLASH, CLOSEANGLE, NL, NULL));
5639  }
5640  else {
5641  add_margin(global_margin, sb_result);
5642  string_buffer_append(sb_result,
5644  "Precondition Param=", QUOTE,entity_user_name(ve), QUOTE,
5645  " Numeric=", QUOTE, int2a(coeff), QUOTE,SLASH, CLOSEANGLE, NL, NULL));
5646  }
5647  }
5648  }
5649  vect_rm(pv2);
5650  }
5651  }
5652  for (pc = prec->inegalites; pc!=NULL; pc=pc->succ) {
5653  pv = contrainte_vecteur(pc);
5654  if (vect_size(pv)<=2 && vect_dimension(pv)==1) {
5655  Pvecteur pv2 = vect_copy(pv);
5656  int coeff = - vect_coeff(TCST,pv2);
5657  vect_chg_coeff(&pv2,TCST,0);
5658  if (!VECTEUR_UNDEFINED_P(pv2) && !VECTEUR_NUL_P(pv2)) {
5659  entity etmp = (entity) pv2->var;
5660  if (!old_value_entity_p(etmp)) {
5661  entity ve = value_to_variable(etmp);
5662  int val = pv2->val;
5665  entity v = reference_variable(r);
5666  region reg = region_undefined;
5667  add_margin(global_margin, sb_result);
5668  string_buffer_append(sb_result,
5670  "Precondition Param=", QUOTE,entity_user_name(v), QUOTE,
5671  " Field=", QUOTE, words_points_to_reference(r,true,reg), QUOTE,
5672  (val<=0) ? " MinNumeric=":" MaxNumeric=", QUOTE, int2a(coeff), QUOTE, SLASH,CLOSEANGLE, NL, NULL));
5673  }
5674  else {
5675  add_margin(global_margin, sb_result);
5676  string_buffer_append(sb_result,
5678  "Precondition Param=", QUOTE,entity_user_name(ve), QUOTE,
5679  (val<=0)?" MinNumeric=":" MaxNumeric=", QUOTE, int2a(coeff), QUOTE, SLASH,CLOSEANGLE, NL, NULL));
5680 
5681  }
5682  }
5683  }
5684  }
5685  }
5686  global_margin--;
5687  string_buffer_append_word("/CallPreconditions", sb_result);
5688 }
5689 
5690 static void xml_Call(entity module, int code_tag,int taskNumber, nest_context_p nest, string_buffer sb_result)
5691 {
5692  statement s = gen_array_item(nest->nested_call,taskNumber);
5694  // if (instruction_call_p(statement_instruction(s))) {
5695  stack st = gen_array_item(nest->nested_loops,taskNumber);
5696  stack statif = gen_array_item(nest->nested_if,taskNumber);
5699  call c = call_undefined;
5700  list pattern_region=NIL;
5701  Pvecteur paving_indices = VECTEUR_NUL;
5703  bool motif_in_te_p=false;
5704  bool func_as_rhs_of_assign =false;
5705  int nb_cond=0;
5706  entity cond, encapsulated_func,func ;
5707  expression lhs,rhs;
5708 
5711  }
5712  else {
5715  c =encapsulated_call;
5716  }
5717  if (c==call_undefined)
5718  pips_internal_error("Unexpected call in statement number %d \n",(int) statement_number(s));
5719 
5720  //used by statement_in_truebranch
5722  func= call_function(c);
5723  const char * strtmp = entity_user_name(func);
5724 
5726  pattern_region =load_proper_rw_effects_list(s);
5727  }
5728  else
5729  pattern_region = regions_dup(load_statement_local_regions(s));
5730 
5731  if (ENTITY_ASSIGN_P(func)) {
5732  list largs = call_arguments(c);
5733  expression lhs_exp = EXPRESSION(CAR(largs));
5734  lhs_exp = skip_field_and_cast_expression(lhs_exp);
5735  if (array_argument_p(lhs_exp)) // lhs not scalar
5736  spear_warning(s,"Please use only scalar variable on the left hand side of assignements not included in a MOTIF",
5737  "Non scalar variable as LHS part of a LocalAssignment");
5738 
5739  FOREACH(EXPRESSION,expt,POP(largs)){
5741  if (array_argument_p(arg_exp)) // rhs not scalar
5742  spear_warning(s,"Please use only scalar variable on the right hand side of assignements not included in a MOTIF",
5743  "Non scalar variable as RHS part of a LocalAssignment");
5744  }
5745  largs = call_arguments(c);
5746  if(gen_length(largs)>2)
5747  spear_warning(s,"Please use only one varaible on the right hand side of assignements not included in a MOTIF",
5748  "More than 1 variable as RHS part of a LocalAssignment");
5749 
5750  if(gen_length(largs)==2) {
5751  POP(largs);
5752  expression rhs_exp = EXPRESSION(CAR(largs));
5753  syntax sr = expression_syntax(rhs_exp);
5754  if(syntax_call_p(sr)) {
5755  call rhs_call = syntax_call(sr);
5756  encapsulated_func=call_function(rhs_call);
5757  func_as_rhs_of_assign = (entity_subroutine_p(encapsulated_func)|| entity_function_p(encapsulated_func));
5758  }
5759  //spear_warning(s,"Please encapsulate assignments into TASK or into the existing MOTIF","LocalAssignment detected");
5760  }
5761  }
5762  if (statif != STACK_NULL) {
5763  STACK_MAP_X(sx, statement,
5764  { if (logic_condition_filter(s,sx,&cond,&lhs,&rhs)) {
5770  add_margin(global_margin,sb_result);
5771 
5772  string_buffer_append(sb_result,
5774  "CallCondition Branch=",
5775  QUOTE, (statement_in_truebranch_p ? "TRUE":"FALSE"),
5776  QUOTE, BL,
5777  "Test=", QUOTE, NULL));
5778  string_buffer_append_xml_text(sb_result,(string)entity_user_name(cond),false);
5779  string_buffer_append(sb_result,
5780  concatenate(QUOTE, BL,
5781  "LHS=",QUOTE, NULL));
5783  string_buffer_append(sb_result,
5784  concatenate(QUOTE, BL, "RHS=",QUOTE, NULL));
5785  string_buffer_append_xml_text(sb_result, expression_to_string(rhs), false);
5786  string_buffer_append(sb_result,
5788  "StNumber=",QUOTE,int2a(statement_number(sx)),QUOTE,
5789  CLOSEANGLE,NL, NULL));
5790  // For special character : string_buffer_append_xml_text(buffer_cond,exps,false);
5791  global_margin++;nb_cond++;
5792  (void) pop_statement_global_stack();
5793  }
5794  },
5795  statif, 0);
5796  }
5797  add_margin(global_margin,sb_result);
5798  string_buffer_append(sb_result,
5800  "Call Name=",
5801  QUOTE,
5802  ENTITY_ASSIGN_P(func) ? (
5803  (func_as_rhs_of_assign) ? entity_user_name(encapsulated_func):
5804  "LocalAssignment")
5805  : entity_user_name(func),
5806  QUOTE,BL,
5807  "StNumber=",QUOTE,int2a(statement_number(s)),QUOTE,
5808  CLOSEANGLE,NL, NULL));
5809  global_margin++;
5810  print_call_precondition(prec, sb_result);
5811  // only detect Opengpu 2D and 3D 4D and 5D cornerturns
5812  if (strstr(strtmp,"cornerturn_5D")!=NULL)
5813  xml_Transposition(s,c,5,sb_result,0);
5814  else if (strstr(strtmp,"cornerturn_4D")!=NULL)
5815  xml_Transposition(s,c,4,sb_result,0);
5816  else if (strstr(strtmp,"cornerturn_3D")!=NULL)
5817  xml_Transposition(s,c,3,sb_result,0);
5818  else
5819  if (strstr(strtmp,"cornerturn_2D")!=NULL)
5820  xml_Transposition(s,c,2,sb_result,0);
5821 
5822  if (strstr(strtmp,"transpose_5D")!=NULL)
5823  xml_Transposition(s,c,5,sb_result,1);
5824  else if (strstr(strtmp,"transpose_4D")!=NULL)
5825  xml_Transposition(s,c,4,sb_result,1);
5826  else if (strstr(strtmp,"transpose_3D")!=NULL)
5827  xml_Transposition(s,c,3,sb_result,1);
5828  else
5829  if (strstr(strtmp,"transpose_2D")!=NULL)
5830  xml_Transposition(s,c,2,sb_result,1);
5831  xml_Region_Parameter(pattern_region, sb_result);
5832  xml_Loops(st,true,&pattern_region,&paving_indices, &pattern_indices,motif_in_te_p, sb_result);
5833  if (ENTITY_ASSIGN_P(func) && !func_as_rhs_of_assign)
5834  xml_TaskParameters(s,true,code_tag, module,pattern_region,paving_indices,sb_result);
5835  else // it may be an assignment but with a (non intrinsic) function at the RHS
5836  xml_Arguments(s,func,statement_number(s),ENTITY_ASSIGN_P(func), paving_indices, t, prec,sb_result);
5837  global_margin--;
5838  string_buffer_append_word("/Call",sb_result);
5839 
5840  if (statif != STACK_NULL) {
5841  for (int tp=1;tp<=nb_cond;tp++) {
5842  global_margin--;
5843  string_buffer_append_word("/CallCondition",sb_result);
5844  }
5845  }
5847  sc_free(prec);
5848 }
5849 
5851  entity func,list effects_list, Pvecteur vargs,string_buffer sb_result)
5852 {
5853  string_buffer buffer_needs = string_buffer_make(true);
5854  string string_needs = "";
5855  Pvecteur vr = VECTEUR_NUL,vw = VECTEUR_NUL;
5856  list pc;
5857  Pvecteur va2 = vect_dup(vargs);
5858 
5859  vars_read_and_written(effects_list,&vr,&vw);
5860 
5861  for (pc= effects_list;pc != NIL; pc = CDR(pc)){
5862  effect e = EFFECT(CAR(pc));
5864  action ac = effect_action(e);
5865  entity v = reference_variable(r);
5866  // get last function which modified v, if any...
5867  entity t = def_to_task_get(v);
5868  if ( store_effect_p(e)
5870  // To avoid the multiple references to the same user array (Array of struct, Read-Written arrays, ..)
5871  && action_read_p(ac) && vect_coeff(v,vr) && ((vect_coeff(v,vw) && (t != NULL)) || !vect_coeff(v,vw) )
5872  // to avoid private variables
5874  && !string_parameter_p(v)) {
5875  vect_chg_coeff(&vr,v,0);
5876  global_margin++;
5877  add_margin(global_margin,buffer_needs);
5878  string_buffer_append(buffer_needs,
5880  "Needs ",(array_entity_p(v))?"ArrayName=": "ScalarName=",
5881  QUOTE,NULL));
5882  string_buffer_append_xml_text(buffer_needs,(string) entity_user_name(v),false);
5883  string_buffer_append(buffer_needs,
5884  concatenate(QUOTE, BL,
5885  "DefinedBy=",QUOTE,
5886  (t != NULL) ? entity_local_name(t): "IN_VALUE",QUOTE,"/",
5887  CLOSEANGLE,NL,NULL));
5888  global_margin--;
5889  }
5890  }
5891  for (pc= effects_list;pc != NIL; pc = CDR(pc)){
5892  effect e = EFFECT(CAR(pc));
5894  action ac = effect_action(e);
5895  entity v = reference_variable(r);
5897  // to avoid private variables and the multiple references to the same user array (Array of struct, ..)
5898  &&!action_read_p(ac) && vect_coeff(v,vw)
5899  && !(entity_static_variable_p(v) && !top_level_entity_p(v))) {
5900  vect_chg_coeff(&vw,v,0);
5901  global_margin++;
5902  add_margin(global_margin,sb_result);
5903  string_buffer_append(sb_result,
5905  "Computes ",(array_entity_p(v))?"ArrayName=": "ScalarName=",
5906  QUOTE,NULL));
5907  string_buffer_append_xml_text(sb_result,(string) entity_user_name(v),false);
5908  string_buffer_append(sb_result,
5909  concatenate(QUOTE,"/", CLOSEANGLE,NL,NULL));
5910  def_to_task_store(v, func);
5911  global_margin--;
5912  }
5913  }
5914 
5915  vect_rm(va2);
5916  string_needs =string_buffer_to_string(buffer_needs);
5917  string_buffer_append(sb_result,string_needs);
5918  free(string_needs);
5919  string_needs=NULL;
5920 }
5921 
5922 static int find_code_status(const char* module_name)
5923 {
5924  statement stat=(statement) db_get_memory_resource(DBR_CODE,
5925  module_name, true);
5926  bool wmotif = false;
5927  bool wbox = false;
5928  motif_in_statement_p = false;
5930  wmotif = motif_in_statement_p;
5931  box_in_statement_p = false;
5933  wbox = box_in_statement_p;
5934 
5935  if (same_string_p(module_name, get_string_property("XML_APPLICATION_MAIN")))
5936  return code_is_a_main;
5937  else {
5938  if (wmotif && !wbox)
5939  return code_is_a_te;
5940  else
5941  return code_is_a_box;
5942  }
5943 }
5944 
5945 static void xml_Boxes(const char* module_name, int code_tag,string_buffer sb_result)
5946 {
5949  string_buffer type_buffer = string_buffer_make(true);
5950  string string_types;
5951  Psysteme prec = SC_UNDEFINED;
5953  nest_context_t nest;
5954  int st_nb1=0, st_sauv=0;
5955  Pvecteur pv=VECTEUR_NUL;
5960  nest.testif = stack_make(statement_domain,0,0);
5961  nest.nested_if= gen_array_make(0);
5962  nest.nested_loops= gen_array_make(0);
5964  nest.nested_call= gen_array_make(0);
5965 
5966  global_margin++;
5967  add_margin(global_margin,sb_result);
5968  string_buffer_append(sb_result,
5970  "Box Name=", QUOTE,module_name,QUOTE,
5971  CLOSEANGLE,NL, NULL));
5972  global_margin++;
5975  if (!entity_main_module_p(module)) {
5976  xml_GlobalVariables(t,prec,true,sb_result);
5977  xml_LocalVariables(module,t,prec,sb_result);
5978  xml_FormalVariables(module,t,prec,sb_result);
5979  }
5980  else {
5981  xml_GlobalVariables(t,prec,false,sb_result);
5982  //string_buffer_append_word("GlobalVariables/",sb_result);
5983  xml_LocalVariables(module,t,prec,sb_result);
5984  string_buffer_append_word("FormalVariables/",sb_result);
5985  }
5986 
5987  /*CA*/
5990  string_buffer_append_word("GlobalReferencedTypes",type_buffer);
5991  global_margin++;
5992  for (pv = global_application_variables;pv!=NULL;pv=pv->succ) {
5993  xml_Type_Entity((entity)pv->var,type_buffer);
5994  }
5995  /* for validation */
5996  global_margin--;
5997  string_buffer_append_word("/GlobalReferencedTypes",type_buffer);
5998  string_buffer_append_word("LocalReferencedTypes",type_buffer);
5999  global_margin++;
6000 
6001  for (pv = local_application_variables;pv!=NULL;pv=pv->succ) {
6002  xml_Type_Entity((entity)pv->var,type_buffer);
6003  }
6004  global_margin--;
6005  string_buffer_append_word("/LocalReferencedTypes",type_buffer);
6006  string_types =string_buffer_to_string(type_buffer);
6007  string_buffer_append(sb_result,string_types);
6008  free(string_types);
6009 
6010  /*CA*/
6011  /* Search calls in Box */
6012  find_loops_and_calls_in_box(stat,&nest);
6013  int nb_call = (int)gen_array_nitems(nest.nested_call);
6014  for (int callnumber = 0; callnumber<nb_call; callnumber++) {
6015  statement st= gen_array_item(nest.nested_call,callnumber);
6016  st_nb1 = statement_number(st);
6017  // to deal with nested calls in the same instruction
6018  if (callnumber==0 || st_nb1!=st_sauv)
6019  xml_Call(module, code_tag, callnumber, &nest,sb_result);
6020  st_sauv=st_nb1;
6021  }
6022 
6023  // xml_BoxGraph(module,&nest,sb_result);
6024  xml_Chains(module, module_name,stat,&nest,sb_result);
6025  global_margin--;
6026  string_buffer_append_word("/Box",sb_result);
6027 
6028  /* AGGREGATION TRANSFERED TO "tspear"
6029  *
6030  * string_buffer_append_word("Tasks",sb_result);
6031  * insert_xml_callees(module_name);
6032  * string_buffer_append_word("/Tasks",sb_result);
6033  */
6034 
6035  global_margin--;
6039  gen_array_free(nest.nested_if);
6040  stack_free(&(nest.testif));
6041  stack_free(&(nest.loops_for_call));
6042  stack_free(&(nest.loop_indices));
6043  stack_free(&(nest.current_stat));
6045  sc_free(prec);
6046 }
6047 
6048 
6049 static void xml_Application(
6050  const char* module_name,
6051  int code_tag,
6052  string_buffer sb_result)
6053 {
6056  Psysteme prec = SC_UNDEFINED;
6058  Pvecteur vargs = VECTEUR_NUL;
6059 
6060  pips_assert("code is a main", code_tag == code_is_a_main);
6061 
6062  global_margin = 0;
6063  // <Application ...>
6064  string_buffer_append(sb_result, concatenate(
6065  OPENANGLE, "Application Name=", QUOTE, get_current_module_name(), QUOTE, BL,
6066  "Language=",QUOTE, (fortran_appli)? "FORTRAN": "C", QUOTE, BL,
6067  "PassingMode=", QUOTE,(fortran_appli)? "BYREFERENCE": "BYVALUE", QUOTE,
6068  CLOSEANGLE, NL, NULL));
6069 
6070  global_margin ++;
6071 
6072  // IncludedFiles will be written here
6073  add_margin(global_margin, sb_result);
6074  string_buffer_append(sb_result, "<!-- Included Files -->" NL);
6075 
6076  // <GlobalVariables>...</GlobalVariables>
6077  xml_GlobalVariables( t, prec, true, sb_result);
6078 
6079  // Box/Task will be written here
6080  add_margin(global_margin, sb_result);
6081  string_buffer_append(sb_result, "<!-- Main Box -->" NL);
6082 
6083  // <ApplicationGraph>
6084  add_margin(global_margin, sb_result);
6085  string_buffer_append(sb_result,
6087  "ApplicationGraph Name=", QUOTE, module_name, QUOTE,
6088  CLOSEANGLE,NL, NULL));
6089 
6090  // <TaskRef>
6091  global_margin ++;
6092  add_margin(global_margin,sb_result);
6093  string_buffer_append(sb_result,
6095  "TaskRef Name=", QUOTE,entity_user_name(module), QUOTE,
6096  CLOSEANGLE,NL,NULL));
6097 
6098  cumulated_list = NIL;
6100  xml_Compute_and_Need(module,cumulated_list, vargs, sb_result);
6101 
6102  // </TaskRef>
6103  string_buffer_append_word("/TaskRef", sb_result);
6104  global_margin --;
6105 
6106  // </ApplicationGraph>
6107  string_buffer_append_word("/ApplicationGraph", sb_result);
6108  global_margin --;
6109 
6110  // </Application>
6111  string_buffer_append_word("/Application", sb_result);
6112 
6113  sc_free(prec);
6114 }
6115 
6116 /******************************************************** PIPSMAKE INTERFACE */
6117 
6118 static bool generic_print_xml_application(const char* module_name, bool is_app)
6119 {
6120  FILE * out;
6121  entity module;
6122  string dir, filename;
6123  statement stat;
6124  string_buffer sb_result = string_buffer_make(true);
6125  int code_tag;
6126  string resource = is_app? DBR_SPEAR_APP_FILE : DBR_SPEAR_CODE_FILE;
6127 
6128  // globals...
6130 
6132  string xml = db_build_file_resource_name
6133  (resource, module_name, is_app? ".app.xml": ".xml");
6135  filename = strdup(concatenate(dir, "/", xml, NULL));
6136  stat = (statement) db_get_memory_resource(DBR_CODE, module_name, true);
6140  if(statement_undefined_p(stat)) {
6141  pips_internal_error("No statement for module %s", module_name);
6142  }
6144  db_get_memory_resource(DBR_PROPER_EFFECTS,
6145  module_name,true));
6147  db_get_memory_resource(DBR_CUMULATED_EFFECTS,
6148  module_name,true));
6149  init_cost_table();
6150  // set_complexity_map( (statement_mapping)
6151  // db_get_memory_resource(DBR_COMPLEXITIES, module_name, true));
6152 
6153  /* Get the READ and WRITE regions of the module */
6155  db_get_memory_resource(DBR_REGIONS, module_name, true));
6156 
6158  db_get_memory_resource(DBR_PRECONDITIONS,
6159  module_name,
6160  true));
6161 
6163 
6164  debug_on("XMLPRETTYPRINTER_DEBUG_LEVEL");
6165  out = safe_fopen(filename, "w");
6166  code_tag = find_code_status(module_name);
6167  fprintf(out,"%s<!-- XML prettyprint for %s \"%s\" --> \n",
6168  is_app? "": " ",
6169  is_app? "application": code_tag == code_is_a_te? "task": "box",
6170  module_name);
6171 
6172  if (is_app)
6174  db_get_memory_resource(DBR_TASK_VARIABLE_CHANGED_BY,
6175  module_name, true));
6176  else
6177  def_to_task_init();
6178 
6180 
6181  if (is_app)
6182  {
6183  pips_assert("application is a main", code_tag == code_is_a_main);
6184  xml_Application(module_name, code_tag, sb_result);
6185  }
6186  else
6187  {
6188  switch (code_tag)
6189  {
6190  case code_is_a_main:
6191  case code_is_a_box:
6192  // xml_Boxes(module_name, code_is_a_main, sb_result);
6193  xml_Boxes(module_name, code_tag, sb_result);
6194  break;
6195  case code_is_a_te:
6196  xml_Task(module_name, code_tag, sb_result);
6197  break;
6198  default:
6199  pips_internal_error("unexpected kind of code for xml_prettyprinter");
6200  }
6201  }
6202 
6203  pips_debug(1, "End XML prettyprinter for %s\n", module_name);
6204  debug_off();
6205 
6206  string sr = string_buffer_to_string(sb_result);
6207  fputs(sr, out);
6208  free(sr);
6209  safe_fclose(out, filename);
6210 
6211  string_buffer_free(&sb_result);
6213  free(dir);
6214  free(filename);
6215 
6217  if (!is_app)
6218  DB_PUT_MEMORY_RESOURCE(DBR_TASK_VARIABLE_CHANGED_BY, module_name,
6220 
6227  reset_rw_effects();
6231  return true;
6232 }
6233 
6235 {
6237  db_get_memory_resource(DBR_POINTS_TO, module_name, true) );
6238  bool result = generic_print_xml_application(module_name, false);
6239  reset_pt_to_list();
6240  return result;
6241 }
6242 
6244 {
6245  bool result = generic_print_xml_application(module_name, false);
6246  return result;
6247 }
6248 
6250 {
6251  bool result = generic_print_xml_application(module_name, true);
6252  return result;
6253 }
6255 {
6257  db_get_memory_resource(DBR_POINTS_TO, module_name, true) );
6258  bool result = generic_print_xml_application(module_name, true);
6259  reset_pt_to_list();
6260  return result;
6261 }
void free_transformer(transformer p)
Definition: ri.c:2616
entity_to_entity make_entity_to_entity(void)
Definition: ri.c:719
bool bound_entity_to_entity_p(entity_to_entity f, entity k)
Definition: ri.c:734
void update_entity_to_entity(entity_to_entity f, entity k, entity v)
Definition: ri.c:725
void extend_entity_to_entity(entity_to_entity f, entity k, entity v)
Definition: ri.c:728
entity apply_entity_to_entity(entity_to_entity f, entity k)
Definition: ri.c:722
struct _newgen_struct_entity_ * entity
Definition: abc_private.h:14
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
static FILE * out
Definition: alias_check.c:128
void list_to_array(list l, gen_array_t a)
args.c
Definition: args.c:38
string list_to_string(list l)
Return the malloc()ed version of the concatenation of all the strings in the list.
Definition: args.c:74
#define value_pos_p(val)
void const char const char const int
int Value
#define VALUE_ONE
#define value_abs(val)
#define value_neg_p(val)
size_t gen_array_nitems(const gen_array_t a)
Definition: array.c:131
gen_array_t gen_array_make(size_t size)
declarations...
Definition: array.c:40
void ** gen_array_pointer(const gen_array_t a)
Observers...
Definition: array.c:125
void * gen_array_item(const gen_array_t a, size_t i)
Definition: array.c:143
void gen_array_append(gen_array_t a, void *what)
Definition: array.c:105
void gen_array_free(gen_array_t a)
Definition: array.c:70
Pbase base_normalize(Pbase b)
Definition: base.c:594
bool transformer_is_rn_p(transformer t)
Check that transformer t is the canonical representation of the whole afine space defined by its basi...
Definition: basic.c:183
static graph dg
dg is the dependency graph ; FIXME : should not be static global ?
Definition: chains.c:124
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
bool complexity_zero_p(complexity comp)
zero complexity check.
Definition: comp_math.c:244
char * complexity_sprint(complexity comp, bool print_stats_p, bool print_local_names_p)
Definition: comp_util.c:175
void init_cost_table()
Completes the intrinsic cost table with the costs read from the files specified in the "COMPLEXITY_CO...
Definition: comp_util.c:519
static bool reduction_p(set reductions_l[STEP_UNDEF_REDUCE], entity e)
complexity load_statement_complexity(statement)
void reset_complexity_map(void)
void set_complexity_map(statement_mapping)
#define CONTRAINTE_UNDEFINED_P(c)
#define contrainte_vecteur(c)
passage au champ vecteur d'une contrainte "a la Newgen"
#define CONTRAINTE_UNDEFINED
Pcontrainte contrainte_make(Pvecteur pv)
Pcontrainte contrainte_make(Pvecteur pv): allocation et initialisation d'une contrainte avec un vecte...
Definition: alloc.c:73
Pcontrainte contrainte_dup(Pcontrainte c_in)
Pcontrainte contrainte_dup(Pcontrainte c_in): allocation d'une contrainte c_out prenant la valeur de ...
Definition: alloc.c:132
struct _newgen_struct_dg_arc_label_ * dg_arc_label
Definition: dg.h:60
#define conflict_sink(x)
Definition: dg.h:167
#define CONFLICT(x)
CONFLICT.
Definition: dg.h:134
#define dg_arc_label_conflicts(x)
Definition: dg.h:201
#define conflict_source(x)
Definition: dg.h:165
#define region_write_p(reg)
#define region_system(reg)
#define region_undefined
#define region_read_p(reg)
useful region macros
#define region_undefined_p(reg)
#define REGION
#define region
simulation of the type region
#define min(a, b)
#define max(a, b)
entity make_phi_entity(int)
list regions_dup(list)
void regions_free(list)
void set_rw_effects(statement_effects)
list load_proper_rw_effects_list(statement)
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
void reset_cumulated_rw_effects(void)
list load_statement_local_regions(statement)
void reset_rw_effects(void)
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
#define effect_read_p(eff)
#define effect_scalar_p(eff) entity_scalar_p(effect_entity(eff))
bool store_effect_p(effect)
Definition: effects.c:1062
void set_pt_to_list(statement_points_to)
bool environment_effect_p(effect)
Definition: effects.c:1071
void reset_pt_to_list(void)
#define effect_undefined_p(x)
Definition: effects.h:615
#define effect_action(x)
Definition: effects.h:642
#define effect_undefined
Definition: effects.h:614
#define action_write_p(x)
Definition: effects.h:314
#define action_read_p(x)
Definition: effects.h:311
#define EFFECT(x)
EFFECT.
Definition: effects.h:608
#define effect_cell(x)
Definition: effects.h:640
string make_entity_fullname(const char *module_name, const char *local_name)
END_EOLE.
Definition: entity_names.c:230
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
char * get_string_property(const char *)
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
#define STRING(x)
Definition: genC.h:87
#define gen_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
static char start[1024]
The name of the variable from which to start counting domain numbers.
Definition: genLisp.c:55
if(!(yy_init))
Definition: genread_lex.c:1029
void * malloc(YYSIZE_T)
void free(void *)
#define successor_vertex(x)
Definition: graph.h:118
#define successor_arc_label(x)
Definition: graph.h:116
struct _newgen_struct_graph_ * graph
Definition: graph.h:31
#define vertex_successors(x)
Definition: graph.h:154
#define SUCCESSOR(x)
SUCCESSOR.
Definition: graph.h:86
#define graph_vertices(x)
Definition: graph.h:82
#define VERTEX(x)
VERTEX.
Definition: graph.h:122
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement(void)
Reset the current module statement.
Definition: static.c:221
const char * get_current_module_name(void)
Get the name of the current module.
Definition: static.c:121
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
void push_current_module_statement(statement)
Set the statement of the current module and push the statement of the previous one on a stack.
Definition: static.c:180
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
void pop_current_module_statement(void)
Pop the current module statement stack and use it as the current module statement.
Definition: static.c:194
void gen_context_multi_recurse(void *o, void *context,...)
Multi-recursion with context function visitor.
Definition: genClib.c:3373
void gen_null2(__attribute__((unused)) void *u1, __attribute__((unused)) void *u2)
idem with 2 args, to please overpeaky compiler checks
Definition: genClib.c:2758
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define list_undefined_p(c)
Return if a list is undefined.
Definition: newgen_list.h:75
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
size_t gen_length(const list l)
Definition: list.c:150
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#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 CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
list gen_append(list l1, const list l2)
Definition: list.c:471
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69
#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
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
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 DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
#define DB_PUT_FILE_RESOURCE
Put a file resource into the current workspace database.
Definition: pipsdbm-local.h:85
bool statement_call_p(statement)
Definition: statement.c:364
bool statement_loop_p(statement)
Definition: statement.c:349
bool return_statement_p(statement)
Test if a statement is a C or Fortran "return".
Definition: statement.c:172
bool continue_statement_p(statement)
Test if a statement is a CONTINUE, that is the FORTRAN nop, the ";" in C or the "pass" in Python....
Definition: statement.c:203
bool declaration_statement_p(statement)
Had to be optimized according to Beatrice Creusillet.
Definition: statement.c:224
char end
Definition: gtk_status.c:82
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
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
void * hash_del(hash_table htp, const void *key)
this function removes from the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:439
#define full_name(dir, name)
Definition: compile.c:414
bool expression_constant_p(expression)
HPFC module by Fabien COELHO.
Definition: expression.c:2453
statement vertex_to_statement(vertex v)
Vertex_to_statement looks for the statement that is pointed to by vertex v.
Definition: util.c:45
static list indices
Definition: icm.c:204
static statement mod_stat
We want to keep track of the current statement inside the recurse.
Definition: impact_check.c:41
static int upperbound(Pproblem XX, struct rproblem *RR, int iv, int rvar, float epss)
static int cutbounds(Pproblem XX,struct rproblem *RR,int iv, int rvar,float epss)
Definition: isolve.c:1685
bool vect_opposite_except(Pvecteur v1, Pvecteur v2, Variable var)
bool vect_opposite_except(Pvecteur v1, Pvecteur v2, Variable var): test a egalite des projections sel...
Definition: reductions.c:399
int vect_dimension(Pvecteur v)
int vect_dimension(Pvecteur v): calcul du nombre de composantes non nulles et non constantes d'un vec...
Definition: reductions.c:64
int vect_size(Pvecteur v)
package vecteur - reductions
Definition: reductions.c:47
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 matrix_free(m)
Allocation et desallocation d'une matrice.
Definition: matrix-local.h:73
#define MATRIX_ELEM(matrix, i, j)
Macros d'acces aux elements d'une matrice.
Definition: matrix-local.h:80
Pmatrix matrix_new(int m, int n)
package matrix
Definition: alloc.c:41
#define debug_on(env)
Definition: misc-local.h:157
#define _UNUSED_
Definition: misc-local.h:232
#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_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define pips_internal_error
Definition: misc-local.h:149
#define debug_off()
Definition: misc-local.h:160
#define pips_user_error
Definition: misc-local.h:147
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
#define spear_warning(...)
#define TYPEDEF_PREFIX
Definition: naming-local.h:62
#define UNION_PREFIX
Definition: naming-local.h:58
#define ENUM_PREFIX
Definition: naming-local.h:60
#define TOP_LEVEL_MODULE_NAME
Module containing the global variables in Fortran and C.
Definition: naming-local.h:101
#define MEMBER_SEP_STRING
Definition: naming-local.h:53
#define STRUCT_PREFIX
Definition: naming-local.h:56
#define GEN_ARRAY_FOREACH(type, s, array)
Definition: newgen_array.h:50
string gen_strndup0(string, size_t)
Like strdup() but copy at most n characters.
Definition: string.c:83
char * i2a(int)
I2A (Integer TO Ascii) yields a string for a given Integer.
Definition: string.c:121
string strupper(string, const char *)
Definition: string.c:213
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
@ hash_pointer
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
Value of an undefined hash_table.
Definition: newgen_hash.h:49
#define same_string_p(s1, s2)
void * gen_find_tabulated(const char *, int)
Definition: tabulated.c:218
#define STACK_NULL
defines for empty values
Definition: newgen_stack.h:52
#define STACK_MAP_X(_item, _itemtype, _code, _stack, _downwards)
not needed
Definition: newgen_stack.h:104
stack stack_copy(const stack)
duplicate a stack with its contents.
Definition: stack.c:267
void * stack_head(const stack)
returns the item on top of stack s
Definition: stack.c:420
int stack_size(const stack)
observers
void stack_push(void *, stack)
stack use
Definition: stack.c:373
void stack_free(stack *)
type, bucket_size, policy
Definition: stack.c:292
stack stack_make(int, int, int)
allocation
Definition: stack.c:246
void * stack_pop(stack)
POPs one item from stack s.
Definition: stack.c:399
void string_buffer_append(string_buffer, const string)
append string s (if non empty) to string buffer sb, the duplication is done if needed according to th...
string string_buffer_to_string(const string_buffer)
return malloc'ed string from string buffer sb
void string_buffer_free(string_buffer *)
free string buffer structure, also free string contents according to the dup field
Definition: string_buffer.c:82
string_buffer string_buffer_make(bool dup)
allocate a new string buffer
Definition: string_buffer.c:58
bool string_buffer_empty_p(const string_buffer)
return whether string_buffer sb is empty.
void string_buffer_append_xml_text(string_buffer, const string, bool)
append a string with XML escapes
#define string_undefined
Definition: newgen_types.h:40
char * string
STRING.
Definition: newgen_types.h:39
#define string_undefined_p(s)
Definition: newgen_types.h:41
int(* gen_cmp_func_t)(const void *, const void *)
Definition: newgen_types.h:114
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
void print_ordering_to_statement(void)
Dump the ordering with the corresponding statement address.
Definition: ordering.c:71
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
void reset_ordering_to_statement(void)
Reset the mapping from ordering to statement.
Definition: ordering.c:185
normalized NormalizeExpression(expression e)
normalize.c
Definition: normalize.c:81
static char * module
Definition: pips.c:74
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
string expression_to_string(expression e)
Definition: expression.c:77
void print_reference(reference r)
Definition: expression.c:142
list Words_Syntax(syntax obj)
Definition: misc.c:2664
string basic_to_string(basic)
Definition: type.c:87
void print_statement(statement)
Print a statement on stderr.
Definition: statement.c:98
Pvecteur vect_reversal(Pvecteur vect_in)
Pvecteur vect_reversal(Pvecteur vect_in); produces the reversal vector of the vect_in.
Definition: private.c:237
#define pattern_indices(x)
Definition: reduction.h:135
#define ENTITY_ASSIGN_P(e)
#define PLUS_OPERATOR_NAME
#define NORMALIZE_EXPRESSION(e)
#define ADDRESS_OF_OPERATOR_NAME
#define ENTITY_LOGICAL_OPERATOR_P(e)
Attention : This definition is different with the Fortran Standard where the logical operators are th...
#define ASSIGN_OPERATOR_NAME
Definition: ri-util-local.h:95
bool stack_area_p(entity aire)
Definition: area.c:104
bool heap_area_p(entity aire)
Definition: area.c:86
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
bool io_intrinsic_p(entity e)
rue is a statement s is an io intrinsic
Definition: entity.c:1655
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
bool array_entity_p(entity e)
Definition: entity.c:793
bool same_entity_p(entity e1, entity e2)
predicates on entities
Definition: entity.c:1321
bool entity_subroutine_p(entity e)
Definition: entity.c:737
bool std_file_entity_p(entity e)
Definition: entity.c:1232
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
bool entity_main_module_p(entity e)
Definition: entity.c:700
bool entity_function_p(entity e)
Definition: entity.c:724
bool effects_package_entity_p(entity e)
checks if an entity is an IO_EFFECTS_PACKAGE_NAME, a MALLOC_EFFECTS_NAME or a RAND_EFFECTS_PACKAGE_NA...
Definition: entity.c:1181
void print_entities(list l)
Definition: entity.c:167
bool fortran_module_p(entity m)
Test if a module is in Fortran.
Definition: entity.c:2799
bool top_level_entity_p(entity e)
Check if the scope of entity e is global.
Definition: entity.c:1130
entity find_ith_formal_parameter(entity the_fnct, int rank)
This function gives back the ith formal parameter, which is found in the declarations of a call or a ...
Definition: entity.c:1863
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
value EvalExpression(expression e)
Evaluate statically an expression.
Definition: eval.c:108
bool expression_integer_value(expression e, intptr_t *pval)
Definition: eval.c:792
expression make_vecteur_expression(Pvecteur pv)
make expression for vector (Pvecteur)
Definition: expression.c:1650
bool expression_field_p(expression e)
The expression is of kind "s.a", where "s" is a struct and a "a" field.
Definition: expression.c:491
int expression_to_int(expression exp)
================================================================
Definition: expression.c:2205
expression make_call_expression(entity e, list l)
Build an expression that call an function entity with an argument list.
Definition: expression.c:321
call expression_call(expression e)
Definition: expression.c:445
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
Definition: expression.c:1188
bool reference_equal_p(reference r1, reference r2)
Definition: expression.c:1500
bool array_argument_p(expression e)
Definition: expression.c:513
list module_formal_parameters(entity func)
list module_formal_parameters(entity func) input : an entity representing a function.
Definition: module.c:327
bool array_type_p(type)
Definition: type.c:2942
dimension find_ith_dimension(list, int)
This function returns the ith dimension of a list of dimensions.
Definition: type.c:5621
bool entity_static_variable_p(entity)
return true if the entity is declared with the keyword static
Definition: variable.c:1146
type expression_to_type(expression)
For an array declared as int a[10][20], the type returned for a[i] is int [20].
Definition: type.c:2486
statement pop_statement_global_stack(void)
Definition: static.c:352
size_t maximal_type_depth(type)
Number of steps to access the lowest leave of type t without a recursive test.
Definition: type.c:4856
bool integer_type_p(type)
Definition: type.c:3298
type entity_basic_concrete_type(entity)
retrieves or computes and then returns the basic concrete type of an entity
Definition: type.c:3677
_int SizeOfElements(basic)
This function returns the length in bytes of the Fortran or C type represented by a basic,...
Definition: size.c:297
void push_statement_on_statement_global_stack(statement)
Definition: static.c:333
type compute_basic_concrete_type(type)
computes a new type which is the basic concrete type of the input type (this new type is not stored i...
Definition: type.c:3556
bool variable_heap_p(entity)
Definition: variable.c:1600
void free_statement_global_stack(void)
Definition: static.c:358
int variable_entity_dimension(entity)
variable_entity_dimension(entity v): returns the dimension of variable v; scalar have dimension 0.
Definition: variable.c:1293
void make_statement_global_stack(void)
Definition: static.c:318
#define type_functional_p(x)
Definition: ri.h:2950
#define entity_to_entity_undefined_p(x)
Definition: ri.h:1085
#define value_undefined_p(x)
Definition: ri.h:3017
#define loop_body(x)
Definition: ri.h:1644
#define type_struct(x)
Definition: ri.h:2964
#define test_domain
newgen_entity_domain_defined
Definition: ri.h:418
#define value_code_p(x)
Definition: ri.h:3065
#define basic_pointer(x)
Definition: ri.h:637
#define normalized_undefined
Definition: ri.h:1745
#define syntax_reference_p(x)
Definition: ri.h:2728
#define transformer_undefined
Definition: ri.h:2847
#define functional_result(x)
Definition: ri.h:1444
#define transformer_undefined_p(x)
Definition: ri.h:2848
#define loop_execution(x)
Definition: ri.h:1648
#define storage_formal_p(x)
Definition: ri.h:2522
#define value_constant(x)
Definition: ri.h:3073
#define loop_undefined
Definition: ri.h:1612
#define syntax_reference(x)
Definition: ri.h:2730
#define syntax_tag(x)
Definition: ri.h:2727
#define value_reference(x)
Definition: ri.h:3085
#define reference_undefined
Definition: ri.h:2302
#define extension_pragma_p(x)
Definition: ri.h:1293
#define pragma_string(x)
Definition: ri.h:2033
#define call_function(x)
Definition: ri.h:709
#define reference_variable(x)
Definition: ri.h:2326
#define loop_domain
newgen_language_domain_defined
Definition: ri.h:218
#define basic_derived(x)
Definition: ri.h:640
#define basic_typedef_p(x)
Definition: ri.h:641
#define range_upper(x)
Definition: ri.h:2290
#define type_tag(x)
Definition: ri.h:2940
#define reference_undefined_p(x)
Definition: ri.h:2303
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define constant_int(x)
Definition: ri.h:850
#define syntax_call_p(x)
Definition: ri.h:2734
#define instruction_loop(x)
Definition: ri.h:1520
#define syntax_cast(x)
Definition: ri.h:2739
#define type_functional(x)
Definition: ri.h:2952
#define dimension_lower(x)
Definition: ri.h:980
#define pragma_string_p(x)
Definition: ri.h:2031
#define call_undefined_p(x)
Definition: ri.h:686
#define type_variable(x)
Definition: ri.h:2949
#define basic_pointer_p(x)
Definition: ri.h:635
#define basic_derived_p(x)
Definition: ri.h:638
#define entity_storage(x)
Definition: ri.h:2794
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define code_declarations(x)
Definition: ri.h:784
@ is_syntax_call
Definition: ri.h:2693
@ is_syntax_reference
Definition: ri.h:2691
#define range_increment(x)
Definition: ri.h:2292
#define storage_ram_p(x)
Definition: ri.h:2519
#define value_constant_p(x)
Definition: ri.h:3071
#define call_domain
newgen_callees_domain_defined
Definition: ri.h:58
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define cast_expression(x)
Definition: ri.h:747
#define basic_typedef(x)
Definition: ri.h:643
#define extension_pragma(x)
Definition: ri.h:1295
#define EXTENSION(x)
EXTENSION.
Definition: ri.h:1253
#define entity_undefined_p(x)
Definition: ri.h:2762
#define type_enum(x)
Definition: ri.h:2970
#define reference_domain
newgen_range_domain_defined
Definition: ri.h:338
#define entity_undefined
Definition: ri.h:2761
#define constant_int_p(x)
Definition: ri.h:848
#define expression_undefined
Definition: ri.h:1223
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_sequence
Definition: ri.h:1469
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511
#define loop_undefined_p(x)
Definition: ri.h:1613
#define entity_name(x)
Definition: ri.h:2790
#define transformer_relation(x)
Definition: ri.h:2873
#define expression_normalized(x)
Definition: ri.h:1249
#define test_true(x)
Definition: ri.h:2835
#define sequence_statements(x)
Definition: ri.h:2360
#define dimension_upper(x)
Definition: ri.h:982
#define reference_indices(x)
Definition: ri.h:2328
#define statement_extensions(x)
Definition: ri.h:2464
#define value_code(x)
Definition: ri.h:3067
#define instruction_sequence(x)
Definition: ri.h:1514
#define syntax_call(x)
Definition: ri.h:2736
#define dimension_undefined
Definition: ri.h:955
#define instruction_call_p(x)
Definition: ri.h:1527
#define test_condition(x)
Definition: ri.h:2833
#define range_lower(x)
Definition: ri.h:2288
#define value_reference_p(x)
Definition: ri.h:3083
#define variable_dimensions(x)
Definition: ri.h:3122
#define statement_declarations(x)
Definition: ri.h:2460
#define statement_instruction(x)
Definition: ri.h:2458
#define statement_comments(x)
Definition: ri.h:2456
#define instruction_call(x)
Definition: ri.h:1529
#define loop_range(x)
Definition: ri.h:1642
#define extensions_extension(x)
Definition: ri.h:1330
struct _newgen_struct_transformer_ * transformer
Definition: ri.h:431
#define instruction_test_p(x)
Definition: ri.h:1515
#define call_arguments(x)
Definition: ri.h:711
#define syntax_cast_p(x)
Definition: ri.h:2737
#define instruction_test(x)
Definition: ri.h:1517
#define statement_undefined_p(x)
Definition: ri.h:2420
@ is_type_enum
Definition: ri.h:2907
@ is_type_variable
Definition: ri.h:2900
@ is_type_union
Definition: ri.h:2906
@ is_type_struct
Definition: ri.h:2905
#define entity_type(x)
Definition: ri.h:2792
#define call_undefined
Definition: ri.h:685
#define statement_number(x)
Definition: ri.h:2452
#define normalized_linear(x)
Definition: ri.h:1781
#define expression_syntax(x)
Definition: ri.h:1247
#define execution_parallel_p(x)
Definition: ri.h:1211
#define storage_return_p(x)
Definition: ri.h:2516
#define type_variable_p(x)
Definition: ri.h:2947
#define predicate_system(x)
Definition: ri.h:2069
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
#define loop_index(x)
Definition: ri.h:1640
#define type_union(x)
Definition: ri.h:2967
#define variable_basic(x)
Definition: ri.h:3120
#define statement_undefined
Definition: ri.h:2419
#define entity_to_entity_undefined
Definition: ri.h:1084
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
#define entity_initial(x)
Definition: ri.h:2796
int vertex_sort_callback(const vertex *, const vertex *)
This is a callback for qsort function, it compares two vertex.
Definition: util.c:105
int successor_sort_callback(const successor *, const successor *)
This is a callback for qsort function, it compares two successor.
Definition: util.c:116
int conflicts_sort_callback(conflict *, conflict *)
This is a callback for qsort function, it compares two conflicts.
Definition: util.c:126
void sc_rm(Psysteme ps)
void sc_rm(Psysteme ps): liberation de l'espace memoire occupe par le systeme de contraintes ps;
Definition: sc_alloc.c:277
Psysteme sc_dup(Psysteme ps)
Psysteme sc_dup(Psysteme ps): should becomes a link.
Definition: sc_alloc.c:176
Psysteme sc_free(Psysteme in_ps)
Psysteme sc_free( in_ps ) AL 30/05/94 Free of in_ps.
Definition: sc_list.c:112
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()
int printf()
void sc_transform_eg_in_ineg(Psysteme sc)
Package sc.
void vect_chg_sgn(Pvecteur v)
void vect_chg_sgn(Pvecteur v): multiplie v par -1
Definition: scalaires.c:151
void module_to_value_mappings(entity m)
void module_to_value_mappings(entity m): build hash tables between variables and values (old,...
Definition: mappings.c:624
void integer_expression_and_precondition_to_integer_interval(expression, transformer, int *, int *)
Could be used for bool expressions too? Extended to any kind of expression?
Definition: utils.c:386
transformer load_statement_precondition(statement)
void reset_precondition_map(void)
void set_precondition_map(statement_mapping)
s1
Definition: set.c:247
#define ifdebug(n)
Definition: sg.c:47
#define intptr_t
Definition: stdint.in.h:294
static size_t current
Definition: string.c:115
package matrice
Definition: matrix-local.h:63
int number_of_lines
Definition: matrix-local.h:65
int number_of_columns
Definition: matrix-local.h:66
Pvecteur vecteur
struct Scontrainte * succ
Pvecteur upper
Pvecteur lower
struct Spattern * next
Pcontrainte inegalites
Definition: sc-local.h:71
Pcontrainte egalites
Definition: sc-local.h:70
Pbase base
Definition: sc-local.h:75
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
Value val
Definition: vecteur-local.h:91
Variable var
Definition: vecteur-local.h:90
struct Svecteur * succ
Definition: vecteur-local.h:92
the stack head
Definition: stack.c:62
internally defined structure.
Definition: string_buffer.c:47
struct callst * succ
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Warning! Do not modify this file that is automatically generated!
Definition: modeling-local.h:4
gen_array_t nested_loop_indices
gen_array_t nested_call
stack loops_for_call
Definition: modeling-local.h:5
gen_array_t nested_if
gen_array_t nested_loops
Definition: modeling-local.h:9
Definition: statement.c:4047
#define CHAIN_SWORD(l, s)
string words_to_string(cons *lw)
Definition: print.c:211
char * int2a(int)
util.c
Definition: util.c:42
static int depth
la sequence de nids
static int k1
transformer transformer_range(transformer tf)
Return the range of relation tf in a newly allocated transformer.
Definition: transformer.c:714
void set_analyzed_types(void)
Definition: value.c:271
bool old_value_entity_p(entity)
Definition: value.c:936
void reset_analyzed_types(void)
Definition: value.c:289
void free_value_mappings(void)
Normal call to free the mappings.
Definition: value.c:1212
entity value_to_variable(entity)
Get the primitive variable associated to any value involved in a transformer.
Definition: value.c:1624
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define VECTEUR_NUL
DEFINITION DU VECTEUR NUL.
#define NO_OFL_CTRL
#define VECTEUR_UNDEFINED
struct Svecteur * Pvecteur
#define VECTEUR_NUL_P(v)
#define base_rm(b)
void * Variable
arithmetique is a requirement for vecteur, but I do not want to inforce it in all pips files....
Definition: vecteur-local.h:60
#define var_of(varval)
#define BASE_NULLE
MACROS SUR LES BASES.
#define VECTEUR_UNDEFINED_P(v)
Pbase vect_copy(Pvecteur b)
direct duplication.
Definition: alloc.c:240
Pvecteur vect_dup(Pvecteur v_in)
Pvecteur vect_dup(Pvecteur v_in): duplication du vecteur v_in; allocation de et copie dans v_out;.
Definition: alloc.c:51
Pvecteur vect_new(Variable var, Value coeff)
Pvecteur vect_new(Variable var,Value coeff): allocation d'un vecteur colineaire au vecteur de base va...
Definition: alloc.c:110
void vect_rm(Pvecteur v)
void vect_rm(Pvecteur v): desallocation des couples de v;
Definition: alloc.c:78
Pvecteur vect_cl2(Value x1, Pvecteur v1, Value x2, Pvecteur v2)
Definition: binaires.c:247
Pvecteur vect_add(Pvecteur v1, Pvecteur v2)
package vecteur - operations binaires
Definition: binaires.c:53
void vect_erase_var(Pvecteur *ppv, Variable v)
void vect_erase_var(Pvecteur * ppv, Variable v): projection du vecteur *ppv selon la direction v (i....
Definition: unaires.c:106
void vect_add_elem(Pvecteur *pvect, Variable var, Value val)
void vect_add_elem(Pvecteur * pvect, Variable var, Value val): addition d'un vecteur colineaire au ve...
Definition: unaires.c:72
Value vect_coeff(Variable var, Pvecteur vect)
Variable vect_coeff(Variable var, Pvecteur vect): coefficient de coordonnee var du vecteur vect —> So...
Definition: unaires.c:228
void vect_chg_coeff(Pvecteur *ppv, Variable var, Value val)
void vect_chg_coeff(Pvecteur *ppv, Variable var, Value val): mise de la coordonnee var du vecteur *pp...
Definition: unaires.c:143
static bool variable_p(entity e)
static void push_if(_UNUSED_ test l, nest_context_p nest)
static string array_mem_string
static void xml_Connection(list ActualArrayInd, int ActualArrayDim, int FormalArrayDim, string_buffer sb_result)
static string xml_code_string(entity module, statement stat)
Creates string for xml pretty printer.
struct Spattern * Ppattern
#define ITEM_NOT_IN_ARRAY
static string xml_sequence_from_task(sequence seq)
Concatentates each task to the final result.
#define XML_MOTIF_PREFIX
static void xml_Arguments(statement s, entity function, int statnb, bool assign_func, Pvecteur loop_indices, transformer t, Psysteme prec, string_buffer sb_result)
static string xml_array_in_task(reference r, bool first, int task_number)
bool print_xml_application_main(const char *module_name)
static string this_entity_xmldeclaration(entity var)
static int int_compare(void const *a, void const *b)
static bool same_callst_p(Pcallst c1, Pcallst c2)
static void xml_ConstOffset(list ActualArrayInd, int ActualArrayDim, string_buffer sb_result)
static void xml_task(int taskNumber, nest_context_p nest, string_buffer result)
#define code_is_a_main
static bool box_in_statement_p
#define CLOSEBRACKET
static loop sequence_loop(sequence seq)
static void xml_LoopOffset(list ActualArrayInd, int ActualArrayDim, Pvecteur loop_indices, string_buffer sb_result)
#define CLOSEANGLE
static Pvecteur global_application_variables
static transformer first_precondition_of_module(const char *module_name __attribute__((unused)), Psysteme *ps)
static void xml_Regions(string_buffer sb_result __attribute__((unused)))
static void string_buffer_append_word(string str, string_buffer sb_result)
static void push_current_statement(statement s, nest_context_p nest)
#define EMPTY
static void motif_in_statement(statement s)
static hash_table hash_entity_def_into_tasks
static expression skip_cast_and_addop_expression(expression exp)
static void xml_Matrix(Pmatrix mat, int n, int m, string_buffer sb_result)
static int gen_array_index(gen_array_t ar, string item)
static void xml_FormalVariables(entity module, transformer t, Psysteme prec, string_buffer sb_result)
static statement test_statement_of_reference
static void type_and_size_of_var(entity var, const char **datatype, int *size)
UNUSED static bool vect_one_p(Pvecteur v) { return (!VECTEUR_NUL_P(v) && vect_size(v) == 1 && vect_co...
static void xml_Argument(statement s, entity function, int statnb, bool assign_func, expression exp0, entity FormalName, Pvecteur loop_indices, transformer t, _UNUSED_ Psysteme prec, string_buffer sb_result)
static void find_pattern(Psysteme ps, Pvecteur paving_indices, Pvecteur formal_parameters, int dim, Ppattern *patt)
static gen_array_t extern_indices_array
array containing extern loop indices names
static void xml_Loops(stack st, bool call_external_loop_p, list *pattern_region, Pvecteur *paving_indices, Pvecteur *pattern_indices, bool motif_in_te_p, string_buffer sb_result)
static int find_effect_actions_for_entity(list leff, effect *effr, effect *effw, entity e)
static void def_to_task_store(entity var, entity fun)
static bool fortran_appli
static void string_buffer_append_numeric(string str, string_buffer sb_result)
bool print_xml_application_main_with_points_to(const char *module_name)
static string xml_entity_local_name(entity var)
static void xml_AccessFunction(string_buffer sb_result __attribute__((unused)))
static void xml_Chain_Graph(entity module, statement mod_stat, graph mod_graph, nest_context_p nest, string_buffer sb_result)
static void xml_TaskReturnParameter(entity function, _UNUSED_ int statnb, string_buffer sb_result)
static bool string_parameter_p(entity e)
static void __attribute__((unused))
static void find_loops_and_calls_in_box(statement stmp, nest_context_p nest)
static void update_def_into_tasks_table(entity v, Pcallst c1)
bool print_xml_application_with_points_to(const char *module_name)
static void xml_Full_Type(type pt, int max_step, string_buffer type_result)
static void xml_data(int taskNumber, statement s, stack indices, string_buffer result)
static void two_string_buffer_append_symbolic(string str1, string str2, string_buffer sb_result)
#define NL
static void xml_loop(stack st, string_buffer result)
static gen_array_t array_names
static void store_call_context(call c __attribute__((unused)), nest_context_p nest)
static expression skip_field_and_cast_expression(expression exp)
static void xml_TaskParameter(bool assign_function, _UNUSED_ entity function, int statnb, bool is_not_main_p, entity var, Pvecteur formal_parameters, list pattern_region, Pvecteur paving_indices, string_buffer sb_result, string_buffer buffer_assign)
static bool logic_condition_filter(statement s1, statement sx, entity *cond, expression *lhs, expression *rhs)
static gen_array_t intern_indices_array
array containing intern loop indices (name : "M_")
static bool statement_in_truebranch_p
static bool region_range_nul_p(region reg, Variable phi)
tatic bool string_in_list_p(string ts,list lr){ bool trouve=false; MAPL(tt, {trouve= trouve || strcmp...
static void pop_current_statement(statement s __attribute__((unused)), nest_context_p nest)
static void xml_reference(int taskNumber __attribute__((unused)), reference r, bool wmode, string_buffer result)
static list local_declaration_list
#define SPACE
static string memory_location_for_array_p(const char *sa)
static void xml_Transposition(statement s, call c, int d, string_buffer sb_result, int version)
#define OPENBRACKET
static bool print_name_1_level_p()
static void xml_Compute_and_Need(entity func, list effects_list, Pvecteur vargs, string_buffer sb_result)
static bool valid_specification_p(entity module __attribute__((unused)), statement stat __attribute__((unused)))
static void xml_call_from_indice(call c, string *offset_array, string paving_array[], string fitting_array[])
static void xml_Boxes(const char *module_name, int code_tag, string_buffer sb_result)
#define SLASH
static bool pragma_motif_p(statement s)
static void xml_Library(string_buffer sb_result)
static void search_nested_loops_and_calls(statement stmp, nest_context_p nest)
#define OPENANGLE
static void dependencies_filter(statement s1, int *k1)
static string xml_expression(expression)
forward declaration
static entity_to_entity def_to_task_mapping
static void find_motif(Psysteme ps, Pvecteur nested_indices, int dim, int nb_dim __attribute__((unused)), Pcontrainte *bound_inf, Pcontrainte *bound_sup, Pcontrainte *iterator, int *motif_up_bound, int *lowerbound, int *upperbound)
static void xml_Bounds(expression elow, expression eup, transformer t, _UNUSED_ Psysteme prec, bool formal_p, string_buffer sb_result)
UNUSED static bool eval_linear_expression2( expression exp, Psysteme ps, int *val,...
dg_vertex_label vertex_label
static void xml_Type_Entity(entity vv, string_buffer type_buffer)
static bool entity_in_expression_p(expression exp, entity e)
bool print_xml_code(const char *module_name)
Initiates xml pretty print modules.
static void xml_Region_Parameter(list pattern_region, string_buffer sb_result)
static void string_buffer_append_symbolic(string str, string_buffer sb_result)
static void pop_loop(_UNUSED_ loop l, nest_context_p nest)
static entity def_to_task_get(entity var)
static void xml_Application(const char *module_name, int code_tag, string_buffer sb_result)
static void pop_test(test t __attribute__((unused)), nest_context_p nest __attribute__((unused)))
static call xml_loop_from_loop(loop l, string *result, int task_number)
#define CLOSEPAREN
static void tri_abc(int a[12], int dim, int result[12])
struct callst * Pcallst
#define QUOTE
static void xml_declarations(entity module, string_buffer result)
static string xml_reference_with_explicit_motif(reference r)
Attention with Fortran: the indices are reversed.
static void xml_Pattern_Paving(region reg, entity var, bool effet_read, Pvecteur formal_parameters, Pvecteur paving_indices, string_buffer sb_result)
static void xml_Scalar(entity var, _UNUSED_ Psysteme prec, string_buffer sb_result)
char * pointer_to_initial_name(char *ts, _UNUSED_ char *ste)
static void xml_Chains(entity module, const char *mod_name, statement mod_stat, nest_context_p nest, string_buffer sb_result)
static void xml_references(int taskNumber, list l_regions, stack indices, string_buffer result)
static void xml_tiling(int taskNumber, reference ref, region reg, stack indices, string_buffer result)
static expression skip_cast_expression(expression exp)
static bool indice_p(stack indices, entity v)
static void xml_Array(entity var, transformer t, Psysteme prec, bool formal_p, string_buffer sb_result)
#define XML_TASK_PREFIX
static void store_local_array_declaration(statement s)
static void xml_TaskParameters(statement stat, bool assign_function, int code_tag, entity module, list pattern_region, Pvecteur paving_indices, string_buffer sb_result)
#define current_module_is_a_function()
static const char * global_module_name
static bool push_test(test t __attribute__((unused)), nest_context_p nest __attribute__((unused)))
static void xml_Bounds_and_Stride(expression elow, expression eup, expression stride, transformer t, Psysteme prec, bool formal_p, string_buffer sb_result)
static string task_complexity(statement s)
#define COMMA
dg_arc_label arc_label
static void add_margin(int gm, string_buffer sb_result)
struct callst callst
static void add_def_into_tasks_table(entity v, Pcallst c1)
static void xml_ParameterUseToArrayBound(entity var, string_buffer sb_result)
static Pvecteur local_application_variables
#define XML_RL
static bool print_full_name_p()
=======================================================
static bool entity_xml_parameter_p(entity e)
#define RESULT_NAME
static string vect_to_string(Pvecteur pv)
static string xml_declarations_with_explicit_motif(entity module, bool(*consider_this_entity)(entity), string separator, bool lastsep)
static void cumul_and_update_effects_of_statement(statement s)
static call encapsulated_call
static void vars_read_and_written(list effects_list, Pvecteur *vr, Pvecteur *vw)
UNUSED static void array_vars_read_or_written(list effects_list, Pvecteur *vl) { Pvecteur vin=VECTEUR...
static gen_array_t array_dims
static call sequence_call(sequence seq)
static gen_array_t extern_upperbounds_array
array containing extern upperbounds
static string array_location_string
static void print_call_precondition(Psysteme prec, string_buffer sb_result)
static int check_alias_args(reference r, alias_in_args *p)
static void choose_pattern(Ppattern *patt)
static void xml_Returns(string_buffer sb_result __attribute__((unused)))
static bool motif_in_statement_p
static int find_code_status(const char *module_name)
static void def_to_task_init(void)
char * str_sub(const char *s, int start, int end)
static void xml_Timecosts(string_buffer sb_result __attribute__((unused)))
static void xml_Call(entity module, int code_tag, int taskNumber, nest_context_p nest, string_buffer sb_result)
#define code_is_a_te
static void xml_tasks(statement stat, string_buffer result)
static string xml_loop_from_sequence(loop l, int task_number)
We enter a loop nest.
static void xml_Transposed_Matrix3_5D(Pmatrix mat, int a[12], int ArrayDim1, _UNUSED_ int ArrayDim2)
static string xml_dim_string(list ldim, string name)
static void xml_AssignArgument(_UNUSED_ statement s, entity function, int statnb, bool assign_func, expression exp, entity FormalName, Pvecteur loop_indices, transformer t, _UNUSED_ Psysteme prec, string_buffer sb_result)
static void xml_LocalVariables(entity module, transformer t, Psysteme prec, string_buffer sb_result)
bool eval_linear_expression(expression exp, transformer ps, int *val, int *min, int *max)
static bool call_selection(call c, nest_context_p nest __attribute__((unused)))
static void xml_Region_Range(region reg, string_buffer sb_result)
static void xml_Loop(statement s, string_buffer sb_result)
static void search_1r_function_call(call c)
static void xml_Task(const char *module_name, int code_tag, string_buffer sb_result)
static void pop_if(test l __attribute__((unused)), nest_context_p nest)
static string xml_call_from_loopnest(call c, int task_number)
static list cumulated_list
#define BL
#define TAB
static string xml_call_from_assignation(call c, int task_number, bool *input_provided)
static string xml_statement_from_sequence(statement s, int task_number)
We are here at the highest level of statements.
static string xml_code(entity module, statement stat)
Creates string for xml pretty printer.
static void statement_in_truebranch(statement s)
static void box_in_statement(statement s)
currently unused static void motif_in_statement2(statement s) { string comm = statement_comments(s); ...
static void def_to_task_set(entity_to_entity mapping)
#define MEM_PREFIX
static gen_array_t intern_upperbounds_array
array containing intern upperbounds
bool print_xml_application(const char *module_name)
static int global_margin
static bool generic_print_xml_application(const char *module_name, bool is_app)
static string xml_tasks_with_motif(statement stat)
Manages tasks.
struct Spattern Spattern
static gen_array_t tasks_names
array containing the tasks names
static void def_to_task_reset(void)
static void same_entities(reference r, expression_ctxt *ctxt)
static void push_loop(loop l, nest_context_p nest)
static void xml_Transposed_Matrix2D(Pmatrix mat)
static expression expression_plusplus(expression e)
static void find_memory_comment_on_array(statement s)
static bool aliasing_p(call c, reference refname)
static void xml_GlobalVariables(transformer t, Psysteme prec, bool printp, string_buffer sb_result)
static void cumul_effects_of_statement(statement s)
static const char * words_points_to_reference(reference rv, bool suffix_only_p, region reg)
#define XML_ARRAY_PREFIX
bool print_xml_code_with_explicit_motif(const char *module_name)
Initiates xml pretty print modules.
#define code_is_a_box
static void matrix_init(Pmatrix mat, int n, int m)
static void xml_CodeSize(string_buffer sb_result)