2 /*+------- <| --------------------------------------------------------**
4 **--- /.\ -----------------------------------------------------**
6 **- A | # -----------------------------------------------------**
7 ** /.\ [""M# First version: 30/04/2008 **
8 **- [""M# | # U"U#U -----------------------------------------------**
11 ****** | "--' .-" ******************************************************
12 * |"-"-"-"-"-#-#-## Clan : the Chunky Loop Analyzer (experimental) *
13 **** | # ## ###### *****************************************************
15 * \ ::::'/ Copyright (C) 2008 Cedric Bastoul *
17 * ::88a ### This is free software; you can redistribute it *
18 * ::::888a 8a ##::. and/or modify it under the terms of the GNU Lesser *
19 * ::::::::888a88a[]::: General Public License as published by the Free *
20 *::8:::::::::SUNDOGa8a::. Software Foundation, either version 3 of the *
21 *::::::::8::::888:Y8888:: License, or (at your option) any later version. *
22 *::::':::88::::888::Y88a::::::::::::... *
23 *::'::.. . ..... .. ... . *
24 * This software is distributed in the hope that it will be useful, but *
25 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
26 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
29 * You should have received a copy of the GNU Lesser General Public License *
30 * along with software; if not, write to the Free Software Foundation, Inc., *
31 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
33 * Clan, the Chunky Loop Analyzer *
34 * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
36 ******************************************************************************/
43 # include <clan/scop.h>
44 # include <clan/clan.h>
48 /*+****************************************************************************
49 * Processing functions *
50 ******************************************************************************/
53 clan_parse(FILE *, clan_options_p
);
56 * clan_scop_extract function:
57 * this function is a wrapper clan_parse function that parses a file to
58 * extract a SCoP and returns, if successful, a pointer to the scoplib_scop_t
60 * \param input The file to parse (already open).
61 * \param options Options for file parsing.
63 * - 24/05/2008: First version.
66 clan_scop_extract(FILE * input
, clan_options_p options
)
68 return clan_parse(input
,options
);
73 * clan_scop_compact function:
74 * This function scans the SCoP to put the right number of columns to every
75 * matrix (during construction we used CLAN_MAX_DEPTH and CLAN_MAX_PARAMETERS
76 * to define matrix and vector sizes).
77 * \param scop The scop to scan to compact matrices.
79 * - 02/05/2008: first version.
82 clan_scop_compact(scoplib_scop_p scop
)
84 clan_statement_compact(scop
->statement
,scop
->nb_parameters
);
89 * clan_scop_fill_options:
90 * This function stores the list of variables id in 'varlist' in the
91 * option tag of the scop, enclosed by
92 * <local-vars></local-vars>.
96 clan_scop_fill_options(scoplib_scop_p scop
, int* localvars
, int* liveoutvars
)
98 /* Build the string of ids. */
103 if (localvars
&& localvars
[0] != -1)
105 /* localvars is a -1-terminated array. */
106 for (i
= 0; localvars
[i
] != -1; ++i
)
109 char* ids
= (char*)malloc(((size
* 5) + 1) * sizeof(char));
112 for (i
= 0; i
< size
; ++i
)
115 sprintf(buffer
, "%d", localvars
[i
]);
117 sprintf(buffer
, " %d", localvars
[i
]);
120 size
= strlen("<local-vars>\n") + strlen (ids
) +
121 strlen ("</local-vars>\n");
122 tag1
= (char*)malloc((size
+ 1) * sizeof(char));
123 strcpy(tag1
, "<local-vars>\n");
126 strcat(tag1
, "</local-vars>\n");
130 if (liveoutvars
&& liveoutvars
[0] != -1)
132 /* liveoutvars is a -1-terminated array. */
133 for (i
= 0; liveoutvars
[i
] != -1; ++i
)
136 char* ids
= (char*)malloc(((size
* 5) + 1) * sizeof(char));
139 for (i
= 0; i
< size
; ++i
)
142 sprintf(buffer
, "%d", liveoutvars
[i
]);
144 sprintf(buffer
, " %d", liveoutvars
[i
]);
147 size
= strlen("<live-out-vars>\n") + strlen (ids
) +
148 strlen ("</live-out-vars>\n");
149 tag2
= (char*)malloc((size
+ 1) * sizeof(char));
150 strcpy(tag2
, "<live-out-vars>\n");
153 strcat(tag2
, "</live-out-vars>\n");
157 /* Concatenate the tags. */
162 else if (tag2
== NULL
)
166 tag
= (char*)malloc((strlen(tag1
) + strlen(tag2
) + 1));
174 if (scop
->optiontags
== NULL
)
175 scop
->optiontags
= tag
;
178 char* newtag
= (char*)malloc((strlen(tag
) + strlen(scop
->optiontags
) + 2)
180 strcpy(newtag
, scop
->optiontags
);
181 strcat(newtag
, "\n");
183 free(scop
->optiontags
);
184 scop
->optiontags
= newtag
;