Fix problem when adding a signed scalar to a vector
[openscop.git] / source / names.c
blob82b5436e01591d6875b3ed921da84cc25e929693
2 /*+-----------------------------------------------------------------**
3 ** OpenScop Library **
4 **-----------------------------------------------------------------**
5 ** extensions/names.c **
6 **-----------------------------------------------------------------**
7 ** First version: 18/04/2011 **
8 **-----------------------------------------------------------------**
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 *****************************************************************************/
63 # include <stdlib.h>
64 # include <stdio.h>
65 # include <string.h>
66 # include <osl/names.h>
69 /*+***************************************************************************
70 * Structure display function *
71 *****************************************************************************/
74 /**
75 * osl_names_idump function:
76 * this function displays an osl_names_t structure (*names) into a
77 * file (file, possibly stdout) in a way that trends to be understandable. It
78 * includes an indentation level (level) in order to work with others
79 * print_structure functions.
80 * \param[in] file The file where the information has to be printed.
81 * \param[in] names The names structure whose information has to be printed.
82 * \param[in] level Number of spaces before printing, for each line.
84 void osl_names_idump(FILE * file, osl_names_p names, int level) {
85 int j;
87 // Go to the right level.
88 for (j = 0; j < level; j++)
89 fprintf(file, "|\t");
91 if (names != NULL)
92 fprintf(file, "+-- osl_names_t\n");
93 else
94 fprintf(file, "+-- NULL names\n");
96 if (names != NULL) {
97 // A blank line.
98 for (j = 0; j <= level+1; j++)
99 fprintf(file, "|\t");
100 fprintf(file, "\n");
102 // Print the various names.
103 osl_strings_idump(file, names->parameters, level + 1);
104 osl_strings_idump(file, names->iterators, level + 1);
105 osl_strings_idump(file, names->scatt_dims, level + 1);
106 osl_strings_idump(file, names->local_dims, level + 1);
107 osl_strings_idump(file, names->arrays, level + 1);
110 // The last line.
111 for (j = 0; j <= level; j++)
112 fprintf(file, "|\t");
113 fprintf(file, "\n");
118 * osl_names_dump function:
119 * this function prints the content of an osl_names_t structure
120 * (*names) into a file (file, possibly stdout).
121 * \param[in] file The file where the information has to be printed.
122 * \param[in] names The names structure whose information has to be printed.
124 void osl_names_dump(FILE * file, osl_names_p names) {
125 osl_names_idump(file, names, 0);
129 /*****************************************************************************
130 * Reading function *
131 *****************************************************************************/
134 /*+***************************************************************************
135 * Memory allocation/deallocation function *
136 *****************************************************************************/
140 * osl_names_malloc function:
141 * this function allocates the memory space for an osl_names_t
142 * structure and sets its fields with default values. Then it returns a
143 * pointer to the allocated space.
144 * \return A pointer to an empty names structure with fields set to
145 * default values.
147 osl_names_p osl_names_malloc() {
148 osl_names_p names;
150 OSL_malloc(names, osl_names_p, sizeof(osl_names_t));
151 names->parameters = NULL;
152 names->iterators = NULL;
153 names->scatt_dims = NULL;
154 names->local_dims = NULL;
155 names->arrays = NULL;
157 return names;
162 * osl_names_free function:
163 * This function frees the allocated memory for an osl_names_t
164 * structure. If the names are not character strings, it is the
165 * responsibility of the user to free each array of elements (including
166 * the array itself), this function will only free the osl_names_t shell.
167 * \param[in,out] names The pointer to the names structure we want to free.
169 void osl_names_free(osl_names_p names) {
170 if (names != NULL) {
171 osl_strings_free(names->parameters);
172 osl_strings_free(names->iterators);
173 osl_strings_free(names->scatt_dims);
174 osl_strings_free(names->local_dims);
175 osl_strings_free(names->arrays);
177 free(names);
182 /*+***************************************************************************
183 * Processing functions *
184 *****************************************************************************/
188 * osl_names_generate function:
189 * this function generates some names. For each kind of name it will generate
190 * a given number of names with a given prefix followed by a number.
191 * \param[in] parameter_prefix Prefix for parameter names.
192 * \param[in] nb_parameters Number of parameters names to generate.
193 * \param[in] iterator_prefix Prefix for iterator names.
194 * \param[in] nb_iteratorrs Number of iterators names to generate.
195 * \param[in] scatt_dim_prefix Prefix for scattering dimension names.
196 * \param[in] nb_scatt_dims Number of scattering dim names to generate.
197 * \param[in] local_dim_prefix Prefix for local dimension names.
198 * \param[in] nb_local_dims Number of local dimension names to generate.
199 * \param[in] array_prefix Prefix for array names.
200 * \param[in] nb_arrays Number of array names to generate.
201 * \return A new names structure containing generated names.
203 osl_names_p osl_names_generate(
204 char * parameter_prefix, int nb_parameters,
205 char * iterator_prefix, int nb_iterators,
206 char * scatt_dim_prefix, int nb_scatt_dims,
207 char * local_dim_prefix, int nb_local_dims,
208 char * array_prefix, int nb_arrays) {
209 osl_names_p names = osl_names_malloc();
211 names->parameters= osl_strings_generate(parameter_prefix,nb_parameters);
212 names->iterators = osl_strings_generate(iterator_prefix, nb_iterators);
213 names->scatt_dims= osl_strings_generate(scatt_dim_prefix,nb_scatt_dims);
214 names->local_dims= osl_strings_generate(local_dim_prefix,nb_local_dims);
215 names->arrays = osl_strings_generate(array_prefix, nb_arrays);
217 return names;
221 * osl_names_clone function:
222 * this function builds and returns a "hard copy" (not a pointer copy) of an
223 * osl_names_t data structure provided as parameter.
224 * \param[in] names The pointer to the names structure we want to clone.
225 * \return A pointer to the clone of the names structure provided as parameter.
227 osl_names_p osl_names_clone(osl_names_p names) {
228 osl_names_p clone = NULL;
230 if (names != NULL) {
231 clone = osl_names_malloc();
232 clone->parameters = osl_strings_clone(names->parameters);
233 clone->iterators = osl_strings_clone(names->iterators);
234 clone->scatt_dims = osl_strings_clone(names->scatt_dims);
235 clone->local_dims = osl_strings_clone(names->local_dims);
236 clone->arrays = osl_strings_clone(names->arrays);
238 return clone;