3 /* gras_stub_generator - creates the main() to use a GRAS program */
5 /* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier. */
6 /* All rights reserved. */
8 /* This program is free software; you can redistribute it and/or modify it
9 * under the terms of the license (GNU LGPL) which comes with this package. */
11 /* specific to Borland Compiler */
17 #include "xbt/sysdep.h"
18 #include "xbt/function_types.h"
20 #include "surf/surfxml_parse.h"
21 #include "surf/surf.h"
22 #include "portable.h" /* Needed for the time of the SIMIX convertion */
24 #include "gras_stub_generator.h"
29 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen,gras,"Stub generator");
36 /* specific to Borland Compiler */
42 /**********************************************/
43 /********* Parse XML deployment file **********/
44 /**********************************************/
45 xbt_dict_t process_function_set = NULL;
46 xbt_dynar_t process_list = NULL;
47 xbt_dict_t machine_set = NULL;
49 void s_process_free(void *process) {
50 s_process_t*p = (s_process_t*)process;
52 for (i=0; i<p->argc ; i++)
58 static s_process_t process;
60 static void parse_process_init(void)
62 xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL);
63 xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
65 process.argv = xbt_new(char*,1);
66 process.argv[0] = xbt_strdup(A_surfxml_process_function);
67 process.host=strdup(A_surfxml_process_host);
68 /*VERB1("Function: %s",A_surfxml_process_function);*/
71 static void parse_argument(void)
74 process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *));
75 process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
78 static void parse_process_finalize(void)
80 xbt_dynar_push(process_list,&process);
81 /*VERB1("Function: %s",process.argv[0]);*/
84 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
86 xbt_dynar_push(cb_list, &function);
90 int main(int argc, char *argv[])
92 char *project_name = NULL;
93 char *deployment_file = NULL;
96 surf_init(&argc, argv);
97 process_function_set = xbt_dict_new();
98 process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
99 machine_set = xbt_dict_new();
101 for (i=1; i<argc; i++) {
102 int need_removal = 0;
103 if (!strncmp("--extra-process=",argv[i], strlen("--extra-process="))) {
104 xbt_dict_set(process_function_set, argv[i]+strlen("--extra-process="), NULL, NULL);
109 if (need_removal) { /* remove the handled argument from argv */
111 for (j=i+1; j<argc; j++) {
116 i--; /* compensate effect of next loop incrementation */
120 xbt_assert1((argc >= 3),"Usage: %s project_name deployment_file [deployment_file...]\n",argv[0]);
122 project_name = argv[1];
124 surf_parse_reset_parser();
125 DEBUG2("%p %p",parse_process_init,&parse_process_init);
126 surfxml_add_callback(STag_surfxml_process_cb_list, &parse_process_init);
127 surfxml_add_callback(ETag_surfxml_argument_cb_list, &parse_argument);
128 surfxml_add_callback(ETag_surfxml_process_cb_list, &parse_process_finalize);
130 for(i=2; i<argc; i++) {
131 deployment_file = argv[i];
132 surf_parse_open(deployment_file);
134 xbt_assert1(0,"Parse error in %s",deployment_file);
140 warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
141 sprintf(warning,WARN,deployment_file);
143 /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
144 xbt_dict_cursor_t cursor=NULL;
148 for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
149 xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
150 xbt_dict_cursor_step(cursor) ) {
151 DEBUG1("Function %s", key);
154 xbt_dict_dump(process_function_set,print);
157 generate_sim(project_name);
158 generate_rl(project_name);
159 generate_makefile_local(project_name, deployment_file);
161 generate_borland_simulation_project(project_name);
162 generate_borland_real_life_project(project_name);
163 generate_simulation_dsp_file(project_name);
164 generate_real_live_dsp_file(project_name);
167 xbt_free(__gras_path);