X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d6ad35ac6e43974e007dc2f81978e669c206d740..b8892821525cf5204c842476d26f530ddcca4908:/tools/gras/stub_generator.c diff --git a/tools/gras/stub_generator.c b/tools/gras/stub_generator.c index eb5de727f0..fbba2fffb3 100644 --- a/tools/gras/stub_generator.c +++ b/tools/gras/stub_generator.c @@ -2,339 +2,145 @@ /* gras_stub_generator - creates the main() to use a GRAS program */ -/* Copyright (c) 2003,2004,2005 Martin Quinson, Arnaud Legrand. - All rights reserved. */ +/* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier. */ +/* All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include"xbt/sysdep.h" -#include"xbt/dict.h" -#include"xbt/error.h" -#include "surf/surf_parse.h" +/* specific to Borland Compiler */ +#ifdef __BORLANDDC__ +#pragma hdrstop +#endif + +#include +#include "xbt/sysdep.h" +#include "xbt/function_types.h" +#include "xbt/log.h" +#include "surf/surfxml_parse.h" #include "surf/surf.h" +#include "portable.h" /* Needed for the time of the SIMIX convertion */ -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen,gras,"Stub generator"); +#include "gras_stub_generator.h" +#include -#define WARN "/***********\n * DO NOT EDIT! THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM %s BY gras_stub_generator\n ***********/\n" -#define SIM_SOURCENAME "_%s_simulator.c" -#define SIM_OBJNAME "_%s_simulator.o" -#define SIM_BINARYNAME "%s_simulator" -#define SIM_SOURCENAME_LDADD "%s_simulator_LDADD" -#define SIM_SOURCENAME_SOURCES "%s_simulator_SOURCES" -#define RL_SOURCENAME "_%s_%s.c" -#define RL_OBJNAME "_%s_%s.o" -#define RL_BINARYNAME "%s_%s" -#define RL_SOURCENAME_LDADD "%s_%s_LDADD" -#define RL_SOURCENAME_SOURCES "%s_%s_SOURCES" -#define MAKEFILE_FILENAME_AM "%s.Makefile.am" -#define MAKEFILE_FILENAME_LOCAL "%s.Makefile.local" -#define MAKEFILE_FILENAME_REMOTE "%s.Makefile.remote" - -char *warning = NULL; -/**********************************************/ -/**** Generate the file for the simulator *****/ -/**********************************************/ -const char *SIM_PREEMBULE = -"#include \n" -"#include \n" -"#include \"msg/msg.h\"\n" -"#include \n" -"\n" -"char *gras_log=NULL;\n"; - - -#define SIM_LAUNCH_FUNC \ -"int launch_%s(int argc, char **argv) {\n" \ -" char **myargv=argv;\n" \ -" int myargc=argc;\n" \ -" int i;\n" \ -" int retcode;\n"\ -" \n"\ -" if (gras_log) {\n"\ -" myargv=malloc((argc+1) * sizeof(char**));\n" \ -" for (i=0; i\n" \ -"#include \n" \ -"#include \n" \ -"\n" \ -"/* user code */\n" \ -"int %s(int argc, char *argv[]);\n" \ -"\n" \ -"int main(int argc, char *argv[]){\n" \ -" int errcode;\n" \ -"\n" \ -" errcode=%s(argc,argv);\n"\ -" \n" \ -" return errcode;\n"\ -"}\n" +#ifdef _WIN32 +#include +#endif + +/* specific to Borland Compiler */ +#ifdef __BORLANDDC__ +#pragma argsused +#endif + /**********************************************/ /********* Parse XML deployment file **********/ /**********************************************/ xbt_dict_t process_function_set = NULL; - -static void parse_process_init(void) -{ - void *p = (void *) 1234; - xbt_dict_set(process_function_set, A_process_function, p, NULL); +xbt_dynar_t process_list = NULL; +xbt_dict_t machine_set = NULL; + +void s_process_free(void *process) { + s_process_t*p = (s_process_t*)process; + int i; + for (i=0; iargc ; i++) + free(p->argv[i]); + free(p->argv); + free(p->host); } -static void generate_sim(char *project) -{ - xbt_dict_cursor_t cursor=NULL; - char *key = NULL; - void *data = NULL; - char *filename = NULL; - FILE *OUT = NULL; - filename = xbt_new(char,strlen(project) + strlen(SIM_SOURCENAME)); - sprintf(filename,SIM_SOURCENAME,project); - - OUT=fopen(filename,"w"); - xbt_assert1(OUT, "Unable to open %s for writing",filename); - - fprintf(OUT, "%s\n",warning); - fprintf(OUT, "%s", SIM_PREEMBULE); - xbt_dict_foreach(process_function_set,cursor,key,data) { - fprintf(OUT,"int %s(int argc,char *argv[]);\n",key); - } - fprintf(OUT,"\n"); - xbt_dict_foreach(process_function_set,cursor,key,data) { - fprintf(OUT,"int launch_%s(int argc,char *argv[]);\n",key); - } - fprintf(OUT, "\n%s\n",warning); - xbt_dict_foreach(process_function_set,cursor,key,data) { - fprintf(OUT,SIM_LAUNCH_FUNC,key,key); - } - fprintf(OUT, "\n%s\n",warning); - - fprintf(OUT, "%s", SIM_MAIN_PREEMBULE); - xbt_dict_foreach(process_function_set,cursor,key,data) { - fprintf(OUT," MSG_function_register(\"%s\", launch_%s);\n",key,key); - } - fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE); - fclose(OUT); - free(filename); -} +static s_process_t process; -static void generate_rl(char *project) +static void parse_process_init(void) { - xbt_dict_cursor_t cursor=NULL; - char *key = NULL; - void *data = NULL; - char *filename = NULL; - FILE *OUT = NULL; - - xbt_dict_foreach(process_function_set,cursor,key,data) { - filename = xbt_new(char,strlen(project) + strlen(RL_SOURCENAME) + strlen(key)); - sprintf(filename,RL_SOURCENAME,project,key); - - OUT=fopen(filename,"w"); - xbt_assert1(OUT, "Unable to open %s for writing",filename); - - fprintf(OUT, "\n%s\n",warning); - fprintf(OUT, RL_CODE, key,key); - fprintf(OUT, "\n%s\n",warning); - fclose(OUT); - free(filename); - } + xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL); + xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL); + process.argc = 1 ; + process.argv = xbt_new(char*,1); + process.argv[0] = xbt_strdup(A_surfxml_process_function); + process.host=strdup(A_surfxml_process_host); + /*VERB1("Function: %s",A_surfxml_process_function);*/ } -static void generate_makefile_am(char *project, char *deployment) +static void parse_argument(void) { - xbt_dict_cursor_t cursor=NULL; - char *key = NULL; - void *data = NULL; - char *filename = NULL; - FILE *OUT = NULL; - - filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_AM)); - sprintf(filename,MAKEFILE_FILENAME_AM, project); - - OUT=fopen(filename,"w"); - xbt_assert1(OUT, "Unable to open %s for writing",filename); - - fprintf(OUT, "# AUTOMAKE variable definition\n"); - fprintf(OUT, "INCLUDES= @CFLAGS_SimGrid@\n\n"); - fprintf(OUT, "PROGRAMS="); - fprintf(OUT, SIM_BINARYNAME,project); - - xbt_dict_foreach(process_function_set,cursor,key,data) { - fprintf(OUT, " "); - fprintf(OUT, RL_BINARYNAME, project, key); - } - - fprintf(OUT, "\n\n"); - fprintf(OUT, SIM_SOURCENAME_SOURCES,project); - fprintf(OUT, "=\t"); - fprintf(OUT, SIM_SOURCENAME,project); - fprintf(OUT, " %s.c\n", project); - fprintf(OUT, SIM_SOURCENAME_LDADD, project); - fprintf(OUT, "=\tpath/to/libsimgrid.a\n\n"); - - xbt_dict_foreach(process_function_set,cursor,key,data) { - fprintf(OUT, RL_SOURCENAME_SOURCES, project,key); - fprintf(OUT, "=\t"); - fprintf(OUT, RL_SOURCENAME, project,key); - fprintf(OUT, " %s.c\n", project); - fprintf(OUT, RL_SOURCENAME_LDADD, project, key); - fprintf(OUT, "=\tpath/to/libgras.a\n\n"); - } - - fprintf(OUT, "\n# cleanup temps\n"); - fprintf(OUT, "CLEANFILES= "); - fprintf(OUT, SIM_SOURCENAME, project); - - xbt_dict_foreach(process_function_set,cursor,key,data) { - fprintf(OUT, " "); - fprintf(OUT, RL_SOURCENAME, project,key); - } - fprintf(OUT, "\n"); - - fprintf(OUT, "\n# generate temps\n"); - fprintf(OUT, "\n# A rule to generate the source file each time the deployment file changes\n"); - - xbt_dict_foreach(process_function_set,cursor,key,data) { - fprintf(OUT, RL_SOURCENAME, project,key); - fprintf(OUT, " "); - } - fprintf(OUT, SIM_SOURCENAME, project); - fprintf(OUT, ": %s\n", deployment); - fprintf(OUT, "\tstub_generator %s %s >/dev/null\n", project, deployment); - fclose(OUT); + process.argc++; + process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *)); + process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value); } - -static void generate_makefile(char *project, char *deployment) +static void parse_process_finalize(void) { - xbt_dict_cursor_t cursor=NULL; - char *key = NULL; - void *data = NULL; - char *filename = NULL; - FILE *OUT = NULL; - - filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL)); - sprintf(filename,MAKEFILE_FILENAME_LOCAL, project); - - OUT=fopen(filename,"w"); - xbt_assert1(OUT, "Unable to open %s for writing",filename); - - fprintf(OUT, "PROJECT_NAME=%s\n",project); - fprintf(OUT, - "DISTDIR=gras-$(PROJECT_NAME)\n\n" - "SIMGRID_INSTALL_PATH?= $(shell echo \"\\\"<<<< SIMGRID_INSTALL_PATH undefined !!! >>>>\\\"\")\n" - "CFLAGS = -O3 -w\n" - "INCLUDES = -I$(SIMGRID_INSTALL_PATH)/include\n" - "LIBS = -lm -L$(SIMGRID_INSTALL_PATH)/lib/ -lsimgrid\n" - "\n" - "C_FILES = _chrono_multiplier.c _chrono_simulator.c chrono.c\n" - "BIN_FILES = chrono_multiplier chrono_simulator\n" - "\n" - "all: $(BIN_FILES)\n" - "\n"); - fprintf(OUT, SIM_BINARYNAME ": " SIM_OBJNAME " %s.c\n",project, project, project); - xbt_dict_foreach(process_function_set,cursor,key,data) { - fprintf(OUT, RL_BINARYNAME " : " RL_OBJNAME " %s.c\n", project, key, project, key, project); - } - fprintf(OUT, - "\n" - "%%: %%.o\n" - "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ \n" - "\n" - "%%.o: %%.c\n" - "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<\n" - "\n" - "distdir: $(C_FILES) $(PROJECT_NAME).Makefile\n" - "\trm -rf $(DISTDIR)\n" - "\tmkdir -p $(DISTDIR)\n" - "\tcp $^ $(DISTDIR)\n" - "\n" - "dist: clean distdir\n" - "\ttar c $(DISTDIR) | gzip -c > $(DISTDIR).tar.gz\n" - "\n" - "clean:\n" - "\trm -f $(BIN_FILES) *.o *~\n" - "\trm -rf $(DISTDIR)\n" - "\n" - ".SUFFIXES:\n" - ".PHONY : clean\n"); - fclose(OUT); + xbt_dynar_push(process_list,&process); + /*VERB1("Function: %s",process.argv[0]);*/ } -static void print(void *p) +void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function) { - printf("%p",p); + xbt_dynar_push(cb_list, &function); } + int main(int argc, char *argv[]) { char *project_name = NULL; char *deployment_file = NULL; - + int i; + surf_init(&argc, argv); - - xbt_assert1((argc ==3),"Usage: %s project_name deployment_file\n",argv[0]); + process_function_set = xbt_dict_new(); + process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free); + machine_set = xbt_dict_new(); + + for (i=1; i