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 3827 2005-12-01 19:38:20Z 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/hashtable.h"
63 #include "vm/loader.h"
64 #include "vm/options.h"
65 #include "vm/statistics.h"
66 #include "vm/stringlocal.h"
70 /* define heap sizes **********************************************************/
72 #define HEAP_MAXSIZE 2 * 1024 * 1024; /* default 2MB */
73 #define HEAP_STARTSIZE 100 * 1024; /* default 100kB */
76 /* define cacaoh options ******************************************************/
81 #define OPT_DIRECTORY 5
82 #define OPT_CLASSPATH 6
83 #define OPT_BOOTCLASSPATH 7
86 { "help", false, OPT_HELP },
87 { "version", false, OPT_VERSION },
88 { "verbose", false, OPT_VERBOSE },
89 { "d", true, OPT_DIRECTORY },
90 { "classpath", true, OPT_CLASSPATH },
91 { "bootclasspath", true, OPT_BOOTCLASSPATH },
96 /* usage ***********************************************************************
98 Obviously prints usage information of cacaoh.
100 *******************************************************************************/
102 static void usage(void)
104 printf("Usage: cacaoh [options] <classes>\n"
107 " -help Print this message\n"
108 " -classpath <path> \n"
109 " -bootclasspath <path> \n"
110 " -d <dir> Output directory\n"
111 " -version Print version information\n"
112 " -verbose Enable verbose output\n");
114 /* exit with error code */
120 /* version *********************************************************************
122 Prints cacaoh version information.
124 *******************************************************************************/
126 static void version(void)
128 printf("cacaoh version "VERSION"\n");
129 printf("Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,\n");
130 printf("R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,\n");
131 printf("C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,\n");
132 printf("Institut f. Computersprachen - TU Wien\n\n");
134 printf("This program is free software; you can redistribute it and/or\n");
135 printf("modify it under the terms of the GNU General Public License as\n");
136 printf("published by the Free Software Foundation; either version 2, or (at\n");
137 printf("your option) any later version.\n\n");
139 printf("This program is distributed in the hope that it will be useful, but\n");
140 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
141 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
142 printf("General Public License for more details.\n");
148 /* main ************************************************************************
152 *******************************************************************************/
154 int main(int argc, char **argv)
161 /********** internal (only used by main) *****************************/
174 /* set the bootclasspath */
176 cp = getenv("BOOTCLASSPATH");
178 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
179 strcpy(bootclasspath, cp);
182 cplen = strlen(CACAO_INSTALL_PREFIX) +
183 strlen(CACAO_VM_ZIP_PATH) +
185 strlen(CLASSPATH_INSTALL_DIR) +
186 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
189 bootclasspath = MNEW(char, cplen);
190 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
191 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
192 strcat(bootclasspath, ":");
193 strcat(bootclasspath, CLASSPATH_INSTALL_DIR);
194 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
198 /* set the classpath */
200 cp = getenv("CLASSPATH");
202 classpath = MNEW(char, strlen(cp) + strlen("0"));
203 strcat(classpath, cp);
206 classpath = MNEW(char, strlen(".") + strlen("0"));
207 strcpy(classpath, ".");
211 /* initialize options with default values */
214 opt_directory = NULL;
216 heapmaxsize = HEAP_MAXSIZE;
217 heapstartsize = HEAP_STARTSIZE;
219 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
229 /* forget old classpath and set the argument as new classpath */
230 MFREE(classpath, char, strlen(classpath));
232 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
233 strcpy(classpath, opt_arg);
236 case OPT_BOOTCLASSPATH:
237 /* Forget default bootclasspath and set the argument as new boot */
239 MFREE(bootclasspath, char, strlen(bootclasspath));
241 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
242 strcpy(bootclasspath, opt_arg);
246 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
247 strcpy(opt_directory, opt_arg);
265 /**************************** Program start **************************/
269 log_text("Java - header-generator started");
272 /* initialize the garbage collector */
274 gc_init(heapmaxsize, heapstartsize);
276 #if defined(USE_THREADS)
277 #if defined(NATIVE_THREADS)
283 /* initialize the utf8 hashtable stuff: lock, often used utf8 strings
284 (must be done _after_ threads_preinit) */
287 throw_main_exception_exit();
289 /* initialize the classcache hashtable stuff: lock, hashtable
290 (must be done _after_ threads_preinit) */
292 if (!classcache_init())
293 throw_main_exception_exit();
295 /* initialize the loader with bootclasspath (must be done _after_
298 suck_init(bootclasspath);
300 /* Also add the normal classpath, so the bootstrap class loader can find */
303 suck_init(classpath);
305 /* initialize the loader subsystems (must be done _after_ classcache_init) */
307 if (!loader_init((u1 *) &dummy))
308 throw_main_exception_exit();
311 /*********************** Load JAVA classes **************************/
313 nativemethod_chain = chain_new();
314 nativeclass_chain = chain_new();
316 for (a = opt_ind; a < argc; a++) {
319 /* convert classname */
321 for (i = strlen(cp) - 1; i >= 0; i--) {
323 case '.': cp[i] = '/';
325 case '_': cp[i] = '$';
329 /* exceptions are catched with new_exception call */
331 if (!(c = load_class_bootstrap(utf_new_char(cp))))
332 throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
336 throw_cacao_exception_exit(string_java_lang_LinkageError,
339 headerfile_generate(c, opt_directory);
342 /************************ Release all resources **********************/
347 log_text("Java - header-generator stopped");
348 #if defined(STATISTICS)
358 * These are local overrides for various environment variables in Emacs.
359 * Please do not remove this and leave it at the end of the file, where
360 * Emacs will automagically detect them.
361 * ---------------------------------------------------------------------
364 * indent-tabs-mode: t