1 /* src/cacaoh/cacaoh.c - main for header generation (cacaoh)
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Reinhard Grafl
33 $Id: cacaoh.c 5809 2006-10-20 13:09:54Z twisti $
46 #include "cacaoh/headers.h"
48 #include "mm/memory.h"
49 #include "native/include/java_lang_Throwable.h"
51 #if defined(ENABLE_THREADS)
52 # include "threads/native/threads.h"
55 #include "toolbox/logging.h"
56 #include "vm/classcache.h"
57 #include "vm/exceptions.h"
58 #include "vm/global.h"
59 #include "vm/hashtable.h"
60 #include "vm/loader.h"
61 #include "vm/options.h"
62 #include "vm/statistics.h"
63 #include "vm/stringlocal.h"
67 /* define heap sizes **********************************************************/
69 #define HEAP_MAXSIZE 2 * 1024 * 1024 /* default 2MB */
70 #define HEAP_STARTSIZE 100 * 1024 /* default 100kB */
73 /* define cacaoh options ******************************************************/
88 { "help", false, OPT_HELP },
89 { "version", false, OPT_VERSION },
90 { "verbose", false, OPT_VERBOSE },
91 { "d", true, OPT_DIRECTORY },
92 { "classpath", true, OPT_CLASSPATH },
93 { "bootclasspath", true, OPT_BOOTCLASSPATH },
98 /* usage ***********************************************************************
100 Obviously prints usage information of cacaoh.
102 *******************************************************************************/
104 static void usage(void)
106 printf("Usage: cacaoh [options] <classes>\n"
109 " -help Print this message\n"
110 " -classpath <path> \n"
111 " -bootclasspath <path> \n"
112 " -d <dir> Output directory\n"
113 " -version Print version information\n"
114 " -verbose Enable verbose output\n");
116 /* exit with error code */
122 /* version *********************************************************************
124 Prints cacaoh version information.
126 *******************************************************************************/
128 static void version(void)
130 printf("cacaoh version "VERSION"\n");
131 printf("Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,\n");
132 printf("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,\n");
133 printf("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,\n");
134 printf("J. Wenninger, Institut f. Computersprachen - TU Wien\n\n");
136 printf("This program is free software; you can redistribute it and/or\n");
137 printf("modify it under the terms of the GNU General Public License as\n");
138 printf("published by the Free Software Foundation; either version 2, or (at\n");
139 printf("your option) any later version.\n\n");
141 printf("This program is distributed in the hope that it will be useful, but\n");
142 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
143 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
144 printf("General Public License for more details.\n");
150 /* forward declarations *******************************************************/
152 static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv);
155 /* main ************************************************************************
159 *******************************************************************************/
161 int main(int argc, char **argv)
163 JavaVMInitArgs *vm_args;
169 /********** internal (only used by main) *****************************/
182 #if defined(DISABLE_GC)
183 nogc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
186 /* set the bootclasspath */
188 cp = getenv("BOOTCLASSPATH");
191 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
192 strcpy(bootclasspath, cp);
195 cplen = strlen(CACAO_VM_ZIP) +
197 strlen(CLASSPATH_GLIBJ_ZIP) +
200 bootclasspath = MNEW(char, cplen);
201 strcat(bootclasspath, CACAO_VM_ZIP);
202 strcat(bootclasspath, ":");
203 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP);
207 /* set the classpath */
209 cp = getenv("CLASSPATH");
212 classpath = MNEW(char, strlen(cp) + strlen("0"));
213 strcat(classpath, cp);
216 classpath = MNEW(char, strlen(".") + strlen("0"));
217 strcpy(classpath, ".");
221 /* initialize options with default values */
224 opt_directory = NULL;
226 heapmaxsize = HEAP_MAXSIZE;
227 heapstartsize = HEAP_STARTSIZE;
230 /* parse the options ******************************************************/
232 vm_args = cacaoh_options_prepare(argc, argv);
234 while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
244 /* forget old classpath and set the argument as new classpath */
245 MFREE(classpath, char, strlen(classpath));
247 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
248 strcpy(classpath, opt_arg);
251 case OPT_BOOTCLASSPATH:
252 /* Forget default bootclasspath and set the argument as
253 new boot classpath. */
254 MFREE(bootclasspath, char, strlen(bootclasspath));
256 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
257 strcpy(bootclasspath, opt_arg);
261 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
262 strcpy(opt_directory, opt_arg);
280 /**************************** Program start **************************/
284 log_text("Java - header-generator started");
287 #if defined(ENABLE_THREADS)
288 /* pre-initialize some core thread stuff, like the stopworldlock,
289 thus this has to happen _before_ gc_init()!!! */
294 /* initialize the garbage collector */
296 gc_init(heapmaxsize, heapstartsize);
298 /* initialize the string hashtable stuff: lock (must be done
299 _after_ threads_preinit) */
302 throw_main_exception_exit();
304 /* initialize the utf8 hashtable stuff: lock, often used utf8 strings
305 (must be done _after_ threads_preinit) */
308 throw_main_exception_exit();
310 /* initialize the classcache hashtable stuff: lock, hashtable
311 (must be done _after_ threads_preinit) */
313 if (!classcache_init())
314 throw_main_exception_exit();
316 /* initialize the loader with bootclasspath (must be done _after_
320 throw_main_exception_exit();
322 suck_add(bootclasspath);
324 /* Also add the normal classpath, so the bootstrap class loader
325 can find the files. */
329 /* initialize the loader subsystems (must be done _after_
333 throw_main_exception_exit();
336 /* load Java classes ******************************************************/
338 for (i = opt_index; i < vm_args->nOptions; i++) {
339 cp = vm_args->options[i].optionString;
341 /* convert classname */
343 for (j = strlen(cp) - 1; j >= 0; j--) {
354 /* exceptions are catched with new_exception call */
356 if (!(c = load_class_bootstrap(utf_new_char(cp))))
357 throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
361 throw_cacao_exception_exit(string_java_lang_LinkageError,
364 headerfile_generate(c, opt_directory);
367 /************************ Release all resources **********************/
372 log_text("Java - header-generator stopped");
373 #if defined(ENABLE_STATISTICS)
382 /* cacaoh_options_prepare ******************************************************
384 Prepare the JavaVMInitArgs.
386 *******************************************************************************/
388 static JavaVMInitArgs *cacaoh_options_prepare(int argc, char **argv)
390 JavaVMInitArgs *vm_args;
393 vm_args = NEW(JavaVMInitArgs);
395 vm_args->nOptions = argc - 1;
396 vm_args->options = MNEW(JavaVMOption, argc);
398 for (i = 1; i < argc; i++)
399 vm_args->options[i - 1].optionString = argv[i];
406 * These are local overrides for various environment variables in Emacs.
407 * Please do not remove this and leave it at the end of the file, where
408 * Emacs will automagically detect them.
409 * ---------------------------------------------------------------------
412 * indent-tabs-mode: t