2
/*+-----------------------------------------------------------------**
4
**-----------------------------------------------------------------**
5
** extensions/clay.c **
6
**-----------------------------------------------------------------**
7
** First version: 09/05/2012 **
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
* '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' *
30
* Copyright (C) 2008 University Paris-Sud 11 and INRIA *
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 *
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. *
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. *
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> *
61
*****************************************************************************/
67
#include <osl/macros.h>
69
#include <osl/interface.h>
70
#include <osl/extensions/clay.h>
73
/*+***************************************************************************
74
* Structure display function *
75
*****************************************************************************/
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
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.
88
void osl_clay_idump(FILE * file, osl_clay_p clay, int level) {
93
// Go to the right level.
94
for (j = 0; j < level; j++)
98
fprintf(file, "+-- osl_clay_t\n");
100
fprintf(file, "+-- NULL clay\n");
103
// Go to the right level.
104
for(j = 0; j <= level; j++)
105
fprintf(file, "|\t");
107
// Display the clay script (without any carriage return).
108
OSL_strdup(tmp, clay->script);
109
for (l = 0; l < strlen(tmp); l++)
112
fprintf(file, "script: %s\n", tmp);
117
for (j = 0; j <= level; j++)
118
fprintf(file, "|\t");
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.
130
void osl_clay_dump(FILE * file, osl_clay_p clay) {
131
osl_clay_idump(file, clay, 0);
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.
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];
148
OSL_malloc(string, char *, high_water_mark * sizeof(char));
152
sprintf(buffer, "%s", clay->script);
153
osl_util_safe_strcat(&string, buffer, &high_water_mark);
155
// Keep only the memory space we need.
156
OSL_realloc(string, char *, (strlen(string) + 1) * sizeof(char));
163
/*****************************************************************************
165
*****************************************************************************/
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.
178
osl_clay_p osl_clay_sread(char ** input) {
182
if (*input == NULL) {
183
OSL_debug("no clay optional tag");
187
if (strlen(*input) > OSL_MAX_STRING)
188
OSL_error("clay script too long");
190
// Build the clay structure
191
clay = osl_clay_malloc();
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'))
198
OSL_strdup(clay->script, script);
200
// Update the input pointer (everything has been read).
201
input += strlen(*input);
207
/*+***************************************************************************
208
* Memory allocation/deallocation function *
209
*****************************************************************************/
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
220
osl_clay_p osl_clay_malloc() {
223
OSL_malloc(clay, osl_clay_p, sizeof(osl_clay_t));
231
* osl_clay_free function:
232
* this function frees the allocated memory for an osl_clay_t
234
* \param[in,out] clay The pointer to the clay structure to free.
236
void osl_clay_free(osl_clay_p clay) {
238
if(clay->script != NULL)
245
/*+***************************************************************************
246
* Processing functions *
247
*****************************************************************************/
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.
257
osl_clay_p osl_clay_clone(osl_clay_p clay) {
263
clone = osl_clay_malloc();
264
OSL_strdup(clone->script, clay->script);
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.
278
int osl_clay_equal(osl_clay_p c1, osl_clay_p c2) {
282
if (((c1 == NULL) && (c2 != NULL)) || ((c1 != NULL) && (c2 == NULL))) {
283
OSL_info("clay extensions are not the same");
287
if (strcmp(c1->script, c2->script)) {
288
OSL_info("clay scripts are not the same");
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.
302
osl_interface_p osl_clay_interface() {
303
osl_interface_p interface = osl_interface_malloc();
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;