Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove gras from the main documentation
[simgrid.git] / tools / gras / stub_generator.c
1 /* gras_stub_generator - creates the main() to use a GRAS program           */
2
3 /* Copyright (c) 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
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. */
8
9 /* specific to Borland Compiler */
10 #ifdef __BORLANDDC__
11 #pragma hdrstop
12 #endif
13
14 #include <stdio.h>
15 #include "xbt/sysdep.h"
16 #include "xbt/function_types.h"
17 #include "xbt/log.h"
18 #include "surf/surfxml_parse.h"
19 #include "surf/surf.h"
20 #include "portable.h"           /* Needed for the time of the SIMIX convertion */
21
22 #include "gras_stub_generator.h"
23 #include <stdarg.h>
24 XBT_PUBLIC(char*)xbt_binary_name;
25
26 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen, gras, "Stub generator");
27
28 #ifdef _XBT_WIN32
29 #include <windows.h>
30 #endif
31
32 /* specific to Borland Compiler */
33 #ifdef __BORLANDDC__
34 #pragma argsused
35 #endif
36
37
38 /**********************************************/
39 /********* Parse XML deployment file **********/
40 /**********************************************/
41 xbt_dict_t process_function_set = NULL;
42 xbt_dynar_t process_list = NULL;
43 xbt_dict_t machine_set = NULL;
44 char *warning = NULL;
45
46 void s_process_free(void *process)
47 {
48   s_process_t *p = (s_process_t *) process;
49   free(p->host);
50 }
51
52 static s_process_t process;
53
54 static void parse_process(sg_platf_process_cbarg_t process_arg)
55 {
56   xbt_dict_set(process_function_set, process_arg->function, NULL, NULL);
57   xbt_dict_set(machine_set, process_arg->host, NULL, NULL);
58   process.argc = process_arg->argc;
59   process.argv = (char**)(process_arg->argv);
60   process.host = strdup(process_arg->host);
61   /*XBT_VERB("Function: %s",A_surfxml_process_function); */
62   xbt_dynar_push(process_list, &process);
63 }
64
65 int main(int argc, char *argv[])
66 {
67   char *project_name = NULL;
68   char *deployment_file = NULL;
69   int i;
70
71   XBT_LOG_CONNECT(stubgen);
72
73   xbt_binary_name=xbt_strdup(argv[0]);
74
75   surf_init(&argc, argv);
76   process_function_set = xbt_dict_new_homogeneous(NULL);
77   process_list = xbt_dynar_new(sizeof(s_process_t), s_process_free);
78   machine_set = xbt_dict_new_homogeneous(NULL);
79
80   for (i = 1; i < argc; i++) {
81     int need_removal = 0;
82     if (!strncmp("--extra-process=", argv[i], strlen("--extra-process="))) {
83       xbt_dict_set(process_function_set,
84                    argv[i] + strlen("--extra-process="), NULL, NULL);
85       need_removal = 1;
86     }
87
88
89     if (need_removal) {         /* remove the handled argument from argv */
90       int j;
91       for (j = i + 1; j < argc; j++) {
92         argv[j - 1] = argv[j];
93       }
94       argv[j - 1] = NULL;
95       argc--;
96       i--;                      /* compensate effect of next loop incrementation */
97     }
98   }
99
100   xbt_assert((argc >= 3),
101               "Usage: %s project_name deployment_file [deployment_file...]\n",
102               argv[0]);
103
104   project_name = argv[1];
105
106   surf_parse_reset_callbacks();
107   sg_platf_process_add_cb(parse_process);
108
109   for (i = 2; i < argc; i++) {
110     deployment_file = argv[i];
111     surf_parse_open(deployment_file);
112     if (surf_parse())
113       xbt_die("Parse error in %s", deployment_file);
114
115     surf_parse_close();
116   }
117
118
119   warning = xbt_new(char, strlen(WARN) + strlen(deployment_file) + 10);
120   sprintf(warning, WARN, deployment_file);
121
122   /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
123      xbt_dict_cursor_t cursor=NULL;
124      char *key = NULL;
125      void *data = NULL;
126
127      for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
128      xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
129      xbt_dict_cursor_step(cursor) ) {
130      XBT_DEBUG("Function %s", key);
131      }
132
133      xbt_dict_dump(process_function_set,print);
134      } */
135
136   generate_sim(project_name);
137   generate_rl(project_name);
138   generate_makefile_local(project_name, deployment_file);
139 #ifdef __BORLANDC__
140   generate_borland_simulation_project(project_name);
141   generate_borland_real_life_project(project_name);
142   generate_simulation_dsp_file(project_name);
143   generate_real_live_dsp_file(project_name);
144
145   xbt_free(__gras_path);
146 #endif
147
148   free(warning);
149
150
151   xbt_free(process.argv);
152
153   xbt_dict_free(&process_function_set);
154   xbt_dynar_free(&process_list);
155   xbt_dict_free(&machine_set);
156   surf_exit();
157
158   return 0;
159 }