1 /* src/cacaoh/cacaoh.c - main for header generation (cacaoh)
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Reinhard Grafl
33 $Id: cacaoh.c 3957 2005-12-20 23:09:36Z 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 R. Grafl, A. Krall, C. Kruegel, C. Oates,\n");
136 printf("R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,\n");
137 printf("C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,\n");
138 printf("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 /* set the bootclasspath */
182 cp = getenv("BOOTCLASSPATH");
184 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
185 strcpy(bootclasspath, cp);
188 cplen = strlen(CACAO_INSTALL_PREFIX) +
189 strlen(CACAO_VM_ZIP_PATH) +
191 strlen(CLASSPATH_INSTALL_DIR) +
192 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
195 bootclasspath = MNEW(char, cplen);
196 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
197 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
198 strcat(bootclasspath, ":");
199 strcat(bootclasspath, CLASSPATH_INSTALL_DIR);
200 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
204 /* set the classpath */
206 cp = getenv("CLASSPATH");
208 classpath = MNEW(char, strlen(cp) + strlen("0"));
209 strcat(classpath, cp);
212 classpath = MNEW(char, strlen(".") + strlen("0"));
213 strcpy(classpath, ".");
217 /* initialize options with default values */
220 opt_directory = NULL;
222 heapmaxsize = HEAP_MAXSIZE;
223 heapstartsize = HEAP_STARTSIZE;
225 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
235 /* forget old classpath and set the argument as new classpath */
236 MFREE(classpath, char, strlen(classpath));
238 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
239 strcpy(classpath, opt_arg);
242 case OPT_BOOTCLASSPATH:
243 /* Forget default bootclasspath and set the argument as new boot */
245 MFREE(bootclasspath, char, strlen(bootclasspath));
247 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
248 strcpy(bootclasspath, opt_arg);
252 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
253 strcpy(opt_directory, opt_arg);
271 /**************************** Program start **************************/
275 log_text("Java - header-generator started");
278 /* initialize the garbage collector */
280 gc_init(heapmaxsize, heapstartsize);
282 #if defined(USE_THREADS)
283 #if defined(NATIVE_THREADS)
289 /* initialize the utf8 hashtable stuff: lock, often used utf8 strings
290 (must be done _after_ threads_preinit) */
293 throw_main_exception_exit();
295 /* initialize the classcache hashtable stuff: lock, hashtable
296 (must be done _after_ threads_preinit) */
298 if (!classcache_init())
299 throw_main_exception_exit();
301 /* initialize the loader with bootclasspath (must be done _after_
306 suck_add(bootclasspath);
308 /* Also add the normal classpath, so the bootstrap class loader can find */
313 /* initialize the loader subsystems (must be done _after_
316 if (!loader_init((u1 *) &dummy))
317 throw_main_exception_exit();
320 /*********************** Load JAVA classes **************************/
322 nativemethod_chain = chain_new();
323 nativeclass_chain = chain_new();
325 for (a = opt_ind; a < argc; a++) {
328 /* convert classname */
330 for (i = strlen(cp) - 1; i >= 0; i--) {
332 case '.': cp[i] = '/';
334 case '_': cp[i] = '$';
338 /* exceptions are catched with new_exception call */
340 if (!(c = load_class_bootstrap(utf_new_char(cp))))
341 throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
345 throw_cacao_exception_exit(string_java_lang_LinkageError,
348 headerfile_generate(c, opt_directory);
351 /************************ Release all resources **********************/
356 log_text("Java - header-generator stopped");
357 #if defined(ENABLE_STATISTICS)
367 * These are local overrides for various environment variables in Emacs.
368 * Please do not remove this and leave it at the end of the file, where
369 * Emacs will automagically detect them.
370 * ---------------------------------------------------------------------
373 * indent-tabs-mode: t