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"
24 XBT_PUBLIC(char*)xbt_binary_name;
26 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen, gras, "Stub generator");
32 /* specific to Borland Compiler */
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;
46 void s_process_free(void *process)
48 s_process_t *p = (s_process_t *) process;
52 static s_process_t process;
54 static void parse_process(sg_platf_process_cbarg_t process_arg)
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);
65 int main(int argc, char *argv[])
67 char *project_name = NULL;
68 char *deployment_file = NULL;
71 XBT_LOG_CONNECT(stubgen);
73 xbt_binary_name=xbt_strdup(argv[0]);
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);
80 for (i = 1; i < argc; i++) {
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);
89 if (need_removal) { /* remove the handled argument from argv */
91 for (j = i + 1; j < argc; j++) {
92 argv[j - 1] = argv[j];
96 i--; /* compensate effect of next loop incrementation */
100 xbt_assert((argc >= 3),
101 "Usage: %s project_name deployment_file [deployment_file...]\n",
104 project_name = argv[1];
106 surf_parse_reset_callbacks();
107 sg_platf_process_add_cb(parse_process);
109 for (i = 2; i < argc; i++) {
110 deployment_file = argv[i];
111 surf_parse_open(deployment_file);
113 xbt_die("Parse error in %s", deployment_file);
119 warning = xbt_new(char, strlen(WARN) + strlen(deployment_file) + 10);
120 sprintf(warning, WARN, deployment_file);
122 /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
123 xbt_dict_cursor_t cursor=NULL;
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);
133 xbt_dict_dump(process_function_set,print);
136 generate_sim(project_name);
137 generate_rl(project_name);
138 generate_makefile_local(project_name, deployment_file);
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);
145 xbt_free(__gras_path);
151 xbt_free(process.argv);
153 xbt_dict_free(&process_function_set);
154 xbt_dynar_free(&process_list);
155 xbt_dict_free(&machine_set);