modified autogen.sh to remove reference to osl/
[converter.git] / source / converter.c
blobddade858a5c27226400d45c0c86051ae6917b3c4
2 #include <stdio.h>
3 #include <stdlib.h>
5 #include "converter/converter.h"
8 void display_usage(){
9 printf("Usage\n");
10 printf("./converter 0 scoplib_scop_filename\n");
11 printf("./converter 1 osl_scop_filename\n");
14 int main( int argc, char* argv[]){
16 if(argc<3 || argc>3 ||
17 (strtol(argv[0],NULL,10)!=0 && strtol(argv[0],NULL,10)!=1) ){
18 display_usage();
19 return 1;
22 char o_filename[100];
23 //read osl scop from file
24 FILE * infile = fopen( argv[2], "r");
25 if(!infile){
26 fprintf(stderr, "Error: Unable to open infile:%s\n", argv[2]);
27 return 1;
31 scoplib_scop_p scop0 = NULL;
32 osl_scop_p scop1 = NULL;
34 if(strtol(argv[1],NULL, 10)==0){
35 printf("reading scoplib_scop\n");
36 scop0 = scoplib_scop_read( infile );
37 //scoplib_scop_print_structure(stdout, scop0, 0);
38 //scoplib_scop_print_dot_scop(stdout, scop0);
39 printf("read scoplib_scop\n");
40 scop1 = convert_scop_scoplib2osl(scop0);
41 printf("converted scoplib_scop to osl_scop\n");
42 // print osl scop to file
43 sprintf(o_filename, "%s.osl", argv[2]);
44 FILE *outfile0 = fopen(o_filename, "w+");
45 osl_scop_print(outfile0, scop1);
46 fclose(outfile0);
47 printf("OSL scop printed to file\n");
49 else{
50 printf("reading osl_scop\n");
51 scop1 = osl_scop_read ( infile );
52 printf("read osl_scop\n");
55 fclose(infile);
57 //printf("oritinal scop:\n");
58 //osl_relation_print(stdout, scop1->context);
60 //convert osl to scoplib
61 scoplib_scop_p scop2 = convert_scop_osl2scoplib(scop1);
62 if(scop2==NULL)
63 printf("OSL to Scoplib conversion failed\n");
64 //scoplib_scop_print_structure(stdout, scop2, 0);
65 //print scoplib scop to file
66 sprintf(o_filename, "%s.scoplib", argv[2]);
67 FILE *outfile = fopen(o_filename, "w+");
68 scoplib_scop_print_dot_scop(outfile, scop2);
69 //printf("scoptagoptions:\n%s\n", scop2->optiontags);
70 fclose(outfile);
71 printf("Scoplib scop printed to file\n");
72 //manually generate code and compare to original
73 //read scoplib scop from file
75 FILE *infile2 = fopen(o_filename, "r");
76 scoplib_scop_p scop3 = NULL;
77 scop3 = scoplib_scop_read( infile2);
78 fclose(infile2);
80 //scoplib_scop_print_structure(stdout, scop3, 0);
81 //printf("Scoplib scop read from file\n");
86 // convert scoplib to osl
87 osl_scop_p scop4 = convert_scop_scoplib2osl( scop2 );
89 //exit(0);
90 printf("Scoplib scop converted to OSL scop\n");
93 // print osl scop to file
94 sprintf(o_filename, "%s.scoplib.osl", argv[2]);
95 FILE *outfile2 = fopen(o_filename, "w+");
96 osl_scop_print(outfile2, scop4);
97 fclose(outfile2);
98 printf("OSL scop printed to file\n");
99 //manually generate code and compare to original
105 if(strtol(argv[1],NULL, 10)==1){
107 printf("scop1 language = %s\n", scop1->language);
108 CONVERTER_strdup(scop4->language, scop1->language);
110 if( convert_osl_scop_equal(scop1, scop4) )
111 printf("OSL -> Scoplib -> OSL works :D\n");
112 else
113 printf("OSL -> Scoplib -> OSL failed :(\n");
116 else{
118 if( convert_scoplib_scop_equal(scop0, scop2) )
119 printf("Scoplib -> OSL -> Scoplib works :D\n");
120 else
121 printf("Scoplib -> OSL -> Scoplib failed :(\n");
127 if(scop0) scoplib_scop_free( scop0 );
128 if(scop1){
129 osl_statement_p stmt = scop1->statement;
130 while(stmt){
131 candl_statement_usr_cleanup(stmt);
132 stmt = stmt->next;
134 osl_scop_free( scop1 );
136 if(scop4){
137 osl_statement_p stmt = scop4->statement;
138 while(stmt){
139 candl_statement_usr_cleanup(stmt);
140 stmt = stmt->next;
142 osl_scop_free( scop4 );
144 if(scop2) scoplib_scop_free (scop2 );
145 if(scop3) scoplib_scop_free (scop3 );
147 return 0;