modified autogen.sh to remove reference to osl/
[converter.git] / source / osl2scoplib.c
blob26a705eceed6cab1a6c0a63c0a2574e8decb9271
1 #include "converter/converter.h"
2 #include "converter/converter_dep.h"
3 //#include "converter_int.h"
4 #include "osl/scop.h"
5 #include "osl/body.h"
6 #include "osl/generic.h"
7 #include "osl/util.h"
8 #include "osl/extensions/arrays.h"
9 #include <string.h> // warnings for strlen() incomatible implicit declaration
10 #include "osl/macros.h"
12 #include "scoplib/scop.h"
13 #include "scoplib/matrix.h"
16 #include <stdio.h>
17 #include <stdlib.h>
20 * this functions converts an osl relation into a scoplib matrix
22 * \param[in] in_rln osl relation to convert
23 * \return equivalent coverted scoplib matrix
25 scoplib_matrix_p convert_relation_osl2scoplib(osl_relation_p in_rln){
27 int i = 0;
28 int j = 0;
30 if(in_rln==NULL){
31 return NULL;
34 if(in_rln->nb_local_dims)
35 CONVERTER_error("Cannot handle Local Dimensions in a relation. Abort.\n");
37 scoplib_matrix_p ctx = scoplib_matrix_malloc(in_rln->nb_rows,
38 in_rln->nb_columns);
40 ctx->NbRows = in_rln->nb_rows;
41 ctx->NbColumns = in_rln->nb_columns;
43 //copy matrix
44 for(i=0; i < in_rln->nb_rows; i++){
45 for(j=0; j < in_rln->nb_columns; j++){
46 convert_int_assign_osl2scoplib(&(ctx->p[i][j]),
47 in_rln->precision, in_rln->m[i][j]);
51 return ctx;
55 * this functions converts an list of osl relations into a scoplib_matrix_list
57 * \param[in] in_rln osl relation to convert
58 * \return equivalent coverted scoplib_matrix_list
60 scoplib_matrix_list_p convert_relation_list_osl2scoplib(osl_relation_p in_rln){
62 scoplib_matrix_list_p m_list = NULL;
63 scoplib_matrix_list_p ml_head= NULL;
65 if(in_rln == NULL)
66 return NULL;
68 osl_relation_p rln = in_rln;
69 for(;rln; rln=rln->next){
71 scoplib_matrix_list_p ml_tmp=scoplib_matrix_list_malloc();
72 ml_tmp->elt = convert_relation_osl2scoplib(rln);
74 if(!m_list){
75 m_list = ml_head = ml_tmp;
77 else{
78 ml_head->next = ml_tmp;
79 ml_head = ml_head->next;
83 return m_list;
89 * this functions converts scattering osl relation into a scoplib schedule
91 * \param[in] scattering osl access relation to convert
92 * \return equivalent coverted scoplib schedule
94 scoplib_matrix_p convert_scattering_osl2scoplib(osl_relation_p scattering){
96 int i=0;
97 int j=0;
99 if(scattering==NULL){
100 return NULL;
103 if(scattering->nb_local_dims)
104 CONVERTER_error("Cannot handle Scattering Local Dimensions. Abort.\n");
106 int nb_cols = scattering->nb_columns -
107 scattering->nb_output_dims;
108 int nb_rows = scattering->nb_rows;
110 scoplib_matrix_p scat = scoplib_matrix_malloc(nb_rows, nb_cols);
111 scat->NbRows = nb_rows;
112 scat->NbColumns = nb_cols;
114 // TODO: FIND the order of the scat_dims
116 //copy the eq/neq column
117 for(i=0; i < scattering->nb_rows; i++)
118 convert_int_assign_osl2scoplib(&scat->p[i][0],
119 scattering->precision, scattering->m[i][0]);
121 //copy input_dims and the rest
122 for(i=0; i < scattering->nb_rows; i++)
123 for(j=scattering->nb_output_dims+1; j < scattering->nb_columns; j++)
124 convert_int_assign_osl2scoplib(
125 &scat->p[i][j-(scattering->nb_output_dims)],
126 scattering->precision, scattering->m[i][j]);
128 return scat;
132 * given a list of osl access relations, this fucntions calculates the
133 * number of rows and columns for the scoplib read/write matrices based
134 * on the dimensions of read/write array accesses in the statement
136 * \param[in] access osl access relation list
137 * \param[out] nb_rows_read number of rows for the read access matrix
138 * \param[out] nb_columns_read number of columns for the read access matrix
139 * \param[out] nb_rows_write number of rows for the write access matrix
140 * \param[out] nb_columns_write number of columns for the write access matrix
141 * \param[out] nb_rows_maywrite number of rows for the maywrite access matrix
142 * \param[out] nb_columns_maywrite number of columns for the maywrite acc matrix
143 * \return void
145 void convert_access_calc_dimensions( osl_relation_list_p access,
146 int *nb_rows_read,
147 int *nb_columns_read,
148 int *nb_rows_write,
149 int *nb_columns_write,
150 int *nb_rows_may_write,
151 int *nb_columns_may_write){
152 if(access==NULL)
153 CONVERTER_warning("NULL access relation pointer passed\n");
156 osl_relation_list_p head = access;
158 while (head) {
159 if (head->elt != NULL) {
160 if (head->elt->type == OSL_TYPE_READ) {
161 if (head->elt->nb_rows == 1)
162 (*nb_rows_read)++;
163 else
164 (*nb_rows_read) += head->elt->nb_rows - 1; // remove the 'Arr'
166 (*nb_columns_read) = head->elt->nb_columns -
167 head->elt->nb_output_dims;
169 } else if (head->elt->type == OSL_TYPE_WRITE) {
170 if (head->elt->nb_rows == 1)
171 (*nb_rows_write)++;
172 else
173 (*nb_rows_write) += head->elt->nb_rows - 1; // remove the 'Arr'
176 (*nb_columns_write) = head->elt->nb_columns -
177 head->elt->nb_output_dims;
178 } else if (head->elt->type == OSL_TYPE_MAY_WRITE) {
179 if (head->elt->nb_rows == 1)
180 (*nb_rows_may_write)++;
181 else
182 (*nb_rows_may_write) += head->elt->nb_rows - 1; // remove the 'Arr'
184 (*nb_columns_may_write) = head->elt->nb_columns -
185 head->elt->nb_output_dims;
189 if(head->elt->next != NULL)
190 CONVERTER_error("Union of Access relation detected. Abort.\n");
192 head = head->next;
195 return;
200 * this functions converts an osl access relation into a scoplib access matrix
202 * \param[in] head osl access relation to convert
203 * \param[in] type type of acccess relation: read/write
204 * \param[in] type2 mayrite accesses to be combined with write type
205 * \param[in] nb_rows number of rows for the [out] scoplib_matrix
206 * \param[in] nb_columns number of columns for the [out] scoplib_matrix
207 * \return new scoplib access matrix
209 scoplib_matrix_p convert_access_osl2scoplib(osl_relation_list_p head,
210 int type, int type2,
211 int nb_rows,
212 int nb_columns){
214 if(head==NULL)
215 return NULL;
217 scoplib_matrix_p m_read = scoplib_matrix_malloc(nb_rows,
218 nb_columns);
219 // copy
220 //head = p->access;
221 int i = 0;
222 int j = 0;
223 while(head){
224 if(head->elt->nb_local_dims)
225 CONVERTER_error("Cannot handle Access Local Dimensions. Abort.\n");
227 if ( head->elt != NULL
228 && (head->elt->type == type || head->elt->type == type2)){
230 //type2 only may_write
231 if(type==OSL_TYPE_READ && head->elt->type == type2)
232 CONVERTER_error("Unknown Access type!! Abort.");
234 // get array id
235 // assuming first row, last element: TODO:search for it ??
236 scoplib_int_t array_id;
237 SCOPVAL_init_set_si(array_id, 0);
239 convert_int_assign_osl2scoplib(&array_id,
240 head->elt->precision, head->elt->m[0][head->elt->nb_columns-1]);
242 int first_access = 1;
243 // arrange dimensions in order ????
244 int k=0;
245 // assign array id here, as some matrices have only one row!
246 SCOPVAL_assign(m_read->p[i][0], array_id);
247 SCOPVAL_clear(array_id);
249 if(head->elt->nb_rows==1) i++; //single row matrix
251 //skip the frist row; array_id already been recovered
252 for(k=1; k< head->elt->nb_rows; k++,i++){
254 if(first_access){
255 first_access = 0;// do nothing. array_id assigned above
257 else{
258 //m_read->p[i][0] = 0;
259 SCOPVAL_set_si(m_read->p[i][0], 0);
262 for(j=head->elt->nb_output_dims+1; j< head->elt->nb_columns; j++){
263 //copy matrix, but skip output_dims
264 convert_int_assign_osl2scoplib(
265 &m_read->p[i][j-head->elt->nb_output_dims],
266 head->elt->precision, head->elt->m[k][j]);
270 head = head->next;
273 return m_read;
277 * convert_osl_strings_sprint function:
278 * this function prints the content of an osl_strings_t structure
279 * (*strings) into a string (returned) in the OpenScop textual format.
281 * \param[in] strings The strings structure which has to be printed.
282 * \return A string containing the OpenScop dump of the strings structure.
284 // commented the '\n' at the end of the string
285 char * convert_osl_strings_sprint(osl_strings_p strings) {
286 int i;
287 int high_water_mark = OSL_MAX_STRING;
288 char * string = NULL;
289 char buffer[OSL_MAX_STRING];
291 OSL_malloc(string, char *, high_water_mark * sizeof(char));
292 string[0] = '\0';
294 if (strings != NULL) {
295 for (i = 0; i < osl_strings_size(strings); i++) {
296 sprintf(buffer, "%s", strings->string[i]);
297 osl_util_safe_strcat(&string, buffer, &high_water_mark);
298 if (i < osl_strings_size(strings) - 1)
299 osl_util_safe_strcat(&string, " ", &high_water_mark);
301 //sprintf(buffer, "\n");
302 //osl_util_safe_strcat(&string, buffer, &high_water_mark);
304 else {
305 sprintf(buffer, "# NULL strings\n");
306 osl_util_safe_strcat(&string, buffer, &high_water_mark);
309 return string;
313 * this functions converts an osl strings structure into a scoplib strings
315 * \param[in] str osl strings structure
316 * \return scoplib strings
318 char ** convert_strings_osl2scoplib(osl_strings_p str){
320 if(str==NULL)
321 return NULL;
323 int i=0;
324 char **out_str = NULL;
325 int nb_strings=0;
327 if ((nb_strings = osl_strings_size(str)) == 0){
328 CONVERTER_malloc(out_str, char**, 1*sizeof(char*) );
329 *out_str=NULL;
330 return out_str;
333 CONVERTER_malloc(out_str, char **, (nb_strings + 1) * sizeof(char *));
334 out_str[nb_strings] = NULL;
335 for (i = 0; i < nb_strings; i++)
336 CONVERTER_strdup(out_str[i], str->string[i]);
339 return out_str;
344 * this functions converts an osl statemetn into a scoplib statement
346 * \param[in] p osl statemetn to convert
347 * \param[in] precision input statmenet precsion TODO: get rid of it
348 * \return equivalent coverted scoplib statement
350 scoplib_statement_p convert_statement_osl2scoplib(osl_statement_p p,
351 int precision){
353 scoplib_statement_p stmt_head = NULL;
354 scoplib_statement_p last_stmt = NULL;
356 int nb_stmt = 1;
358 if(p==NULL)
359 return NULL;
361 for( ; p; p = p->next, nb_stmt++){
363 scoplib_statement_p stmt = scoplib_statement_malloc();
365 //domain
366 //domain list
367 stmt->domain = convert_relation_list_osl2scoplib(p->domain);
369 //scattering
370 stmt->schedule = convert_scattering_osl2scoplib(p->scattering);
372 // calculate the read/write dimensions
373 int nb_rows_write = 0;
374 int nb_columns_write = 0;
375 int nb_rows_may_write = 0;
376 int nb_columns_may_write = 0;
377 int nb_rows_read = 0;
378 int nb_columns_read = 0;
380 //access list
381 convert_access_calc_dimensions(p->access,
382 &nb_rows_read, &nb_columns_read,
383 &nb_rows_write, &nb_columns_write,
384 &nb_rows_may_write, &nb_columns_may_write);
386 // allocate read
387 //TODO: could be done more neatly with a relation_filter!
388 stmt->read = convert_access_osl2scoplib( p->access, OSL_TYPE_READ,
389 0, //dummy
390 nb_rows_read, nb_columns_read);
392 // allocate write
393 //if(nb_rows_write || nb_rows_may_write){
394 stmt->write = convert_access_osl2scoplib( p->access, OSL_TYPE_WRITE,
395 OSL_TYPE_MAY_WRITE, nb_rows_write+nb_rows_may_write,
396 nb_columns_write+nb_columns_may_write);
398 // iterators
399 osl_body_p stmt_body=NULL;
400 if(p->body)
401 stmt_body = (osl_body_p)(p->body->data);
403 if(stmt_body==NULL)
404 CONVERTER_warning("Statement body not found!!\n");
405 else{
406 stmt->nb_iterators = osl_strings_size(stmt_body->iterators);
408 stmt->iterators = convert_strings_osl2scoplib(stmt_body->iterators);
409 //body
410 stmt->body = convert_osl_strings_sprint(stmt_body->expression);
413 //usr not used??? TODO:
414 //stmt->usr = NULL;
418 if(!stmt_head){
419 stmt_head = last_stmt = stmt;
421 else{
422 last_stmt->next = stmt;
423 last_stmt = last_stmt->next;
429 return stmt_head;
434 * osl_scop_names function:
435 * this function generates as set of names for all the dimensions
436 * involved in a given scop.
438 * \param[in] scop The scop (list) we have to generate names for.
439 * \return A set of generated names for the input scop dimensions.
441 static
442 osl_names_p convert_osl_scop_names(osl_scop_p scop) {
443 int nb_parameters = OSL_UNDEFINED;
444 int nb_iterators = OSL_UNDEFINED;
445 int nb_scattdims = OSL_UNDEFINED;
446 int nb_localdims = OSL_UNDEFINED;
447 int array_id = OSL_UNDEFINED;
449 osl_scop_get_attributes(scop, &nb_parameters, &nb_iterators,
450 &nb_scattdims, &nb_localdims, &array_id);
452 return osl_names_generate("P", nb_parameters,
453 "i", nb_iterators,
454 "c", nb_scattdims,
455 "l", nb_localdims,
456 "A", array_id);
460 * osl_arrays_sprint function:
461 * this function prints the content of an osl_arrays_t structure
462 * (*arrays) into a string (returned) in the OpenScop textual format.
464 * \param[in] arrays The arrays structure to print.
465 * \return A string containing the OpenScop dump of the arrays structure.
467 char * convert_osl_arrays_sprint(osl_strings_p arrays) {
468 int i;
469 int high_water_mark = OSL_MAX_STRING;
470 char * string = NULL;
471 char buffer[OSL_MAX_STRING];
473 int nb_names = osl_strings_size(arrays);
475 if (arrays != NULL) {
476 OSL_malloc(string, char *, high_water_mark * sizeof(char));
477 string[0] = '\0';
479 sprintf(buffer, "# Number of arrays\n");
480 osl_util_safe_strcat(&string, buffer, &high_water_mark);
482 sprintf(buffer, "%d\n", nb_names);
483 osl_util_safe_strcat(&string, buffer, &high_water_mark);
485 if (nb_names) {
486 sprintf(buffer, "# Mapping array-identifiers/array-names\n");
487 osl_util_safe_strcat(&string, buffer, &high_water_mark);
489 for (i = 0; i < nb_names; i++) {
490 sprintf(buffer, "%d %s\n", i+1, arrays->string[i]);
491 osl_util_safe_strcat(&string, buffer, &high_water_mark);
494 OSL_realloc(string, char *, (strlen(string) + 1) * sizeof(char));
497 return string;
502 void convert_scoplib_strings_print(char** s1){
504 int i= 0;
505 int nb_strings = 0;
506 char **s1_cpy = s1;
508 while( *s1_cpy++ )
509 nb_strings++;
511 printf("scoplib strings size=%d\n", nb_strings);
512 printf("scoplib strings with indexes:\n");
513 for(i=0; i< nb_strings; i++){
514 //strcmp returns non-zero if strings not equal
515 printf("%d %s\n", i, s1[i]);
522 * this functions checks of two arrays of strings are equal
524 * \param[in] s1 array of strings
525 * \param[in] s2 array of strings
526 * \return 1 if equal, 0 therwise
528 int convert_scoplib_strings_equal(char** s1, char** s2){
530 if(s1==s2)
531 return 1;
533 int i= 0;
534 int nb_strings_1 = 0;
535 int nb_strings_2 = 0;
536 char **s1_cpy = s1;
537 char **s2_cpy = s2;
539 while( *s1_cpy++) nb_strings_1++;
540 while( *s2_cpy++) nb_strings_2++;
542 if( nb_strings_1 != nb_strings_2){
543 CONVERTER_info("scoplib sizes of strings not equal\n");
544 printf("s1_size=%d, s2_size=%d\n", nb_strings_1, nb_strings_1);
545 return 0;
548 for(i=0; i< nb_strings_1; i++){
549 //strcmp returns non-zero if strings not equal
550 if(strcmp(s1[i], s2[i]) ){
551 CONVERTER_info("scoplib two strings not equal\n");
552 printf("s1: %s, s2: %s\n", s1[i], s2[i]);
553 return 0;
557 return 1;
562 * scoplib_matrix_equal function:
563 * this function returns true if the two matrices are the same, false
564 * otherwise.
566 * \param m1 The first matrix.
567 * \param m2 The second matrix.
571 convert_scoplib_matrix_equal(scoplib_matrix_p m1, scoplib_matrix_p m2)
573 if (m1 == m2)
574 return 1;
575 if (m1 == NULL || m2 == NULL)
576 return 0;
577 if (m1->NbRows != m2->NbRows || m1->NbColumns != m2->NbColumns)
578 return 0;
579 int i, j;
580 for (i = 0; i < m1->NbRows; ++i)
581 for (j = 0; j < m1->NbColumns; ++j)
582 if (SCOPVAL_ne(m1->p[i][j], m2->p[i][j]))
583 return 0;
584 return 1;
589 * scoplib_matrix_list_equal function:
590 * this function returns true if the two matric lists are the same, false
591 * otherwise.
593 * \param[in] ml1 scoplib matrix list
594 * \param[in] ml2 scoplib matrix list
595 * \return 1 if equal, 0 otherwise
597 int convert_scoplib_matrix_list_equal( scoplib_matrix_list_p ml1,
598 scoplib_matrix_list_p ml2){
600 if(ml1==ml2)
601 return 1;
603 if (((ml1->next != NULL) && (ml2->next == NULL)) ||
604 ((ml1->next == NULL) && (ml2->next != NULL))) {
605 CONVERTER_info("scoplib sizes of matrid_lists are not the same\n");
606 return 0;
609 if ((ml1->next != NULL) && (ml2->next != NULL)) {
610 if (!convert_scoplib_matrix_list_equal(ml1->next, ml2->next)) {
611 CONVERTER_info("scoplib matrid_lists are not the same\n");
612 return 0;
616 if( !convert_scoplib_matrix_equal(ml1->elt, ml2->elt) ){
617 CONVERTER_info("scoplib matrixes not equal\n");
618 return 0;
621 return 1;
625 * scoplib_statement_equal function:
626 * this function returns true if the two scoplib statements are the same, false
627 * otherwise.
629 * \param[in] s1 scoplib statment
630 * \param[in] s2 scoplib statment
631 * \return 1 if equal, 0 otherwise
633 int convert_scoplib_statement_equal(scoplib_statement_p s1,
634 scoplib_statement_p s2){
636 if(s1==s2)
637 return 1;
639 if (((s1->next != NULL) && (s2->next == NULL)) ||
640 ((s1->next == NULL) && (s2->next != NULL))) {
641 CONVERTER_info("scoplib number of statements are not the same\n");
642 return 0;
645 if ((s1->next != NULL) && (s2->next != NULL)) {
646 if (!convert_scoplib_statement_equal(s1->next, s2->next)) {
647 CONVERTER_info("scoplib statements is not the same\n");
648 return 0;
652 if( !convert_scoplib_matrix_list_equal(s1->domain, s2->domain) ){
653 CONVERTER_info("scoplib statements domains not equal\n");
654 return 0;
656 //else
657 // printf("scoplib statement domains are the same\n");
659 if( !convert_scoplib_matrix_equal(s1->schedule, s2->schedule) ){
660 CONVERTER_info("scoplib statements scatterings not equal\n");
661 return 0;
663 //else
664 // printf("scoplib statement scatterings are the same\n");
666 if( !convert_scoplib_matrix_equal(s1->read, s2->read) ){
667 CONVERTER_info("scoplib statements read matrixes not equal\n");
668 return 0;
670 //else
671 // printf("scoplib statement read_matrixes are the same\n");
673 if( !convert_scoplib_matrix_equal(s1->write, s2->write) ){
674 CONVERTER_info("scoplib statements write matrixes not equal\n");
675 return 0;
677 //else
678 // printf("scoplib statement write_matrixes are the same\n");
680 if( s1->nb_iterators != s2->nb_iterators ){
681 CONVERTER_info("scoplib statements nb_iterators not equal\n");
682 return 0;
684 //else
685 // printf("scoplib statement nb_tertaros are the same\n");
687 if( !convert_scoplib_strings_equal(s1->iterators, s2->iterators) ){
688 CONVERTER_info("scoplib statements iterators not equal\n");
689 convert_scoplib_strings_print(s1->iterators);
690 convert_scoplib_strings_print(s2->iterators);
691 return 0;
693 //else
694 // printf("scoplib statement iterators are the same\n");
696 //strcmp returns non-zero if strings not equal
697 if( strcmp(s1->body, s2->body) ){
698 CONVERTER_info("scoplib statements bodies not equal\n");
699 return 0;
701 //else
702 // printf("scoplib statement bodies are the same\n");
704 return 1;
709 * scoplib_scop_equal function:
710 * this function returns true if the scoplib scops are the same, false
711 * otherwise.
713 * \param[in] s1 scoplib scop
714 * \param[in] s2 scoplib scop
715 * \return 1 if equal, 0 otherwise
717 int convert_scoplib_scop_equal( scoplib_scop_p s1, scoplib_scop_p s2){
719 if(s1!=NULL && s2!=NULL && s1==s2) // same scop
720 return 1;
722 if (((s1 == NULL) && (s2 != NULL)) || ((s1 != NULL) && (s2 == NULL))){
723 CONVERTER_info("unequal scops! one is NULL!\n");
724 return 0;
727 if( !scoplib_matrix_equal(s1->context, s2->context) ){
728 CONVERTER_info("contexts not same! \n");
729 return 0;
731 //else
732 // printf("scoplib scop contexts are the same\n");
734 if(s1->nb_parameters != s2->nb_parameters ){
735 CONVERTER_info("nb_paramters not equal! \n");
736 return 0;
738 //else
739 // printf("scoplib scop nb_parameters are the same\n");
741 if(!convert_scoplib_strings_equal(s1->parameters, s2->parameters)){
742 CONVERTER_info("paramters not equal! \n");
743 return 0;
745 //else
746 // printf("scoplib scop parameters are the same\n");
748 if(s1->nb_arrays != s2->nb_arrays ){
749 CONVERTER_info("nb_arrasy not equal! \n");
750 return 0;
752 //else
753 // printf("scoplib scop nb_arrays are the same\n");
755 if(!convert_scoplib_strings_equal(s1->arrays, s2->arrays)){
756 CONVERTER_info("arrays not equal! \n");
757 return 0;
759 //else
760 // printf("scoplib scop arrays are the same\n");
762 if(!convert_scoplib_statement_equal(s1->statement, s2->statement)){
763 CONVERTER_info("statements not equal! \n");
764 return 0;
766 //else
767 // printf("scoplib scop statements are the same\n");
769 //strcmp returns non-zero if strings not equal
770 if(strcmp(s1->optiontags, s2->optiontags)){
771 CONVERTER_info("optiontags not equal! \n");
772 return 0;
774 //else
775 // printf("scoplib scop optiontags are the same\n");
777 // usr defined hj
779 return 1;
784 /***************************************************************************
785 * Translates osl_scop to scoplib_scop
786 * Return: NULL if unsuccessful
787 * : pointer to scoplib_scop if successful
789 * \param[in] inscop osl scop to be converted
790 * \return equivalent scoplib scop
791 ****************************************************************************/
792 scoplib_scop_p convert_scop_osl2scoplib( osl_scop_p inscop){
794 // int i=0;
795 // int j=0;
796 scoplib_scop_p out_scop = NULL; //return arg
797 // scoplib_scop_p last_scop = NULL;
798 scoplib_scop_p tmp_scop = NULL;
800 //NULL input pointer
801 if (inscop == NULL)
802 return out_scop;
804 if (osl_scop_integrity_check(inscop) == 0)
805 CONVERTER_warning("OSL integrity check failed. Something may go wrong.");
806 //TODO: return here?
809 tmp_scop = scoplib_scop_malloc();
811 int precision = osl_util_get_precision();
812 //version
813 //language //not used??
814 //context
815 tmp_scop->context = convert_relation_osl2scoplib(inscop->context);
818 //parameters
819 tmp_scop->nb_parameters = inscop->context->nb_columns - 2;
820 if(tmp_scop->nb_parameters){
821 osl_strings_p params = osl_strings_clone(inscop->parameters->data);
822 tmp_scop->parameters = convert_strings_osl2scoplib(params);
823 osl_strings_free(params);
828 tmp_scop->statement = convert_statement_osl2scoplib(inscop->statement,
829 precision);
830 //registry
831 //externsion
832 osl_names_p names = NULL;
833 names = convert_osl_scop_names(inscop);
834 //externsion -> arrays
835 osl_arrays_p arrays = osl_generic_lookup(inscop->extension,
836 OSL_URI_ARRAYS);
837 if(arrays){
838 tmp_scop->nb_arrays = arrays->nb_names; //??
839 osl_strings_p arr = osl_arrays_to_strings(arrays);
840 tmp_scop->arrays = convert_strings_osl2scoplib(arr);
841 osl_strings_free(arr);
843 else{ //assign generated names
844 tmp_scop->nb_arrays = osl_strings_size(names->arrays);
845 tmp_scop->arrays = convert_strings_osl2scoplib(names->arrays);
848 //optoin tags
849 // arrays
850 char *string = NULL;
851 if(arrays){
852 string = osl_arrays_sprint((osl_arrays_p) arrays);
854 else{
855 string = convert_osl_arrays_sprint(names->arrays);
859 if(names)
860 osl_names_free(names);
863 char *new_str = NULL;
864 if (string != NULL) {
865 OSL_malloc(new_str, char *, (strlen(string) + 20) * sizeof(char));
866 sprintf(new_str, "<arrays>\n%s</arrays>\n", string);
867 free(string);
869 tmp_scop->optiontags = new_str;
872 // dependenceies
873 convert_dep_osl2scoplib(inscop, tmp_scop);
877 //usr not used???
878 tmp_scop->usr = NULL;
882 if(inscop->next)
883 CONVERTER_warning("Multiple SCoPs detected. Converting first only!!!\n");
886 out_scop = tmp_scop;
889 return out_scop;