Annotation of rpl/src/optimisation.c, revision 1.25

1.1       bertrand    1: /*
                      2: ================================================================================
1.23      bertrand    3:   RPL/2 (R) version 4.1.0.prerelease.1
1.18      bertrand    4:   Copyright (C) 1989-2011 Dr. BERTRAND Joël
1.1       bertrand    5: 
                      6:   This file is part of RPL/2.
                      7: 
                      8:   RPL/2 is free software; you can redistribute it and/or modify it
                      9:   under the terms of the CeCILL V2 License as published by the french
                     10:   CEA, CNRS and INRIA.
                     11:  
                     12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
                     13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                     14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
                     15:   for more details.
                     16:  
                     17:   You should have received a copy of the CeCILL License
                     18:   along with RPL/2. If not, write to info@cecill.info.
                     19: ================================================================================
                     20: */
                     21: 
                     22: 
1.13      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
1.3       bertrand   28:   Boucle principale optimisé de l'interprète RPL/2
1.1       bertrand   29: ================================================================================
                     30:   Entrées : structure sur l'état du processus
                     31: --------------------------------------------------------------------------------
                     32:   Sorties : Néant
                     33: --------------------------------------------------------------------------------
                     34:   Effets de bord : néant
                     35: ================================================================================
                     36: */
                     37: 
                     38: logical1
                     39: sequenceur_optimise(struct_processus *s_etat_processus)
                     40: {
1.24      bertrand   41:    int                         i;
                     42:    int                         nb_variables;
                     43:    int                         point_entree;
1.1       bertrand   44: 
1.24      bertrand   45:    logical1                    erreur;
1.1       bertrand   46: 
1.24      bertrand   47:    struct_objet                *programme_principal;
1.1       bertrand   48: 
1.24      bertrand   49:    struct_tableau_variables    *tableau;
                     50: 
                     51:    unsigned char               *message;
                     52: 
                     53:    unsigned long               adresse_point_entree;
1.1       bertrand   54: 
                     55:    if ((*s_etat_processus).debug == d_vrai)
                     56:        if (((*s_etat_processus).type_debug &
                     57:                d_debug_analyse) != 0)
                     58:    {
                     59:        if ((*s_etat_processus).langue == 'F')
                     60:        {
1.17      bertrand   61:            printf("+++Optimisation [%d]\n", (int) getpid());
1.1       bertrand   62:        }
                     63:        else
                     64:        {
                     65:            printf("+++Optimization [%d]\n", (int) getpid());
                     66:        }
                     67: 
                     68:        printf("\n");
                     69:        fflush(stdout);
                     70:    }
                     71: 
                     72:    point_entree = -1;
                     73:    adresse_point_entree = 0;
                     74: 
                     75:    empilement_pile_systeme(s_etat_processus);
                     76:    (*(*s_etat_processus).l_base_pile_systeme).retour_definition = 'Y';
                     77:    (*s_etat_processus).autorisation_empilement_programme = 'Y';
                     78:    (*s_etat_processus).mode_execution_programme = 'N';
                     79: 
1.24      bertrand   80:    nb_variables = nombre_variables(s_etat_processus,
                     81:            (*s_etat_processus).s_arbre_variables);
                     82: 
                     83:    if ((tableau = malloc(nb_variables * sizeof(struct_tableau_variables)))
                     84:            == NULL)
                     85:    {
                     86:        if ((*s_etat_processus).langue == 'F')
                     87:        {
                     88:            printf("+++Système : Mémoire insuffisante\n");
                     89:        }
                     90:        else
                     91:        {
                     92:            printf("+++System : Not enough memory\n");
                     93:        }
                     94: 
                     95:        return(d_erreur);
                     96:    }
                     97: 
                     98:    liste_variables(s_etat_processus, tableau, 0,
                     99:            (*s_etat_processus).s_arbre_variables);
                    100: 
                    101:    for(i = 0; i < nb_variables; i++)
1.1       bertrand  102:    {
1.24      bertrand  103:        if (tableau[i].niveau == 0)
1.1       bertrand  104:        {
                    105:            // Variables qui contiennent les points d'entrée des définitions.
                    106: 
                    107:            (*s_etat_processus).position_courante = (*((unsigned long *)
1.24      bertrand  108:                    (*(tableau[i].objet)).objet));
1.1       bertrand  109: 
                    110:            if (point_entree == -1)
                    111:            {
                    112:                adresse_point_entree = (*s_etat_processus).position_courante;
                    113:                point_entree = i;
                    114:            }
                    115:            else
                    116:            {
                    117:                if ((*s_etat_processus).position_courante <
                    118:                        adresse_point_entree)
                    119:                {
                    120:                    adresse_point_entree = (*s_etat_processus)
                    121:                            .position_courante;
                    122:                    point_entree = i;
                    123:                }
                    124:            }
                    125: 
                    126:            if ((erreur = recherche_instruction_suivante(s_etat_processus))
                    127:                    == d_erreur)
                    128:            {
                    129:                if ((*s_etat_processus).langue == 'F')
                    130:                {
                    131:                    printf("+++Fatal : Optimisation impossible\n");
                    132:                }
                    133:                else
                    134:                {
                    135:                    printf("+++Fatal : Optimization failed\n");
                    136:                }
                    137: 
1.24      bertrand  138:                free(tableau);
1.1       bertrand  139:                return(d_erreur);
                    140:            }
                    141: 
                    142:            recherche_type(s_etat_processus);
                    143: 
                    144:            if (((*s_etat_processus).erreur_execution != d_ex) ||
                    145:                    ((*s_etat_processus).erreur_systeme != d_es))
                    146:            {
                    147:                if ((*s_etat_processus).langue == 'F')
                    148:                {
                    149:                    printf("+++Fatal : Optimisation impossible\n");
                    150:                }
                    151:                else
                    152:                {
                    153:                    printf("+++Fatal : Optimization failed\n");
                    154:                }
                    155: 
1.24      bertrand  156:                free(tableau);
1.1       bertrand  157:                return(d_erreur);
                    158:            }
                    159: 
1.24      bertrand  160:            // Modification de la variable. Il n'existe à cet instant
                    161:            // que des variables de niveau 0.
                    162: 
                    163:            if (recherche_variable(s_etat_processus, tableau[i].nom) ==
                    164:                    d_faux)
                    165:            {
                    166:                if ((*s_etat_processus).langue == 'F')
                    167:                {
                    168:                    printf("+++Fatal : Optimisation impossible\n");
                    169:                }
                    170:                else
                    171:                {
                    172:                    printf("+++Fatal : Optimization failed\n");
                    173:                }
                    174: 
                    175:                free(tableau);
                    176:                return(d_erreur);
                    177:            }
                    178: 
                    179:            liberation(s_etat_processus, tableau[i].objet);
1.1       bertrand  180: 
                    181:            if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1.24      bertrand  182:                    &((*(*s_etat_processus).pointeur_variable_courante).objet))
1.1       bertrand  183:                    == d_erreur)
                    184:            {
                    185:                if ((*s_etat_processus).langue == 'F')
                    186:                {
                    187:                    printf("+++Fatal : Optimisation impossible\n");
                    188:                }
                    189:                else
                    190:                {
                    191:                    printf("+++Fatal : Optimization failed\n");
                    192:                }
                    193: 
1.24      bertrand  194:                free(tableau);
1.1       bertrand  195:                return(d_erreur);
                    196:            }
                    197: 
1.24      bertrand  198:            (*(*s_etat_processus).pointeur_variable_courante).origine = 'E';
1.1       bertrand  199:            free((*s_etat_processus).instruction_courante);
1.24      bertrand  200: 
                    201:            if (point_entree == i)
                    202:            {
                    203:                programme_principal = (*(*s_etat_processus)
                    204:                        .pointeur_variable_courante).objet;
                    205:            }
1.1       bertrand  206:        }
                    207:    }
                    208: 
                    209:    if (point_entree == -1)
                    210:    {
                    211:        if ((*s_etat_processus).langue == 'F')
                    212:        {
                    213:            printf("+++Fatal : Optimisation impossible\n");
                    214:        }
                    215:        else
                    216:        {
                    217:            printf("+++Fatal : Optimization failed\n");
                    218:        }
                    219: 
1.24      bertrand  220:        free(tableau);
1.1       bertrand  221:        return(d_erreur);
                    222:    }
                    223: 
                    224:    if ((*s_etat_processus).debug == d_vrai)
                    225:    {
                    226:        if (((*s_etat_processus).type_debug &
                    227:                d_debug_analyse) != 0)
                    228:        {
                    229:            printf("\n");
                    230: 
                    231:            if ((*s_etat_processus).langue == 'F')
                    232:            {
                    233:                printf("[%d] Optimisation achevée\n", (int) getpid());
                    234:            }
                    235:            else
                    236:            {
                    237:                printf("[%d] Optimization done\n", (int) getpid());
                    238:            }
                    239: 
                    240:            printf("\n");
                    241:            fflush(stdout);
                    242:        }
                    243:    }
                    244: 
                    245:    (*s_etat_processus).retour_routine_evaluation = 'Y';
                    246: 
                    247:    free((*s_etat_processus).definitions_chainees);
                    248: 
                    249:    if (((*s_etat_processus).definitions_chainees =
                    250:            malloc(sizeof(unsigned char))) == NULL)
                    251:    {
                    252:        if ((*s_etat_processus).langue == 'F')
                    253:        {
                    254:            printf("+++Fatal : Optimisation impossible\n");
                    255:        }
                    256:        else
                    257:        {
                    258:            printf("+++Fatal : Optimization failed\n");
                    259:        }
                    260: 
1.24      bertrand  261:        free(tableau);
1.1       bertrand  262:        return(d_erreur);
                    263:    }
                    264: 
                    265:    (*s_etat_processus).definitions_chainees[0] = d_code_fin_chaine;
                    266:    (*s_etat_processus).longueur_definitions_chainees = 0;
                    267:    (*s_etat_processus).evaluation_expression_compilee = 'Y';
                    268: 
                    269:    if ((*s_etat_processus).profilage == d_vrai)
                    270:    {
1.24      bertrand  271:        profilage(s_etat_processus, tableau[point_entree].nom);
1.1       bertrand  272:    }
                    273: 
                    274:    if ((*s_etat_processus).erreur_systeme != d_es)
                    275:    {
                    276:        if ((*s_etat_processus).langue == 'F')
                    277:        {
                    278:            printf("+++Système : Mémoire insuffisante\n");
                    279:        }
                    280:        else
                    281:        {
                    282:            printf("+++System : Not enough memory\n");
                    283:        }
                    284: 
1.24      bertrand  285:        free(tableau);
1.1       bertrand  286:        return(d_erreur);
                    287:    }
                    288: 
1.24      bertrand  289:    free(tableau);
                    290: 
                    291:    erreur = evaluation(s_etat_processus, programme_principal, 'E');
1.1       bertrand  292: 
                    293:    if ((*s_etat_processus).profilage == d_vrai)
                    294:    {
                    295:        profilage(s_etat_processus, NULL);
                    296:    }
                    297: 
                    298:    (*s_etat_processus).mode_execution_programme = 'N';
                    299: 
                    300:    if (((*s_etat_processus).erreur_execution != d_ex) ||
                    301:            ((*s_etat_processus).exception != d_ep) ||
                    302:            ((*s_etat_processus).erreur_systeme != d_es))
                    303:    {
                    304:        printf("%s [%d]\n", message = messages(s_etat_processus),
                    305:                (int) getpid());
                    306: 
                    307:        if (test_cfsf(s_etat_processus, 51) == d_faux)
                    308:        {
                    309:            printf("%s", ds_beep);
                    310:        }
                    311: 
                    312:        free(message);
                    313:    }
                    314: 
                    315:    return(erreur);
                    316: }
                    317: 
                    318: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>