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 3674 2005-11-16 12:03:58Z twisti $
45 #include "cacaoh/headers.h"
47 #include "mm/memory.h"
48 #include "native/include/java_lang_Throwable.h"
50 #if defined(USE_THREADS)
51 # if defined(NATIVE_THREADS)
52 # include "threads/native/threads.h"
54 # include "threads/green/threads.h"
58 #include "toolbox/logging.h"
59 #include "vm/classcache.h"
60 #include "vm/exceptions.h"
61 #include "vm/global.h"
62 #include "vm/loader.h"
63 #include "vm/options.h"
64 #include "vm/statistics.h"
65 #include "vm/stringlocal.h"
66 #include "vm/tables.h"
69 /* define heap sizes **********************************************************/
71 #define HEAP_MAXSIZE 2 * 1024 * 1024; /* default 2MB */
72 #define HEAP_STARTSIZE 100 * 1024; /* default 100kB */
75 /* define cacaoh options ******************************************************/
80 #define OPT_DIRECTORY 5
81 #define OPT_CLASSPATH 6
82 #define OPT_BOOTCLASSPATH 7
85 { "help", false, OPT_HELP },
86 { "version", false, OPT_VERSION },
87 { "verbose", false, OPT_VERBOSE },
88 { "d", true, OPT_DIRECTORY },
89 { "classpath", true, OPT_CLASSPATH },
90 { "bootclasspath", true, OPT_BOOTCLASSPATH },
95 /* usage ***********************************************************************
97 Obviously prints usage information of cacaoh.
99 *******************************************************************************/
101 static void usage(void)
103 printf("Usage: cacaoh [options] <classes>\n"
106 " -help Print this message\n"
107 " -classpath <path> \n"
108 " -bootclasspath <path> \n"
109 " -d <dir> Output directory\n"
110 " -version Print version information\n"
111 " -verbose Enable verbose output\n");
113 /* exit with error code */
119 /* version *********************************************************************
121 Prints cacaoh version information.
123 *******************************************************************************/
125 static void version(void)
127 printf("cacaoh version "VERSION"\n");
128 printf("Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,\n");
129 printf("R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,\n");
130 printf("C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,\n");
131 printf("Institut f. Computersprachen - TU Wien\n\n");
133 printf("This program is free software; you can redistribute it and/or\n");
134 printf("modify it under the terms of the GNU General Public License as\n");
135 printf("published by the Free Software Foundation; either version 2, or (at\n");
136 printf("your option) any later version.\n\n");
138 printf("This program is distributed in the hope that it will be useful, but\n");
139 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
140 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
141 printf("General Public License for more details.\n");
147 /* main ************************************************************************
151 *******************************************************************************/
153 int main(int argc, char **argv)
160 /********** internal (only used by main) *****************************/
173 /* set the bootclasspath */
175 cp = getenv("BOOTCLASSPATH");
177 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
178 strcpy(bootclasspath, cp);
181 cplen = strlen(CACAO_INSTALL_PREFIX) +
182 strlen(CACAO_VM_ZIP_PATH) +
184 strlen(CLASSPATH_INSTALL_DIR) +
185 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
188 bootclasspath = MNEW(char, cplen);
189 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
190 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
191 strcat(bootclasspath, ":");
192 strcat(bootclasspath, CLASSPATH_INSTALL_DIR);
193 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
197 /* set the classpath */
199 cp = getenv("CLASSPATH");
201 classpath = MNEW(char, strlen(cp) + strlen("0"));
202 strcat(classpath, cp);
205 classpath = MNEW(char, strlen(".") + strlen("0"));
206 strcpy(classpath, ".");
210 /* initialize options with default values */
213 opt_directory = NULL;
215 heapmaxsize = HEAP_MAXSIZE;
216 heapstartsize = HEAP_STARTSIZE;
218 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
228 /* forget old classpath and set the argument as new classpath */
229 MFREE(classpath, char, strlen(classpath));
231 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
232 strcpy(classpath, opt_arg);
235 case OPT_BOOTCLASSPATH:
236 /* Forget default bootclasspath and set the argument as new boot */
238 MFREE(bootclasspath, char, strlen(bootclasspath));
240 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
241 strcpy(bootclasspath, opt_arg);
245 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
246 strcpy(opt_directory, opt_arg);
264 /**************************** Program start **************************/
268 log_text("Java - header-generator started");
271 /* initialize the garbage collector */
273 gc_init(heapmaxsize, heapstartsize);
275 /* intialize the utf8 and string hashtable */
278 throw_main_exception_exit();
280 #if defined(USE_THREADS)
281 #if defined(NATIVE_THREADS)
287 /* initialize the utf8 hashtable stuff: lock, often used utf8 strings
288 (must be done _after_ threads_preinit) */
291 throw_main_exception_exit();
293 /* initialize the classcache hashtable stuff: lock, hashtable
294 (must be done _after_ threads_preinit) */
296 if (!classcache_init())
297 throw_main_exception_exit();
299 /* initialize the loader with bootclasspath (must be done _after_
302 suck_init(bootclasspath);
304 /* Also add the normal classpath, so the bootstrap class loader can find */
307 suck_init(classpath);
309 /* initialize the loader subsystems (must be done _after_ classcache_init) */
311 if (!loader_init((u1 *) &dummy))
312 throw_main_exception_exit();
315 /*********************** Load JAVA classes **************************/
317 nativemethod_chain = chain_new();
318 nativeclass_chain = chain_new();
320 for (a = opt_ind; a < argc; a++) {
323 /* convert classname */
325 for (i = strlen(cp) - 1; i >= 0; i--) {
327 case '.': cp[i] = '/';
329 case '_': cp[i] = '$';
333 /* exceptions are catched with new_exception call */
335 if (!(c = load_class_bootstrap(utf_new_char(cp))))
336 throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
340 throw_cacao_exception_exit(string_java_lang_LinkageError,
343 headerfile_generate(c, opt_directory);
346 /************************ Release all resources **********************/
352 log_text("Java - header-generator stopped");
353 #if defined(STATISTICS)
363 * These are local overrides for various environment variables in Emacs.
364 * Please do not remove this and leave it at the end of the file, where
365 * Emacs will automagically detect them.
366 * ---------------------------------------------------------------------
369 * indent-tabs-mode: t