3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "surf/surfxml_parse_private.h"
11 #include "surf/surf_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(parse, surf ,"Logging specific to the SURF module");
17 static xbt_dynar_t surf_input_buffer_stack=NULL;
18 static xbt_dynar_t surf_file_to_parse_stack=NULL;
20 void nil_function(void);
21 void nil_function(void)
26 void_f_void_t *STag_surfxml_platform_description_fun = nil_function;
27 void_f_void_t *ETag_surfxml_platform_description_fun = nil_function;
28 void_f_void_t *STag_surfxml_cpu_fun = nil_function;
29 void_f_void_t *ETag_surfxml_cpu_fun = nil_function;
30 void_f_void_t *STag_surfxml_router_fun = nil_function;
31 void_f_void_t *ETag_surfxml_router_fun = nil_function;
32 void_f_void_t *STag_surfxml_network_link_fun = nil_function;
33 void_f_void_t *ETag_surfxml_network_link_fun = nil_function;
34 void_f_void_t *STag_surfxml_route_fun = nil_function;
35 void_f_void_t *ETag_surfxml_route_fun = nil_function;
36 void_f_void_t *STag_surfxml_route_element_fun = nil_function;
37 void_f_void_t *ETag_surfxml_route_element_fun = nil_function;
38 void_f_void_t *STag_surfxml_process_fun = nil_function;
39 void_f_void_t *ETag_surfxml_process_fun = nil_function;
40 void_f_void_t *STag_surfxml_argument_fun = nil_function;
41 void_f_void_t *ETag_surfxml_argument_fun = nil_function;
43 YY_BUFFER_STATE surf_input_buffer;
44 FILE *surf_file_to_parse;
46 void surf_parse_reset_parser(void)
48 STag_surfxml_platform_description_fun = nil_function;
49 ETag_surfxml_platform_description_fun = nil_function;
50 STag_surfxml_cpu_fun = nil_function;
51 ETag_surfxml_cpu_fun = nil_function;
52 STag_surfxml_router_fun = nil_function;
53 ETag_surfxml_router_fun = nil_function;
54 STag_surfxml_network_link_fun = nil_function;
55 ETag_surfxml_network_link_fun = nil_function;
56 STag_surfxml_route_fun = nil_function;
57 ETag_surfxml_route_fun = nil_function;
58 STag_surfxml_route_element_fun = nil_function;
59 ETag_surfxml_route_element_fun = nil_function;
60 STag_surfxml_process_fun = nil_function;
61 ETag_surfxml_process_fun = nil_function;
62 STag_surfxml_argument_fun = nil_function;
63 ETag_surfxml_argument_fun = nil_function;
66 void STag_surfxml_include(void)
68 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
69 xbt_dynar_push(surf_file_to_parse_stack,&surf_file_to_parse);
71 surf_file_to_parse = surf_fopen(A_surfxml_include_file,"r");
72 xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",
73 A_surfxml_include_file);
74 surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10);
75 surf_parse__switch_to_buffer(surf_input_buffer);
76 printf("STAG\n"); fflush(NULL);
79 void ETag_surfxml_include(void)
81 printf("ETAG\n"); fflush(NULL);
82 surf_parse__delete_buffer(surf_input_buffer);
83 fclose(surf_file_to_parse);
84 xbt_dynar_pop(surf_file_to_parse_stack,&surf_file_to_parse);
85 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
88 void STag_surfxml_platform_description(void)
92 sscanf(A_surfxml_platform_description_version,"%lg",&version);
94 xbt_assert0((version>=1.0),"******* BIG FAT WARNING *********\n "
95 "You're using an old XML file. "
96 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
97 "instead of MBytes, MFlops and seconds. "
98 "A script (surfxml_update.pl) to help you convert your old "
100 "is available in the contrib/platform_generation directory "
101 "of the simgrid repository. Please check also out the "
102 "SURF section of the ChangeLog for the 3.1 version. "
103 "Last, do not forget to also update your values for "
104 "the calls to MSG_task_create (if any).");
106 STag_surfxml_platform_description_fun();
109 void ETag_surfxml_platform_description(void)
111 ETag_surfxml_platform_description_fun();
114 void STag_surfxml_cpu(void)
116 STag_surfxml_cpu_fun();
119 void ETag_surfxml_cpu(void)
121 ETag_surfxml_cpu_fun();
124 void STag_surfxml_router(void)
126 STag_surfxml_router_fun();
129 void ETag_surfxml_router(void)
131 ETag_surfxml_router_fun();
134 void STag_surfxml_network_link(void)
136 STag_surfxml_network_link_fun();
139 void ETag_surfxml_network_link(void)
141 ETag_surfxml_network_link_fun();
144 void STag_surfxml_route(void)
146 STag_surfxml_route_fun();
149 void ETag_surfxml_route(void)
151 ETag_surfxml_route_fun();
154 void STag_surfxml_route_element(void)
156 STag_surfxml_route_element_fun();
159 void ETag_surfxml_route_element(void)
161 ETag_surfxml_route_element_fun();
164 void STag_surfxml_process(void)
166 STag_surfxml_process_fun();
169 void ETag_surfxml_process(void)
171 ETag_surfxml_process_fun();
174 void STag_surfxml_argument(void)
176 STag_surfxml_argument_fun();
179 void ETag_surfxml_argument(void)
181 ETag_surfxml_argument_fun();
184 void surf_parse_open(const char *file) {
185 static int warned = 0; /* warn only once */
188 WARN0("Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code.");
193 if(!surf_input_buffer_stack)
194 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE),NULL);
195 if(!surf_file_to_parse_stack)
196 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE*),NULL);
198 surf_file_to_parse = surf_fopen(file,"r");
199 xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",file);
200 surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10);
201 surf_parse__switch_to_buffer(surf_input_buffer);
202 surf_parse_lineno = 1;
205 void surf_parse_close(void) {
206 if(surf_input_buffer_stack)
207 xbt_dynar_free(&surf_input_buffer_stack);
208 if(surf_file_to_parse_stack)
209 xbt_dynar_free(&surf_file_to_parse_stack);
211 if(surf_file_to_parse) {
212 surf_parse__delete_buffer(surf_input_buffer);
213 fclose(surf_file_to_parse);
218 static int _surf_parse(void)
220 return surf_parse_lex();
223 int_f_void_t *surf_parse = _surf_parse;
225 void surf_parse_get_double(double *value,const char *string)
229 ret = sscanf(string, "%lg", value);
230 xbt_assert2((ret==1), "Parse error line %d : %s not a number", surf_parse_lineno,
234 void surf_parse_get_trace(tmgr_trace_t *trace, const char *string)
236 if ((!string) || (strcmp(string, "") == 0))
239 *trace = tmgr_trace_new(string);