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