Added throw_exception
[cacao.git] / src / cacaoh / headers.c
1 /* headers.c - main for header generation (cacaoh)
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Reinhard Grafl
28
29    Changes: Mark Probst
30             Philipp Tomsich
31
32    $Id: headers.c 1179 2004-06-17 17:12:40Z twisti $
33
34 */
35
36
37 #include <stdlib.h>
38 #include <string.h>
39 #include <ctype.h>
40 #include "config.h"
41 #include "global.h"
42 #include "tables.h"
43 #include "loader.h"
44 #include "builtin.h"
45 #include "mm/boehm.h"
46 #include "toolbox/chain.h"
47 #include "toolbox/memory.h"
48 #include "toolbox/logging.h"
49 #include "nat/java_lang_String.h"
50
51
52 /* replace command line options */
53
54 bool verbose =  false;
55 bool verboseexception =  false;
56 bool compileall = false;
57 bool runverbose = false;
58 bool collectverbose = false;
59
60 bool loadverbose = false;
61 bool linkverbose = false;
62 bool initverbose = false;
63
64 bool opt_rt = false;            /* true if RTA parse should be used     RT-CO */
65 bool opt_xta = false;           /* true if XTA parse should be used    XTA-CO */
66 bool opt_vta = false;           /* true if VTA parse should be used    VTA-CO */
67 bool opt_verify = true;        /* true if classfiles should be verified      */
68 bool opt_liberalutf = false;   /* Don't check overlong UTF-8 sequences       */
69
70 bool opt_stat = false;
71 bool opt_eager = false;
72
73 bool showmethods = false;
74 bool showconstantpool = false;
75 bool showutf = false;
76
77 bool makeinitializations = true;
78
79 bool getloadingtime = false;
80 s8 loadingtime = 0;
81
82
83 /******* replace some external functions  *********/
84  
85 functionptr native_findfunction(utf *cname, utf *mname, utf *desc, bool isstatic)
86 { return NULL; }
87
88 java_objectheader *javastring_new(utf *text)
89 { return NULL; }
90
91 utf *javastring_toutf(java_lang_String *string, bool isclassname)
92 { return NULL; }
93
94
95 /* some exception stuff */
96
97 char *string_java_lang_IllegalMonitorStateException =
98     "java/lang/IllegalMonitorStateException";
99
100 char *string_java_lang_NegativeArraySizeException =
101     "java/lang/NegativeArraySizeException";
102
103
104 char *string_java_lang_AbstractMethodError =
105     "java/lang/AbstractMethodError";
106
107 char *string_java_lang_ClassCircularityError =
108     "java/lang/ClassCircularityError";
109
110 char *string_java_lang_ClassFormatError =
111     "java/lang/ClassFormatError";
112
113 char *string_java_lang_ExceptionInInitializerError =
114     "java/lang/ExceptionInInitializerError";
115
116 char *string_java_lang_IncompatibleClassChangeError =
117     "java/lang/IncompatibleClassChangeError";
118
119 char *string_java_lang_InternalError =
120     "java/lang/InternalError";
121
122 char *string_java_lang_LinkageError =
123     "java/lang/LinkageError";
124
125 char *string_java_lang_NoClassDefFoundError =
126     "java/lang/NoClassDefFoundError";
127
128 char *string_java_lang_NoSuchFieldError =
129     "java/lang/NoSuchFieldError";
130
131 char *string_java_lang_NoSuchMethodError =
132         "java/lang/NoSuchMethodError";
133
134 char *string_java_lang_OutOfMemoryError =
135     "java/lang/OutOfMemoryError";
136
137
138 void throw_exception() {}
139 void throw_exception_exit() {}
140
141 void throw_cacao_exception_exit(char *exception, char *message)
142 {
143         fprintf(stderr,
144                         "Exception in thread \"main\" %s: %s\n", exception, message);
145         fflush(stderr);
146
147         /* good bye! */
148         exit(1);
149 }
150
151
152 void new_exception(char *classname) {}
153 void new_exception_message(char *classname, char *message) {}
154 void new_exception_throwable(char *classname, java_objectheader *t) {}
155 void new_exception_utfmessage(char *classname, utf *message)
156 {
157         printf("%s: ", classname);
158         utf_display(message);
159         printf("\n");
160         exit(1);
161 }
162
163 java_objectheader *literalstring_new(utf *u) { return NULL; }  
164
165
166 void literalstring_free(java_objectheader *o) { }
167 void stringtable_update() { }
168 void synchronize_caches() { }
169 void asm_call_jit_compiler() { }
170 void asm_calljavafunction() { }
171 s4 asm_builtin_checkcast(java_objectheader *obj, classinfo *class) { return 0; }
172
173 s4 asm_builtin_idiv(s4 a, s4 b) {return 0;}
174 s4 asm_builtin_irem(s4 a, s4 b) {return 0;}
175 s8 asm_builtin_ldiv(s8 a, s8 b) {return 0;}
176 s8 asm_builtin_lrem(s8 a, s8 b) {return 0;}
177
178 s4 asm_builtin_f2i(float a) { return 0; }
179 s8 asm_builtin_f2l(float a) { return 0; }
180 s4 asm_builtin_d2i(double a) { return 0; }
181 s8 asm_builtin_d2l(double a) { return 0; }
182
183 void asm_builtin_monitorenter(java_objectheader *o) {}
184 void asm_builtin_monitorexit(java_objectheader *o) {}
185
186 s4 asm_builtin_checkarraycast(java_objectheader *obj, vftbl *target) {return 0;}
187
188 #if defined(__MIPS__)
189 void atomic_swap() {}
190 void compare_and_swap() {}
191 #endif
192
193
194 #if defined(__I386__)
195 s4 asm_builtin_arrayinstanceof(java_objectheader *obj, classinfo *class) { return 0; }
196 void asm_builtin_newarray(s4 size, vftbl *arrayvftbl) {}
197 #endif
198
199 void asm_builtin_aastore(java_objectarray *a, s4 index, java_objectheader *o) {}
200
201 u1 *createcompilerstub(methodinfo *m) {return NULL;}
202 u1 *createnativestub(functionptr f, methodinfo *m) {return NULL;}
203 u1 *oldcreatenativestub(functionptr f, methodinfo *m) {return NULL;}
204
205 void removecompilerstub(u1 *stub) {}
206 void removenativestub(u1 *stub) {}
207
208 void asm_perform_threadswitch(u1 **from, u1 **to, u1 **stackTop) {}
209 u1* asm_initialize_thread_stack(void *func, u1 *stack) { return NULL; }
210 void thread_restartcriticalsection() {}
211 void asm_switchstackandcall() {}
212 void asm_handle_builtin_exception(classinfo *c) {}
213 void asm_getclassvalues_atomic() {}
214
215 #if defined(__DARWIN__)
216 int cacao_catch_Handler() {}
217 #endif
218
219 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
220 threadcritnode asm_criticalsections;
221 #endif
222
223 java_objectheader *native_new_and_init(void *p) { return NULL; }
224
225
226 /************************ global variables **********************/
227
228 THREADSPECIFIC java_objectheader *_exceptionptr;
229
230 static chain *nativemethod_chain;    /* chain with native methods     */
231 static chain *nativeclass_chain;                               /* chain with processed classes  */      
232 static chain *ident_chain;        /* chain with method and field names in current class */
233 static FILE *file = NULL;
234 static u4 outputsize;
235 static bool dopadding;
236
237
238 static void printIDpart(int c) 
239 {
240         if ((c >= 'a' && c <= 'z')
241                 || (c >= 'A' && c <= 'Z')
242                 || (c >= '0' && c <= '9')
243                 || (c == '_'))
244                 putc(c, file);
245         else
246                 putc('_', file);
247 }
248
249
250 static void printID(utf *u)
251 {
252         char *utf_ptr = u->text;
253         int i;
254
255         for (i = 0; i < utf_strlen(u); i++) 
256                 printIDpart(utf_nextu2(&utf_ptr));
257 }
258
259
260 static void addoutputsize (int len)
261 {
262         u4 newsize,i;
263         if (!dopadding) return;
264
265         newsize = ALIGN(outputsize, len);
266         
267         for (i = outputsize; i < newsize; i++) fprintf(file, "   u1 pad%d\n", (int) i);
268         outputsize = newsize;
269 }
270
271 static void printOverloadPart(utf *desc)
272 {
273         char *utf_ptr=desc->text;
274         u2 c;
275
276         fprintf(file,"__");
277         while ((c=utf_nextu2(&utf_ptr))!=')') {
278                 switch (c) {
279                         case 'I':
280                         case 'S':
281                         case 'B':
282                         case 'C':
283                         case 'Z':
284                         case 'J':
285                         case 'F':
286                         case 'D': 
287                                 fprintf (file, "%c",(char)c);
288                                 break;
289                         case '[':
290                                 fprintf(file,"_3");
291                                 break;
292                         case 'L':
293                                 putc('L',file);
294                                 while ( (c=utf_nextu2(&utf_ptr)) != ';')
295                                         printIDpart (c);
296                                 fprintf(file,"_2");
297                                 break;
298                         case '(':
299                                 break;
300                         default: panic ("invalid method descriptor");
301                 }
302         }
303 }
304
305 static char *printtype(char *utf_ptr)
306 {
307         u2 c;
308
309         switch (utf_nextu2(&utf_ptr)) {
310         case 'V': fprintf (file, "void");
311                 break;
312         case 'I':
313         case 'S':
314         case 'B':
315         case 'C':
316         case 'Z': addoutputsize (4);
317                 fprintf (file, "s4");
318                 break;
319         case 'J': addoutputsize (8);
320                 fprintf (file, "s8");
321                 break;
322         case 'F': addoutputsize (4);
323                 fprintf (file, "float");
324                 break;
325         case 'D': addoutputsize (8);
326                 fprintf (file, "double");
327                 break;
328         case '[':
329                 addoutputsize ( sizeof(java_arrayheader*) ); 
330                 switch (utf_nextu2(&utf_ptr)) {
331                 case 'I':  fprintf (file, "java_intarray*"); break;
332                 case 'J':  fprintf (file, "java_longarray*"); break;
333                 case 'Z':  fprintf (file, "java_booleanarray*"); break;
334                 case 'B':  fprintf (file, "java_bytearray*"); break;
335                 case 'S':  fprintf (file, "java_shortarray*"); break;
336                 case 'C':  fprintf (file, "java_chararray*"); break;
337                 case 'F':  fprintf (file, "java_floatarray*"); break;
338                 case 'D':  fprintf (file, "java_doublearray*"); break;
339                                 
340                 case '[':  fprintf (file, "java_objectarray*");                                        
341                         while ((c = utf_nextu2(&utf_ptr)) == '[') ;
342                         if (c=='L') 
343                                 while (utf_nextu2(&utf_ptr) != ';');
344                         break;
345                            
346                 case 'L':  fprintf (file, "java_objectarray*");
347                         while ( utf_nextu2(&utf_ptr) != ';');
348                         break;
349                 default: panic ("invalid type descriptor");
350                 }
351                 break;
352                 
353         case 'L': 
354                 addoutputsize ( sizeof(java_objectheader*));
355                 fprintf (file, "struct ");
356                 while ( (c = utf_nextu2(&utf_ptr)) != ';' ) printIDpart (c);     
357                 fprintf (file, "*");
358                 break;
359                                         
360         default:  panic ("Unknown type in field descriptor");
361         }
362         
363         return utf_ptr;
364 }
365
366
367 /***** determine the number of entries of a utf string in the ident chain *****/
368
369 static int searchidentchain_utf(utf *ident) 
370 {
371         utf *u = chain_first(ident_chain);     /* first element of list */
372         int count = 0;
373
374         while (u) {
375                 if (u==ident) count++;         /* string found */
376                 u = chain_next(ident_chain);   /* next element in list */ 
377         }
378
379         return count;
380 }
381
382
383 /************** print structure for direct access to objects ******************/
384
385 static void printfields(classinfo *c)
386 {
387         u4 i;
388         fieldinfo *f;
389         int ident_count;
390         
391         if (!c) {
392                 addoutputsize(sizeof(java_objectheader));
393                 fprintf(file, "   java_objectheader header;\n");
394                 return;
395         }
396                 
397         printfields(c->super);
398         
399         for (i = 0; i < c->fieldscount; i++) {
400                 f = &(c->fields[i]);
401                 
402                 if (!(f->flags & ACC_STATIC)) {
403                         fprintf(file, "   ");
404                         printtype(f->descriptor->text);
405                         fprintf(file, " ");
406                         utf_fprint(file, f->name);
407
408                         /* rename multiple fieldnames */
409                         if ((ident_count = searchidentchain_utf(f->name)))
410                                 fprintf(file, "%d", ident_count - 1);
411                         chain_addlast(ident_chain, f->name);    
412
413                         fprintf(file, ";\n");
414                 }
415         }
416 }
417
418
419 /***************** store prototype for native method in file ******************/
420
421 static void printmethod(methodinfo *m)
422 {
423         char *utf_ptr;
424         u2 paramnum = 1;
425         u2 ident_count;
426
427         /* search for return-type in descriptor */      
428         utf_ptr = m->descriptor->text;
429         while (utf_nextu2(&utf_ptr) != ')');
430
431         /* create remarks */
432         fprintf(file, "\n/*\n * Class:     ");
433         utf_fprint(file, m->class->name);
434         fprintf(file, "\n * Method:    ");
435         utf_fprint(file, m->name);
436         fprintf(file, "\n * Signature: ");
437         utf_fprint(file, m->descriptor);
438         fprintf(file, "\n */\n");       
439
440         /* create prototype */                  
441         fprintf(file, "JNIEXPORT ");                            
442         printtype(utf_ptr);
443         fprintf(file, " JNICALL Java_");
444         printID(m->class->name);           
445
446         chain_addlast(ident_chain, m->name);    
447
448         fprintf(file, "_");
449         printID(m->name);
450         if (m->nativelyoverloaded) printOverloadPart(m->descriptor);
451         fprintf(file, "(JNIEnv *env");
452         
453         utf_ptr = m->descriptor->text + 1;
454                         
455         if (!(m->flags & ACC_STATIC)) {
456                 fprintf(file, ", struct ");
457                 printID(m->class->name);
458                 fprintf(file, "* this");
459
460         } else {
461                 fprintf(file, ", jclass clazz");
462         }
463
464         if ((*utf_ptr) != ')') fprintf(file, ", ");
465                         
466         while ((*utf_ptr) != ')') {
467                 utf_ptr = printtype(utf_ptr);
468                 fprintf(file, " par%d", paramnum++);
469                 if ((*utf_ptr)!=')') fprintf(file, ", ");
470         }
471                         
472         fprintf(file, ");\n\n");
473 }
474
475
476 /******* remove package-name in fully-qualified classname *********************/
477
478 static void gen_header_filename(char *buffer, utf *u)
479 {
480         int i;
481   
482         for (i = 0;i < utf_strlen(u); i++) {
483                 if ((u->text[i] == '/') || (u->text[i] == '$')) buffer[i] = '_';  /* convert '$' and '/' to '_' */
484                 else buffer[i] = u->text[i];
485         }
486         buffer[utf_strlen(u)] = '\0';
487 }
488
489
490 /* create headerfile for classes and store native methods in chain ************/
491
492 static void headerfile_generate(classinfo *c)
493 {
494         char header_filename[1024] = "";
495         char classname[1024]; 
496         char uclassname[1024];
497         u2 i;
498         methodinfo *m;                  
499         u2 i2;
500         methodinfo *m2;
501         u2 nativelyoverloaded;                  
502                       
503         /* store class in chain */                    
504         chain_addlast(nativeclass_chain, c);
505                                 
506         /* open headerfile for class */
507         gen_header_filename(classname, c->name);
508
509         /* create chain for renaming fields */
510         ident_chain = chain_new();
511         
512         sprintf(header_filename, "nat/%s.h", classname);
513         file = fopen(header_filename, "w");
514         if (!file) panic("Can not open file to store header information");
515
516         fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n");
517
518         /* convert to uppercase */
519         for (i = 0; classname[i]; i++) {
520                 uclassname[i] = toupper(classname[i]);
521         }
522         uclassname[i] = '\0';
523
524         fprintf(file, "#ifndef _%s_H\n#define _%s_H\n\n", uclassname, uclassname);
525
526         /* create structure for direct access to objects */     
527         fprintf(file, "/* Structure information for class: ");
528         utf_fprint(file, c->name);
529         fprintf(file, " */\n\n");
530         fprintf(file, "typedef struct ");
531         printID(c->name);                                                       
532         fprintf(file, " {\n");
533         outputsize = 0;
534         dopadding = true;
535
536         printfields(c);
537
538         fprintf(file, "} ");
539         printID(c->name);
540         fprintf(file, ";\n\n");
541
542         /* create chain for renaming overloaded methods */
543         chain_free(ident_chain);
544         ident_chain = chain_new();
545
546         /* create method-prototypes */
547                                 
548         /* find overloaded methods */
549         for (i = 0; i < c->methodscount; i++) {
550
551                 m = &(c->methods[i]);
552
553                 if (!(m->flags & ACC_NATIVE)) continue;
554                 if (!m->nativelyoverloaded) {
555                         nativelyoverloaded=false;
556                         for (i2=i+1;i2<c->methodscount; i2++) {
557                                 m2 = &(c->methods[i2]);
558                                 if (!(m2->flags & ACC_NATIVE)) continue;
559                                 if (m->name==m2->name) {
560                                         m2->nativelyoverloaded=true;
561                                         nativelyoverloaded=true;
562                                 }
563                         }
564                         m->nativelyoverloaded=nativelyoverloaded;
565                 }
566
567         }
568
569         for (i = 0; i < c->methodscount; i++) {
570
571                 m = &(c->methods[i]);
572
573                 if (m->flags & ACC_NATIVE) {
574                         chain_addlast(nativemethod_chain, m);
575                         printmethod(m);
576                 }
577         }
578
579         chain_free(ident_chain);
580
581         fprintf(file, "#endif\n\n");
582
583         fclose(file);
584 }
585
586
587 /******** print classname, '$' used to seperate inner-class name ***********/
588
589 void print_classname(classinfo *clazz)
590 {
591         utf *u = clazz->name;
592     char *endpos  = u->text + u->blength;
593     char *utf_ptr = u->text; 
594         u2 c;
595
596     while (utf_ptr < endpos) {
597                 if ((c = utf_nextu2(&utf_ptr)) == '_') {
598                         putc('$', file);
599
600                 } else {
601                         putc(c, file);
602                 }
603         }
604
605
606
607 /*************** create table for locating native functions ****************/
608
609 static void printnativetableentry(methodinfo *m)
610 {
611         fprintf(file, "   { \"");
612         print_classname(m->class);
613         fprintf(file, "\",\n     \"");
614         utf_fprint(file, m->name);
615         fprintf(file, "\",\n     \"");
616         utf_fprint(file, m->descriptor);
617         fprintf(file, "\",\n     ");
618
619         if ((m->flags & ACC_STATIC) != 0)
620                 fprintf(file, "true");
621         else
622                 fprintf(file, "false");
623
624         fprintf(file, ",\n     ");
625         fprintf(file, "(functionptr) Java_");
626         printID(m->class->name);
627         fprintf(file,"_");
628         printID(m->name);
629         if (m->nativelyoverloaded) printOverloadPart(m->descriptor);
630         fprintf(file,"\n   },\n");
631 }
632
633
634 /***************************************************************************
635
636         create the nativetypes-headerfile which includes 
637         the headerfiles of the classes stored in the classes-chain 
638
639 ****************************************************************************/
640
641 static void headers_finish()
642 {
643         methodinfo *m;
644         classinfo *c;
645         char classname[1024];
646         
647         file = fopen("nativetypes.hh", "w");
648
649         if (!file)
650                 panic("Can not open file 'native.h' to store header information");
651         
652         fprintf(file, "/* Headerfile for native methods: nativetypes.hh */\n");
653         fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n");      
654         fprintf(file, "\n/* include native-Headerfiles */\n\n");
655                         
656         c = chain_first(nativeclass_chain);
657         while (c) {
658                 dopadding = false;
659                 gen_header_filename(classname, c->name);                                                                                                                                                                                        
660                 fprintf(file, "#include \"nat/%s.h\"\n", classname);            
661                 c = chain_next(nativeclass_chain);              
662         }
663
664     fclose(file);
665         chain_free(nativeclass_chain);
666         
667         /* create table of native-methods */
668
669         file = fopen("nativetable.hh", "w");
670
671         if (!file)
672                 panic("Can not open file 'nativetable' to store native-link-table");
673
674         fprintf(file, "/* Table of native methods: nativetables.hh */\n");
675         fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n"); 
676
677         while ((m = chain_first(nativemethod_chain)) != NULL) {
678                 chain_remove(nativemethod_chain);               
679                 printnativetableentry(m);
680         }
681                 
682         chain_free(nativemethod_chain);
683         fclose(file);
684 }
685
686
687 /******************** internal function: print_usage ************************
688
689 Prints usage information for the JAVA header generator to stdout.
690
691 ***************************************************************************/
692
693 static void print_usage()
694 {
695         printf("Usage: cacaoh class [class..]\n");
696 }   
697
698
699
700 /************************** Function: main *******************************
701
702    Main program.
703    
704 **************************************************************************/
705
706 int main(int argc, char **argv)
707 {
708         s4 i,a;
709         char *cp;
710         classinfo *topclass;
711                 
712
713         /********** internal (only used by main) *****************************/
714    
715         char classpath[500] = "";
716         char offsets_filename[1024] = ""; /* phil */
717         u4 heapmaxsize = 1000000;
718         u4 heapstartsize = 100000;
719
720         /*********** options so only headers are generated *******************/
721    
722         makeinitializations = false;
723    
724
725         /************ Collect some info from the environment *****************/
726
727         cp = getenv("CLASSPATH");
728         if (cp) {
729                 strcpy(classpath + strlen(classpath), ":");
730                 strcpy(classpath + strlen(classpath), cp);
731         }
732
733         if (argc < 2) {
734                 print_usage();
735                 exit(10);
736         }
737
738
739         /**************************** Program start **************************/
740
741         log_init(NULL);
742         log_text("Java - header-generator started"); 
743         
744         sprintf(offsets_filename, "jit/%s/offsets.h", ARCH_DIR);
745         file = fopen(offsets_filename, "w");
746         if (file == NULL) {
747                 fprintf(stderr, "Can not open file '%s' for write", offsets_filename);
748                 exit(-1);
749         }
750         
751         fprintf(file, "/* This file is machine generated, don't edit it !*/\n\n"); 
752
753         fprintf(file, "#define offobjvftbl    %3d\n", (int) OFFSET(java_objectheader, vftbl));
754         fprintf(file, "#define offarraysize   %3d\n", (int) OFFSET(java_arrayheader, size));
755         fprintf(file, "#define offobjarrdata  %3d\n\n", (int) OFFSET(java_objectarray, data[0]));
756         fprintf(file, "#define offbaseval     %3d\n", (int) OFFSET(vftbl, baseval));
757         fprintf(file, "#define offdiffval     %3d\n\n", (int) OFFSET(vftbl, diffval));
758         fprintf(file, "#define offclass     %3d\n\n", (int) OFFSET(vftbl, class));
759
760         fprintf(file, "#define offclassvftbl  %3d\n", (int) OFFSET(classinfo, vftbl));
761         fprintf(file, "#define offclassinit   %3d\n", (int) OFFSET(classinfo, initialized));
762         fprintf(file, "#define offclassloaded %3d\n", (int) OFFSET(classinfo, loaded));
763         fprintf(file, "#define offclasslinked %3d\n\n", (int) OFFSET(classinfo, linked));
764
765         fprintf(file, "#define offjniitemtype %3d\n", (int) OFFSET(jni_callblock, itemtype));
766         fprintf(file, "#define offjniitem     %3d\n", (int) OFFSET(jni_callblock, item));
767         fprintf(file, "#define sizejniblock   %3d\n\n", (int) sizeof(jni_callblock));
768
769         fprintf(file, "#define offclassmethodinfo   %3d\n\n", (int) OFFSET(methodinfo,class));
770
771         fprintf(file, "#define offmethodnative %3d\n", (int) OFFSET(native_stackframeinfo,method));
772 /*      fprintf(file, "#define offreturnfromnative %3d\n", (int) OFFSET(native_stackframeinfo,returnFromNative));
773         fprintf(file, "#define offaddrreturnfromnative %3d\n", (int) OFFSET(native_stackframeinfo,addrReturnFromNative));
774         fprintf(file, "#define offprevnative %3d\n", (int) OFFSET(native_stackframeinfo,prev));
775         fprintf(file, "#define offnextnative %3d\n", (int) OFFSET(native_stackframeinfo,next));*/
776
777         fprintf(file, "\n");
778         fprintf(file, "#define offcast_super_baseval  %3d\n", (int) OFFSET(castinfo, super_baseval));
779         fprintf(file, "#define offcast_super_diffval  %3d\n", (int) OFFSET(castinfo, super_diffval));
780         fprintf(file, "#define offcast_sub_baseval    %3d\n", (int) OFFSET(castinfo, sub_baseval));
781
782         fclose(file);
783
784         /* initialize the garbage collector */
785         gc_init(heapmaxsize, heapstartsize);
786
787         suck_init(classpath);
788    
789         tables_init();
790
791 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
792         initThreadsEarly();
793 #endif
794         loader_init();
795
796
797         /*********************** Load JAVA classes  **************************/
798         
799         nativemethod_chain = chain_new();
800         nativeclass_chain = chain_new();
801         
802         for (a = 1; a < argc; a++) {
803                 cp = argv[a];
804
805                 /* convert classname */
806                 for (i = strlen(cp) - 1; i >= 0; i--) {
807                         switch (cp[i]) {
808                         case '.': cp[i]='/';
809                                 break;
810                         case '_': cp[i]='$';    
811                         }
812                 }
813         
814 /*              topclass = loader_load(utf_new_char(cp)); */
815                 topclass = class_load(class_new(utf_new_char(cp)));
816                 class_link(topclass);
817
818         headerfile_generate(topclass);
819         }
820
821         headers_finish();
822
823         /************************ Release all resources **********************/
824
825         loader_close();
826         tables_close(literalstring_free);
827
828         /* Print "finished" message */
829
830         log_text("Java - header-generator stopped");
831         log_cputime();
832         mem_usagelog(1);
833         
834         return 0;
835 }
836
837
838 void setVMClassField(classinfo *c)
839 {
840 }
841
842
843 void *Java_java_lang_VMObject_clone(void *env, void *clazz, void * this) {
844         return 0;
845 }
846
847
848 /*
849  * These are local overrides for various environment variables in Emacs.
850  * Please do not remove this and leave it at the end of the file, where
851  * Emacs will automagically detect them.
852  * ---------------------------------------------------------------------
853  * Local variables:
854  * mode: c
855  * indent-tabs-mode: t
856  * c-basic-offset: 4
857  * tab-width: 4
858  * End:
859  */