diff --git a/Codes_en_COREC/tests/test3_max.corec b/Codes_en_COREC/tests/test3_max.corec new file mode 100644 index 0000000000000000000000000000000000000000..924f715129e91c92a5a7637f8777b93f57ff2f99 --- /dev/null +++ b/Codes_en_COREC/tests/test3_max.corec @@ -0,0 +1,64 @@ +// Print big 1D arrays + +prog Test3 { + def Main{ + Loc : (array1,50) + Rec : { + array1[0] = 5.32; + array1[1] = 12; + array1[2] = 7.89; + array1[3] = 3.14; + array1[4] = 42; + array1[5] = 18.27; + array1[6] = 1.11; + array1[7] = 6; + array1[8] = 21.95; + array1[9] = 14.01; + array1[10] = 9; + array1[11] = 2.71; + array1[12] = 8.56; + array1[13] = 17; + array1[14] = 4.44; + array1[15] = 10.11; + array1[16] = 3.33; + array1[17] = 22; + array1[18] = 19.5; + array1[19] = 7.77; + array1[20] = 13.37; + array1[21] = 5; + array1[22] = 25.25; + array1[23] = 8; + array1[24] = 20.2; + array1[25] = 11.11; + array1[26] = 15; + array1[27] = 30.3; + array1[28] = 16.66; + array1[29] = 4; + array1[30] = 18; + array1[31] = 7.07; + array1[32] = 12.34; + array1[33] = 9.87; + array1[34] = 14; + array1[35] = 6.66; + array1[36] = 5.55; + array1[37] = 19; + array1[38] = 2.22; + array1[39] = 20; + array1[40] = 3; + array1[41] = 18.88; + array1[42] = 4.04; + array1[43] = 22.22; + array1[44] = 8.8; + array1[45] = 16; + array1[46] = 11.23; + array1[47] = 7.5; + array1[48] = 6.25; + array1[49] = 9.9; + + printstr("Expected result : \n5.32 12.00 7.89 3.14 42.00 18.27 1.11 6.00 21.95 14.01 9.00 2.71 8.56 17.00 4.44 10.11 3.33 22.00 19.50 7.77 \n13.37 5.00 25.25 8.00 20.20 11.11 15.00 30.30 16.66 4.00 18.00 7.07 12.34 9.87 14.00 6.66 5.55 19.00 2.22 20.00 \n3.00 18.88 4.04 22.22 8.80 16.00 11.23 7.50 6.25 9.90"); + + printstr("\nObtained Result : \n"); + print(array1) // contain all the values exchanges here if the code is correct + } + } +} diff --git a/corec.l b/corec.l index ff6f3aa3fb40e335c1593fb3089909b6dbe29359..e6706992c532d8c3f8c74b7f956f38de5e1475ce 100644 --- a/corec.l +++ b/corec.l @@ -81,8 +81,8 @@ in {return in_dom;} ["]([^"]|[\\]["])*["] { if ( yyleng > 1023 ) fprintf(stderr,"Error at line %u: Identifier '%s' too long (> 1023), truncated\n",lineNumber,yytext); - strncpy(yylval.strval,yytext,1023); - yylval.strval[1024] = '\0'; + strncpy(yylval.chain,yytext,1023); + yylval.chain[1023] = '\0'; return chaine; } diff --git a/corec.y b/corec.y index 839648557e64cd6693f4b6d0e7a413049d03b028..3212409829d15e8fae7d43f1fe4c10e716706c7c 100644 --- a/corec.y +++ b/corec.y @@ -42,6 +42,7 @@ void exit_safely(){ float floatval; name_t strval; wardLabels label; + name_64_t chain; struct { struct symbol* ptr; @@ -83,7 +84,7 @@ void exit_safely(){ %token <strval> ID1 %token <strval> ID2 -%token <strval> chaine +%token <chain> chaine %token <intval> entier %token <floatval> flottant diff --git a/lib.c b/lib.c index bace0fd0c3445deb22038f18caf32e2b30794e02..cad7ea927e54800137dc26f0ad724c6e2ea23fec 100644 --- a/lib.c +++ b/lib.c @@ -971,6 +971,8 @@ void print_print(struct symtable * t,struct code * c, FILE* fout,int i) // putting array address in $t1 load_symbol_macro("$t1","NULL",c->quads[i].sym1,t,fout); fprintf(fout,"%sli $t2, 0\n",tabulation); + // initilize t4 to be used as the counter of elements printed on one line (at 20 we print a newline) + fprintf(fout,"%sli $t4, 0\n",tabulation); // we avoid having 2 identical labels by putting the quad index at the end of it @@ -991,10 +993,26 @@ void print_print(struct symtable * t,struct code * c, FILE* fout,int i) // increment to next address fprintf(fout,"%saddi $t2, $t2, 4\n",tabulation); + // increment the counter of elements printed on this line + fprintf(fout,"%saddi $t4, $t4, 1\n",tabulation); + fprintf(fout,"%sli $t5, 20\n",tabulation); + fprintf(fout,"%sbeq $t4, $t5, print_array_loop_aux%d\n",tabulation,i); + // jump to the start of the loop fprintf(fout,"%sj print_array_loop%d\n",tabulation,i); // /!\ end of the loop /!\ -- remove_indent(); + + // auxiliary function that enables us to have a new line every 20 floats printed + fprintf(fout,"%sprint_array_loop_aux%d:\n",tabulation,i); + add_indent(c,t,fout); + fprintf(fout,"%sLF\n",tabulation); + // we reset the counter of elements printed on one line + fprintf(fout,"%sli $t4, 0\n",tabulation); + // jump back to the print loop + fprintf(fout,"%sj print_array_loop%d\n",tabulation,i); + remove_indent(); + fprintf(fout,"%send_array_loop%d:\n",tabulation,i); fprintf(fout,"%sLF\n",tabulation); break;