OpenScop  0.9.0
names.c
Go to the documentation of this file.
1 
2  /*+-----------------------------------------------------------------**
3  ** OpenScop Library **
4  **-----------------------------------------------------------------**
5  ** extensions/names.c **
6  **-----------------------------------------------------------------**
7  ** First version: 18/04/2011 **
8  **-----------------------------------------------------------------**
9 
10 
11  *****************************************************************************
12  * OpenScop: Structures and formats for polyhedral tools to talk together *
13  *****************************************************************************
14  * ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__, *
15  * / / / // // // // / / / // // / / // / /|,_, *
16  * / / / // // // // / / / // // / / // / / / /\ *
17  * |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/ \ *
18  * | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\ \ /\ *
19  * | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\ *
20  * | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \ \ *
21  * | P |n| l | = | s | t |=| = |d| = | = | = | | |=| o | | \# \ \ *
22  * | H | | y | | e | o | | = |l| | | = | | | | G | | \ \ \ *
23  * | I | | | | e | | | | | | | | | | | | | \ \ \ *
24  * | T | | | | | | | | | | | | | | | | | \ \ \ *
25  * | E | | | | | | | | | | | | | | | | | \ \ \ *
26  * | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | / \* \ \ *
27  * | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/ \ \ / *
28  * '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' *
29  * *
30  * Copyright (C) 2008 University Paris-Sud 11 and INRIA *
31  * *
32  * (3-clause BSD license) *
33  * Redistribution and use in source and binary forms, with or without *
34  * modification, are permitted provided that the following conditions *
35  * are met: *
36  * *
37  * 1. Redistributions of source code must retain the above copyright notice, *
38  * this list of conditions and the following disclaimer. *
39  * 2. Redistributions in binary form must reproduce the above copyright *
40  * notice, this list of conditions and the following disclaimer in the *
41  * documentation and/or other materials provided with the distribution. *
42  * 3. The name of the author may not be used to endorse or promote products *
43  * derived from this software without specific prior written permission. *
44  * *
45  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR *
46  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *
47  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. *
48  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, *
49  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT *
50  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
51  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
52  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
53  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF *
54  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
55  * *
56  * OpenScop Library, a library to manipulate OpenScop formats and data *
57  * structures. Written by: *
58  * Cedric Bastoul <Cedric.Bastoul@u-psud.fr> and *
59  * Louis-Noel Pouchet <Louis-Noel.pouchet@inria.fr> *
60  * *
61  *****************************************************************************/
62 
63 #include <stdlib.h>
64 #include <stdio.h>
65 #include <string.h>
66 
67 #include <osl/macros.h>
68 #include <osl/strings.h>
69 #include <osl/names.h>
70 
71 
72 /*+***************************************************************************
73  * Structure display function *
74  *****************************************************************************/
75 
76 
87 void osl_names_idump(FILE * file, osl_names_p names, int level) {
88  int j;
89 
90  // Go to the right level.
91  for (j = 0; j < level; j++)
92  fprintf(file, "|\t");
93 
94  if (names != NULL)
95  fprintf(file, "+-- osl_names_t\n");
96  else
97  fprintf(file, "+-- NULL names\n");
98 
99  if (names != NULL) {
100  // A blank line.
101  for (j = 0; j <= level+1; j++)
102  fprintf(file, "|\t");
103  fprintf(file, "\n");
104 
105  // Print the various names.
106  osl_strings_idump(file, names->parameters, level + 1);
107  osl_strings_idump(file, names->iterators, level + 1);
108  osl_strings_idump(file, names->scatt_dims, level + 1);
109  osl_strings_idump(file, names->local_dims, level + 1);
110  osl_strings_idump(file, names->arrays, level + 1);
111  }
112 
113  // The last line.
114  for (j = 0; j <= level; j++)
115  fprintf(file, "|\t");
116  fprintf(file, "\n");
117 }
118 
119 
127 void osl_names_dump(FILE * file, osl_names_p names) {
128  osl_names_idump(file, names, 0);
129 }
130 
131 
132 /*****************************************************************************
133  * Reading function *
134  *****************************************************************************/
135 
136 
137 /*+***************************************************************************
138  * Memory allocation/deallocation function *
139  *****************************************************************************/
140 
141 
151  osl_names_p names;
152 
153  OSL_malloc(names, osl_names_p, sizeof(osl_names_t));
154  names->parameters = NULL;
155  names->iterators = NULL;
156  names->scatt_dims = NULL;
157  names->local_dims = NULL;
158  names->arrays = NULL;
159 
160  return names;
161 }
162 
163 
173  if (names != NULL) {
175  osl_strings_free(names->iterators);
178  osl_strings_free(names->arrays);
179 
180  free(names);
181  }
182 }
183 
184 
185 /*+***************************************************************************
186  * Processing functions *
187  *****************************************************************************/
188 
189 
207  char * parameter_prefix, int nb_parameters,
208  char * iterator_prefix, int nb_iterators,
209  char * scatt_dim_prefix, int nb_scatt_dims,
210  char * local_dim_prefix, int nb_local_dims,
211  char * array_prefix, int nb_arrays) {
212  osl_names_p names = osl_names_malloc();
213 
214  names->parameters= osl_strings_generate(parameter_prefix,nb_parameters);
215  names->iterators = osl_strings_generate(iterator_prefix, nb_iterators);
216  names->scatt_dims= osl_strings_generate(scatt_dim_prefix,nb_scatt_dims);
217  names->local_dims= osl_strings_generate(local_dim_prefix,nb_local_dims);
218  names->arrays = osl_strings_generate(array_prefix, nb_arrays);
219 
220  return names;
221 }
222 
231  osl_names_p clone = NULL;
232 
233  if (names != NULL) {
234  clone = osl_names_malloc();
235  clone->parameters = osl_strings_clone(names->parameters);
236  clone->iterators = osl_strings_clone(names->iterators);
237  clone->scatt_dims = osl_strings_clone(names->scatt_dims);
238  clone->local_dims = osl_strings_clone(names->local_dims);
239  clone->arrays = osl_strings_clone(names->arrays);
240  }
241  return clone;
242 }
osl_names_p osl_names_generate(char *parameter_prefix, int nb_parameters, char *iterator_prefix, int nb_iterators, char *scatt_dim_prefix, int nb_scatt_dims, char *local_dim_prefix, int nb_local_dims, char *array_prefix, int nb_arrays)
Definition: names.c:206
osl_names_p osl_names_clone(osl_names_p names)
Definition: names.c:230
osl_strings_p osl_strings_clone(osl_strings_p strings)
Definition: strings.c:328
osl_strings_p iterators
Definition: names.h:83
void osl_strings_idump(FILE *file, osl_strings_p strings, int level)
Definition: strings.c:89
void osl_names_dump(FILE *file, osl_names_p names)
Definition: names.c:127
osl_strings_p local_dims
Definition: names.h:85
void osl_names_free(osl_names_p names)
Definition: names.c:172
void osl_names_idump(FILE *file, osl_names_p names, int level)
Definition: names.c:87
osl_strings_p arrays
Definition: names.h:86
osl_names_p osl_names_malloc()
Definition: names.c:150
osl_strings_p scatt_dims
Definition: names.h:84
void osl_strings_free(osl_strings_p strings)
Definition: strings.c:299
osl_strings_p parameters
Definition: names.h:82
osl_strings_p osl_strings_generate(char *prefix, int nb_strings)
Definition: strings.c:475