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_network_link_fun = nil_function;
31 void_f_void_t ETag_surfxml_network_link_fun = nil_function;
32 void_f_void_t STag_surfxml_route_fun = nil_function;
33 void_f_void_t ETag_surfxml_route_fun = nil_function;
34 void_f_void_t STag_surfxml_route_element_fun = nil_function;
35 void_f_void_t ETag_surfxml_route_element_fun = nil_function;
36 void_f_void_t STag_surfxml_process_fun = nil_function;
37 void_f_void_t ETag_surfxml_process_fun = nil_function;
38 void_f_void_t STag_surfxml_argument_fun = nil_function;
39 void_f_void_t ETag_surfxml_argument_fun = nil_function;
41 YY_BUFFER_STATE surf_input_buffer;
42 FILE *surf_file_to_parse;
44 void surf_parse_reset_parser(void)
46 STag_surfxml_platform_description_fun = nil_function;
47 ETag_surfxml_platform_description_fun = nil_function;
48 STag_surfxml_cpu_fun = nil_function;
49 ETag_surfxml_cpu_fun = nil_function;
50 STag_surfxml_network_link_fun = nil_function;
51 ETag_surfxml_network_link_fun = nil_function;
52 STag_surfxml_route_fun = nil_function;
53 ETag_surfxml_route_fun = nil_function;
54 STag_surfxml_route_element_fun = nil_function;
55 ETag_surfxml_route_element_fun = nil_function;
56 STag_surfxml_process_fun = nil_function;
57 ETag_surfxml_process_fun = nil_function;
58 STag_surfxml_argument_fun = nil_function;
59 ETag_surfxml_argument_fun = nil_function;
62 void STag_surfxml_include(void)
64 xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer);
65 xbt_dynar_push(surf_file_to_parse_stack,&surf_file_to_parse);
67 surf_file_to_parse = surf_fopen(A_surfxml_include_file,"r");
68 xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",
69 A_surfxml_include_file);
70 surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10);
71 surf_parse__switch_to_buffer(surf_input_buffer);
72 printf("STAG\n"); fflush(NULL);
75 void ETag_surfxml_include(void)
77 printf("ETAG\n"); fflush(NULL);
78 surf_parse__delete_buffer(surf_input_buffer);
79 fclose(surf_file_to_parse);
80 xbt_dynar_pop(surf_file_to_parse_stack,&surf_file_to_parse);
81 xbt_dynar_pop(surf_input_buffer_stack,&surf_input_buffer);
84 void STag_surfxml_platform_description(void)
88 sscanf(A_surfxml_platform_description_version,"%lg",&version);
90 xbt_assert0((version>=1.1),"******* BIG FAT WARNING *********\n "
91 "You're using an old XML file. "
92 "Since SimGrid 3.0.2, units are Bytes, Flops, and seconds "
93 "instead of MBytes, MFlops and seconds. "
94 "A script to help you convert your old platform files "
95 "is available in the contrib/platform_generation directory "
96 "of the simgrid repository. Please check also out the "
97 "SURF section of the ChangeLog for the 3.0.2 version. "
98 "Last, do not forget to also update your values for "
99 "the calls to MSG_task_create.");
101 STag_surfxml_platform_description_fun();
104 void ETag_surfxml_platform_description(void)
106 ETag_surfxml_platform_description_fun();
109 void STag_surfxml_cpu(void)
111 STag_surfxml_cpu_fun();
114 void ETag_surfxml_cpu(void)
116 ETag_surfxml_cpu_fun();
119 void STag_surfxml_network_link(void)
121 STag_surfxml_network_link_fun();
124 void ETag_surfxml_network_link(void)
126 ETag_surfxml_network_link_fun();
129 void STag_surfxml_route(void)
131 STag_surfxml_route_fun();
134 void ETag_surfxml_route(void)
136 ETag_surfxml_route_fun();
139 void STag_surfxml_route_element(void)
141 STag_surfxml_route_element_fun();
144 void ETag_surfxml_route_element(void)
146 ETag_surfxml_route_element_fun();
149 void STag_surfxml_process(void)
151 STag_surfxml_process_fun();
154 void ETag_surfxml_process(void)
156 ETag_surfxml_process_fun();
159 void STag_surfxml_argument(void)
161 STag_surfxml_argument_fun();
164 void ETag_surfxml_argument(void)
166 ETag_surfxml_argument_fun();
169 void surf_parse_open(const char *file) {
171 WARN0("I hope you know what you're doing... you just gave me a NULL pointer!");
174 if(!surf_input_buffer_stack)
175 surf_input_buffer_stack = xbt_dynar_new(sizeof(YY_BUFFER_STATE),NULL);
176 if(!surf_file_to_parse_stack)
177 surf_file_to_parse_stack = xbt_dynar_new(sizeof(FILE*),NULL);
179 surf_file_to_parse = surf_fopen(file,"r");
180 xbt_assert1((surf_file_to_parse), "Unable to open \"%s\"\n",file);
181 surf_input_buffer = surf_parse__create_buffer( surf_file_to_parse, 10);
182 surf_parse__switch_to_buffer(surf_input_buffer);
183 surf_parse_lineno = 1;
186 void surf_parse_close(void) {
187 if(surf_input_buffer_stack)
188 xbt_dynar_free(&surf_input_buffer_stack);
189 if(surf_file_to_parse_stack)
190 xbt_dynar_free(&surf_file_to_parse_stack);
192 if(surf_file_to_parse) {
193 surf_parse__delete_buffer(surf_input_buffer);
194 fclose(surf_file_to_parse);
199 static int _surf_parse(void)
201 return surf_parse_lex();
204 int_f_void_t surf_parse = _surf_parse;
206 void surf_parse_get_double(double *value,const char *string)
210 ret = sscanf(string, "%lg", value);
211 xbt_assert2((ret==1), "Parse error line %d : %s not a number", surf_parse_lineno,
215 void surf_parse_get_trace(tmgr_trace_t *trace, const char *string)
217 if ((!string) || (strcmp(string, "") == 0))
220 *trace = tmgr_trace_new(string);