PIPS
pragma.c
Go to the documentation of this file.
1 /*
2 
3  $Id: pragma.c 22777 2015-08-23 20:56:50Z irigoin $
4 
5  Copyright 1989-2010 HPC Project
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 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /*
28  This file define methods to deal with objects extensions and pragma
29  used as extensions to statements in the PIPS internal representation.
30 
31  A middle term, extensions method could go in another file.
32 
33  It is a trivial implementation based on strings for a proof of concept.
34 
35  Pierre.Villalon@hpc-project.com
36  Ronan.Keryell@hpc-project.com
37 */
38 
39 #include "linear.h"
40 #include "genC.h"
41 #include "misc.h"
42 #include "ri.h"
43 #include "ri-util.h"
44 #include "text-util.h"
45 #include "prettyprint.h"
46 
47 /***************************************************** PRETTYPRINT PART
48  */
49 /** @return a new allocated string to close the pragma.
50  * @param p, the pragma to be closed
51  *
52  */
53 string close_pragma(pragma p __attribute__ ((unused))) {
54  string result = string_undefined;
56  /* STEP -> les pragma ne sont pas toujours fermés par des "omp end parallel do"
57 
58  result = strdup(concatenate(FORTRAN_PRAGMA_HEADER,
59  "omp end parallel do",
60  NULL));
61  */
62  }
63  return result;
64 }
65 
66 /** @return a new allocated string with the pragma textual representation.
67  */
68 string
70  bool flg = false;
71  list l_str = NULL; //list of string
72  list l_expr = NULL; // list of expression
73  size_t line_sz = 0; // the pragma line size
74  string s = string_undefined;
76 
77  switch(pragma_tag (p)) {
78  case is_pragma_string:
79  s = pragma_string(p);
80  break;
82  l_expr = gen_nreverse(pragma_expression (p));
83  FOREACH (EXPRESSION, e, l_expr)
84  {
85  if(flg ) {
87  line_sz += 1;
88  }
89  flg = true;
90  list pdl = NIL;
91  l_str = words_expression(e, &pdl);
92  gen_free_list(pdl);
93  // l_str = gen_nreverse (l_str);
95  // In fortran line size can not be more than 72
96  FOREACH (STRING, str, l_str)
97  {
98  pips_assert ("algo bug", line_sz < MAX_LINE_LENGTH - 7);
99  size_t size = strlen(str);
100  pips_assert ("not handled case need to split the str between two lines",
101  size < (MAX_LINE_LENGTH - 7));
102  line_sz += size;
103  if(line_sz >= MAX_LINE_LENGTH - 8) {
105  str,
106  l_str);
107  line_sz = size;
108  }
109  }
110  }
112  gen_free_list(l_str);
113  }
115  // Free the buffer with its strings
117  // restore the list as it was at the begining
118  gen_nreverse(l_expr);
119  break;
120  default:
121  pips_internal_error("Unknown pragma type");
122  break;
123  }
124  if(s != string_undefined) {
125  switch(get_prettyprint_language_tag()) {
126  case is_language_fortran:
129  break;
130  case is_language_c:
131  s = strdup(concatenate(C_PRAGMA_HEADER_STRING, " ", s, NULL));
132  break;
133  default:
134  pips_internal_error("Language unknown !");
135  break;
136  }
137  }
138  return s;
139 }
140 
141 /** @brief Add an expression to the pragma current expression list.
142  * @return void
143  * @param pr, the pragma to process.
144  * @param ex, the expression to add.
145  */
146 void
148  pips_assert ("the pragma need to be an expression", pragma_expression_p (pr) );
149  /* Add the new pragma to the extension list: */
150  list exprs = pragma_expression (pr);
151  exprs = gen_expression_cons (ex, exprs);
152  pragma_expression (pr) = exprs;
153  string str = pragma_to_string (pr);
154  pips_debug(5, "after: %s", str);
155  free (str);
156  return;
157 }
float a2sf[2] __attribute__((aligned(16)))
USER generates a user error (i.e., non fatal) by printing the given MSG according to the FMT.
Definition: 3dnow.h:3
list gen_expression_cons(expression p, list l)
Definition: ri.c:866
#define STRING(x)
Definition: genC.h:87
void free(void *)
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
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
list gen_insert_before(const void *no, const void *o, list l)
Definition: list.c:238
enum language_utype get_prettyprint_language_tag()
Definition: language.c:67
bool prettyprint_language_is_fortran_p()
Definition: language.c:75
#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 FORTRAN_PRAGMA_HEADER_STRING
Definition: naming-local.h:116
#define C_PRAGMA_HEADER_STRING
Constants for pragma management.
Definition: naming-local.h:115
#define FORTRAN_OMP_CONTINUATION_STRING
Definition: naming-local.h:117
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
void string_buffer_free_all(string_buffer *)
free string buffer structure and force string freeing
Definition: string_buffer.c:94
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
string_buffer string_buffer_make(bool dup)
allocate a new string buffer
Definition: string_buffer.c:58
void string_buffer_append_list(string_buffer, const list)
append a list of string to a string buffer.
#define string_undefined
Definition: newgen_types.h:40
list words_expression(expression obj, list *ppdl)
This one is exported.
Definition: misc.c:2611
string close_pragma(pragma p __attribute__((unused)))
Definition: pragma.c:53
void add_expr_to_pragma_expr_list(pragma pr, expression ex)
Add an expression to the pragma current expression list.
Definition: pragma.c:147
string pragma_to_string(pragma p)
Definition: pragma.c:69
#define pragma_expression_p(x)
Definition: ri.h:2034
#define pragma_string(x)
Definition: ri.h:2033
@ is_pragma_expression
Definition: ri.h:2013
@ is_pragma_string
Definition: ri.h:2012
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define pragma_expression(x)
Definition: ri.h:2036
#define pragma_tag(x)
Definition: ri.h:2030
@ is_language_fortran
Definition: ri.h:1566
@ is_language_fortran95
Definition: ri.h:1568
@ is_language_c
Definition: ri.h:1567
char * strdup()
internally defined structure.
Definition: string_buffer.c:47
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: statement.c:4047
#define MAX_LINE_LENGTH
maximum length of a line when prettyprinting...