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 3216 2005-09-19 13:07:54Z 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/exceptions.h"
60 #include "vm/global.h"
61 #include "vm/loader.h"
62 #include "vm/options.h"
63 #include "vm/statistics.h"
64 #include "vm/stringlocal.h"
65 #include "vm/tables.h"
68 /* define heap sizes **********************************************************/
70 #define HEAP_MAXSIZE 2 * 1024 * 1024; /* default 2MB */
71 #define HEAP_STARTSIZE 100 * 1024; /* default 100kB */
74 /* define cacaoh options ******************************************************/
79 #define OPT_DIRECTORY 5
80 #define OPT_CLASSPATH 6
81 #define OPT_BOOTCLASSPATH 7
84 { "help", false, OPT_HELP },
85 { "version", false, OPT_VERSION },
86 { "verbose", false, OPT_VERBOSE },
87 { "d", true, OPT_DIRECTORY },
88 { "classpath", true, OPT_CLASSPATH },
89 { "bootclasspath", true, OPT_BOOTCLASSPATH },
94 /* usage ***********************************************************************
96 Obviously prints usage information of cacaoh.
98 *******************************************************************************/
100 static void usage(void)
102 printf("Usage: cacaoh [options] <classes>\n"
105 " -help Print this message\n"
106 " -classpath <path> \n"
107 " -bootclasspath <path> \n"
108 " -d <dir> Output directory\n"
109 " -version Print version information\n"
110 " -verbose Enable verbose output\n");
112 /* exit with error code */
118 /* version *********************************************************************
120 Prints cacaoh version information.
122 *******************************************************************************/
124 static void version(void)
126 printf("cacaoh version "VERSION"\n");
127 printf("Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,\n");
128 printf("R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,\n");
129 printf("C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,\n");
130 printf("Institut f. Computersprachen - TU Wien\n\n");
132 printf("This program is free software; you can redistribute it and/or\n");
133 printf("modify it under the terms of the GNU General Public License as\n");
134 printf("published by the Free Software Foundation; either version 2, or (at\n");
135 printf("your option) any later version.\n\n");
137 printf("This program is distributed in the hope that it will be useful, but\n");
138 printf("WITHOUT ANY WARRANTY; without even the implied warranty of\n");
139 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
140 printf("General Public License for more details.\n");
146 /* main ************************************************************************
150 *******************************************************************************/
152 int main(int argc, char **argv)
159 /********** internal (only used by main) *****************************/
172 /* set the bootclasspath */
174 cp = getenv("BOOTCLASSPATH");
176 bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
177 strcpy(bootclasspath, cp);
180 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_RT_JAR_PATH) +
183 bootclasspath = MNEW(char, cplen);
184 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
185 strcat(bootclasspath, CACAO_RT_JAR_PATH);
189 /* set the classpath */
191 cp = getenv("CLASSPATH");
193 classpath = MNEW(char, strlen(cp) + strlen("0"));
194 strcat(classpath, cp);
197 classpath = MNEW(char, strlen(".") + strlen("0"));
198 strcpy(classpath, ".");
202 /* initialize options with default values */
205 opt_directory = NULL;
207 heapmaxsize = HEAP_MAXSIZE;
208 heapstartsize = HEAP_STARTSIZE;
210 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
220 /* forget old classpath and set the argument as new classpath */
221 MFREE(classpath, char, strlen(classpath));
223 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
224 strcpy(classpath, opt_arg);
227 case OPT_BOOTCLASSPATH:
228 /* Forget default bootclasspath and set the argument as new boot */
230 MFREE(bootclasspath, char, strlen(bootclasspath));
232 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
233 strcpy(bootclasspath, opt_arg);
237 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
238 strcpy(opt_directory, opt_arg);
256 /**************************** Program start **************************/
260 log_text("Java - header-generator started");
263 /* initialize the garbage collector */
265 gc_init(heapmaxsize, heapstartsize);
269 /* initialize the loader with bootclasspath */
271 suck_init(bootclasspath);
273 /* Also add the normal classpath, so the bootstrap class loader can find */
276 suck_init(classpath);
278 #if defined(USE_THREADS)
279 #if defined(NATIVE_THREADS)
285 /* initialize some cacao subsystems */
288 loader_init((u1 *) &dummy);
291 /*********************** Load JAVA classes **************************/
293 nativemethod_chain = chain_new();
294 nativeclass_chain = chain_new();
296 for (a = opt_ind; a < argc; a++) {
299 /* convert classname */
301 for (i = strlen(cp) - 1; i >= 0; i--) {
303 case '.': cp[i] = '/';
305 case '_': cp[i] = '$';
309 /* exceptions are catched with new_exception call */
311 if (!(c = load_class_bootstrap(utf_new_char(cp))))
312 throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
316 throw_cacao_exception_exit(string_java_lang_LinkageError,
319 headerfile_generate(c, opt_directory);
322 /************************ Release all resources **********************/
328 log_text("Java - header-generator stopped");
329 #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