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 2879 2005-06-30 09:58:38Z twisti $
44 #include "cacaoh/headers.h"
46 #include "mm/memory.h"
47 #include "native/include/java_lang_Throwable.h"
49 #if defined(USE_THREADS)
50 # if defined(NATIVE_THREADS)
51 # include "threads/native/threads.h"
53 # include "threads/green/threads.h"
57 #include "toolbox/logging.h"
58 #include "vm/exceptions.h"
59 #include "vm/global.h"
60 #include "vm/loader.h"
61 #include "vm/options.h"
62 #include "vm/statistics.h"
63 #include "vm/stringlocal.h"
64 #include "vm/tables.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 ******************************************************/
78 #define OPT_DIRECTORY 5
79 #define OPT_CLASSPATH 6
80 #define OPT_BOOTCLASSPATH 7
83 { "help", false, OPT_HELP },
84 { "version", false, OPT_VERSION },
85 { "verbose", false, OPT_VERBOSE },
86 { "d", true, OPT_DIRECTORY },
87 { "classpath", true, OPT_CLASSPATH },
88 { "bootclasspath", true, OPT_BOOTCLASSPATH },
93 /* usage ***********************************************************************
95 Obviously prints usage information of cacaoh.
97 *******************************************************************************/
99 static void usage(void)
101 printf("Usage: cacaoh [options] <classes>\n"
104 " -help Print this message\n"
105 " -classpath <path> \n"
106 " -bootclasspath <path> \n"
107 " -d <dir> Output directory\n"
108 " -version Print version information\n"
109 " -verbose Enable verbose output\n");
111 /* exit with error code */
117 /* version *********************************************************************
119 Prints cacaoh version information.
121 *******************************************************************************/
123 static void version(void)
125 printf("cacaoh version "VERSION"\n");
126 printf("Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,\n");
127 printf("R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,\n");
128 printf("C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,\n");
129 printf("Institut f. Computersprachen - TU Wien\n\n");
131 printf("This program is free software; you can redistribute it and/or\n");
132 printf("modify it under the terms of the GNU General Public License as\n");
133 printf("published by the Free Software Foundation; either version 2, or (at\n");
134 printf("your option) any later version.\n\n");
136 printf("This program is distributed in the hope that it will be useful, but\n");
137 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
138 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
139 printf("General Public License for more details.\n");
145 /* main ************************************************************************
149 *******************************************************************************/
151 int main(int argc, char **argv)
158 /********** internal (only used by main) *****************************/
171 /* set the bootclasspath */
173 cp = getenv("BOOTCLASSPATH");
175 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
176 strcpy(bootclasspath, cp);
179 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_RT_JAR_PATH) +
182 bootclasspath = MNEW(char, cplen);
183 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
184 strcat(bootclasspath, CACAO_RT_JAR_PATH);
188 /* set the classpath */
190 cp = getenv("CLASSPATH");
192 classpath = MNEW(char, strlen(cp) + strlen("0"));
193 strcat(classpath, cp);
196 classpath = MNEW(char, strlen(".") + strlen("0"));
197 strcpy(classpath, ".");
201 /* initialize options with default values */
204 opt_directory = NULL;
206 heapmaxsize = HEAP_MAXSIZE;
207 heapstartsize = HEAP_STARTSIZE;
209 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
219 /* forget old classpath and set the argument as new classpath */
220 MFREE(classpath, char, strlen(classpath));
222 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
223 strcpy(classpath, opt_arg);
226 case OPT_BOOTCLASSPATH:
227 /* Forget default bootclasspath and set the argument as new boot */
229 MFREE(bootclasspath, char, strlen(bootclasspath));
231 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
232 strcpy(bootclasspath, opt_arg);
236 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
237 strcpy(opt_directory, opt_arg);
255 /**************************** Program start **************************/
259 log_text("Java - header-generator started");
262 /* initialize the garbage collector */
264 gc_init(heapmaxsize, heapstartsize);
268 /* initialize the loader with bootclasspath */
270 suck_init(bootclasspath);
272 /* Also add the normal classpath, so the bootstrap class loader can find */
275 suck_init(classpath);
277 #if defined(USE_THREADS)
278 #if defined(NATIVE_THREADS)
284 /* initialize some cacao subsystems */
287 loader_init((u1 *) &dummy);
290 /*********************** Load JAVA classes **************************/
292 nativemethod_chain = chain_new();
293 nativeclass_chain = chain_new();
295 for (a = opt_ind; a < argc; a++) {
298 /* convert classname */
300 for (i = strlen(cp) - 1; i >= 0; i--) {
302 case '.': cp[i] = '/';
304 case '_': cp[i] = '$';
308 /* exceptions are catched with new_exception call */
310 if (!(c = load_class_bootstrap(utf_new_char(cp))))
311 throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
315 throw_cacao_exception_exit(string_java_lang_LinkageError,
318 headerfile_generate(c, opt_directory);
321 /************************ Release all resources **********************/
327 log_text("Java - header-generator stopped");
328 #if defined(STATISTICS)
339 * These are local overrides for various environment variables in Emacs.
340 * Please do not remove this and leave it at the end of the file, where
341 * Emacs will automagically detect them.
342 * ---------------------------------------------------------------------
345 * indent-tabs-mode: t