1 /**-------------------------------------------------------------------**
3 **-------------------------------------------------------------------**
5 **-------------------------------------------------------------------**/
8 /******************************************************************************
9 * CLooG : the Chunky Loop Generator (experimental) *
10 ******************************************************************************
12 * Copyright (C) 2001-2005 Cedric Bastoul *
14 * This library is free software; you can redistribute it and/or *
15 * modify it under the terms of the GNU Lesser General Public *
16 * License as published by the Free Software Foundation; either *
17 * version 2.1 of the License, or (at your option) any later version. *
19 * This library is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Lesser General Public License for more details. *
24 * You should have received a copy of the GNU Lesser General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
27 * Boston, MA 02110-1301 USA *
29 * CLooG, the Chunky Loop Generator *
30 * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
32 ******************************************************************************/
36 #include "../include/cloog/cloog.h"
40 * Allocate a CloogMatrix data structure with NbRows rows and NbColumns columns.
41 * All values are initialized to 0.
42 * This method returns a pointer to the data structure if successful or a NULL
45 CloogMatrix
*cloog_matrix_alloc(unsigned NbRows
, unsigned NbColumns
)
51 matrix
= (CloogMatrix
*)malloc(sizeof(CloogMatrix
));
56 matrix
->NbRows
= NbRows
;
57 matrix
->NbColumns
= NbColumns
;
59 if (!NbRows
|| !NbColumns
) {
61 matrix
->p_Init
= NULL
;
65 p
= (cloog_int_t
**)malloc(NbRows
* sizeof(cloog_int_t
*));
72 q
= (cloog_int_t
*)malloc(NbRows
* NbColumns
* sizeof(cloog_int_t
));
83 for (i
= 0; i
< NbRows
; i
++) {
85 for (j
= 0; j
< NbColumns
; j
++) {
86 cloog_int_init(*(q
+j
));
87 cloog_int_set_si(*(q
+j
), 0);
99 void cloog_matrix_free(CloogMatrix
* matrix
)
103 int size
= matrix
->NbRows
* matrix
->NbColumns
;
107 for (i
= 0; i
< size
; i
++)
108 cloog_int_clear(*p
++);
111 free(matrix
->p_Init
);
119 * Print the elements of CloogMatrix M to file, with each row prefixed
120 * by prefix and suffixed by suffix.
122 void cloog_matrix_print_structure(FILE *file
, CloogMatrix
*M
,
123 const char *prefix
, const char *suffix
)
127 for (i
= 0; i
< M
->NbRows
; ++i
) {
128 fprintf(file
, "%s", prefix
);
129 for (j
= 0; j
< M
->NbColumns
; ++j
) {
130 cloog_int_print(file
, M
->p
[i
][j
]);
133 fprintf(file
, "%s\n", suffix
);
138 * cloog_matrix_print function:
139 * This function prints the content of a CloogMatrix structure (matrix) into a
140 * file (foo, possibly stdout).
142 void cloog_matrix_print(FILE* foo
, CloogMatrix
* m
)
145 fprintf(foo
, "(null)\n");
147 fprintf(foo
, "%d %d\n", m
->NbRows
, m
->NbColumns
);
148 cloog_matrix_print_structure(foo
, m
, "", "");