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 3548 2005-11-03 20:39:46Z 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) +
181 strlen(CACAO_VM_ZIP_PATH) +
183 strlen(CLASSPATH_INSTALL_DIR) +
184 strlen(CLASSPATH_GLIBJ_ZIP_PATH) +
187 bootclasspath = MNEW(char, cplen);
188 strcpy(bootclasspath, CACAO_INSTALL_PREFIX);
189 strcat(bootclasspath, CACAO_VM_ZIP_PATH);
190 strcat(bootclasspath, ":");
191 strcat(bootclasspath, CLASSPATH_INSTALL_DIR);
192 strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP_PATH);
196 /* set the classpath */
198 cp = getenv("CLASSPATH");
200 classpath = MNEW(char, strlen(cp) + strlen("0"));
201 strcat(classpath, cp);
204 classpath = MNEW(char, strlen(".") + strlen("0"));
205 strcpy(classpath, ".");
209 /* initialize options with default values */
212 opt_directory = NULL;
214 heapmaxsize = HEAP_MAXSIZE;
215 heapstartsize = HEAP_STARTSIZE;
217 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
227 /* forget old classpath and set the argument as new classpath */
228 MFREE(classpath, char, strlen(classpath));
230 classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
231 strcpy(classpath, opt_arg);
234 case OPT_BOOTCLASSPATH:
235 /* Forget default bootclasspath and set the argument as new boot */
237 MFREE(bootclasspath, char, strlen(bootclasspath));
239 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
240 strcpy(bootclasspath, opt_arg);
244 opt_directory = MNEW(char, strlen(opt_arg) + strlen("0"));
245 strcpy(opt_directory, opt_arg);
263 /**************************** Program start **************************/
267 log_text("Java - header-generator started");
270 /* initialize the garbage collector */
272 gc_init(heapmaxsize, heapstartsize);
276 /* initialize the loader with bootclasspath */
278 suck_init(bootclasspath);
280 /* Also add the normal classpath, so the bootstrap class loader can find */
283 suck_init(classpath);
285 #if defined(USE_THREADS)
286 #if defined(NATIVE_THREADS)
292 /* initialize some cacao subsystems */
295 loader_init((u1 *) &dummy);
298 /*********************** Load JAVA classes **************************/
300 nativemethod_chain = chain_new();
301 nativeclass_chain = chain_new();
303 for (a = opt_ind; a < argc; a++) {
306 /* convert classname */
308 for (i = strlen(cp) - 1; i >= 0; i--) {
310 case '.': cp[i] = '/';
312 case '_': cp[i] = '$';
316 /* exceptions are catched with new_exception call */
318 if (!(c = load_class_bootstrap(utf_new_char(cp))))
319 throw_cacao_exception_exit(string_java_lang_NoClassDefFoundError,
323 throw_cacao_exception_exit(string_java_lang_LinkageError,
326 headerfile_generate(c, opt_directory);
329 /************************ Release all resources **********************/
335 log_text("Java - header-generator stopped");
336 #if defined(STATISTICS)
346 * These are local overrides for various environment variables in Emacs.
347 * Please do not remove this and leave it at the end of the file, where
348 * Emacs will automagically detect them.
349 * ---------------------------------------------------------------------
352 * indent-tabs-mode: t