2 /*+-----------------------------------------------------------------**
4 **-----------------------------------------------------------------**
5 ** extensions/scatnames.c **
6 **-----------------------------------------------------------------**
7 ** First version: 03/12/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 * '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' *
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/strings.h>
71 #include <osl/extensions/scatnames.h>
74 /*+***************************************************************************
75 * Structure display function *
76 *****************************************************************************/
80 * osl_scatnames_idump function:
81 * this function displays an osl_scatnames_t structure (*scatnames) into a
82 * file (file, possibly stdout) in a way that trends to be understandable. It
83 * includes an indentation level (level) in order to work with others
85 * \param[in] file The file where the information has to be printed.
86 * \param[in] scatnames Scatnames structure to print.
87 * \param[in] level Number of spaces before printing, for each line.
89 void osl_scatnames_idump(FILE * file
, osl_scatnames_p scatnames
, int level
) {
92 // Go to the right level.
93 for (j
= 0; j
< level
; j
++)
96 if (scatnames
!= NULL
)
97 fprintf(file
, "+-- osl_scatnames_t\n");
99 fprintf(file
, "+-- NULL scatnames\n");
101 if (scatnames
!= NULL
) {
102 // Go to the right level.
103 for(j
= 0; j
<= level
+ 1; j
++)
104 fprintf(file
, "|\t");
107 // Display the list of scattering names.
108 osl_strings_idump(file
, scatnames
->names
, level
+ 1);
112 for (j
= 0; j
<= level
; j
++)
113 fprintf(file
, "|\t");
119 * osl_scatnames_dump function:
120 * this function prints the content of an osl_scatnames_t structure
121 * (*scatnames) into a file (file, possibly stdout).
122 * \param[in] file The file where the information has to be printed.
123 * \param[in] scatnames The scatnames structure to print.
125 void osl_scatnames_dump(FILE * file
, osl_scatnames_p scatnames
) {
126 osl_scatnames_idump(file
, scatnames
, 0);
131 * osl_scatnames_sprint function:
132 * this function prints the content of an osl_scatnames_t structure
133 * (*scatnames) into a string (returned) in the OpenScop textual format.
134 * \param[in] scatnames The scatnames structure to print.
135 * \return A string containing the OpenScop dump of the scatnames structure.
137 char * osl_scatnames_sprint(osl_scatnames_p scatnames
) {
138 return osl_strings_sprint(scatnames
->names
);
142 /*****************************************************************************
144 *****************************************************************************/
148 * osl_scatnames_sread function:
149 * this function reads a scatnames structure from a string complying to the
150 * OpenScop textual format and returns a pointer to this scatnames structure.
151 * The input parameter is updated to the position in the input string this
152 * function reach right after reading the scatnames structure. If there
153 * is nothing to read, the function returns NULL.
154 * \param[in,out] input The input string where to find a scatnames.
155 * Updated to the position after what has been read.
156 * \return A pointer to the scatnames structure that has been read.
158 osl_scatnames_p
osl_scatnames_sread(char ** input
) {
159 osl_scatnames_p scatnames
= NULL
;
160 osl_strings_p names
= NULL
;
162 if (*input
== NULL
) {
163 OSL_debug("no scatnames optional tag");
167 // Build the scatnames structure
168 names
= osl_strings_sread(input
);
170 scatnames
= osl_scatnames_malloc();
171 scatnames
->names
= names
;
178 /*+***************************************************************************
179 * Memory allocation/deallocation function *
180 *****************************************************************************/
184 * osl_scatnames_malloc function:
185 * this function allocates the memory space for an osl_scatnames_t
186 * structure and sets its fields with default values. Then it returns a
187 * pointer to the allocated space.
188 * \return A pointer to an empty scatnames structure with fields set to
191 osl_scatnames_p
osl_scatnames_malloc() {
192 osl_scatnames_p scatnames
;
194 OSL_malloc(scatnames
, osl_scatnames_p
, sizeof(osl_scatnames_t
));
195 scatnames
->names
= NULL
;
202 * osl_scatnames_free function:
203 * this function frees the allocated memory for an osl_scatnames_t
205 * \param[in,out] scatnames The pointer to the scatnames structure to free.
207 void osl_scatnames_free(osl_scatnames_p scatnames
) {
208 if (scatnames
!= NULL
) {
209 osl_strings_free(scatnames
->names
);
215 /*+***************************************************************************
216 * Processing functions *
217 *****************************************************************************/
221 * osl_scatnames_clone function:
222 * This function builds and returns a "hard copy" (not a pointer copy) of an
223 * osl_scatnames_t data structure.
224 * \param[in] scatnames The pointer to the scatnames structure to clone.
225 * \return A pointer to the clone of the scatnames structure.
227 osl_scatnames_p
osl_scatnames_clone(osl_scatnames_p scatnames
) {
228 osl_scatnames_p clone
;
230 if (scatnames
== NULL
)
233 clone
= osl_scatnames_malloc();
234 clone
->names
= osl_strings_clone(scatnames
->names
);
241 * osl_scatnames_equal function:
242 * this function returns true if the two scatnames structures are the same
243 * (content-wise), false otherwise.
244 * \param[in] s1 The first scatnames structure.
245 * \param[in] s2 The second scatnames structure.
246 * \return 1 if s1 and s2 are the same (content-wise), 0 otherwise.
248 int osl_scatnames_equal(osl_scatnames_p s1
, osl_scatnames_p s2
) {
253 if (((s1
== NULL
) && (s2
!= NULL
)) || ((s1
!= NULL
) && (s2
== NULL
)))
256 if (!osl_strings_equal(s1
->names
, s2
->names
))
264 * osl_scatnames_interface function:
265 * this function creates an interface structure corresponding to the scatnames
266 * extension and returns it).
267 * \return An interface structure for the scatnames extension.
269 osl_interface_p
osl_scatnames_interface() {
270 osl_interface_p interface
= osl_interface_malloc();
272 interface
->URI
= strdup(OSL_URI_SCATNAMES
);
273 interface
->idump
= (osl_idump_f
)osl_scatnames_idump
;
274 interface
->sprint
= (osl_sprint_f
)osl_scatnames_sprint
;
275 interface
->sread
= (osl_sread_f
)osl_scatnames_sread
;
276 interface
->malloc
= (osl_malloc_f
)osl_scatnames_malloc
;
277 interface
->free
= (osl_free_f
)osl_scatnames_free
;
278 interface
->clone
= (osl_clone_f
)osl_scatnames_clone
;
279 interface
->equal
= (osl_equal_f
)osl_scatnames_equal
;