PIPS
extension.c
Go to the documentation of this file.
1 /*
2 
3  Copyright 1989-2010 HPC Project
4 
5  This file is part of PIPS.
6 
7  PIPS is free software: you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  any later version.
11 
12  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
13  WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  FITNESS FOR A PARTICULAR PURPOSE.
15 
16  See the GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
20 
21 */
22 /*
23  Functions dealing with the Newgen objects "extension", which are
24  part of "statement"; they are used to encode pragmas.
25 
26  Pierre.Villalon@hpc-project.com
27  Ronan.Keryell@hpc-project.com
28 */
29 #ifdef HAVE_CONFIG_H
30  #include "pips_config.h"
31 #endif
32 
33 #include "linear.h"
34 #include "genC.h"
35 #include "ri-util.h"
36 #include "text-util.h"
37 #include "prettyprint.h"
38 
39 /***************************************************** PRETTYPRINT PART
40  */
41 
42 /** @return a new allocated string to close the extension.
43  * @param es, the extension to be closed
44  *
45  * Today we only generate omp parallel do pragma so the close is pretty
46  * easy. Later we will have to analyze the extension to generate the
47  * close string accordingly.
48  */
50  return close_pragma (extension_pragma(e));
51 }
52 
53 /** @return a new allocated string to close the extensions.
54  * @param es, the extensions to be closed
55  * @param nl, set to true to get the string with a final new line character
56  */
57 string
59  string s = string_undefined;
60 
61  if (!empty_extensions_p (es) ) {
62  /* Use a string_buffer for efficient string concatenation: */
64 
65  list el = extensions_extension(es);
66  FOREACH(EXTENSION, e, el) {
67  s = close_extension(e);
68  if (s != string_undefined) {
70  if (nl ) string_buffer_append(sb, strdup ("\n"));
71  nl = true;
72  }
73  }
75  /* Free the buffer with its strings: */
77  }
78 
79  return s;
80 }
81 
82 
83 /** @return a new allocated string with the extension textual representation.
84  */
85 string
87  string s;
88  /* to be added later when extension can be something else than pragma
89  switch (extension_tag(e)) {
90  case is_extension_pragma:
91  */
93  /* default:
94  pips_internal_error("Unknown extension type");
95  }*/
96  return s;
97 }
98 
99 /** @brief return a new allocated string with the string representation of the
100  * extensions. Basically you'll get one extension per line
101  *
102  * Assume that all the extension from the extensions (note the presence
103  * or not of the "s"...) are defined below.
104  *
105  * @return string_undefined if es is extension_undefined, an malloc()ed
106  * textual string either.
107  * @param es, the extensions to translate to strings
108  * @param nl, set to true to get the string with a final new line character
109  */
110 string
112  string s = string_undefined;
113 
114  /* Prettyprint in the correct language: */
115 // set_prettyprint_language_from_property ();
116 
117  if (!empty_extensions_p (es) ) {
118  /* Use a string_buffer for efficient string concatenation: */
120 
121  list el = extensions_extension(es);
122  FOREACH(EXTENSION, e, el) {
123  s = extension_to_string(e);
125  if (nl ) string_buffer_append(sb, strdup ("\n"));
126  nl = true;
127  }
129  /* Free the buffer with its strings: */
131  }
132 
133  return s;
134 }
#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
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
#define string_undefined
Definition: newgen_types.h:40
string close_extension(extension e)
extension.c
Definition: extension.c:49
string close_extensions(extensions es, bool nl)
Definition: extension.c:58
string extension_to_string(extension e)
Definition: extension.c:86
string extensions_to_string(extensions es, bool nl)
return a new allocated string with the string representation of the extensions.
Definition: extension.c:111
string close_pragma(pragma p __attribute__((unused)))
Definition: pragma.c:53
string pragma_to_string(pragma p)
Definition: pragma.c:69
bool empty_extensions_p(extensions es)
Definition: extension.c:50
#define extension_pragma(x)
Definition: ri.h:1295
#define EXTENSION(x)
EXTENSION.
Definition: ri.h:1253
#define extensions_extension(x)
Definition: ri.h:1330
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