~ubuntu-branches/ubuntu/wily/cloog/wily-proposed

« back to all changes in this revision

Viewing changes to osl/source/extensions/clay.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2015-04-24 15:07:57 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20150424150757-wumy8mdonvtgf29j
Tags: 0.18.3-1
* New upstream version.
* Update symbols file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
    /*+-----------------------------------------------------------------**
 
3
     **                       OpenScop Library                          **
 
4
     **-----------------------------------------------------------------**
 
5
     **                      extensions/clay.c                          **
 
6
     **-----------------------------------------------------------------**
 
7
     **                   First version: 09/05/2012                     **
 
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/util.h>
 
69
#include <osl/interface.h>
 
70
#include <osl/extensions/clay.h>
 
71
 
 
72
 
 
73
/*+***************************************************************************
 
74
 *                          Structure display function                       *
 
75
 *****************************************************************************/
 
76
 
 
77
 
 
78
/**
 
79
 * osl_clay_idump function:
 
80
 * this function displays an osl_clay_t structure (*clay) into a
 
81
 * file (file, possibly stdout) in a way that trends to be understandable. It
 
82
 * includes an indentation level (level) in order to work with others
 
83
 * idump functions.
 
84
 * \param[in] file  The file where the information has to be printed.
 
85
 * \param[in] clay  The clay structure to print.
 
86
 * \param[in] level Number of spaces before printing, for each line.
 
87
 */
 
88
void osl_clay_idump(FILE * file, osl_clay_p clay, int level) {
 
89
  int j;
 
90
  size_t l;
 
91
  char * tmp;
 
92
 
 
93
  // Go to the right level.
 
94
  for (j = 0; j < level; j++)
 
95
    fprintf(file, "|\t");
 
96
 
 
97
  if (clay != NULL)
 
98
    fprintf(file, "+-- osl_clay_t\n");
 
99
  else
 
100
    fprintf(file, "+-- NULL clay\n");
 
101
 
 
102
  if (clay != NULL) {
 
103
    // Go to the right level.
 
104
    for(j = 0; j <= level; j++)
 
105
      fprintf(file, "|\t");
 
106
  
 
107
    // Display the clay script (without any carriage return).
 
108
    OSL_strdup(tmp, clay->script);
 
109
    for (l = 0; l < strlen(tmp); l++)
 
110
      if (tmp[l] == '\n')
 
111
        tmp[l] = ' ';
 
112
    fprintf(file, "script: %s\n", tmp);
 
113
    free(tmp);
 
114
  }
 
115
 
 
116
  // The last line.
 
117
  for (j = 0; j <= level; j++)
 
118
    fprintf(file, "|\t");
 
119
  fprintf(file, "\n");
 
120
}
 
121
 
 
122
 
 
123
/**
 
124
 * osl_clay_dump function:
 
125
 * this function prints the content of an osl_clay_t structure
 
126
 * (*clay) into a file (file, possibly stdout).
 
127
 * \param[in] file The file where the information has to be printed.
 
128
 * \param[in] clay The clay structure to print.
 
129
 */
 
130
void osl_clay_dump(FILE * file, osl_clay_p clay) {
 
131
  osl_clay_idump(file, clay, 0);
 
132
}
 
133
 
 
134
 
 
135
/**
 
136
 * osl_clay_sprint function:
 
137
 * this function prints the content of an osl_clay_t structure
 
138
 * (*clay) into a string (returned) in the OpenScop textual format.
 
139
 * \param[in] clay The clay structure to print.
 
140
 * \return A string containing the OpenScop dump of the clay structure.
 
141
 */
 
142
char * osl_clay_sprint(osl_clay_p clay) {
 
143
  int high_water_mark = OSL_MAX_STRING;
 
144
  char * string = NULL;
 
145
  char buffer[OSL_MAX_STRING];
 
146
 
 
147
  if (clay != NULL) {
 
148
    OSL_malloc(string, char *, high_water_mark * sizeof(char));
 
149
    string[0] = '\0';
 
150
   
 
151
    // Print the clay.
 
152
    sprintf(buffer, "%s", clay->script);
 
153
    osl_util_safe_strcat(&string, buffer, &high_water_mark);
 
154
 
 
155
    // Keep only the memory space we need.
 
156
    OSL_realloc(string, char *, (strlen(string) + 1) * sizeof(char));
 
157
  }
 
158
 
 
159
  return string;
 
160
}
 
161
 
 
162
 
 
163
/*****************************************************************************
 
164
 *                               Reading function                            *
 
165
 *****************************************************************************/
 
166
 
 
167
 
 
168
/**
 
169
 * osl_clay_sread function:
 
170
 * this function reads a clay structure from a string complying to the
 
171
 * OpenScop textual format and returns a pointer to this clay structure.
 
172
 * The input parameter is updated to the position in the input string this
 
173
 * function reach right after reading the clay structure.
 
174
 * \param[in,out] input The input string where to find a clay.
 
175
 *                      Updated to the position after what has been read.
 
176
 * \return A pointer to the clay structure that has been read.
 
177
 */
 
