1 /* $Id: stub_generator.c 6309 2009-05-26 15:29:22Z mquinson $ */
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)
51 s_process_t *p = (s_process_t *) process;
53 for (i = 0; i < p->argc; i++)
59 static s_process_t process;
61 static void parse_process_init(void)
63 xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL);
64 xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
66 process.argv = xbt_new(char *, 1);
67 process.argv[0] = xbt_strdup(A_surfxml_process_function);
68 process.host = strdup(A_surfxml_process_host);
69 /*VERB1("Function: %s",A_surfxml_process_function); */
72 static void parse_argument(void)
75 process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *));
76 process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
79 static void parse_process_finalize(void)
81 xbt_dynar_push(process_list, &process);
82 /*VERB1("Function: %s",process.argv[0]); */
85 /*void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
87 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, argv[i] + strlen("--extra-process="),
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_assert1((argc >= 3),
123 "Usage: %s project_name deployment_file [deployment_file...]\n",
126 project_name = argv[1];
128 surf_parse_reset_parser();
129 DEBUG2("%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, &parse_process_finalize);
134 for (i = 2; i < argc; i++) {
135 deployment_file = argv[i];
136 surf_parse_open(deployment_file);
138 xbt_assert1(0, "Parse error in %s", deployment_file);
144 warning = xbt_new(char, strlen(WARN) + strlen(deployment_file) + 10);
145 sprintf(warning, WARN, deployment_file);
147 /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
148 xbt_dict_cursor_t cursor=NULL;
152 for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
153 xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
154 xbt_dict_cursor_step(cursor) ) {
155 DEBUG1("Function %s", key);
158 xbt_dict_dump(process_function_set,print);
161 generate_sim(project_name);
162 generate_rl(project_name);
163 generate_makefile_local(project_name, deployment_file);
165 generate_borland_simulation_project(project_name);
166 generate_borland_real_life_project(project_name);
167 generate_simulation_dsp_file(project_name);
168 generate_real_live_dsp_file(project_name);
171 xbt_free(__gras_path);