-/***************************************************************************
-
- create the nativetypes-headerfile which includes
- the headerfiles of the classes stored in the classes-chain
-
-****************************************************************************/
-
-static void headers_finish()
-{
- methodinfo *m;
- classinfo *c;
- char classname[1024];
-
- file = fopen("nativetypes.hh", "w");
-
- if (!file)
- panic("Can not open file 'native.h' to store header information");
-
- fprintf(file, "/* Headerfile for native methods: nativetypes.hh */\n");
- fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n");
- fprintf(file, "\n/* include native-Headerfiles */\n\n");
-
- c = chain_first(nativeclass_chain);
- while (c) {
- dopadding = false;
- gen_header_filename(classname, c->name);
- fprintf(file, "#include \"nat/%s.h\"\n", classname);
- c = chain_next(nativeclass_chain);
- }
-
- fclose(file);
- chain_free(nativeclass_chain);
-
- /* create table of native-methods */
-
- file = fopen("nativetable.hh", "w");
-
- if (!file)
- panic("Can not open file 'nativetable' to store native-link-table");
-
- fprintf(file, "/* Table of native methods: nativetables.hh */\n");
- fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n");
-
- while ((m = chain_first(nativemethod_chain)) != NULL) {
- chain_remove(nativemethod_chain);
- printnativetableentry(m);
- }
-
- chain_free(nativemethod_chain);
- fclose(file);
-}
-
-
-/******************** internal function: print_usage ************************
-
-Prints usage information for the JAVA header generator to stdout.
-
-***************************************************************************/
-
-static void print_usage()
-{
- printf("Usage: cacaoh class [class..]\n");
-}
-
-
-
-/************************** Function: main *******************************
-
- Main program.
-
-**************************************************************************/
-
-int main(int argc, char **argv)
-{
- s4 i,a;
- char *cp;
- classinfo *topclass;
- void *dummy;
-
-
- /********** internal (only used by main) *****************************/
-
- char classpath[500] = "";
- char offsets_filename[1024] = ""; /* phil */
- u4 heapsize = 100000;
-
- /*********** options so only headers are generated *******************/
-
- makeinitializations = false;
-
-
- /************ Collect some info from the environment *****************/
-
- cp = getenv("CLASSPATH");
- if (cp) {
- strcpy(classpath + strlen(classpath), ":");
- strcpy(classpath + strlen(classpath), cp);
- }
-
- if (argc < 2) {
- print_usage();
- exit(10);
- }
-
-
- /**************************** Program start **************************/
-
- log_init(NULL);
- log_text("Java - header-generator started");
-
- sprintf(offsets_filename, "jit/%s/offsets.h", ARCH_DIR); /* phil */
- file = fopen(offsets_filename, "w");
- if (file == NULL) {
- fprintf(stderr, "Can not open file '%s' for write", offsets_filename);
- exit(-1);
- }
-
- fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n");
-
- fprintf(file, "#define offobjvftbl %3d\n", (int) OFFSET(java_objectheader, vftbl));
- fprintf(file, "#define offarraysize %3d\n", (int) OFFSET(java_arrayheader, size));
- fprintf(file, "#define offobjarrdata %3d\n\n", (int) OFFSET(java_objectarray, data[0]));
- fprintf(file, "#define offbaseval %3d\n", (int) OFFSET(vftbl, baseval));
- fprintf(file, "#define offdiffval %3d\n\n", (int) OFFSET(vftbl, diffval));
-
- fprintf(file, "#define offjniitemtype %3d\n", (int) OFFSET(jni_callblock, itemtype));
- fprintf(file, "#define offjniitem %3d\n", (int) OFFSET(jni_callblock, item));
- fprintf(file, "#define sizejniblock %3d\n\n", (int) sizeof(jni_callblock));
-
- fclose(file);
-
- suck_init(classpath);
-
- tables_init();
- heap_init(heapsize, heapsize, &dummy);
- loader_init();
-
-
- /*********************** Load JAVA classes **************************/
-
- nativemethod_chain = chain_new();
- nativeclass_chain = chain_new();
-
- for (a = 1; a < argc; a++) {
- cp = argv[a];
-
- /* convert classname */
- for (i = strlen(cp) - 1; i >= 0; i--) {
- switch (cp[i]) {
- case '.': cp[i]='/';
- break;
- case '_': cp[i]='$';
- }
- }
-
- topclass = loader_load(utf_new_char(cp));
-
- headerfile_generate(topclass);
- }
-
- headers_finish();
-
- /************************ Release all resources **********************/
-
- loader_close();
- heap_close();
- tables_close(literalstring_free);
-
-
- /* Print "finished" message */
-
- log_text("Java - header-generator stopped");
- log_cputime();
- mem_usagelog(1);
-
- return 0;
-}
-
-