initial version of ppcg
[ppcg.git] / clan / source / vector.c
blob0846e39bef09ef502ddce0c08df42ed32f358d2e
2 /*+------- <| --------------------------------------------------------**
3 ** A Clan **
4 **--- /.\ -----------------------------------------------------**
5 ** <| [""M# vector.c **
6 **- A | # -----------------------------------------------------**
7 ** /.\ [""M# First version: 01/05/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 <clan/vector.h>
45 /*+****************************************************************************
46 * Processing functions *
47 ******************************************************************************/
50 /**
51 * clan_vector_term function:
52 * This function generates the vector representation of a term. It allocates
53 * a vector with maximal size and put the term value at the right place
54 * depending if the term is a constant, an iterator coefficient or a
55 * parameter coefficient (see the structure of a PolyLib row if unsure!).
56 * \param symbol The first node of the list of symbols.
57 * \param coefficient The constant or coefficient.
58 * \param identifier Identifier of iterator or parameter (NULL for constant).
60 * - 01/05/2008: first version.
62 scoplib_vector_p
63 clan_vector_term(clan_symbol_p symbol, int coefficient, char * identifier)
65 int rank, size;
66 scoplib_vector_p vector;
68 size = CLAN_MAX_DEPTH + CLAN_MAX_PARAMETERS + 2 ;
69 vector = scoplib_vector_malloc(size);
71 if (identifier == NULL)
72 SCOPVAL_set_si(vector->p[size - 1],coefficient);
73 else
75 rank = clan_symbol_get_rank(symbol,identifier);
77 if (clan_symbol_get_type(symbol,identifier) == SCOPLIB_TYPE_ITERATOR)
78 SCOPVAL_set_si(vector->p[rank],coefficient);
79 else
80 SCOPVAL_set_si(vector->p[CLAN_MAX_DEPTH + rank],coefficient);
82 return vector;