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]);*/
85 int main(int argc, char *argv[])
87 char *project_name = NULL;
88 char *deployment_file = NULL;
91 surf_init(&argc, argv);
92 process_function_set = xbt_dict_new();
93 process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
94 machine_set = xbt_dict_new();
96 for (i=1; i<argc; i++) {
98 if (!strncmp("--extra-process=",argv[i], strlen("--extra-process="))) {
99 xbt_dict_set(process_function_set, argv[i]+strlen("--extra-process="), NULL, NULL);
104 if (need_removal) { /* remove the handled argument from argv */
106 for (j=i+1; j<argc; j++) {
111 i--; /* compensate effect of next loop incrementation */
115 xbt_assert1((argc >= 3),"Usage: %s project_name deployment_file [deployment_file...]\n",argv[0]);
117 project_name = argv[1];
119 STag_surfxml_process_fun = parse_process_init;
120 ETag_surfxml_argument_fun = parse_argument;
121 ETag_surfxml_process_fun = parse_process_finalize;
123 for(i=2; i<argc; i++) {
124 deployment_file = argv[i];
125 surf_parse_open(deployment_file);
127 xbt_assert1(0,"Parse error in %s",deployment_file);
133 warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
134 sprintf(warning,WARN,deployment_file);
136 /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
137 xbt_dict_cursor_t cursor=NULL;
141 for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
142 xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
143 xbt_dict_cursor_step(cursor) ) {
144 DEBUG1("Function %s", key);
147 xbt_dict_dump(process_function_set,print);
150 generate_sim(project_name);
151 generate_rl(project_name);
152 generate_makefile_local(project_name, deployment_file);
154 generate_borland_simulation_project(project_name);
155 generate_borland_real_life_project(project_name);
156 generate_simulation_dsp_file(project_name);
157 generate_real_live_dsp_file(project_name);
160 xbt_free(__gras_path);