Annotation of rpl/src/optimisation.c, revision 1.61
1.1 bertrand 1: /*
2: ================================================================================
1.59 bertrand 3: RPL/2 (R) version 4.1.19
1.61 ! bertrand 4: Copyright (C) 1989-2015 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.28 bertrand 28: Boucle principale optimisée 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.49 bertrand 41: integer8 adresse_point_entree;
42: integer8 i;
1.50 bertrand 43: integer8 j;
1.49 bertrand 44: integer8 nb_variables;
45: integer8 point_entree;
1.1 bertrand 46:
1.24 bertrand 47: logical1 erreur;
1.1 bertrand 48:
1.24 bertrand 49: struct_objet *programme_principal;
1.1 bertrand 50:
1.24 bertrand 51: struct_tableau_variables *tableau;
52:
53: unsigned char *message;
1.28 bertrand 54: unsigned char registre;
1.24 bertrand 55:
1.1 bertrand 56: if ((*s_etat_processus).debug == d_vrai)
57: if (((*s_etat_processus).type_debug &
58: d_debug_analyse) != 0)
59: {
60: if ((*s_etat_processus).langue == 'F')
61: {
1.28 bertrand 62: printf("+++Compilation [%d]\n", (int) getpid());
1.1 bertrand 63: }
64: else
65: {
1.28 bertrand 66: printf("+++Compilation [%d]\n", (int) getpid());
1.1 bertrand 67: }
68:
69: printf("\n");
70: fflush(stdout);
71: }
72:
73: point_entree = -1;
74: adresse_point_entree = 0;
1.34 bertrand 75: programme_principal = NULL;
1.1 bertrand 76:
77: empilement_pile_systeme(s_etat_processus);
78: (*(*s_etat_processus).l_base_pile_systeme).retour_definition = 'Y';
79: (*s_etat_processus).autorisation_empilement_programme = 'Y';
80: (*s_etat_processus).mode_execution_programme = 'N';
81:
1.44 bertrand 82: nb_variables = nombre_variables(s_etat_processus);
1.24 bertrand 83:
1.49 bertrand 84: if ((tableau = malloc(((size_t) nb_variables) *
85: sizeof(struct_tableau_variables))) == NULL)
1.24 bertrand 86: {
87: if ((*s_etat_processus).langue == 'F')
88: {
89: printf("+++Système : Mémoire insuffisante\n");
90: }
91: else
92: {
93: printf("+++System : Not enough memory\n");
94: }
95:
1.44 bertrand 96: liberation_mutexes_arbre_variables_partagees(s_etat_processus,
97: (*(*s_etat_processus).s_arbre_variables_partagees));
1.24 bertrand 98: return(d_erreur);
99: }
100:
1.50 bertrand 101: nb_variables = liste_variables(s_etat_processus, tableau);
102:
1.24 bertrand 103: for(i = 0; i < nb_variables; i++)
1.1 bertrand 104: {
1.24 bertrand 105: if (tableau[i].niveau == 0)
1.1 bertrand 106: {
107: // Variables qui contiennent les points d'entrée des définitions.
108:
1.49 bertrand 109: (*s_etat_processus).position_courante = (*((integer8 *)
1.24 bertrand 110: (*(tableau[i].objet)).objet));
1.1 bertrand 111:
112: if (point_entree == -1)
113: {
114: adresse_point_entree = (*s_etat_processus).position_courante;
115: point_entree = i;
116: }
117: else
118: {
119: if ((*s_etat_processus).position_courante <
120: adresse_point_entree)
121: {
122: adresse_point_entree = (*s_etat_processus)
123: .position_courante;
124: point_entree = i;
125: }
126: }
127:
128: if ((erreur = recherche_instruction_suivante(s_etat_processus))
129: == d_erreur)
130: {
131: if ((*s_etat_processus).langue == 'F')
132: {
1.28 bertrand 133: printf("+++Fatal : Compilation impossible\n");
1.1 bertrand 134: }
135: else
136: {
1.28 bertrand 137: printf("+++Fatal : Compilation failed\n");
1.1 bertrand 138: }
139:
1.50 bertrand 140: for(j = 0; j < nb_variables; j++)
141: {
142: if (tableau[j].mutex != NULL)
143: {
144: pthread_mutex_unlock(tableau[j].mutex);
145: }
146: }
147:
1.24 bertrand 148: free(tableau);
1.1 bertrand 149: return(d_erreur);
150: }
151:
1.28 bertrand 152: // Il faut désactiver la vérification des variables
153: // implicites car aucune variable de niveau strictement
154: // positif étant créée, la fonction recherche_type() pourrait
155: // échouer.
156:
157: registre = (*s_etat_processus).autorisation_nom_implicite;
158: (*s_etat_processus).autorisation_nom_implicite = 'Y';
1.60 bertrand 159: (*s_etat_processus).type_en_cours = NON;
1.1 bertrand 160: recherche_type(s_etat_processus);
1.28 bertrand 161: (*s_etat_processus).autorisation_nom_implicite = registre;
1.1 bertrand 162:
163: if (((*s_etat_processus).erreur_execution != d_ex) ||
164: ((*s_etat_processus).erreur_systeme != d_es))
165: {
1.28 bertrand 166: if ((*s_etat_processus).core == d_vrai)
167: {
168: if ((*s_etat_processus).langue == 'F')
169: {
170: printf("+++Information : "
171: "Génération du fichier rpl-core "
172: "[%d]\n", (int) getpid());
173: }
174: else
175: {
176: printf("+++Information : "
177: "Writing rpl-core file [%d]\n",
178: (int) getpid());
179: }
180:
181: rplcore(s_etat_processus);
182:
183: if ((*s_etat_processus).langue == 'F')
184: {
185: printf("+++Information : "
186: "Processus tracé [%d]\n",
187: (int) getpid());
188: }
189: else
190: {
191: printf("+++Information : Done [%d]\n",
192: (int) getpid());
193: }
194:
195: fflush(stdout);
196: }
197:
1.1 bertrand 198: if ((*s_etat_processus).langue == 'F')
199: {
1.28 bertrand 200: printf("+++Fatal : Compilation impossible\n");
1.1 bertrand 201: }
202: else
203: {
1.28 bertrand 204: printf("+++Fatal : Compilation failed\n");
1.1 bertrand 205: }
206:
1.50 bertrand 207: for(j = 0; j < nb_variables; j++)
208: {
209: if (tableau[j].mutex != NULL)
210: {
211: pthread_mutex_unlock(tableau[j].mutex);
212: }
213: }
214:
1.24 bertrand 215: free(tableau);
1.1 bertrand 216: return(d_erreur);
217: }
218:
1.24 bertrand 219: // Modification de la variable. Il n'existe à cet instant
220: // que des variables de niveau 0.
221:
222: if (recherche_variable(s_etat_processus, tableau[i].nom) ==
223: d_faux)
224: {
225: if ((*s_etat_processus).langue == 'F')
226: {
1.28 bertrand 227: printf("+++Fatal : Compilation impossible\n");
1.24 bertrand 228: }
229: else
230: {
1.28 bertrand 231: printf("+++Fatal : Compilation failed\n");
1.24 bertrand 232: }
233:
1.50 bertrand 234: for(j = 0; j < nb_variables; j++)
235: {
236: if (tableau[j].mutex != NULL)
237: {
238: pthread_mutex_unlock(tableau[j].mutex);
239: }
240: }
241:
1.24 bertrand 242: free(tableau);
243: return(d_erreur);
244: }
245:
246: liberation(s_etat_processus, tableau[i].objet);
1.1 bertrand 247:
248: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1.24 bertrand 249: &((*(*s_etat_processus).pointeur_variable_courante).objet))
1.1 bertrand 250: == d_erreur)
251: {
252: if ((*s_etat_processus).langue == 'F')
253: {
1.28 bertrand 254: printf("+++Fatal : Compilation impossible\n");
1.1 bertrand 255: }
256: else
257: {
1.28 bertrand 258: printf("+++Fatal : Compilation failed\n");
1.1 bertrand 259: }
260:
1.50 bertrand 261: for(j = 0; j < nb_variables; j++)
262: {
263: if (tableau[j].mutex != NULL)
264: {
265: pthread_mutex_unlock(tableau[j].mutex);
266: }
267: }
268:
1.24 bertrand 269: free(tableau);
1.1 bertrand 270: return(d_erreur);
271: }
272:
1.24 bertrand 273: (*(*s_etat_processus).pointeur_variable_courante).origine = 'E';
1.1 bertrand 274: free((*s_etat_processus).instruction_courante);
1.24 bertrand 275:
276: if (point_entree == i)
277: {
278: programme_principal = (*(*s_etat_processus)
279: .pointeur_variable_courante).objet;
280: }
1.1 bertrand 281: }
282: }
283:
284: if (point_entree == -1)
285: {
286: if ((*s_etat_processus).langue == 'F')
287: {
1.28 bertrand 288: printf("+++Fatal : Compilation impossible\n");
1.1 bertrand 289: }
290: else
291: {
1.28 bertrand 292: printf("+++Fatal : Compilation failed\n");
1.1 bertrand 293: }
294:
1.50 bertrand 295: for(j = 0; j < nb_variables; j++)
296: {
297: if (tableau[j].mutex != NULL)
298: {
299: pthread_mutex_unlock(tableau[j].mutex);
300: }
301: }
302:
1.24 bertrand 303: free(tableau);
1.1 bertrand 304: return(d_erreur);
305: }
306:
307: if ((*s_etat_processus).debug == d_vrai)
308: {
309: if (((*s_etat_processus).type_debug &
310: d_debug_analyse) != 0)
311: {
312: printf("\n");
313:
314: if ((*s_etat_processus).langue == 'F')
315: {
1.28 bertrand 316: printf("[%d] Compilation achevée\n", (int) getpid());
1.1 bertrand 317: }
318: else
319: {
1.28 bertrand 320: printf("[%d] Compilation done\n", (int) getpid());
1.1 bertrand 321: }
322:
323: printf("\n");
324: fflush(stdout);
325: }
326: }
327:
328: (*s_etat_processus).retour_routine_evaluation = 'Y';
329:
330: free((*s_etat_processus).definitions_chainees);
331:
332: if (((*s_etat_processus).definitions_chainees =
333: malloc(sizeof(unsigned char))) == NULL)
334: {
335: if ((*s_etat_processus).langue == 'F')
336: {
1.28 bertrand 337: printf("+++Fatal : Compilation impossible\n");
1.1 bertrand 338: }
339: else
340: {
1.28 bertrand 341: printf("+++Fatal : Compilation failed\n");
1.1 bertrand 342: }
343:
1.50 bertrand 344: for(j = 0; j < nb_variables; j++)
345: {
346: if (tableau[j].mutex != NULL)
347: {
348: pthread_mutex_unlock(tableau[j].mutex);
349: }
350: }
351:
1.24 bertrand 352: free(tableau);
1.1 bertrand 353: return(d_erreur);
354: }
355:
356: (*s_etat_processus).definitions_chainees[0] = d_code_fin_chaine;
357: (*s_etat_processus).longueur_definitions_chainees = 0;
358: (*s_etat_processus).evaluation_expression_compilee = 'Y';
359:
360: if ((*s_etat_processus).profilage == d_vrai)
361: {
1.24 bertrand 362: profilage(s_etat_processus, tableau[point_entree].nom);
1.1 bertrand 363: }
364:
365: if ((*s_etat_processus).erreur_systeme != d_es)
366: {
367: if ((*s_etat_processus).langue == 'F')
368: {
369: printf("+++Système : Mémoire insuffisante\n");
370: }
371: else
372: {
373: printf("+++System : Not enough memory\n");
374: }
375:
1.50 bertrand 376: for(j = 0; j < nb_variables; j++)
377: {
378: if (tableau[j].mutex != NULL)
379: {
380: pthread_mutex_unlock(tableau[j].mutex);
381: }
382: }
383:
1.24 bertrand 384: free(tableau);
1.1 bertrand 385: return(d_erreur);
386: }
387:
1.50 bertrand 388: for(j = 0; j < nb_variables; j++)
389: {
390: if (tableau[j].mutex != NULL)
391: {
392: pthread_mutex_unlock(tableau[j].mutex);
393: }
394: }
395:
1.24 bertrand 396: free(tableau);
397:
398: erreur = evaluation(s_etat_processus, programme_principal, 'E');
1.1 bertrand 399:
400: if ((*s_etat_processus).profilage == d_vrai)
401: {
402: profilage(s_etat_processus, NULL);
403: }
404:
405: (*s_etat_processus).mode_execution_programme = 'N';
406:
407: if (((*s_etat_processus).erreur_execution != d_ex) ||
408: ((*s_etat_processus).exception != d_ep) ||
409: ((*s_etat_processus).erreur_systeme != d_es))
410: {
411: printf("%s [%d]\n", message = messages(s_etat_processus),
412: (int) getpid());
413:
414: if (test_cfsf(s_etat_processus, 51) == d_faux)
415: {
416: printf("%s", ds_beep);
417: }
418:
419: free(message);
420: }
421:
422: return(erreur);
423: }
424:
425: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>