Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2b16c03ebc75451b540a887c8a7f33dc2c93b39c
[simgrid.git] / src / surf / xml / surfxml_sax_cb.cpp
1 /* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/s4u/Engine.hpp"
7 #include "simgrid/sg_config.h"
8 #include "src/kernel/routing/NetPoint.hpp"
9 #include "src/surf/network_interface.hpp"
10 #include "xbt/file.h"
11
12 #include "src/surf/xml/platf_private.hpp"
13 #include <boost/algorithm/string.hpp>
14 #include <boost/algorithm/string/classification.hpp>
15 #include <boost/algorithm/string/split.hpp>
16 #include <string>
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
19
20 extern "C" {
21
22 int ETag_surfxml_include_state();
23
24 #include "simgrid_dtd.c"
25
26 char* surf_parsed_filename = nullptr; // to locate parse error messages
27
28 std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of current list link of a route */
29
30 /*
31  * Helping functions
32  */
33 void surf_parse_assert(bool cond, std::string msg)
34 {
35   if (not cond) {
36     int lineno = surf_parse_lineno;
37     cleanup();
38     XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
39     surf_exit();
40     xbt_die("Exiting now");
41   }
42 }
43
44 void surf_parse_error(std::string msg)
45 {
46   int lineno = surf_parse_lineno;
47   cleanup();
48   XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
49   surf_exit();
50   xbt_die("Exiting now");
51 }
52
53 void surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post)
54 {
55   if (sg_netpoint_by_name_or_null(hostname.c_str()) != nullptr) // found
56     return;
57
58   std::string msg = pre + hostname + post + " Existing netpoints: \n";
59
60   std::vector<simgrid::kernel::routing::NetPoint*> list;
61   simgrid::s4u::Engine::getInstance()->getNetpointList(&list);
62   std::sort(list.begin(), list.end(),
63       [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) {
64       return a->name() < b->name();
65   });
66   bool first = true;
67   for (auto const& np : list) {
68     if (np->isNetZone())
69       continue;
70
71     if (not first)
72       msg += ",";
73     first = false;
74     msg += "'" + np->name() + "'";
75     if (msg.length() > 4096) {
76       msg.pop_back(); // remove trailing quote
77       msg += "...(list truncated)......";
78       break;
79     }
80   }
81   surf_parse_error(msg);
82 }
83
84 void surf_parse_warn(std::string msg)
85 {
86   XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg.c_str());
87 }
88
89 double surf_parse_get_double(std::string s)
90 {
91   try {
92     return std::stod(s);
93   } catch (std::invalid_argument& ia) {
94     surf_parse_error(s + " is not a double");
95     return -1;
96   }
97 }
98
99 int surf_parse_get_int(std::string s)
100 {
101   try {
102     return std::stoi(s);
103   } catch (std::invalid_argument& ia) {
104     surf_parse_error(s + " is not a double");
105     return -1;
106   }
107 }
108
109 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
110 static std::vector<int>* explodesRadical(std::string radicals)
111 {
112   std::vector<int>* exploded = new std::vector<int>();
113
114   // Make all hosts
115   std::vector<std::string> radical_elements;
116   boost::split(radical_elements, radicals, boost::is_any_of(","));
117   for (auto const& group : radical_elements) {
118     std::vector<std::string> radical_ends;
119     boost::split(radical_ends, group, boost::is_any_of("-"));
120     int start = surf_parse_get_int(radical_ends.front());
121     int end   = 0;
122
123     switch (radical_ends.size()) {
124       case 1:
125         end = start;
126         break;
127       case 2:
128         end = surf_parse_get_int(radical_ends.back());
129         break;
130       default:
131         surf_parse_error(std::string("Malformed radical: ") + group);
132         break;
133     }
134     for (int i = start; i <= end; i++)
135       exploded->push_back(i);
136   }
137
138   return exploded;
139 }
140
141 struct unit_scale {
142   const char *unit;
143   double scale;
144 };
145
146 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
147 static double surf_parse_get_value_with_unit(const char* string, const struct unit_scale* units,
148                                              const char* entity_kind, std::string name, const char* error_msg,
149                                              const char* default_unit)
150 {
151   char* ptr;
152   int i;
153   errno = 0;
154   double res   = strtod(string, &ptr);
155   if (errno == ERANGE)
156     surf_parse_error(std::string("value out of range: ") + string);
157   if (ptr == string)
158     surf_parse_error(std::string("cannot parse number:") + string);
159   if (ptr[0] == '\0') {
160     if (res == 0)
161       return res; // Ok, 0 can be unit-less
162
163     XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
164     ptr = (char*)default_unit;
165   }
166   for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++);
167
168   if (units[i].unit != nullptr)
169     res *= units[i].scale;
170   else
171     surf_parse_error(std::string("unknown unit: ") + ptr);
172   return res;
173 }
174
175 double surf_parse_get_time(const char* string, const char* entity_kind, std::string name)
176 {
177   const struct unit_scale units[] = {
178     { "w",  7 * 24 * 60 * 60 },
179     { "d",  24 * 60 * 60 },
180     { "h",  60 * 60 },
181     { "m",  60 },
182     { "s",  1.0 },
183     { "ms", 1e-3 },
184     { "us", 1e-6 },
185     { "ns", 1e-9 },
186     { "ps", 1e-12 },
187     { nullptr, 0 }
188   };
189   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
190       "Append 's' to your time to get seconds", "s");
191 }
192
193 double surf_parse_get_size(const char* string, const char* entity_kind, std::string name)
194 {
195   const struct unit_scale units[] = {
196     { "EiB", pow(1024, 6) },
197     { "PiB", pow(1024, 5) },
198     { "TiB", pow(1024, 4) },
199     { "GiB", pow(1024, 3) },
200     { "MiB", pow(1024, 2) },
201     { "KiB", 1024 },
202     { "EB",  1e18 },
203     { "PB",  1e15 },
204     { "TB",  1e12 },
205     { "GB",  1e9 },
206     { "MB",  1e6 },
207     { "kB",  1e3 },
208     { "B",   1.0 },
209     { "Eib", 0.125 * pow(1024, 6) },
210     { "Pib", 0.125 * pow(1024, 5) },
211     { "Tib", 0.125 * pow(1024, 4) },
212     { "Gib", 0.125 * pow(1024, 3) },
213     { "Mib", 0.125 * pow(1024, 2) },
214     { "Kib", 0.125 * 1024 },
215     { "Eb",  0.125 * 1e18 },
216     { "Pb",  0.125 * 1e15 },
217     { "Tb",  0.125 * 1e12 },
218     { "Gb",  0.125 * 1e9 },
219     { "Mb",  0.125 * 1e6 },
220     { "kb",  0.125 * 1e3 },
221     { "b",   0.125 },
222     { nullptr,    0 }
223   };
224   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
225       "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
226 }
227
228 double surf_parse_get_bandwidth(const char* string, const char* entity_kind, std::string name)
229 {
230   const struct unit_scale units[] = {
231     { "EiBps", pow(1024, 6) },
232     { "PiBps", pow(1024, 5) },
233     { "TiBps", pow(1024, 4) },
234     { "GiBps", pow(1024, 3) },
235     { "MiBps", pow(1024, 2) },
236     { "KiBps", 1024 },
237     { "EBps",  1e18 },
238     { "PBps",  1e15 },
239     { "TBps",  1e12 },
240     { "GBps",  1e9 },
241     { "MBps",  1e6 },
242     { "kBps",  1e3 },
243     { "Bps",   1.0 },
244     { "Eibps", 0.125 * pow(1024, 6) },
245     { "Pibps", 0.125 * pow(1024, 5) },
246     { "Tibps", 0.125 * pow(1024, 4) },
247     { "Gibps", 0.125 * pow(1024, 3) },
248     { "Mibps", 0.125 * pow(1024, 2) },
249     { "Kibps", 0.125 * 1024 },
250     { "Tbps",  0.125 * 1e12 },
251     { "Gbps",  0.125 * 1e9 },
252     { "Mbps",  0.125 * 1e6 },
253     { "kbps",  0.125 * 1e3 },
254     { "bps",   0.125 },
255     { nullptr,    0 }
256   };
257   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
258       "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
259 }
260
261 double surf_parse_get_speed(const char* string, const char* entity_kind, std::string name)
262 {
263   const struct unit_scale units[] = {
264     { "yottaflops", 1e24 },
265     { "Yf",         1e24 },
266     { "zettaflops", 1e21 },
267     { "Zf",         1e21 },
268     { "exaflops",   1e18 },
269     { "Ef",         1e18 },
270     { "petaflops",  1e15 },
271     { "Pf",         1e15 },
272     { "teraflops",  1e12 },
273     { "Tf",         1e12 },
274     { "gigaflops",  1e9 },
275     { "Gf",         1e9 },
276     { "megaflops",  1e6 },
277     { "Mf",         1e6 },
278     { "kiloflops",  1e3 },
279     { "kf",         1e3 },
280     { "flops",      1.0 },
281     { "f",          1.0 },
282     { nullptr,         0 }
283   };
284   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
285       "Append 'f' or 'flops' to your speed to get flop per second", "f");
286 }
287
288 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, std::string id)
289 {
290
291   std::vector<double> speed_per_pstate;
292
293   if (strchr(speeds, ',') == nullptr){
294     double speed = surf_parse_get_speed(speeds, entity_kind, id);
295     speed_per_pstate.push_back(speed);
296   } else {
297     std::vector<std::string> pstate_list;
298     boost::split(pstate_list, speeds, boost::is_any_of(","));
299     for (auto speed_str : pstate_list) {
300       boost::trim(speed_str);
301       double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
302       speed_per_pstate.push_back(speed);
303       XBT_DEBUG("Speed value: %f", speed);
304     }
305   }
306   return speed_per_pstate;
307 }
308
309 /*
310  * All the callback lists that can be overridden anywhere.
311  * (this list should probably be reduced to the bare minimum to allow the models to work)
312  */
313
314 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
315
316 /* The default current property receiver. Setup in the corresponding opening callbacks. */
317 std::map<std::string, std::string>* current_property_set       = nullptr;
318 std::map<std::string, std::string>* current_model_property_set = nullptr;
319 int ZONE_TAG                            = 0; // Whether we just opened a zone tag (to see what to do with the properties)
320
321 YY_BUFFER_STATE surf_input_buffer;
322 FILE *surf_file_to_parse = nullptr;
323
324 /* Stuff relative to storage */
325 void STag_surfxml_storage()
326 {
327   ZONE_TAG = 0;
328   XBT_DEBUG("STag_surfxml_storage");
329   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
330 }
331
332 void ETag_surfxml_storage()
333 {
334   StorageCreationArgs storage;
335
336   storage.properties   = current_property_set;
337   current_property_set = nullptr;
338
339   storage.id           = A_surfxml_storage_id;
340   storage.type_id      = A_surfxml_storage_typeId;
341   storage.content      = A_surfxml_storage_content;
342   storage.attach       = A_surfxml_storage_attach;
343
344   sg_platf_new_storage(&storage);
345 }
346 void STag_surfxml_storage___type()
347 {
348   ZONE_TAG = 0;
349   XBT_DEBUG("STag_surfxml_storage___type");
350   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
351   xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
352 }
353 void ETag_surfxml_storage___type()
354 {
355   StorageTypeCreationArgs storage_type;
356
357   storage_type.properties = current_property_set;
358   current_property_set    = nullptr;
359
360   storage_type.model_properties = current_model_property_set;
361   current_model_property_set    = nullptr;
362
363   storage_type.content = A_surfxml_storage___type_content;
364   storage_type.id      = A_surfxml_storage___type_id;
365   storage_type.model   = A_surfxml_storage___type_model;
366   storage_type.size =
367       surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
368   sg_platf_new_storage_type(&storage_type);
369 }
370
371 void STag_surfxml_mount()
372 {
373   XBT_DEBUG("STag_surfxml_mount");
374 }
375
376 void ETag_surfxml_mount()
377 {
378   MountCreationArgs mount;
379
380   mount.name      = A_surfxml_mount_name;
381   mount.storageId = A_surfxml_mount_storageId;
382   sg_platf_new_mount(&mount);
383 }
384
385 /*
386  * Stuff relative to the <include> tag
387  */
388 static std::vector<YY_BUFFER_STATE> surf_input_buffer_stack;
389 static std::vector<FILE*> surf_file_to_parse_stack;
390 static std::vector<char*> surf_parsed_filename_stack;
391
392 void STag_surfxml_include()
393 {
394   XBT_ERROR("<include> tag is deprecated, and will be removed in SimGrid v3.18. Please stop using it now (or tell us why you need it).");
395   parse_after_config();
396   XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
397   surf_parsed_filename_stack.push_back(surf_parsed_filename); // save old file name
398   surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
399
400   surf_file_to_parse_stack.push_back(surf_file_to_parse); // save old file descriptor
401
402   surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
403   xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
404
405   surf_input_buffer_stack.push_back(surf_input_buffer);
406   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
407   surf_parse_push_buffer_state(surf_input_buffer);
408
409   fflush(nullptr);
410 }
411
412 void ETag_surfxml_include() {
413 /* Nothing to do when done with reading the include tag.
414  * Instead, the handling should be deferred until the EOF of current buffer -- see below */
415 }
416
417 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
418  *
419  * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
420  * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
421  * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
422  * error message in that case.
423  *
424  * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
425  * directly: a command line flag could instruct it to do the correct thing when the include directive is encountered
426  * on a line. One day maybe, if the maya allow it.
427  */
428 int ETag_surfxml_include_state()
429 {
430   fflush(nullptr);
431   XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
432
433   if (surf_input_buffer_stack.empty()) // nope, that's a true premature EOF. Let the parser die verbosely.
434     return 0;
435
436   // Yeah, we were in an <include> Restore state and proceed.
437   fclose(surf_file_to_parse);
438   surf_file_to_parse_stack.pop_back();
439   surf_parse_pop_buffer_state();
440   surf_input_buffer_stack.pop_back();
441
442   // Restore the filename for error messages
443   free(surf_parsed_filename);
444   surf_parsed_filename_stack.pop_back();
445
446   return 1;
447 }
448
449 /* Stag and Etag parse functions */
450
451 void STag_surfxml_platform() {
452   XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
453
454   xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
455       "You're using an ancient XML file.\n"
456       "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
457       "instead of MBytes, MFlops and seconds.\n"
458
459       "Use simgrid_update_xml to update your file automatically. "
460       "This program is installed automatically with SimGrid, or "
461       "available in the tools/ directory of the source archive.\n"
462
463       "Please check also out the SURF section of the ChangeLog for "
464       "the 3.1 version for more information. \n"
465
466       "Last, do not forget to also update your values for "
467       "the calls to MSG_task_create (if any).");
468   xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
469       "You're using an old XML file.\n"
470       "Use simgrid_update_xml to update your file automatically. "
471       "This program is installed automatically with SimGrid, or "
472       "available in the tools/ directory of the source archive.");
473   xbt_assert((version >= 4.0),
474              "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
475              "Changes introduced in SimGrid 3.13:\n"
476              "  - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
477              "  - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
478              "  - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
479              "  - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
480              "\n\n"
481              "Use simgrid_update_xml to update your file automatically. "
482              "This program is installed automatically with SimGrid, or "
483              "available in the tools/ directory of the source archive.",
484              surf_parsed_filename, version);
485   if (version < 4.1) {
486     XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
487              "That's fine, the new version is backward compatible. \n\n"
488              "Use simgrid_update_xml to update your file automatically. "
489              "This program is installed automatically with SimGrid, or "
490              "available in the tools/ directory of the source archive.",
491              version, surf_parsed_filename);
492   }
493   xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
494                              "The most recent formalism that this version of SimGrid understands is v4.1.\n"
495                              "Please update your code, or use another, more adapted, file.",
496              surf_parsed_filename, version);
497
498   sg_platf_begin();
499 }
500 void ETag_surfxml_platform(){
501   sg_platf_end();
502 }
503
504 void STag_surfxml_host(){
505   ZONE_TAG = 0;
506   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
507 }
508
509 void STag_surfxml_prop()
510 {
511   if (ZONE_TAG) { // We need to retrieve the most recently opened zone
512     XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
513     simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::getInstance()->getNetzoneByNameOrNull(A_surfxml_zone_id);
514
515     netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
516   } else {
517     if (not current_property_set)
518       current_property_set = new std::map<std::string, std::string>; // Maybe, it should raise an error
519     current_property_set->insert({A_surfxml_prop_id, A_surfxml_prop_value});
520     XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
521               current_property_set);
522   }
523 }
524
525 void ETag_surfxml_host()    {
526   s_sg_platf_host_cbarg_t host;
527   memset(&host,0,sizeof(host));
528
529   host.properties = current_property_set;
530   current_property_set = nullptr;
531
532   host.id = A_surfxml_host_id;
533
534   host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
535
536   XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
537   host.core_amount = surf_parse_get_int(A_surfxml_host_core);
538   host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
539   host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
540   host.pstate      = surf_parse_get_int(A_surfxml_host_pstate);
541   host.coord       = A_surfxml_host_coordinates;
542
543   sg_platf_new_host(&host);
544 }
545
546 void STag_surfxml_host___link(){
547   XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
548   HostLinkCreationArgs host_link;
549
550   host_link.id        = A_surfxml_host___link_id;
551   host_link.link_up   = A_surfxml_host___link_up;
552   host_link.link_down = A_surfxml_host___link_down;
553   sg_platf_new_hostlink(&host_link);
554 }
555
556 void STag_surfxml_router(){
557   sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
558 }
559
560 void ETag_surfxml_cluster(){
561   ClusterCreationArgs cluster;
562   cluster.properties   = current_property_set;
563   current_property_set = nullptr;
564
565   cluster.id          = A_surfxml_cluster_id;
566   cluster.prefix      = A_surfxml_cluster_prefix;
567   cluster.suffix      = A_surfxml_cluster_suffix;
568   cluster.radicals    = explodesRadical(A_surfxml_cluster_radical);
569   cluster.speeds      = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
570   cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
571   cluster.bw          = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
572   cluster.lat         = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
573   if(strcmp(A_surfxml_cluster_bb___bw,""))
574     cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
575   if(strcmp(A_surfxml_cluster_bb___lat,""))
576     cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
577   if(strcmp(A_surfxml_cluster_limiter___link,""))
578     cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
579   if(strcmp(A_surfxml_cluster_loopback___bw,""))
580     cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
581   if(strcmp(A_surfxml_cluster_loopback___lat,""))
582     cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
583
584   switch(AX_surfxml_cluster_topology){
585   case A_surfxml_cluster_topology_FLAT:
586     cluster.topology= SURF_CLUSTER_FLAT ;
587     break;
588   case A_surfxml_cluster_topology_TORUS:
589     cluster.topology= SURF_CLUSTER_TORUS ;
590     break;
591   case A_surfxml_cluster_topology_FAT___TREE:
592     cluster.topology = SURF_CLUSTER_FAT_TREE;
593     break;
594   case A_surfxml_cluster_topology_DRAGONFLY:
595     cluster.topology= SURF_CLUSTER_DRAGONFLY ;
596     break;
597   default:
598     surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
599     break;
600   }
601   cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
602   cluster.router_id = A_surfxml_cluster_router___id;
603
604   switch (AX_surfxml_cluster_sharing___policy) {
605   case A_surfxml_cluster_sharing___policy_SHARED:
606     cluster.sharing_policy = SURF_LINK_SHARED;
607     break;
608   case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
609     cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
610     break;
611   case A_surfxml_cluster_sharing___policy_FATPIPE:
612     cluster.sharing_policy = SURF_LINK_FATPIPE;
613     break;
614   default:
615     surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
616     break;
617   }
618   switch (AX_surfxml_cluster_bb___sharing___policy) {
619   case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
620     cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
621     break;
622   case A_surfxml_cluster_bb___sharing___policy_SHARED:
623     cluster.bb_sharing_policy = SURF_LINK_SHARED;
624     break;
625   default:
626     surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
627     break;
628   }
629
630   sg_platf_new_cluster(&cluster);
631 }
632
633 void STag_surfxml_cluster(){
634   ZONE_TAG = 0;
635   parse_after_config();
636   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
637 }
638
639 void STag_surfxml_cabinet(){
640   parse_after_config();
641   CabinetCreationArgs cabinet;
642   cabinet.id      = A_surfxml_cabinet_id;
643   cabinet.prefix  = A_surfxml_cabinet_prefix;
644   cabinet.suffix  = A_surfxml_cabinet_suffix;
645   cabinet.speed    = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id.c_str());
646   cabinet.bw       = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id.c_str());
647   cabinet.lat      = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id.c_str());
648   cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
649
650   sg_platf_new_cabinet(&cabinet);
651 }
652
653 void STag_surfxml_peer(){
654   parse_after_config();
655   PeerCreationArgs peer;
656
657   peer.id          = std::string(A_surfxml_peer_id);
658   peer.speed       = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str());
659   peer.bw_in       = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
660   peer.bw_out      = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
661   peer.coord       = A_surfxml_peer_coordinates;
662   peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
663   peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
664
665   if (A_surfxml_peer_lat[0] != '\0')
666     XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
667              A_surfxml_peer_lat);
668
669   sg_platf_new_peer(&peer);
670 }
671
672 void STag_surfxml_link(){
673   ZONE_TAG = 0;
674   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
675 }
676
677 void ETag_surfxml_link(){
678   LinkCreationArgs link;
679
680   link.properties          = current_property_set;
681   current_property_set     = nullptr;
682
683   link.id                  = std::string(A_surfxml_link_id);
684   link.bandwidth           = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
685   link.bandwidth_trace     = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
686   link.latency             = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
687   link.latency_trace       = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
688   link.state_trace         = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
689
690   switch (A_surfxml_link_sharing___policy) {
691   case A_surfxml_link_sharing___policy_SHARED:
692     link.policy = SURF_LINK_SHARED;
693     break;
694   case A_surfxml_link_sharing___policy_FATPIPE:
695      link.policy = SURF_LINK_FATPIPE;
696      break;
697   case A_surfxml_link_sharing___policy_FULLDUPLEX:
698      link.policy = SURF_LINK_FULLDUPLEX;
699      break;
700   default:
701     surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
702     break;
703   }
704
705   sg_platf_new_link(&link);
706 }
707
708 void STag_surfxml_link___ctn()
709 {
710   simgrid::surf::LinkImpl* link = nullptr;
711   switch (A_surfxml_link___ctn_direction) {
712   case AU_surfxml_link___ctn_direction:
713   case A_surfxml_link___ctn_direction_NONE:
714     link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
715     break;
716   case A_surfxml_link___ctn_direction_UP:
717     link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_UP");
718     break;
719   case A_surfxml_link___ctn_direction_DOWN:
720     link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_DOWN");
721     break;
722   default:
723     surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
724     break;
725   }
726
727   const char* dirname = "";
728   switch (A_surfxml_link___ctn_direction) {
729     case A_surfxml_link___ctn_direction_UP:
730       dirname = " (upward)";
731       break;
732     case A_surfxml_link___ctn_direction_DOWN:
733       dirname = " (downward)";
734       break;
735     default:
736       dirname = "";
737   }
738   surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
739   parsed_link_list.push_back(link);
740 }
741
742 void ETag_surfxml_backbone(){
743   LinkCreationArgs link;
744
745   link.properties = nullptr;
746   link.id = std::string(A_surfxml_backbone_id);
747   link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
748   link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
749   link.policy = SURF_LINK_SHARED;
750
751   sg_platf_new_link(&link);
752   routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
753 }
754
755 void STag_surfxml_route(){
756   surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
757   surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
758 }
759
760 void STag_surfxml_ASroute(){
761   surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
762   surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
763
764   surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
765   surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
766 }
767 void STag_surfxml_zoneRoute(){
768   surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
769   surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
770   surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
771   surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
772 }
773
774 void STag_surfxml_bypassRoute(){
775   surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
776   surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
777 }
778
779 void STag_surfxml_bypassASroute(){
780   surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
781   surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
782   surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
783   surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
784 }
785 void STag_surfxml_bypassZoneRoute(){
786   surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
787   surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
788   surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
789   surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
790 }
791
792 void ETag_surfxml_route(){
793   s_sg_platf_route_cbarg_t route;
794   memset(&route,0,sizeof(route));
795
796   route.src         = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
797   route.dst         = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
798   route.gw_src    = nullptr;
799   route.gw_dst    = nullptr;
800   route.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
801   route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
802
803   for (auto const& link : parsed_link_list)
804     route.link_list->push_back(link);
805   parsed_link_list.clear();
806
807   sg_platf_new_route(&route);
808   delete route.link_list;
809 }
810
811 void ETag_surfxml_ASroute()
812 {
813   AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
814   AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
815   AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
816   AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
817   AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
818   ETag_surfxml_zoneRoute();
819 }
820 void ETag_surfxml_zoneRoute()
821 {
822   s_sg_platf_route_cbarg_t ASroute;
823   memset(&ASroute,0,sizeof(ASroute));
824
825   ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
826   ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
827
828   ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
829   ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
830
831   ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
832
833   for (auto const& link : parsed_link_list)
834     ASroute.link_list->push_back(link);
835   parsed_link_list.clear();
836
837   switch (A_surfxml_zoneRoute_symmetrical) {
838   case AU_surfxml_zoneRoute_symmetrical:
839   case A_surfxml_zoneRoute_symmetrical_YES:
840     ASroute.symmetrical = true;
841     break;
842   case A_surfxml_zoneRoute_symmetrical_NO:
843     ASroute.symmetrical = false;
844     break;
845   }
846
847   sg_platf_new_route(&ASroute);
848   delete ASroute.link_list;
849 }
850
851 void ETag_surfxml_bypassRoute(){
852   s_sg_platf_route_cbarg_t route;
853   memset(&route,0,sizeof(route));
854
855   route.src         = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
856   route.dst         = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
857   route.gw_src = nullptr;
858   route.gw_dst = nullptr;
859   route.symmetrical = false;
860   route.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
861
862   for (auto const& link : parsed_link_list)
863     route.link_list->push_back(link);
864   parsed_link_list.clear();
865
866   sg_platf_new_bypassRoute(&route);
867   delete route.link_list;
868 }
869
870 void ETag_surfxml_bypassASroute()
871 {
872   AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
873   AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
874   AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
875   AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
876   ETag_surfxml_bypassZoneRoute();
877 }
878 void ETag_surfxml_bypassZoneRoute()
879 {
880   s_sg_platf_route_cbarg_t ASroute;
881   memset(&ASroute,0,sizeof(ASroute));
882
883   ASroute.src         = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
884   ASroute.dst         = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
885   ASroute.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
886   for (auto const& link : parsed_link_list)
887     ASroute.link_list->push_back(link);
888   parsed_link_list.clear();
889
890   ASroute.symmetrical = false;
891
892   ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
893   ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
894
895   sg_platf_new_bypassRoute(&ASroute);
896   delete ASroute.link_list;
897 }
898
899 void ETag_surfxml_trace(){
900   TraceCreationArgs trace;
901
902   trace.id = A_surfxml_trace_id;
903   trace.file = A_surfxml_trace_file;
904   trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
905   trace.pc_data = surfxml_pcdata;
906
907   sg_platf_new_trace(&trace);
908 }
909
910 void STag_surfxml_trace___connect()
911 {
912   parse_after_config();
913   TraceConnectCreationArgs trace_connect;
914
915   trace_connect.element = A_surfxml_trace___connect_element;
916   trace_connect.trace = A_surfxml_trace___connect_trace;
917
918   switch (A_surfxml_trace___connect_kind) {
919   case AU_surfxml_trace___connect_kind:
920   case A_surfxml_trace___connect_kind_SPEED:
921     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_SPEED;
922     break;
923   case A_surfxml_trace___connect_kind_BANDWIDTH:
924     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_BANDWIDTH;
925     break;
926   case A_surfxml_trace___connect_kind_HOST___AVAIL:
927     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
928     break;
929   case A_surfxml_trace___connect_kind_LATENCY:
930     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_LATENCY;
931     break;
932   case A_surfxml_trace___connect_kind_LINK___AVAIL:
933     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
934     break;
935   default:
936     surf_parse_error("Invalid trace kind");
937     break;
938   }
939   sg_platf_trace_connect(&trace_connect);
940 }
941
942 void STag_surfxml_AS()
943 {
944   AX_surfxml_zone_id = AX_surfxml_AS_id;
945   AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
946   STag_surfxml_zone();
947 }
948
949 void ETag_surfxml_AS()
950 {
951   ETag_surfxml_zone();
952 }
953
954 void STag_surfxml_zone()
955 {
956   parse_after_config();
957   ZONE_TAG                 = 1;
958   ZoneCreationArgs zone;
959   zone.id      = A_surfxml_zone_id;
960   zone.routing = static_cast<int>(A_surfxml_zone_routing);
961
962   sg_platf_new_Zone_begin(&zone);
963 }
964
965 void ETag_surfxml_zone()
966 {
967   sg_platf_new_Zone_seal();
968 }
969
970 void STag_surfxml_config()
971 {
972   ZONE_TAG = 0;
973   xbt_assert(current_property_set == nullptr,
974              "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
975   XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
976   if (_sg_cfg_init_status == 2) {
977     surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
978                      "<link>, etc).");
979   }
980 }
981
982 void ETag_surfxml_config()
983 {
984   for (auto const& elm : *current_property_set) {
985     if (xbt_cfg_is_default_value(elm.first.c_str())) {
986       std::string cfg = elm.first + ":" + elm.second;
987       xbt_cfg_set_parse(cfg.c_str());
988     } else
989       XBT_INFO("The custom configuration '%s' is already defined by user!", elm.first.c_str());
990   }
991   XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
992
993   delete current_property_set;
994   current_property_set = nullptr;
995 }
996
997 static int argc;
998 static char **argv;
999
1000 void STag_surfxml_process()
1001 {
1002   AX_surfxml_actor_function = AX_surfxml_process_function;
1003   STag_surfxml_actor();
1004 }
1005
1006 void STag_surfxml_actor()
1007 {
1008   ZONE_TAG  = 0;
1009   argc    = 1;
1010   argv    = xbt_new(char *, 1);
1011   argv[0] = xbt_strdup(A_surfxml_actor_function);
1012   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
1013 }
1014
1015 void ETag_surfxml_process()
1016 {
1017   AX_surfxml_actor_host = AX_surfxml_process_host;
1018   AX_surfxml_actor_function = AX_surfxml_process_function;
1019   AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
1020   AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
1021   AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
1022   ETag_surfxml_actor();
1023 }
1024
1025 void ETag_surfxml_actor()
1026 {
1027   s_sg_platf_process_cbarg_t actor;
1028   memset(&actor,0,sizeof(actor));
1029
1030   actor.properties     = current_property_set;
1031   current_property_set = nullptr;
1032
1033   actor.argc       = argc;
1034   actor.argv       = (const char **)argv;
1035   actor.host       = A_surfxml_actor_host;
1036   actor.function   = A_surfxml_actor_function;
1037   actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
1038   actor.kill_time  = surf_parse_get_double(A_surfxml_actor_kill___time);
1039
1040   switch (A_surfxml_actor_on___failure) {
1041   case AU_surfxml_actor_on___failure:
1042   case A_surfxml_actor_on___failure_DIE:
1043     actor.on_failure =  SURF_ACTOR_ON_FAILURE_DIE;
1044     break;
1045   case A_surfxml_actor_on___failure_RESTART:
1046     actor.on_failure =  SURF_ACTOR_ON_FAILURE_RESTART;
1047     break;
1048   default:
1049     surf_parse_error("Invalid on failure behavior");
1050     break;
1051   }
1052
1053   sg_platf_new_process(&actor);
1054
1055   for (int i = 0; i != argc; ++i)
1056     xbt_free(argv[i]);
1057   xbt_free(argv);
1058   argv = nullptr;
1059 }
1060
1061 void STag_surfxml_argument(){
1062   argc++;
1063   argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
1064   argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
1065 }
1066
1067 void STag_surfxml_model___prop(){
1068   if (not current_model_property_set)
1069     current_model_property_set = new std::map<std::string, std::string>();
1070
1071   current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
1072 }
1073
1074 void ETag_surfxml_prop(){/* Nothing to do */}
1075 void STag_surfxml_random(){/* Nothing to do */}
1076 void ETag_surfxml_random(){/* Nothing to do */}
1077 void ETag_surfxml_trace___connect(){/* Nothing to do */}
1078 void STag_surfxml_trace(){parse_after_config();}
1079 void ETag_surfxml_router(){/*Nothing to do*/}
1080 void ETag_surfxml_host___link(){/* Nothing to do */}
1081 void ETag_surfxml_cabinet(){/* Nothing to do */}
1082 void ETag_surfxml_peer(){/* Nothing to do */}
1083 void STag_surfxml_backbone(){/* Nothing to do */}
1084 void ETag_surfxml_link___ctn(){/* Nothing to do */}
1085 void ETag_surfxml_argument(){/* Nothing to do */}
1086 void ETag_surfxml_model___prop(){/* Nothing to do */}
1087
1088 /* Open and Close parse file */
1089 void surf_parse_open(const char *file)
1090 {
1091   xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
1092
1093   surf_parsed_filename = xbt_strdup(file);
1094   char* dir            = xbt_dirname(file);
1095   surf_path.push_back(std::string(dir));
1096   xbt_free(dir);
1097
1098   surf_file_to_parse = surf_fopen(file, "r");
1099   if (surf_file_to_parse == nullptr)
1100     xbt_die("Unable to open '%s'\n", file);
1101   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1102   surf_parse__switch_to_buffer(surf_input_buffer);
1103   surf_parse_lineno = 1;
1104 }
1105
1106 void surf_parse_close()
1107 {
1108   if (surf_parsed_filename) {
1109     surf_path.pop_back();
1110   }
1111
1112   free(surf_parsed_filename);
1113   surf_parsed_filename = nullptr;
1114
1115   if (surf_file_to_parse) {
1116     surf_parse__delete_buffer(surf_input_buffer);
1117     fclose(surf_file_to_parse);
1118     surf_file_to_parse = nullptr; //Must be reset for Bypass
1119   }
1120 }
1121
1122 /* Call the lexer to parse the currently opened file */
1123 int surf_parse()
1124 {
1125   return surf_parse_lex();
1126 }
1127 }