1 /* gras_stub_generator - creates the main() to use a GRAS program */
3 /* Copyright (c) 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 /* specific to Borland Compiler */
15 #include "xbt/sysdep.h"
16 #include "xbt/function_types.h"
18 #include "surf/surfxml_parse.h"
19 #include "surf/surf.h"
20 #include "portable.h" /* Needed for the time of the SIMIX convertion */
22 #include "gras_stub_generator.h"
25 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen, gras, "Stub generator");
31 /* specific to Borland Compiler */
37 /**********************************************/
38 /********* Parse XML deployment file **********/
39 /**********************************************/
40 xbt_dict_t process_function_set = NULL;
41 xbt_dynar_t process_list = NULL;
42 xbt_dict_t machine_set = NULL;
44 void s_process_free(void *process)
46 s_process_t *p = (s_process_t *) process;
48 for (i = 0; i < p->argc; i++)
54 static s_process_t process;
56 static void parse_process_init(void)
58 xbt_dict_set(process_function_set, A_surfxml_process_function, NULL,
60 xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
62 process.argv = xbt_new(char *, 1);
63 process.argv[0] = xbt_strdup(A_surfxml_process_function);
64 process.host = strdup(A_surfxml_process_host);
65 /*XBT_VERB("Function: %s",A_surfxml_process_function); */
68 static void parse_argument(void)
72 xbt_realloc(process.argv, (process.argc) * sizeof(char *));
73 process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
76 static void parse_process_finalize(void)
78 xbt_dynar_push(process_list, &process);
79 /*XBT_VERB("Function: %s",process.argv[0]); */
82 /*FIXME Defined in surfxml_parse.c*/
84 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
86 xbt_dynar_push(cb_list, &function);
91 int main(int argc, char *argv[])
93 char *project_name = NULL;
94 char *deployment_file = NULL;
97 surf_init(&argc, argv);
98 process_function_set = xbt_dict_new();
99 process_list = xbt_dynar_new(sizeof(s_process_t), s_process_free);
100 machine_set = xbt_dict_new();
102 for (i = 1; i < argc; i++) {
103 int need_removal = 0;
104 if (!strncmp("--extra-process=", argv[i], strlen("--extra-process="))) {
105 xbt_dict_set(process_function_set,
106 argv[i] + strlen("--extra-process="), NULL, NULL);
111 if (need_removal) { /* remove the handled argument from argv */
113 for (j = i + 1; j < argc; j++) {
114 argv[j - 1] = argv[j];
118 i--; /* compensate effect of next loop incrementation */
122 xbt_assert((argc >= 3),
123 "Usage: %s project_name deployment_file [deployment_file...]\n",
126 project_name = argv[1];
128 surf_parse_reset_callbacks();
129 XBT_DEBUG("%p %p", parse_process_init, &parse_process_init);
130 surfxml_add_callback(STag_surfxml_process_cb_list, &parse_process_init);
131 surfxml_add_callback(ETag_surfxml_argument_cb_list, &parse_argument);
132 surfxml_add_callback(ETag_surfxml_process_cb_list,
133 &parse_process_finalize);
135 for (i = 2; i < argc; i++) {
136 deployment_file = argv[i];
137 surf_parse_open(deployment_file);
139 xbt_die("Parse error in %s", deployment_file);
145 warning = xbt_new(char, strlen(WARN) + strlen(deployment_file) + 10);
146 sprintf(warning, WARN, deployment_file);
148 /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
149 xbt_dict_cursor_t cursor=NULL;
153 for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
154 xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
155 xbt_dict_cursor_step(cursor) ) {
156 XBT_DEBUG("Function %s", key);
159 xbt_dict_dump(process_function_set,print);
162 generate_sim(project_name);
163 generate_rl(project_name);
164 generate_makefile_local(project_name, deployment_file);
166 generate_borland_simulation_project(project_name);
167 generate_borland_real_life_project(project_name);
168 generate_simulation_dsp_file(project_name);
169 generate_real_live_dsp_file(project_name);
172 xbt_free(__gras_path);
177 xbt_dict_free(&process_function_set);
178 xbt_dynar_free(&process_list);
179 xbt_dict_free(&machine_set);