1 /* gennativetable.c - generate nativetable.h for native.c
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5 M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6 P. Tomsich, J. Wenninger
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: Christian Thalinger
31 $Id: gennativetable.c 1405 2004-08-17 09:25:01Z twisti $
46 #include "threads/locks.h"
47 #include "threads/thread.h"
48 #include "toolbox/chain.h"
49 #include "toolbox/memory.h"
52 int main(int argc, char **argv)
55 char classpath[500] = "";
60 bool nativelyoverloaded;
61 u4 heapmaxsize = 2 * 1024 * 1024;
62 u4 heapstartsize = 100 * 1024;
69 printf("Usage: gennativetable class [class...]\n");
73 cp = getenv("CLASSPATH");
75 strcpy(classpath + strlen(classpath), ":");
76 strcpy(classpath + strlen(classpath), cp);
79 /* initialize the garbage collector */
80 gc_init(heapmaxsize, heapstartsize);
86 #if defined(USE_THREADS)
87 #if defined(NATIVE_THREADS)
93 loader_init((u1 *) &dummy);
96 /*********************** Load JAVA classes **************************/
98 nativeclass_chain = chain_new();
99 nativemethod_chain = chain_new();
101 for (i = 1; i < argc; i++) {
104 /* convert classname */
105 for (j = strlen(cp) - 1; j >= 0; j--) {
107 case '.': cp[j] = '/';
109 case '_': cp[j] = '$';
113 c = class_new(utf_new_char(cp));
115 /* exceptions are catched with new_exception call */
119 chain_addlast(nativeclass_chain, c);
121 /* find overloaded methods */
122 for (j = 0; j < c->methodscount; j++) {
123 m = &(c->methods[j]);
125 if (!(m->flags & ACC_NATIVE))
128 if (!m->nativelyoverloaded) {
129 nativelyoverloaded = false;
131 for (k = j + 1; k < c->methodscount; k++) {
132 m2 = &(c->methods[k]);
134 if (!(m2->flags & ACC_NATIVE))
137 if (m->name == m2->name) {
138 m2->nativelyoverloaded = true;
139 nativelyoverloaded = true;
142 m->nativelyoverloaded = nativelyoverloaded;
146 for (j = 0; j < c->methodscount; j++) {
147 m = &(c->methods[j]);
149 if (m->flags & ACC_NATIVE) {
150 chain_addlast(nativemethod_chain, m);
155 /* create table of native-methods */
157 /* file = fopen("nativetable.h", "w"); */
161 panic("Can not open file 'nativetable' to store native-link-table");
163 fprintf(file, "/* Table of native methods: nativetables.hh */\n");
164 fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n");
166 c = chain_first(nativeclass_chain);
168 gen_header_filename(classname, c->name);
169 fprintf(file, "#include \"nat/%s.h\"\n", classname);
170 c = chain_next(nativeclass_chain);
172 chain_free(nativeclass_chain);
174 fprintf(file, "\n\n#include \"native.h\"\n\n");
175 fprintf(file, "static nativeref nativetable[] = {\n");
177 m = chain_first(nativemethod_chain);
179 printnativetableentry(m);
180 m = chain_next(nativemethod_chain);
182 chain_free(nativemethod_chain);
184 fprintf(file, "};\n");
188 /* release all resources */
191 tables_close(literalstring_free);
193 /* everything is ok */
200 * These are local overrides for various environment variables in Emacs.
201 * Please do not remove this and leave it at the end of the file, where
202 * Emacs will automagically detect them.
203 * ---------------------------------------------------------------------
206 * indent-tabs-mode: t