178
osl_clay_p osl_clay_sread(char ** input) {
 
179
  osl_clay_p clay;
 
180
  char * script;
 
181
 
 
182
  if (*input == NULL) {
 
183
    OSL_debug("no clay optional tag");
 
184
    return NULL;
 
185
  }
 
186
 
 
187
  if (strlen(*input) > OSL_MAX_STRING) 
 
188
    OSL_error("clay script too long");
 
189
 
 
190
  // Build the clay structure
 
191
  clay = osl_clay_malloc();
 
192
  script = *input;
 
193
  
 
194
  // Pass the carriage returns (this allows to remove those inserted by
 
195
  // osl_generic_print), and copy the textual script.
 
196
  while (*script && (*script == '\n'))
 
197
    script++;
 
198
  OSL_strdup(clay->script, script);
 
199
 
 
200
  // Update the input pointer (everything has been read).
 
201
  input += strlen(*input);
 
202
 
 
203
  return clay;
 
204
}
 
205
 
 
206
 
 
207
/*+***************************************************************************
 
208
 *                    Memory allocation/deallocation function                *
 
209
 *****************************************************************************/
 
210
 
 
211
 
 
212
/**
 
213
 * osl_clay_malloc function:
 
214
 * this function allocates the memory space for an osl_clay_t
 
215
 * structure and sets its fields with default values. Then it returns a
 
216
 * pointer to the allocated space.
 
217
 * \return A pointer to an empty clay structure with fields set to
 
218
 *         default values.
 
219
 */
 
220
osl_clay_p osl_clay_malloc() {
 
221
  osl_clay_p clay;
 
222
 
 
223
  OSL_malloc(clay, osl_clay_p, sizeof(osl_clay_t));
 
224
  clay->script = NULL;
 
225
 
 
226
  return clay;
 
227
}
 
228
 
 
229
 
 
230
/**
 
231
 * osl_clay_free function:
 
232
 * this function frees the allocated memory for an osl_clay_t
 
233
 * structure.
 
234
 * \param[in,out] clay The pointer to the clay structure to free.
 
235
 */
 
236
void osl_clay_free(osl_clay_p clay) {
 
237
  if (clay != NULL) {
 
238
    if(clay->script != NULL)
 
239
      free(clay->script);
 
240
    free(clay);
 
241
  }
 
242
}
 
243
 
 
244
 
 
245
/*+***************************************************************************
 
246
 *                            Processing functions                           *
 
247
 *****************************************************************************/
 
248
 
 
249
 
 
250
/**
 
251
 * osl_clay_clone function:
 
252
 * this function builds and returns a "hard copy" (not a pointer copy) of an
 
253
 * osl_clay_t data structure.
 
254
 * \param[in] clay The pointer to the clay structure to clone.
 
255
 * \return A pointer to the clone of the clay structure.
 
256
 */
 
257
osl_clay_p osl_clay_clone(osl_clay_p clay) {
 
258
  osl_clay_p clone;
 
259
 
 
260
  if (clay == NULL)
 
261
    return NULL;
 
262
 
 
263
  clone = osl_clay_malloc();
 
264
  OSL_strdup(clone->script, clay->script);
 
265
 
 
266
  return clone;
 
267
}
 
268
 
 
269
 
 
270
/**
 
271
 * osl_clay_equal function:
 
272
 * this function returns true if the two clay structures are the same
 
273
 * (content-wise), false otherwise.
 
274
 * \param[in] c1  The first clay structure.
 
275
 * \param[in] c2  The second clay structure.
 
276
 * \return 1 if c1 and c2 are the same (content-wise), 0 otherwise.
 
277
 */
 
278
int osl_clay_equal(osl_clay_p c1, osl_clay_p c2) {
 
279
  if (c1 == c2)
 
280
    return 1;
 
281
 
 
282
  if (((c1 == NULL) && (c2 != NULL)) || ((c1 != NULL) && (c2 == NULL))) {
 
283
    OSL_info("clay extensions are not the same");
 
284
    return 0;
 
285
  }
 
286
 
 
287
  if (strcmp(c1->script, c2->script)) {
 
288
    OSL_info("clay scripts are not the same");
 
289
    return 0;
 
290
  }
 
291
 
 
292
  return 1;
 
293
}
 
294
 
 
295
 
 
296
/**
 
297
 * osl_clay_interface function:
 
298
 * this function creates an interface structure corresponding to the clay
 
299
 * extension and returns it).
 
300
 * \return An interface structure for the clay extension.
 
301
 */
 
302
osl_interface_p osl_clay_interface() {
 
303
  osl_interface_p interface = osl_interface_malloc();
 
304
  
 
305
  OSL_strdup(interface->URI, OSL_URI_CLAY);
 
306
  interface->idump  = (osl_idump_f)osl_clay_idump;
 
307
  interface->sprint = (osl_sprint_f)osl_clay_sprint;
 
308
  interface->sread  = (osl_sread_f)osl_clay_sread;
 
309
  interface->malloc = (osl_malloc_f)osl_clay_malloc;
 
310
  interface->free   = (osl_free_f)osl_clay_free;
 
311
  interface->clone  = (osl_clone_f)osl_clay_clone;
 
312
  interface->equal  = (osl_equal_f)osl_clay_equal;
 
313
 
 
314
  return interface;
 
315
}