1 /* 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 1910 2005-02-10 09:55:49Z 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 *******************************************************************************/
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 static void version()
119 printf("cacaoh "VERSION"\n");
124 /* main ************************************************************************
128 *******************************************************************************/
130 int main(int argc, char **argv)
137 /********** internal (only used by main) *****************************/
150 /* set the bootclasspath */
152 cp = getenv("BOOTCLASSPATH");
154 bootclasspath = MNEW(char, strlen(cp) + 1);
155 strcpy(bootclasspath, cp);
158 cplen = strlen(CACAO_INSTALL_PREFIX) + strlen(CACAO_RT_JAR_PATH);
160 bootclasspath = MNEW(char, cplen + 1);
161 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
162 strcat(bootclasspath, CACAO_RT_JAR_PATH);
166 /* set the classpath */
168 cp = getenv("CLASSPATH");
170 classpath = MNEW(char, strlen(cp) + 1);
171 strcat(classpath, cp);
174 classpath = MNEW(char, 2);
175 strcpy(classpath, ".");
179 /* initialize options with default values */
182 opt_directory = NULL;
184 heapmaxsize = HEAP_MAXSIZE;
185 heapstartsize = HEAP_STARTSIZE;
187 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
197 /* forget old classpath and set the argument as new classpath */
198 MFREE(classpath, char, strlen(classpath));
200 classpath = MNEW(char, strlen(opt_arg) + 1);
201 strcpy(classpath, opt_arg);
204 case OPT_BOOTCLASSPATH:
205 /* Forget default bootclasspath and set the argument as new boot */
207 MFREE(bootclasspath, char, strlen(bootclasspath));
209 bootclasspath = MNEW(char, strlen(opt_arg) + 1);
210 strcpy(bootclasspath, opt_arg);
214 opt_directory = MNEW(char, strlen(opt_arg) + 1);
215 strcpy(opt_directory, opt_arg);
231 /**************************** Program start **************************/
235 log_text("Java - header-generator started");
238 /* initialize the garbage collector */
240 gc_init(heapmaxsize, heapstartsize);
244 /* initialize the loader with bootclasspath and append classpath entries */
246 suck_init(bootclasspath);
247 suck_init(classpath);
249 #if defined(USE_THREADS)
250 #if defined(NATIVE_THREADS)
256 /* initialize some cacao subsystems */
260 loader_init((u1 *) &dummy);
263 /*********************** Load JAVA classes **************************/
265 nativemethod_chain = chain_new();
266 nativeclass_chain = chain_new();
268 for (a = opt_ind; a < argc; a++) {
271 /* convert classname */
273 for (i = strlen(cp) - 1; i >= 0; i--) {
275 case '.': cp[i] = '/';
277 case '_': cp[i] = '$';
281 c = class_new(utf_new_char(cp));
283 /* exceptions are catched with new_exception call */
286 throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
290 throw_cacao_exception_exit(string_java_lang_LinkageError,
293 headerfile_generate(c, opt_directory);
296 /************************ Release all resources **********************/
302 log_text("Java - header-generator stopped");
312 * These are local overrides for various environment variables in Emacs.
313 * Please do not remove this and leave it at the end of the file, where
314 * Emacs will automagically detect them.
315 * ---------------------------------------------------------------------
318 * indent-tabs-mode: t