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. */
11 #include "surf/surfxml_parse_private.h"
12 #include "surf/surf_private.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(parse, surf,
14 "Logging specific to the SURF module");
19 /* make sure these symbols are defined as strong ones in this file so that the linked can resolve them */
20 xbt_dynar_t STag_surfxml_platform_description_cb_list = NULL;
21 xbt_dynar_t ETag_surfxml_platform_description_cb_list = NULL;
22 xbt_dynar_t STag_surfxml_host_cb_list = NULL;
23 xbt_dynar_t ETag_surfxml_host_cb_list = NULL;
24 xbt_dynar_t STag_surfxml_router_cb_list = NULL;
25 xbt_dynar_t ETag_surfxml_router_cb_list = NULL;
26 xbt_dynar_t STag_surfxml_link_cb_list = NULL;
27 xbt_dynar_t ETag_surfxml_link_cb_list = NULL;
28 xbt_dynar_t STag_surfxml_route_cb_list = NULL;
29 xbt_dynar_t ETag_surfxml_route_cb_list = NULL;
30 xbt_dynar_t STag_surfxml_link_c_ctn_cb_list = NULL;
31 xbt_dynar_t ETag_surfxml_link_c_ctn_cb_list = NULL;
32 xbt_dynar_t STag_surfxml_process_cb_list = NULL;
33 xbt_dynar_t ETag_surfxml_process_cb_list = NULL;
34 xbt_dynar_t STag_surfxml_argument_cb_list = NULL;
35 xbt_dynar_t ETag_surfxml_argument_cb_list = NULL;
36 xbt_dynar_t STag_surfxml_prop_cb_list = NULL;
37 xbt_dynar_t ETag_surfxml_prop_cb_list = NULL;
39 static xbt_dynar_t surf_input_buffer_stack = NULL;
40 static xbt_dynar_t surf_file_to_parse_stack = NULL;
42 void surfxml_call_cb_functions(xbt_dynar_t);
44 void nil_function(void);
45 void nil_function(void)
50 YY_BUFFER_STATE surf_input_buffer;
51 FILE *surf_file_to_parse;
53 void surf_parse_reset_parser(void)
56 STag_surfxml_platform_description_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
57 ETag_surfxml_platform_description_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
58 STag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
59 ETag_surfxml_host_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
60 STag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
61 ETag_surfxml_router_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
62 STag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
63 ETag_surfxml_link_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
64 STag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
65 ETag_surfxml_route_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
66 STag_surfxml_link_c_ctn_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
67 ETag_surfxml_link_c_ctn_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
68 STag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
69 ETag_surfxml_process_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
70 STag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
71 ETag_surfxml_argument_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
72 STag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
73 ETag_surfxml_prop_cb_list = xbt_dynar_new(sizeof(void_f_void_t),&free);
77 void STag_surfxml_include(void)
79 xbt_dynar_push(surf_input_buffer_stack, &surf_input_buffer);
80 xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse);
82 surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r");
83 xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",
84 A_surfxml_include_file);
85 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
86 surf_parse__switch_to_buffer(surf_input_buffer);
91 void ETag_surfxml_include(void)
95 surf_parse__delete_buffer(surf_input_buffer);
96 fclose(surf_file_to_parse);
97 xbt_dynar_pop(surf_file_to_parse_stack, &surf_file_to_parse);
98 xbt_dynar_pop(surf_input_buffer_stack, &surf_input_buffer);
101 void STag_surfxml_platform_description(void)
103 double version = 0.0;
105 sscanf(A_surfxml_platform_description_version, "%lg", &version);
107 xbt_assert0((version >= 1.0), "******* BIG FAT WARNING *********\n "
108 "You're using an ancient XML file. "
109 "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
110 "instead of MBytes, MFlops and seconds. "
111 "A script (surfxml_update.pl) to help you convert your old "
113 "is available in the contrib/platform_generation directory "
114 "of the simgrid repository. Please check also out the "
115 "SURF section of the ChangeLog for the 3.1 version. "
116 "Last, do not forget to also update your values for "
117 "the calls to MSG_task_create (if any).");
118 xbt_assert0((version >= 2.0), "******* BIG FAT WARNING *********\n "
119 "You're using an old XML file. "
120 "A script (surfxml_update.pl) to help you convert your old "
122 "is available in the contrib/platform_generation directory "
123 "of the simgrid repository.");
125 surfxml_call_cb_functions(STag_surfxml_platform_description_cb_list);
128 void ETag_surfxml_platform_description(void)
130 surfxml_call_cb_functions(ETag_surfxml_platform_description_cb_list);
133 void STag_surfxml_host(void)
135 surfxml_call_cb_functions(STag_surfxml_host_cb_list);
138 void ETag_surfxml_host(void)
140 surfxml_call_cb_functions(ETag_surfxml_host_cb_list);
143 void STag_surfxml_router(void)
145 surfxml_call_cb_functions(STag_surfxml_router_cb_list);
148 void ETag_surfxml_router(void)
150 surfxml_call_cb_functions(ETag_surfxml_router_cb_list);
153 void STag_surfxml_link(void)
155 surfxml_call_cb_functions(STag_surfxml_link_cb_list);
158 void ETag_surfxml_link(void)
160 surfxml_call_cb_functions(ETag_surfxml_link_cb_list);
163 void STag_surfxml_route(void)
165 surfxml_call_cb_functions(STag_surfxml_route_cb_list);
168 void ETag_surfxml_route(void)
170 surfxml_call_cb_functions(ETag_surfxml_route_cb_list);
173 void STag_surfxml_link_c_ctn(void)
175 surfxml_call_cb_functions(STag_surfxml_link_c_ctn_cb_list);
178 void ETag_surfxml_link_c_ctn(void)
180 surfxml_call_cb_functions(ETag_surfxml_link_c_ctn_cb_list);
183 void STag_surfxml_process(void)
185 surfxml_call_cb_functions(STag_surfxml_process_cb_list);
188 void ETag_surfxml_process(void)
190 surfxml_call_cb_functions(ETag_surfxml_process_cb_list);
193 void STag_surfxml_argument(void)
195 surfxml_call_cb_functions(STag_surfxml_argument_cb_list);
198 void ETag_surfxml_argument(void)
200 surfxml_call_cb_functions(ETag_surfxml_argument_cb_list);
203 void STag_surfxml_prop(void)
205 surfxml_call_cb_functions(STag_surfxml_prop_cb_list);
207 void ETag_surfxml_prop(void)
209 surfxml_call_cb_functions(ETag_surfxml_prop_cb_list);
213 void surf_parse_open(const char *file)
215 static int warned = 0; /* warn only once */
219 ("Bypassing the XML parser since surf_parse_open received a NULL pointer. If it is not what you want, go fix your code.");
224 if (!surf_input_buffer_stack)
225 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE), NULL);
226 if (!surf_file_to_parse_stack)
227 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE *), NULL);
229 surf_file_to_parse = surf_fopen(file, "r");
230 xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n", file);
231 surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, 10);
232 surf_parse__switch_to_buffer(surf_input_buffer);
233 surf_parse_lineno = 1;
236 void surf_parse_close(void)
238 if (surf_input_buffer_stack)
239 xbt_dynar_free(&surf_input_buffer_stack);
240 if (surf_file_to_parse_stack)
241 xbt_dynar_free(&surf_file_to_parse_stack);
243 if (surf_file_to_parse) {
244 surf_parse__delete_buffer(surf_input_buffer);
245 fclose(surf_file_to_parse);
250 static int _surf_parse(void)
252 return surf_parse_lex();
255 int_f_void_t surf_parse = _surf_parse;
257 void surf_parse_get_double(double *value, const char *string)
261 ret = sscanf(string, "%lg", value);
262 xbt_assert2((ret == 1), "Parse error line %d : %s not a number",
263 surf_parse_lineno, string);
266 void surf_parse_get_trace(tmgr_trace_t * trace, const char *string)
268 if ((!string) || (strcmp(string, "") == 0))
271 *trace = tmgr_trace_new(string);
274 void parse_properties(void)
278 if(!current_property_set) current_property_set = xbt_dict_new();
280 value = xbt_strdup(A_surfxml_prop_value);
281 xbt_dict_set(current_property_set, A_surfxml_prop_id, value, free);
285 void free_string(void *d)
290 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
292 xbt_dynar_push(cb_list, &function);
295 void surfxml_call_cb_functions(xbt_dynar_t cb_list)
299 xbt_dynar_foreach(cb_list, iterator, data){