initial version of ppcg
[ppcg.git] / clan / source / scop.c
blobed68c370fdeae26d0cdc53d464f995913b2dd347
2 /*+------- <| --------------------------------------------------------**
3 ** A Clan **
4 **--- /.\ -----------------------------------------------------**
5 ** <| [""M# scop.c **
6 **- A | # -----------------------------------------------------**
7 ** /.\ [""M# First version: 30/04/2008 **
8 **- [""M# | # U"U#U -----------------------------------------------**
9 | # | # \ .:/
10 | # | #___| #
11 ****** | "--' .-" ******************************************************
12 * |"-"-"-"-"-#-#-## Clan : the Chunky Loop Analyzer (experimental) *
13 **** | # ## ###### *****************************************************
14 * \ .::::'/ *
15 * \ ::::'/ Copyright (C) 2008 Cedric Bastoul *
16 * :8a| # # ## *
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 *
27 * for more details. *
28 * *
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 *
32 * *
33 * Clan, the Chunky Loop Analyzer *
34 * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
35 * *
36 ******************************************************************************/
39 # include <stdlib.h>
40 # include <stdio.h>
41 # include <ctype.h>
42 # include <string.h>
43 # include <clan/scop.h>
44 # include <clan/clan.h>
45 # include <parser.h>
48 /*+****************************************************************************
49 * Processing functions *
50 ******************************************************************************/
52 scoplib_scop_p
53 clan_parse(FILE *, clan_options_p);
55 /**
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
59 * structure.
60 * \param input The file to parse (already open).
61 * \param options Options for file parsing.
63 * - 24/05/2008: First version.
65 scoplib_scop_p
66 clan_scop_extract(FILE * input, clan_options_p options)
68 return clan_parse(input,options);
72 /**
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.
81 void
82 clan_scop_compact(scoplib_scop_p scop)
84 clan_statement_compact(scop->statement,scop->nb_parameters);
88 /**
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>.
95 void
96 clan_scop_fill_options(scoplib_scop_p scop, int* localvars, int* liveoutvars)
98 /* Build the string of ids. */
99 int i, size;
100 char* tag = NULL;
101 char* tag1 = NULL;
102 char* tag2 = NULL;
103 if (localvars && localvars[0] != -1)
105 /* localvars is a -1-terminated array. */
106 for (i = 0; localvars[i] != -1; ++i)
108 size = i;
109 char* ids = (char*)malloc(((size * 5) + 1) * sizeof(char));
110 ids[0] = '\0';
111 char buffer[16];
112 for (i = 0; i < size; ++i)
114 if (i == 0)
115 sprintf(buffer, "%d", localvars[i]);
116 else
117 sprintf(buffer, " %d", localvars[i]);
118 strcat(ids, buffer);
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");
124 strcat(tag1, ids);
125 strcat(tag1, "\n");
126 strcat(tag1, "</local-vars>\n");
127 free(ids);
130 if (liveoutvars && liveoutvars[0] != -1)
132 /* liveoutvars is a -1-terminated array. */
133 for (i = 0; liveoutvars[i] != -1; ++i)
135 size = i;
136 char* ids = (char*)malloc(((size * 5) + 1) * sizeof(char));
137 ids[0] = '\0';
138 char buffer[16];
139 for (i = 0; i < size; ++i)
141 if (i == 0)
142 sprintf(buffer, "%d", liveoutvars[i]);
143 else
144 sprintf(buffer, " %d", liveoutvars[i]);
145 strcat(ids, buffer);
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");
151 strcat(tag2, ids);
152 strcat(tag2, "\n");
153 strcat(tag2, "</live-out-vars>\n");
154 free(ids);
157 /* Concatenate the tags. */
158 if (tag1 || tag2)
160 if (tag1 == NULL)
161 tag = tag2;
162 else if (tag2 == NULL)
163 tag = tag1;
164 else
166 tag = (char*)malloc((strlen(tag1) + strlen(tag2) + 1));
167 strcpy(tag, tag1);
168 strcat(tag, tag2);
169 free(tag1);
170 free(tag2);
174 if (scop->optiontags == NULL)
175 scop->optiontags = tag;
176 else
178 char* newtag = (char*)malloc((strlen(tag) + strlen(scop->optiontags) + 2)
179 * sizeof(char));
180 strcpy(newtag, scop->optiontags);
181 strcat(newtag, "\n");
182 strcat(newtag, tag);
183 free(scop->optiontags);
184 scop->optiontags = newtag;