~ubuntu-branches/ubuntu/trusty/cloog/trusty

« back to all changes in this revision

Viewing changes to osl/source/names.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2011-12-15 18:39:17 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20111215183917-uqggmujou8wna9js
Tags: 0.17.0-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
77
/**
 
78
 * osl_names_idump function:
 
79
 * this function displays an osl_names_t structure (*names) into a
 
80
 * file (file, possibly stdout) in a way that trends to be understandable. It
 
81
 * includes an indentation level (level) in order to work with others
 
82
 * idump functions.
 
83
 * \param[in] file  The file where the information has to be printed.
 
84
 * \param[in] names The names structure whose information has to be printed.
 
85
 * \param[in] level Number of spaces before printing, for each line.
 
86
 */
 
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
 
 
120
/**
 
121
 * osl_names_dump function:
 
122
 * this function prints the content of an osl_names_t structure
 
123
 * (*names) into a file (file, possibly stdout).
 
124
 * \param[in] file  The file where the information has to be printed.
 
125
 * \param[in] names The names structure whose information has to be printed.
 
126
 */
 
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
 
 
142
/**
 
143
 * osl_names_malloc function:
 
144
 * this function allocates the memory space for an osl_names_t
 
145
 * structure and sets its fields with default values. Then it returns a
 
146
 * pointer to the allocated space.
 
147
 * \return A pointer to an empty names structure with fields set to
 
148
 *         default values.
 
149
 */
 
150
osl_names_p osl_names_malloc() {
 
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
 
 
164
/**
 
165
 * osl_names_free function:
 
166
 * This function frees the allocated memory for an osl_names_t
 
167
 * structure. If the names are not character strings, it is the
 
168
 * responsibility of the user to free each array of elements (including
 
169
 * the array itself), this function will only free the osl_names_t shell.
 
170
 * \param[in,out] names The pointer to the names structure we want to free.
 
171
 */
 
172
void osl_names_free(osl_names_p names) {
 
173
  if (names != NULL) {
 
174
    osl_strings_free(names->parameters);
 
175
    osl_strings_free(names->iterators);
 
176
    osl_strings_free(names->scatt_dims);
 
177
    osl_strings_free(names->local_dims);
 
178
    osl_strings_free(names->arrays);
 
179
 
 
180
    free(names);
 
181
  }
 
182
}
 
183
 
 
184
 
 
185
/*+***************************************************************************
 
186
 *                            Processing functions                           *
 
187
 *****************************************************************************/
 
188
 
 
189
 
 
190
/**
 
191
 * osl_names_generate function:
 
192
 * this function generates some names. For each kind of name it will generate
 
193
 * a given number of names with a given prefix followed by a number.
 
194
 * \param[in] parameter_prefix Prefix for parameter names.
 
195
 * \param[in] nb_parameters    Number of parameters names to generate.
 
196
 * \param[in] iterator_prefix  Prefix for iterator names.
 
197
 * \param[in] nb_iterators     Number of iterators names to generate.
 
198
 * \param[in] scatt_dim_prefix Prefix for scattering dimension names.
 
199
 * \param[in] nb_scatt_dims    Number of scattering dim names to generate.
 
200
 * \param[in] local_dim_prefix Prefix for local dimension names.
 
201
 * \param[in] nb_local_dims    Number of local dimension names to generate.
 
202
 * \param[in] array_prefix     Prefix for array names.
 
203
 * \param[in] nb_arrays        Number of array names to generate.
 
204
 * \return A new names structure containing generated names.
 
205
 */
 
206
osl_names_p osl_names_generate(
 
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
 
 
223
/**
 
224
 * osl_names_clone function:
 
225
 * this function builds and returns a "hard copy" (not a pointer copy) of an
 
226
 * osl_names_t data structure provided as parameter.
 
227
 * \param[in] names The pointer to the names structure we want to clone.
 
228
 * \return A pointer to the clone of the names structure provided as parameter.
 
229
 */
 
230
osl_names_p osl_names_clone(osl_names_p names) {
 
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
}