Fixed function call.
[cacao.git] / src / native / tools / gennativetable.c
index 736dca0c57b1a7a765200cb7d28a5023d42f6e23..16fa62ab13124ef8f82f974caa8da6e614453802 100644 (file)
@@ -1,9 +1,9 @@
 /* gennativetable.c - generate nativetable.h for native.c
 
-   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
-   R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
-   M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
-   P. Tomsich, J. Wenninger
+   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+   Institut f. Computersprachen - TU Wien
 
    This file is part of CACAO.
 
@@ -28,7 +28,7 @@
 
    Changes:
 
-   $Id: gennativetable.c 1260 2004-06-30 22:26:21Z stefan $
+   $Id: gennativetable.c 1789 2004-12-21 10:09:08Z twisti $
 
 */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include "config.h"
 #include "types.h"
-#include "global.h"
-#include "headers.h"
-#include "loader.h"
-#include "tables.h"
+#include "cacaoh/headers.h"
 #include "mm/boehm.h"
-#include "threads/thread.h"
+#include "mm/memory.h"
+
+#if defined(USE_THREADS)
+# if defined(NATIVE_THREADS)
+#  include "threads/native/threads.h"
+# else
+#  include "threads/green/threads.h"
+# endif
+#endif
+
 #include "toolbox/chain.h"
-#include "toolbox/memory.h"
+#include "vm/exceptions.h"
+#include "vm/global.h"
+#include "vm/loader.h"
+#include "vm/tables.h"
 
 
 int main(int argc, char **argv)
@@ -78,13 +88,17 @@ int main(int argc, char **argv)
        /* initialize the garbage collector */
        gc_init(heapmaxsize, heapstartsize);
 
-       suck_init(classpath);
-   
        tables_init();
 
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+       suck_init(classpath);
+   
+#if defined(USE_THREADS)
+#if defined(NATIVE_THREADS)
        initThreadsEarly();
 #endif
+       initLocks();
+#endif
+
        loader_init((u1 *) &dummy);
 
 
@@ -149,24 +163,23 @@ int main(int argc, char **argv)
 
        /* create table of native-methods */
 
-/*     file = fopen("nativetable.h", "w"); */
        file = stdout;
 
-       if (!file)
-               panic("Can not open file 'nativetable' to store native-link-table");
+       fprintf(file, "/* Table of native methods: nativetables.inc */\n");
+       fprintf(file, "/* This file is machine generated, don't edit it! */\n\n"); 
 
-       fprintf(file, "/* Table of native methods: nativetables.hh */\n");
-       fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n"); 
+       fprintf(file, "#include \"config.h\"\n");
 
        c = chain_first(nativeclass_chain);
        while (c) {
                gen_header_filename(classname, c->name);
-               fprintf(file, "#include \"nat/%s.h\"\n", classname);
+               fprintf(file, "#include \"native/include/%s.h\"\n", classname);
                c = chain_next(nativeclass_chain);
        }
        chain_free(nativeclass_chain);
 
-       fprintf(file, "\n\n#include \"native.h\"\n\n");
+       fprintf(file, "\n\n#include \"native/native.h\"\n\n");
+       fprintf(file, "#if defined(STATIC_CLASSPATH)\n\n");
        fprintf(file, "static nativeref nativetable[] = {\n");
 
        m = chain_first(nativemethod_chain);
@@ -177,13 +190,52 @@ int main(int argc, char **argv)
        chain_free(nativemethod_chain);
 
        fprintf(file, "};\n");
+       fprintf(file, "\n#else\n\n");
+       fprintf(file, "/* Ensure that symbols for functions implemented within cacao are used and    */\n");
+       fprintf(file, "/* exported to dlopen.                                                        */\n\n");
+       fprintf(file, "static functionptr dummynativetable[] = {\n");
 
-       fclose(file);
+       {
+               FILE *implData;
+
+               implData = fopen("vm/implementednatives.data", "r");
+
+               if (!implData) {
+                       fclose(file);
+                       throw_cacao_exception_exit(string_java_lang_InternalError,
+                                                                          "Could not find file");
+               }
 
+               while (!feof(implData)) {
+                       char functionLine[1024];
+                       functionLine[0] = '\0';
+                       fgets(functionLine, 1024, implData);
+
+                       if (strlen(functionLine) < 2)
+                               continue;
+
+                       if (functionLine[strlen(functionLine) - 1] != '\n') {
+                               fclose(implData);
+                               fclose(file);
+                               exit(4);
+                       }
+
+                       functionLine[strlen(functionLine) - 1] = ',';
+                       fprintf(file,"\t(functionptr) %s\n", functionLine);
+               }
+
+               fprintf(file, "\t(functionptr) 0\n");
+               fclose(implData);
+       }
+
+       fprintf(file, "};\n");
+       fprintf(file, "\n#endif\n");
+       fclose(file);
+       
        /* release all resources */
 
        loader_close();
-       tables_close(literalstring_free);
+       tables_close();
 
        /* everything is ok */
 
@@ -203,5 +255,3 @@ int main(int argc, char **argv)
  * tab-width: 4
  * End:
  */
-
-