Annotation of rpl/src/optimisation.c, revision 1.57
1.1 bertrand 1: /*
2: ================================================================================
1.56 bertrand 3: RPL/2 (R) version 4.1.17
1.57 ! bertrand 4: Copyright (C) 1989-2014 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.1 bertrand 159: recherche_type(s_etat_processus);
1.28 bertrand 160: (*s_etat_processus).autorisation_nom_implicite = registre;
1.1 bertrand 161:
162: if (((*s_etat_processus).erreur_execution != d_ex) ||
163: ((*s_etat_processus).erreur_systeme != d_es))
164: {
1.28 bertrand 165: if ((*s_etat_processus).core == d_vrai)
166: {
167: if ((*s_etat_processus).langue == 'F')
168: {
169: printf("+++Information : "
170: "Génération du fichier rpl-core "
171: "[%d]\n", (int) getpid());
172: }
173: else
174: {
175: printf("+++Information : "
176: "Writing rpl-core file [%d]\n",
177: (int) getpid());
178: }
179:
180: rplcore(s_etat_processus);
181:
182: if ((*s_etat_processus).langue == 'F')
183: {
184: printf("+++Information : "
185: "Processus tracé [%d]\n",
186: (int) getpid());
187: }
188: else
189: {
190: printf("+++Information : Done [%d]\n",
191: (int) getpid());
192: }
193:
194: fflush(stdout);
195: }
196:
1.1 bertrand 197: if ((*s_etat_processus).langue == 'F')
198: {
1.28 bertrand 199: printf("+++Fatal : Compilation impossible\n");
1.1 bertrand 200: }
201: else
202: {
1.28 bertrand 203: printf("+++Fatal : Compilation failed\n");
1.1 bertrand 204: }
205:
1.50 bertrand 206: for(j = 0; j < nb_variables; j++)
207: {
208: if (tableau[j].mutex != NULL)
209: {
210: pthread_mutex_unlock(tableau[j].mutex);
211: }
212: }
213:
1.24 bertrand 214: free(tableau);
1.1 bertrand 215: return(d_erreur);
216: }
217:
1.24 bertrand 218: // Modification de la variable. Il n'existe à cet instant
219: // que des variables de niveau 0.
220:
221: if (recherche_variable(s_etat_processus, tableau[i].nom) ==
222: d_faux)
223: {
224: if ((*s_etat_processus).langue == 'F')
225: {
1.28 bertrand 226: printf("+++Fatal : Compilation impossible\n");
1.24 bertrand 227: }
228: else
229: {
1.28 bertrand 230: printf("+++Fatal : Compilation failed\n");
1.24 bertrand 231: }
232:
1.50 bertrand 233: for(j = 0; j < nb_variables; j++)
234: {
235: if (tableau[j].mutex != NULL)
236: {
237: pthread_mutex_unlock(tableau[j].mutex);
238: }
239: }
240:
1.24 bertrand 241: free(tableau);
242: return(d_erreur);
243: }
244:
245: liberation(s_etat_processus, tableau[i].objet);
1.1 bertrand 246:
247: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1.24 bertrand 248: &((*(*s_etat_processus).pointeur_variable_courante).objet))
1.1 bertrand 249: == d_erreur)
250: {
251: if ((*s_etat_processus).langue == 'F')
252: {
1.28 bertrand 253: printf("+++Fatal : Compilation impossible\n");
1.1 bertrand 254: }
255: else
256: {
1.28 bertrand 257: printf("+++Fatal : Compilation failed\n");
1.1 bertrand 258: }
259:
1.50 bertrand 260: for(j = 0; j < nb_variables; j++)
261: {
262: if (tableau[j].mutex != NULL)
263: {
264: pthread_mutex_unlock(tableau[j].mutex);
265: }
266: }
267:
1.24 bertrand 268: free(tableau);
1.1 bertrand 269: return(d_erreur);
270: }
271:
1.24 bertrand 272: (*(*s_etat_processus).pointeur_variable_courante).origine = 'E';
1.1 bertrand 273: free((*s_etat_processus).instruction_courante);
1.24 bertrand 274:
275: if (point_entree == i)
276: {
277: programme_principal = (*(*s_etat_processus)
278: .pointeur_variable_courante).objet;
279: }
1.1 bertrand 280: }
281: }
282:
283: if (point_entree == -1)
284: {
285: if ((*s_etat_processus).langue == 'F')
286: {
1.28 bertrand 287: printf("+++Fatal : Compilation impossible\n");
1.1 bertrand 288: }
289: else
290: {
1.28 bertrand 291: printf("+++Fatal : Compilation failed\n");
1.1 bertrand 292: }
293:
1.50 bertrand 294: for(j = 0; j < nb_variables; j++)
295: {
296: if (tableau[j].mutex != NULL)
297: {
298: pthread_mutex_unlock(tableau[j].mutex);
299: }
300: }
301:
1.24 bertrand 302: free(tableau);
1.1 bertrand 303: return(d_erreur);
304: }
305:
306: if ((*s_etat_processus).debug == d_vrai)
307: {
308: if (((*s_etat_processus).type_debug &
309: d_debug_analyse) != 0)
310: {
311: printf("\n");
312:
313: if ((*s_etat_processus).langue == 'F')
314: {
1.28 bertrand 315: printf("[%d] Compilation achevée\n", (int) getpid());
1.1 bertrand 316: }
317: else
318: {
1.28 bertrand 319: printf("[%d] Compilation done\n", (int) getpid());
1.1 bertrand 320: }
321:
322: printf("\n");
323: fflush(stdout);
324: }
325: }
326:
327: (*s_etat_processus).retour_routine_evaluation = 'Y';
328:
329: free((*s_etat_processus).definitions_chainees);
330:
331: if (((*s_etat_processus).definitions_chainees =
332: malloc(sizeof(unsigned char))) == NULL)
333: {
334: if ((*s_etat_processus).langue == 'F')
335: {
1.28 bertrand 336: printf("+++Fatal : Compilation impossible\n");
1.1 bertrand 337: }
338: else
339: {
1.28 bertrand 340: printf("+++Fatal : Compilation failed\n");
1.1 bertrand 341: }
342:
1.50 bertrand 343: for(j = 0; j < nb_variables; j++)
344: {
345: if (tableau[j].mutex != NULL)
346: {
347: pthread_mutex_unlock(tableau[j].mutex);
348: }
349: }
350:
1.24 bertrand 351: free(tableau);
1.1 bertrand 352: return(d_erreur);
353: }
354:
355: (*s_etat_processus).definitions_chainees[0] = d_code_fin_chaine;
356: (*s_etat_processus).longueur_definitions_chainees = 0;
357: (*s_etat_processus).evaluation_expression_compilee = 'Y';
358:
359: if ((*s_etat_processus).profilage == d_vrai)
360: {
1.24 bertrand 361: profilage(s_etat_processus, tableau[point_entree].nom);
1.1 bertrand 362: }
363:
364: if ((*s_etat_processus).erreur_systeme != d_es)
365: {
366: if ((*s_etat_processus).langue == 'F')
367: {
368: printf("+++Système : Mémoire insuffisante\n");
369: }
370: else
371: {
372: printf("+++System : Not enough memory\n");
373: }
374:
1.50 bertrand 375: for(j = 0; j < nb_variables; j++)
376: {
377: if (tableau[j].mutex != NULL)
378: {
379: pthread_mutex_unlock(tableau[j].mutex);
380: }
381: }
382:
1.24 bertrand 383: free(tableau);
1.1 bertrand 384: return(d_erreur);
385: }
386:
1.50 bertrand 387: for(j = 0; j < nb_variables; j++)
388: {
389: if (tableau[j].mutex != NULL)
390: {
391: pthread_mutex_unlock(tableau[j].mutex);
392: }
393: }
394:
1.24 bertrand 395: free(tableau);
396:
397: erreur = evaluation(s_etat_processus, programme_principal, 'E');
1.1 bertrand 398:
399: if ((*s_etat_processus).profilage == d_vrai)
400: {
401: profilage(s_etat_processus, NULL);
402: }
403:
404: (*s_etat_processus).mode_execution_programme = 'N';
405:
406: if (((*s_etat_processus).erreur_execution != d_ex) ||
407: ((*s_etat_processus).exception != d_ep) ||
408: ((*s_etat_processus).erreur_systeme != d_es))
409: {
410: printf("%s [%d]\n", message = messages(s_etat_processus),
411: (int) getpid());
412:
413: if (test_cfsf(s_etat_processus, 51) == d_faux)
414: {
415: printf("%s", ds_beep);
416: }
417:
418: free(message);
419: }
420:
421: return(erreur);
422: }
423:
424: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>