Commit 60fdcb6c authored by Frédéric Krüger's avatar Frédéric Krüger
Browse files

Ajout d'une fonction custom pour le strndup pour MAC

parent ca98311c
......@@ -22,6 +22,92 @@ Centre de Math�matiques Appliqu�es
#else
#include <unistd.h>
#endif
#ifdef __APPLE__
/* Mac OS X don't have strndup even if _GNU_SOURCE is defined */
char *strndup (const char *s, size_t n){
size_t len = strlen (s);
char *ret;
if (len <= n)
return strdup (s);
ret = (char *)malloc(n + 1);
strncpy(ret, s, n);
ret[n] = '\0';
return ret;
}
ssize_t getline (char **lineptr, size_t *n, FILE *fp){
ssize_t result;
size_t cur_len = 0;
if (lineptr == NULL || n == NULL || fp == NULL){
errno = EINVAL;
return -1;
}
if (*lineptr == NULL || *n == 0){
*n = 120;
*lineptr = (char *) malloc (*n);
if (*lineptr == NULL){
result = -1;
goto end;
}
}
for (;;){
int i;
i = getc (fp);
if (i == EOF){
result = -1;
break;
}
/* Make enough space for len+1 (for final NUL) bytes. */
if (cur_len + 1 >= *n){
size_t needed_max = SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
size_t needed = 2 * *n + 1; /* Be generous. */
char *new_lineptr;
if (needed_max < needed)
needed = needed_max;
if (cur_len + 1 >= needed){
result = -1;
goto end;
}
new_lineptr = (char *) realloc (*lineptr, needed);
if (new_lineptr == NULL){
result = -1;
goto end;
}
*lineptr = new_lineptr;
*n = needed;
}
(*lineptr)[cur_len] = i;
cur_len++;
if (i == '\n')
break;
}
(*lineptr)[cur_len] = '\0';
result = cur_len ? (ssize_t) cur_len : result;
end:
return result;
}
#endif
/* getline implementation is copied from glibc. */
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
#ifndef SSIZE_MAX
# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
#endif
#include "debug.h"
#include <iostream>
#include <sstream>
......@@ -65,24 +151,24 @@ Centre de Math�matiques Appliqu�es
return ret;
}
#line 69 "EaseaLex.cpp"
#line 155 "EaseaLex.cpp"
// repeated because of possible precompiled header
#include <clex.h>
#include "EaseaLex.h"
#line 73 "EaseaLex.l"
#line 159 "EaseaLex.l"
#line 81 "EaseaLex.l"
#line 167 "EaseaLex.l"
// lexical analyser name and class definition
#line 79 "EaseaLex.cpp"
#line 165 "EaseaLex.cpp"
/////////////////////////////////////////////////////////////////////////////
// constructor
YYLEXNAME::YYLEXNAME()
{
yytables();
#line 110 "EaseaLex.l"
#line 196 "EaseaLex.l"
bFunction=bWithinEvaluator=bWithinOptimiser=bDisplayFunction=bInitFunction=bNotFinishedYet=0;
bSymbolInserted=bDoubleQuotes=bWithinDisplayFunction=bWithinInitialiser=bWithinMutator=bWithinXover=0;
......@@ -95,7 +181,7 @@ YYLEXNAME::YYLEXNAME()
iNoOp = 0;
bCOPY_GP_EVAL_GPU,bIsCopyingGPEval = false;
#line 99 "EaseaLex.cpp"
#line 185 "EaseaLex.cpp"
}
#ifndef YYTEXT_SIZE
......@@ -141,99 +227,99 @@ void YYLEXNAME::yyunput(int ch)
int YYLEXNAME::yyaction(int action)
{
#line 130 "EaseaLex.l"
#line 216 "EaseaLex.l"
// extract yylval for use later on in actions
YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
#line 150 "EaseaLex.cpp"
#line 236 "EaseaLex.cpp"
yyreturnflg = 1;
switch (action) {
case 1:
{
#line 136 "EaseaLex.l"
#line 222 "EaseaLex.l"
#line 157 "EaseaLex.cpp"
#line 243 "EaseaLex.cpp"
}
break;
case 2:
{
#line 139 "EaseaLex.l"
#line 225 "EaseaLex.l"
BEGIN TEMPLATE_ANALYSIS; yyless(yyleng-1);
#line 166 "EaseaLex.cpp"
#line 252 "EaseaLex.cpp"
}
break;
case 3:
{
#line 147 "EaseaLex.l"
#line 233 "EaseaLex.l"
char sFileName[1000];
strcpy(sFileName, sRAW_PROJECT_NAME);
strcat(sFileName,".cpp");
fpOutputFile=fopen(sFileName,"w");
#line 178 "EaseaLex.cpp"
#line 264 "EaseaLex.cpp"
}
break;
case 4:
{
#line 153 "EaseaLex.l"
#line 239 "EaseaLex.l"
fprintf(fpOutputFile,"EASEA");
#line 185 "EaseaLex.cpp"
#line 271 "EaseaLex.cpp"
}
break;
case 5:
{
#line 154 "EaseaLex.l"
#line 240 "EaseaLex.l"
fprintf(fpOutputFile,"%s",sPROJECT_NAME);
#line 192 "EaseaLex.cpp"
#line 278 "EaseaLex.cpp"
}
break;
case 6:
{
#line 155 "EaseaLex.l"
#line 241 "EaseaLex.l"
fprintf(fpOutputFile,"%s",sEZ_PATH);
#line 199 "EaseaLex.cpp"
#line 285 "EaseaLex.cpp"
}
break;
case 7:
{
#line 156 "EaseaLex.l"
#line 242 "EaseaLex.l"
fprintf(fpOutputFile,"%s",sTPL_DIR);
#line 206 "EaseaLex.cpp"
#line 292 "EaseaLex.cpp"
}
break;
case 8:
{
#line 157 "EaseaLex.l"
#line 243 "EaseaLex.l"
fprintf(fpOutputFile,"%s",sEO_DIR);
#line 213 "EaseaLex.cpp"
#line 299 "EaseaLex.cpp"
}
break;
case 9:
{
#line 158 "EaseaLex.l"
#line 244 "EaseaLex.l"
fprintf(fpOutputFile,"%s",sLOWER_CASE_PROJECT_NAME);
#line 220 "EaseaLex.cpp"
#line 306 "EaseaLex.cpp"
}
break;
case 10:
{
#line 159 "EaseaLex.l"
#line 245 "EaseaLex.l"
switch (OPERATING_SYSTEM) {
case UNIX : fprintf(fpOutputFile,"UNIX_OS"); break;
case WINDOWS : fprintf(fpOutputFile,"WINDOWS_OS"); break;
case UNKNOWN_OS : fprintf(fpOutputFile,"UNKNOWN_OS"); break;
}
#line 232 "EaseaLex.cpp"
#line 318 "EaseaLex.cpp"
}
break;
case 11:
{
#line 165 "EaseaLex.l"
#line 251 "EaseaLex.l"
if (bVERBOSE) printf ("Inserting user declarations.\n");
yyreset();
......@@ -241,12 +327,12 @@ switch (OPERATING_SYSTEM) {
lineCounter=1;
BEGIN COPY_USER_DECLARATIONS;
#line 245 "EaseaLex.cpp"
#line 331 "EaseaLex.cpp"
}
break;
case 12:
{
#line 173 "EaseaLex.l"
#line 259 "EaseaLex.l"
if (bVERBOSE) printf ("Inserting user cuda.\n");
yyreset();
......@@ -254,12 +340,12 @@ switch (OPERATING_SYSTEM) {
lineCounter=1;
BEGIN COPY_USER_CUDA;
#line 258 "EaseaLex.cpp"
#line 344 "EaseaLex.cpp"
}
break;
case 13:
{
#line 181 "EaseaLex.l"
#line 267 "EaseaLex.l"
if (bVERBOSE) printf ("Inserting initialisation function.\n");
yyreset();
......@@ -267,12 +353,12 @@ switch (OPERATING_SYSTEM) {
lineCounter = 1;
BEGIN COPY_INITIALISATION_FUNCTION;
#line 271 "EaseaLex.cpp"
#line 357 "EaseaLex.cpp"
}
break;
case 14:
{
#line 189 "EaseaLex.l"
#line 275 "EaseaLex.l"
if (bVERBOSE) printf ("Inserting generation before reduce function.\n");
yyreset();
......@@ -280,12 +366,12 @@ switch (OPERATING_SYSTEM) {
bGenerationFunctionBeforeReplacement = true;
BEGIN COPY_GENERATION_FUNCTION_BEFORE_REPLACEMENT;
#line 284 "EaseaLex.cpp"
#line 370 "EaseaLex.cpp"
}
break;
case 15:
{
#line 198 "EaseaLex.l"
#line 284 "EaseaLex.l"
//DEBUG_PRT_PRT("insert beg");
if (bVERBOSE) printf ("Inserting at the begining of each generation function.\n");
......@@ -299,12 +385,12 @@ switch (OPERATING_SYSTEM) {
lineCounter = 1;
BEGIN COPY_BEG_GENERATION_FUNCTION;
#line 303 "EaseaLex.cpp"
#line 389 "EaseaLex.cpp"
}
break;
case 16:
{
#line 217 "EaseaLex.l"
#line 303 "EaseaLex.l"
if( bVERBOSE )printf("inserting gp parameters\n");
// fprintf(fpOutputFile,"#define MAX_XOVER_DEPTH",%d
......@@ -317,12 +403,12 @@ switch (OPERATING_SYSTEM) {
fprintf(fpOutputFile,"#define NO_FITNESS_CASES %d\n",iNO_FITNESS_CASES);
#line 321 "EaseaLex.cpp"
#line 407 "EaseaLex.cpp"
}
break;
case 17:
{
#line 235 "EaseaLex.l"
#line 321 "EaseaLex.l"
fprintf(fpOutputFile,"enum OPCODE {");
......@@ -354,12 +440,12 @@ switch (OPERATING_SYSTEM) {
if( bVERBOSE ) printf("var length is %d\n",var_len);
fprintf(fpOutputFile,"#define VAR_LEN %d\n",var_len);
#line 358 "EaseaLex.cpp"
#line 444 "EaseaLex.cpp"
}
break;
case 18:
{
#line 267 "EaseaLex.l"
#line 353 "EaseaLex.l"
for( unsigned i=0 ; i<iNoOp ; i++ ){
fprintf(fpOutputFile," case %s :\n",opDesc[i]->opcode->c_str());
......@@ -368,12 +454,12 @@ switch (OPERATING_SYSTEM) {
}
#line 372 "EaseaLex.cpp"
#line 458 "EaseaLex.cpp"
}
break;
case 19:
{
#line 276 "EaseaLex.l"
#line 362 "EaseaLex.l"
for( unsigned i=0 ; i<iNoOp ; i++ ){
fprintf(fpOutputFile," case %s :\n",opDesc[i]->opcode->c_str());
......@@ -381,12 +467,12 @@ switch (OPERATING_SYSTEM) {
fprintf(fpOutputFile," break;\n");
}
#line 385 "EaseaLex.cpp"
#line 471 "EaseaLex.cpp"
}
break;
case 20:
{
#line 285 "EaseaLex.l"
#line 371 "EaseaLex.l"
yyreset();
rewind(fpGenomeFile);
......@@ -394,23 +480,23 @@ switch (OPERATING_SYSTEM) {
if (bVERBOSE) printf ("Analysing GP OP code from ez file\n");
BEGIN COPY_GP_OPCODE;
#line 398 "EaseaLex.cpp"
#line 484 "EaseaLex.cpp"
}
break;
case 21:
{
#line 294 "EaseaLex.l"
#line 380 "EaseaLex.l"
if (bVERBOSE) printf ("found begin section\n");
bGPOPCODE_ANALYSIS = true;
BEGIN GP_RULE_ANALYSIS;
#line 409 "EaseaLex.cpp"
#line 495 "EaseaLex.cpp"
}
break;
case 22:
{
#line 300 "EaseaLex.l"
#line 386 "EaseaLex.l"
if (bVERBOSE) printf ("found end section\n");
if( bGPOPCODE_ANALYSIS ){
......@@ -425,38 +511,38 @@ switch (OPERATING_SYSTEM) {
BEGIN TEMPLATE_ANALYSIS;
}
#line 429 "EaseaLex.cpp"
#line 515 "EaseaLex.cpp"
}
break;
case 23:
{
#line 315 "EaseaLex.l"
#line 401 "EaseaLex.l"
if (bVERBOSE) printf("*** No GP OP codes were found. ***\n");
rewind(fpGenomeFile);
yyin = fpTemplateFile;
BEGIN TEMPLATE_ANALYSIS;
#line 441 "EaseaLex.cpp"
#line 527 "EaseaLex.cpp"
}
break;
case 24:
{
#line 321 "EaseaLex.l"
#line 407 "EaseaLex.l"
#line 448 "EaseaLex.cpp"
#line 534 "EaseaLex.cpp"
}
break;
case 25:
{
#line 322 "EaseaLex.l"
#line 408 "EaseaLex.l"
if( bGPOPCODE_ANALYSIS )printf("\n");lineCounter++;
#line 455 "EaseaLex.cpp"
#line 541 "EaseaLex.cpp"
}
break;
case 26:
{
#line 329 "EaseaLex.l"
#line 415 "EaseaLex.l"
// this rule match the OP_NAME
if( iGP_OPCODE_FIELD != 0 ){
......@@ -466,19 +552,19 @@ if( bGPOPCODE_ANALYSIS )printf("\n");lineCounter++;
opDesc[iNoOp] = new OPCodeDesc();
opDesc[iNoOp]->opcode = new string(yytext);
#line 470 "EaseaLex.cpp"
#line 556 "EaseaLex.cpp"
}
break;
case 27:
{
#line 339 "EaseaLex.l"
#line 425 "EaseaLex.l"
#line 477 "EaseaLex.cpp"
#line 563 "EaseaLex.cpp"
}
break;
case 28:
{
#line 341 "EaseaLex.l"
#line 427 "EaseaLex.l"
if( iGP_OPCODE_FIELD != 1 ){
fprintf(stderr,"Error, op code real name must be given at the second place\n");
......@@ -486,12 +572,12 @@ if( bGPOPCODE_ANALYSIS )printf("\n");lineCounter++;
}
opDesc[iNoOp]->realName = new string(yytext);
#line 490 "EaseaLex.cpp"
#line 576 "EaseaLex.cpp"
}
break;
case 29:
{
#line 350 "EaseaLex.l"
#line 436 "EaseaLex.l"
if( iGP_OPCODE_FIELD != 2 ){
fprintf(stderr,"Error, arity must be given at the third place\n");
......@@ -505,38 +591,38 @@ if( bGPOPCODE_ANALYSIS )printf("\n");lineCounter++;
opDesc[iNoOp]->arity = 0;
}
#line 509 "EaseaLex.cpp"
#line 595 "EaseaLex.cpp"
}
break;
case 30:
{
#line 364 "EaseaLex.l"
#line 450 "EaseaLex.l"
#line 516 "EaseaLex.cpp"
#line 602 "EaseaLex.cpp"
}
break;
case 31:
{
#line 365 "EaseaLex.l"
#line 451 "EaseaLex.l"
iGP_OPCODE_FIELD = 0;
iNoOp++;
#line 526 "EaseaLex.cpp"
#line 612 "EaseaLex.cpp"
}
break;
case 32:
{
#line 370 "EaseaLex.l"
#line 456 "EaseaLex.l"
if( bGPOPCODE_ANALYSIS ) iGP_OPCODE_FIELD++;
#line 535 "EaseaLex.cpp"
#line 621 "EaseaLex.cpp"
}
break;
case 33:
{
#line 375 "EaseaLex.l"
#line 461 "EaseaLex.l"
if( iGP_OPCODE_FIELD != 3 ){
fprintf(stderr,"Error, code must be given at the forth place\n");
......@@ -553,23 +639,23 @@ if( bGPOPCODE_ANALYSIS )printf("\n");lineCounter++;
BEGIN GP_COPY_OPCODE_CODE;
#line 557 "EaseaLex.cpp"
#line 643 "EaseaLex.cpp"
}
break;
case 34:
{
#line 396 "EaseaLex.l"
#line 482 "EaseaLex.l"
accolade_counter++;
opDesc[iNoOp]->cpuCodeStream << "{";
opDesc[iNoOp]->gpuCodeStream << "{";
#line 568 "EaseaLex.cpp"
#line 654 "EaseaLex.cpp"
}
break;
case 35:
{
#line 402 "EaseaLex.l"
#line 488 "EaseaLex.l"
accolade_counter--;
if( accolade_counter==0 ){
......@@ -582,12 +668,12 @@ if( bGPOPCODE_ANALYSIS )printf("\n");lineCounter++;
opDesc[iNoOp]->gpuCodeStream << "}";
}
#line 586 "EaseaLex.cpp"
#line 672 "EaseaLex.cpp"
}
break;
case 36:
{
#line 415 "EaseaLex.l"
#line 501 "EaseaLex.l"
char* endptr;
unsigned no_input = strtol(yytext+strlen("INPUT["),&endptr,10);
......@@ -595,44 +681,44 @@ if( bGPOPCODE_ANALYSIS )printf("\n");lineCounter++;
opDesc[iNoOp]->cpuCodeStream << "input["<< no_input <<"]" ;
opDesc[iNoOp]->gpuCodeStream << "input["<< no_input << "]";
#line 599 "EaseaLex.cpp"
#line 685 "EaseaLex.cpp"
}
break;
case 37:
{
#line 423 "EaseaLex.l"
#line 509 "EaseaLex.l"
opDesc[iNoOp]->isERC = true;
opDesc[iNoOp]->cpuCodeStream << "root->erc_value" ;
opDesc[iNoOp]->gpuCodeStream << "k_progs[start_prog++];" ;
// printf("ERC matched\n");
#line 611 "EaseaLex.cpp"
#line 697 "EaseaLex.cpp"
}
break;
case 38:
{
#line 430 "EaseaLex.l"
#line 516 "EaseaLex.l"
opDesc[iNoOp]->cpuCodeStream << "\n ";
opDesc[iNoOp]->gpuCodeStream << "\n ";
#line 621 "EaseaLex.cpp"
#line 707 "EaseaLex.cpp"
}
break;
case 39:
{
#line 436 "EaseaLex.l"
#line 522 "EaseaLex.l"
opDesc[iNoOp]->cpuCodeStream << yytext;
opDesc[iNoOp]->gpuCodeStream << yytext;
#line 631 "EaseaLex.cpp"
#line 717 "EaseaLex.cpp"
}
break;
case 40:
{
#line 441 "EaseaLex.l"
#line 527 "EaseaLex.l"
yyreset();
rewind(fpGenomeFile);
......@@ -643,12 +729,12 @@ if( bGPOPCODE_ANALYSIS )printf("\n");lineCounter++;
fprintf(fpOutputFile," ");
BEGIN COPY_GP_EVAL;
#line 647 "EaseaLex.cpp"
#line 733 "EaseaLex.cpp"
}
break;
case 41:
{
#line 452 "EaseaLex.l"
#line 538 "EaseaLex.l"
yyreset();
rewind(fpGenomeFile);
......@@ -660,12 +746,12 @@ if( bGPOPCODE_ANALYSIS )printf("\n");lineCounter++;
bCOPY_GP_EVAL_GPU = false;
BEGIN COPY_GP_EVAL;
#line 664 "EaseaLex.cpp"
#line 750 "EaseaLex.cpp"
}
break;
case 42:
{
#line 466 "EaseaLex.l"
#line 552 "EaseaLex.l"
yyreset();
rewind(fpGenomeFile);
......@@ -677,12 +763,12 @@ if( bGPOPCODE_ANALYSIS )printf("\n");lineCounter++;
bCOPY_GP_EVAL_GPU = true;
BEGIN COPY_GP_EVAL;
#line 681 "EaseaLex.cpp"
#line 767 "EaseaLex.cpp"
}
break;
case 43:
{
#line 480 "EaseaLex.l"
#line 566 "EaseaLex.l"
yyreset();
rewind(fpGenomeFile);
......@@ -693,12 +779,12 @@ if( bGPOPCODE_ANALYSIS )printf("\n");lineCounter++;
fprintf(fpOutputFile," ");
BEGIN COPY_GP_EVAL;
#line 697 "EaseaLex.cpp"
#line 783 "EaseaLex.cpp"