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 4357 2006-01-22 23:33:38Z twisti $
46 #include "cacaoh/headers.h"
48 #include "mm/memory.h"
49 #include "native/include/java_lang_Throwable.h"
51 #if defined(USE_THREADS)
52 # if defined(NATIVE_THREADS)
53 # include "threads/native/threads.h"
55 # include "threads/green/threads.h"
59 #include "toolbox/logging.h"
60 #include "vm/classcache.h"
61 #include "vm/exceptions.h"
62 #include "vm/global.h"
63 #include "vm/hashtable.h"
64 #include "vm/loader.h"
65 #include "vm/options.h"
66 #include "vm/statistics.h"
67 #include "vm/stringlocal.h"
71 /* define heap sizes **********************************************************/
73 #define HEAP_MAXSIZE 2 * 1024 * 1024 /* default 2MB */
74 #define HEAP_STARTSIZE 100 * 1024 /* default 100kB */
77 /* define cacaoh options ******************************************************/
92 { "help", false, OPT_HELP },
93 { "version", false, OPT_VERSION },
94 { "verbose", false, OPT_VERBOSE },
95 { "d", true, OPT_DIRECTORY },
96 { "classpath", true, OPT_CLASSPATH },
97 { "bootclasspath", true, OPT_BOOTCLASSPATH },
102 /* usage ***********************************************************************
104 Obviously prints usage information of cacaoh.
106 *******************************************************************************/
108 static void usage(void)
110 printf("Usage: cacaoh [options] <classes>\n"
113 " -help Print this message\n"
114 " -classpath <path> \n"
115 " -bootclasspath <path> \n"
116 " -d <dir> Output directory\n"
117 " -version Print version information\n"
118 " -verbose Enable verbose output\n");
120 /* exit with error code */
126 /* version *********************************************************************
128 Prints cacaoh version information.
130 *******************************************************************************/
132 static void version(void)
134 printf("cacaoh version "VERSION"\n");
135 printf("Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,\n");
136 printf("C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,\n");
137 printf("E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,\n");
138 printf("J. Wenninger, Institut f. Computersprachen - TU Wien\n\n");
140 printf("This program is free software; you can redistribute it and/or\n");
141 printf("modify it under the terms of the GNU General Public License as\n");
142 printf("published by the Free Software Foundation; either version 2, or (at\n");
143 printf("your option) any later version.\n\n");
145 printf("This program is distributed in the hope that it will be useful, but\n");
146 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
147 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
148 printf("General Public License for more details.\n");
154 /* main ************************************************************************
158 *******************************************************************************/
160 int main(int argc, char **argv)
167 /********** internal (only used by main) *****************************/
180 #if defined(DISABLE_GC)
181 nogc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
184 /* set the bootclasspath */
186 cp = getenv("BOOTCLASSPATH");
189 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
190 strcpy(bootclasspath, cp);
193 cplen = strlen(CACAO_VM_ZIP_PATH) +
195 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
198 bootclasspath = MNEW(char, cplen);
199 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
200 strcat(bootclasspath, ":");
201 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
205 /* set the classpath */
207 cp = getenv("CLASSPATH");
210 classpath = MNEW(char, strlen(cp) + strlen("0"));
211 strcat(classpath, cp);
214 classpath = MNEW(char, strlen(".") + strlen("0"));
215 strcpy(classpath, ".");
219 /* initialize options with default values */
222 opt_directory = NULL;
224 heapmaxsize = HEAP_MAXSIZE;
225 heapstartsize = HEAP_STARTSIZE;
227 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
237 /* forget old classpath and set the argument as new classpath */
238 MFREE(classpath, char, strlen(classpath));
240 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
241 strcpy(classpath, opt_arg);
244 case OPT_BOOTCLASSPATH:
245 /* Forget default bootclasspath and set the argument as new boot */
247 MFREE(bootclasspath, char, strlen(bootclasspath));
249 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
250 strcpy(bootclasspath, opt_arg);
254 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
255 strcpy(opt_directory, opt_arg);
273 /**************************** Program start **************************/
277 log_text("Java - header-generator started");
280 /* initialize the garbage collector */
282 gc_init(heapmaxsize, heapstartsize);
284 #if defined(USE_THREADS)
285 #if defined(NATIVE_THREADS)
291 /* initialize the utf8 hashtable stuff: lock, often used utf8 strings
292 (must be done _after_ threads_preinit) */
295 throw_main_exception_exit();
297 /* initialize the classcache hashtable stuff: lock, hashtable
298 (must be done _after_ threads_preinit) */
300 if (!classcache_init())
301 throw_main_exception_exit();
303 /* initialize the loader with bootclasspath (must be done _after_
308 suck_add(bootclasspath);
310 /* Also add the normal classpath, so the bootstrap class loader can find */
315 /* initialize the loader subsystems (must be done _after_
318 if (!loader_init((u1 *) &dummy))
319 throw_main_exception_exit();
322 /*********************** Load JAVA classes **************************/
324 nativemethod_chain = chain_new();
325 nativeclass_chain = chain_new();
327 for (a = opt_ind; a < argc; a++) {
330 /* convert classname */
332 for (i = strlen(cp) - 1; i >= 0; i--) {
334 case '.': cp[i] = '/';
336 case '_': cp[i] = '$';
340 /* exceptions are catched with new_exception call */
342 if (!(c = load_class_bootstrap(utf_new_char(cp))))
343 throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
347 throw_cacao_exception_exit(string_java_lang_LinkageError,
350 headerfile_generate(c, opt_directory);
353 /************************ Release all resources **********************/
358 log_text("Java - header-generator stopped");
359 #if defined(ENABLE_STATISTICS)
369 * These are local overrides for various environment variables in Emacs.
370 * Please do not remove this and leave it at the end of the file, where
371 * Emacs will automagically detect them.
372 * ---------------------------------------------------------------------
375 * indent-tabs-mode: t