Added support for statement extensions
[converter.git] / source / osl2scoplib.c
blobaebe9f08edc38f43652241c8c0f550f543fca6cc
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 stmt_body = (osl_body_p)osl_generic_lookup(p->extension, OSL_URI_BODY);
402 if(stmt_body==NULL)
403 CONVERTER_warning("Statement body not found!!\n");
404 else{
405 stmt->nb_iterators = osl_strings_size(stmt_body->iterators);
407 stmt->iterators = convert_strings_osl2scoplib(stmt_body->iterators);
408 //body
409 stmt->body = convert_osl_strings_sprint(stmt_body->expression);
412 //usr not used??? TODO:
413 //stmt->usr = NULL;
417 if(!stmt_head){
418 stmt_head = last_stmt = stmt;
420 else{
421 last_stmt->next = stmt;
422 last_stmt = last_stmt->next;
428 return stmt_head;
433 * osl_scop_names function:
434 * this function generates as set of names for all the dimensions
435 * involved in a given scop.
437 * \param[in] scop The scop (list) we have to generate names for.
438 * \return A set of generated names for the input scop dimensions.
440 static
441 osl_names_p convert_osl_scop_names(osl_scop_p scop) {
442 int nb_parameters = OSL_UNDEFINED;
443 int nb_iterators = OSL_UNDEFINED;
444 int nb_scattdims = OSL_UNDEFINED;
445 int nb_localdims = OSL_UNDEFINED;
446 int array_id = OSL_UNDEFINED;
448 osl_scop_get_attributes(scop, &nb_parameters, &nb_iterators,
449 &nb_scattdims, &nb_localdims, &array_id);
451 return osl_names_generate("P", nb_parameters,
452 "i", nb_iterators,
453 "c", nb_scattdims,
454 "l", nb_localdims,
455 "A", array_id);
459 * osl_arrays_sprint function:
460 * this function prints the content of an osl_arrays_t structure
461 * (*arrays) into a string (returned) in the OpenScop textual format.
463 * \param[in] arrays The arrays structure to print.
464 * \return A string containing the OpenScop dump of the arrays structure.
466 char * convert_osl_arrays_sprint(osl_strings_p arrays) {
467 int i;
468 int high_water_mark = OSL_MAX_STRING;
469 char * string = NULL;
470 char buffer[OSL_MAX_STRING];
472 int nb_names = osl_strings_size(arrays);
474 if (arrays != NULL) {
475 OSL_malloc(string, char *, high_water_mark * sizeof(char));
476 string[0] = '\0';
478 sprintf(buffer, "# Number of arrays\n");
479 osl_util_safe_strcat(&string, buffer, &high_water_mark);
481 sprintf(buffer, "%d\n", nb_names);
482 osl_util_safe_strcat(&string, buffer, &high_water_mark);
484 if (nb_names) {
485 sprintf(buffer, "# Mapping array-identifiers/array-names\n");
486 osl_util_safe_strcat(&string, buffer, &high_water_mark);
488 for (i = 0; i < nb_names; i++) {
489 sprintf(buffer, "%d %s\n", i+1, arrays->string[i]);
490 osl_util_safe_strcat(&string, buffer, &high_water_mark);
493 OSL_realloc(string, char *, (strlen(string) + 1) * sizeof(char));
496 return string;
501 void convert_scoplib_strings_print(char** s1){
503 int i= 0;
504 int nb_strings = 0;
505 char **s1_cpy = s1;
507 while( *s1_cpy++ )
508 nb_strings++;
510 printf("scoplib strings size=%d\n", nb_strings);
511 printf("scoplib strings with indexes:\n");
512 for(i=0; i< nb_strings; i++){
513 //strcmp returns non-zero if strings not equal
514 printf("%d %s\n", i, s1[i]);
521 * this functions checks of two arrays of strings are equal
523 * \param[in] s1 array of strings
524 * \param[in] s2 array of strings
525 * \return 1 if equal, 0 therwise
527 int convert_scoplib_strings_equal(char** s1, char** s2){
529 if(s1==s2)
530 return 1;
532 int i= 0;
533 int nb_strings_1 = 0;
534 int nb_strings_2 = 0;
535 char **s1_cpy = s1;
536 char **s2_cpy = s2;
538 while( *s1_cpy++) nb_strings_1++;
539 while( *s2_cpy++) nb_strings_2++;
541 if( nb_strings_1 != nb_strings_2){
542 CONVERTER_info("scoplib sizes of strings not equal\n");
543 printf("s1_size=%d, s2_size=%d\n", nb_strings_1, nb_strings_1);
544 return 0;
547 for(i=0; i< nb_strings_1; i++){
548 //strcmp returns non-zero if strings not equal
549 if(strcmp(s1[i], s2[i]) ){
550 CONVERTER_info("scoplib two strings not equal\n");
551 printf("s1: %s, s2: %s\n", s1[i], s2[i]);
552 return 0;
556 return 1;
561 * scoplib_matrix_equal function:
562 * this function returns true if the two matrices are the same, false
563 * otherwise.
565 * \param m1 The first matrix.
566 * \param m2 The second matrix.
570 convert_scoplib_matrix_equal(scoplib_matrix_p m1, scoplib_matrix_p m2)
572 if (m1 == m2)
573 return 1;
574 if (m1 == NULL || m2 == NULL)
575 return 0;
576 if (m1->NbRows != m2->NbRows || m1->NbColumns != m2->NbColumns)
577 return 0;
578 int i, j;
579 for (i = 0; i < m1->NbRows; ++i)
580 for (j = 0; j < m1->NbColumns; ++j)
581 if (SCOPVAL_ne(m1->p[i][j], m2->p[i][j]))
582 return 0;
583 return 1;
588 * scoplib_matrix_list_equal function:
589 * this function returns true if the two matric lists are the same, false
590 * otherwise.
592 * \param[in] ml1 scoplib matrix list
593 * \param[in] ml2 scoplib matrix list
594 * \return 1 if equal, 0 otherwise
596 int convert_scoplib_matrix_list_equal( scoplib_matrix_list_p ml1,
597 scoplib_matrix_list_p ml2){
599 if(ml1==ml2)
600 return 1;
602 if (((ml1->next != NULL) && (ml2->next == NULL)) ||
603 ((ml1->next == NULL) && (ml2->next != NULL))) {
604 CONVERTER_info("scoplib sizes of matrid_lists are not the same\n");
605 return 0;
608 if ((ml1->next != NULL) && (ml2->next != NULL)) {
609 if (!convert_scoplib_matrix_list_equal(ml1->next, ml2->next)) {
610 CONVERTER_info("scoplib matrid_lists are not the same\n");
611 return 0;
615 if( !convert_scoplib_matrix_equal(ml1->elt, ml2->elt) ){
616 CONVERTER_info("scoplib matrixes not equal\n");
617 return 0;
620 return 1;
624 * scoplib_statement_equal function:
625 * this function returns true if the two scoplib statements are the same, false
626 * otherwise.
628 * \param[in] s1 scoplib statment
629 * \param[in] s2 scoplib statment
630 * \return 1 if equal, 0 otherwise
632 int convert_scoplib_statement_equal(scoplib_statement_p s1,
633 scoplib_statement_p s2){
635 if(s1==s2)
636 return 1;
638 if (((s1->next != NULL) && (s2->next == NULL)) ||
639 ((s1->next == NULL) && (s2->next != NULL))) {
640 CONVERTER_info("scoplib number of statements are not the same\n");
641 return 0;
644 if ((s1->next != NULL) && (s2->next != NULL)) {
645 if (!convert_scoplib_statement_equal(s1->next, s2->next)) {
646 CONVERTER_info("scoplib statements is not the same\n");
647 return 0;
651 if( !convert_scoplib_matrix_list_equal(s1->domain, s2->domain) ){
652 CONVERTER_info("scoplib statements domains not equal\n");
653 return 0;
655 //else
656 // printf("scoplib statement domains are the same\n");
658 if( !convert_scoplib_matrix_equal(s1->schedule, s2->schedule) ){
659 CONVERTER_info("scoplib statements scatterings not equal\n");
660 return 0;
662 //else
663 // printf("scoplib statement scatterings are the same\n");
665 if( !convert_scoplib_matrix_equal(s1->read, s2->read) ){
666 CONVERTER_info("scoplib statements read matrixes not equal\n");
667 return 0;
669 //else
670 // printf("scoplib statement read_matrixes are the same\n");
672 if( !convert_scoplib_matrix_equal(s1->write, s2->write) ){
673 CONVERTER_info("scoplib statements write matrixes not equal\n");
674 return 0;
676 //else
677 // printf("scoplib statement write_matrixes are the same\n");
679 if( s1->nb_iterators != s2->nb_iterators ){
680 CONVERTER_info("scoplib statements nb_iterators not equal\n");
681 return 0;
683 //else
684 // printf("scoplib statement nb_tertaros are the same\n");
686 if( !convert_scoplib_strings_equal(s1->iterators, s2->iterators) ){
687 CONVERTER_info("scoplib statements iterators not equal\n");
688 convert_scoplib_strings_print(s1->iterators);
689 convert_scoplib_strings_print(s2->iterators);
690 return 0;
692 //else
693 // printf("scoplib statement iterators are the same\n");
695 //strcmp returns non-zero if strings not equal
696 if( strcmp(s1->body, s2->body) ){
697 CONVERTER_info("scoplib statements bodies not equal\n");
698 return 0;
700 //else
701 // printf("scoplib statement bodies are the same\n");
703 return 1;
708 * scoplib_scop_equal function:
709 * this function returns true if the scoplib scops are the same, false
710 * otherwise.
712 * \param[in] s1 scoplib scop
713 * \param[in] s2 scoplib scop
714 * \return 1 if equal, 0 otherwise
716 int convert_scoplib_scop_equal( scoplib_scop_p s1, scoplib_scop_p s2){
718 if(s1!=NULL && s2!=NULL && s1==s2) // same scop
719 return 1;
721 if (((s1 == NULL) && (s2 != NULL)) || ((s1 != NULL) && (s2 == NULL))){
722 CONVERTER_info("unequal scops! one is NULL!\n");
723 return 0;
726 if( !scoplib_matrix_equal(s1->context, s2->context) ){
727 CONVERTER_info("contexts not same! \n");
728 return 0;
730 //else
731 // printf("scoplib scop contexts are the same\n");
733 if(s1->nb_parameters != s2->nb_parameters ){
734 CONVERTER_info("nb_paramters not equal! \n");
735 return 0;
737 //else
738 // printf("scoplib scop nb_parameters are the same\n");
740 if(!convert_scoplib_strings_equal(s1->parameters, s2->parameters)){
741 CONVERTER_info("paramters not equal! \n");
742 return 0;
744 //else
745 // printf("scoplib scop parameters are the same\n");
747 if(s1->nb_arrays != s2->nb_arrays ){
748 CONVERTER_info("nb_arrasy not equal! \n");
749 return 0;
751 //else
752 // printf("scoplib scop nb_arrays are the same\n");
754 if(!convert_scoplib_strings_equal(s1->arrays, s2->arrays)){
755 CONVERTER_info("arrays not equal! \n");
756 return 0;
758 //else
759 // printf("scoplib scop arrays are the same\n");
761 if(!convert_scoplib_statement_equal(s1->statement, s2->statement)){
762 CONVERTER_info("statements not equal! \n");
763 return 0;
765 //else
766 // printf("scoplib scop statements are the same\n");
768 //strcmp returns non-zero if strings not equal
769 if(strcmp(s1->optiontags, s2->optiontags)){
770 CONVERTER_info("optiontags not equal! \n");
771 return 0;
773 //else
774 // printf("scoplib scop optiontags are the same\n");
776 // usr defined hj
778 return 1;
783 /***************************************************************************
784 * Translates osl_scop to scoplib_scop
785 * Return: NULL if unsuccessful
786 * : pointer to scoplib_scop if successful
788 * \param[in] inscop osl scop to be converted
789 * \return equivalent scoplib scop
790 ****************************************************************************/
791 scoplib_scop_p convert_scop_osl2scoplib( osl_scop_p inscop){
793 // int i=0;
794 // int j=0;
795 scoplib_scop_p out_scop = NULL; //return arg
796 // scoplib_scop_p last_scop = NULL;
797 scoplib_scop_p tmp_scop = NULL;
799 //NULL input pointer
800 if (inscop == NULL)
801 return out_scop;
803 if (osl_scop_integrity_check(inscop) == 0)
804 CONVERTER_warning("OSL integrity check failed. Something may go wrong.");
805 //TODO: return here?
808 tmp_scop = scoplib_scop_malloc();
810 int precision = osl_util_get_precision();
811 //version
812 //language //not used??
813 //context
814 tmp_scop->context = convert_relation_osl2scoplib(inscop->context);
817 //parameters
818 tmp_scop->nb_parameters = inscop->context->nb_columns - 2;
819 if(tmp_scop->nb_parameters){
820 osl_strings_p params = osl_strings_clone(inscop->parameters->data);
821 tmp_scop->parameters = convert_strings_osl2scoplib(params);
822 osl_strings_free(params);
827 tmp_scop->statement = convert_statement_osl2scoplib(inscop->statement,
828 precision);
829 //registry
830 //externsion
831 osl_names_p names = NULL;
832 names = convert_osl_scop_names(inscop);
833 //externsion -> arrays
834 osl_arrays_p arrays = osl_generic_lookup(inscop->extension,
835 OSL_URI_ARRAYS);
836 if(arrays){
837 tmp_scop->nb_arrays = arrays->nb_names; //??
838 osl_strings_p arr = osl_arrays_to_strings(arrays);
839 tmp_scop->arrays = convert_strings_osl2scoplib(arr);
840 osl_strings_free(arr);
842 else{ //assign generated names
843 tmp_scop->nb_arrays = osl_strings_size(names->arrays);
844 tmp_scop->arrays = convert_strings_osl2scoplib(names->arrays);
847 //optoin tags
848 // arrays
849 char *string = NULL;
850 if(arrays){
851 string = osl_arrays_sprint((osl_arrays_p) arrays);
853 else{
854 string = convert_osl_arrays_sprint(names->arrays);
858 if(names)
859 osl_names_free(names);
862 char *new_str = NULL;
863 if (string != NULL) {
864 OSL_malloc(new_str, char *, (strlen(string) + 20) * sizeof(char));
865 sprintf(new_str, "<arrays>\n%s</arrays>\n", string);
866 free(string);
868 tmp_scop->optiontags = new_str;
871 // dependenceies
872 convert_dep_osl2scoplib(inscop, tmp_scop);
876 //usr not used???
877 tmp_scop->usr = NULL;
881 if(inscop->next)
882 CONVERTER_warning("Multiple SCoPs detected. Converting first only!!!\n");
885 out_scop = tmp_scop;
888 return out_scop;