[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Jilc-patches] CVS: jilc/src makefile,1.2,1.3 codegen.c,1.2,1.3 codegen.
From: |
Gopal.V <address@hidden> |
Subject: |
[Jilc-patches] CVS: jilc/src makefile,1.2,1.3 codegen.c,1.2,1.3 codegen.h,1.4,1.5 defines.h,1.1,1.2 |
Date: |
Wed, 29 May 2002 23:13:31 -0400 |
Update of /cvsroot/jilc/jilc/src
In directory subversions:/tmp/cvs-serv20441
Modified Files:
makefile codegen.c codegen.h defines.h
Log Message:
do I know what I'm doing heck no !
Index: makefile
===================================================================
RCS file: /cvsroot/jilc/jilc/src/makefile,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- makefile 22 Feb 2002 07:01:32 -0000 1.2
+++ makefile 30 May 2002 03:13:28 -0000 1.3
@@ -29,6 +29,9 @@
jdasm.exe: $(OBJS)
gcc $(INC) -o jdasm.exe $(OBJS)
+codegen.exe: $(OBJS) codegen.o
+ gcc -DCODE_GEN $(INC) -o codegen.exe $(OBJS) codegen.o
+
jdasm: $(OBJS)
gcc $(INC) -o jdasm $(OBJS)
@@ -38,7 +41,10 @@
clean: welcome realClean epilogue
realClean: FORCE
- rm -f *.o *.o~ *.a jdasm jdasm.exe
+ rm -f *.o *.o~ *.a *~
+
+cleanAll: clean
+ rm -f *.exe jdasm codegen
FORCE:
Index: codegen.c
===================================================================
RCS file: /cvsroot/jilc/jilc/src/codegen.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- codegen.c 17 Apr 2002 05:13:34 -0000 1.2
+++ codegen.c 30 May 2002 03:13:28 -0000 1.3
@@ -1,265 +1,1442 @@
-/**
- * codegen.h -- Code generator stub.
- *
- * Author: Abhaya Agarwal ( address@hidden )
- *
- * (C) Abhaya Agarwal : 2002
- *
- */
-
-#include "codegen.h"
-
-int write_class(JVClass* klass, FILE* output)
-{
- int i=0;
- write_class_head(klass,output);
- fprintf(output,"{\n");
- write_class_members(klass,output);
- fprintf(output,"} // Generated by jilc\n");
-}
-
-int write_class_head(JVClass* klass, FILE* output)
-{
- fprintf(output,".class ");
- write_class_attributes(klass->acc_flags,output);
- write_class_name(klass->full_name,output);
- write_super_class(klass->full_super,output);
- if(klass->interface_count>0)
- write_implemented_interfaces(klass,output);
- fprintf(output,"\n");
-}
-
-int write_class_attributes(UInt16 acc_flags,FILE* output)
-{
- fprintf(output,"auto unicode beforefieldinit
%s",jilc_access_flags(acc_flags,CLASS));
-}
-
-char* jilc_access_flags(UInt16 flags,UInt32 type)
-{
- char *retVal = (char *)calloc(101, sizeof(char));
- if(flags == 0x0000)
- strcat(retVal, "");
- if(is_set(flags, ACCESS_PUBLIC))
- strcat(retVal, "public ");
- if(is_set(flags, ACCESS_PRIVATE))
- strcat(retVal, "private ");
- if(is_set(flags, ACCESS_PROTECTED))
- strcat(retVal, "famorassem ");
- if(!is_set(flags,0x0007))
- strcat(retVal,"assembly ");
- if(is_set(flags, ACCESS_STATIC))
- strcat(retVal, "static ");
- if(is_set(flags, ACCESS_FINAL)){
- if(type==CLASS)
- strcat(retVal, "sealed ");
- else if(type==FIELD)
- strcat(retVal, "initonly ");
- else if(type==METHOD)
- strcat(retVal, "final ");
- }
- if(is_set(flags, ACCESS_SYNCHRONIZED)){
- if(type==CLASS)
- strcat(retVal,"specialname ");
- if(is_set(flags, ACCESS_VOLATILE))
- strcat(retVal, "volatile ");
- if(is_set(flags, ACCESS_TRANSIENT))
- strcat(retVal, "transient ");
- if(is_set(flags, ACCESS_NATIVE))
- strcat(retVal, "native ");
- if(is_set(flags, ACCESS_ABSTRACT))
- strcat(retVal, "abstract ");
-
- retVal = (char *)realloc(retVal, strlen(retVal));
-
- return retVal;
-}
-
-int write_class_name(char * name, FILE * output)
-{
- fprintf(output,"%s ",name);
-}
-
-int write_super_class(char * super, FILE * output)
-{
- //Todo: Handle System.object
- fprintf(output,"extends %s ",super);
-}
-
-int write_implemented_interfaces(JVClass* klass, FILE* output)
-{
- fprintf(output,"implements %s",jilc_interface(klass));
-}
-
-char * jilc_interface(JVClass* klass)
-{
- int i=0;
- char * retVal=(char *)calloc(101,sizeof(char));
- for(i=0;i<klass->interface_count;i++){
- strcat(retVal,klass->interface_entries[i].full_name);
- strcat(retVal," ");
- }
- retVal = (char *)realloc(retVal, strlen(retVal));
- return retVal;
-}
-
-int write_class_members(JVClass* klass, FILE* output)
-{
- UInt16 i;
- for(i=0;i<klass->field_count;i++)
- write_field(klass,i,output);
- for(i=0;i<klass->method_count;i++)
- write_method(klass,i,output);
-}
-
-int write_field_attributes(UInt16 acc_flags,FILE* output)
-{
- fprintf(output,"%s",jilc_access_flags(acc_flags,FIELD));
-}
-
-int write_field_type(char* descriptor,FILE* output)
-{
- fprintf(output,"%s",jilc_field_descriptor(descriptor));
-}
-
-int write_field_name(char* full_name,FILE* output)
-{
- fprintf(output,"%s ",full_name);
-}
-
-int write_field( JVClass* klass, UInt16 index, FILE* output)
-{
- fprintf(output,".field ");
- write_field_attributes(klass->field_entries[index].acc_flags,output);
- write_field_type(klass->field_entries[index].full_type,output);
- write_field_name(klass->field_entries[index].full_name,output);
- fprintf(output,"\n");
-}
-
-int write_method(JVClass* klass, UInt16 index, FILE* output)
-{
- fprintf(output,".method ");
- write_method_head(klass,index,output);
- write_method_body(klass,index,output);
-}
-
-int write_method_head(JVClass* klass,UInt16 index,FILE* output)
-{
- write_method_attributes(klass->method_entries[index].acc_flags,output);
- write_call_convention(klass,index,output);
- write_method_type(klass,index,output);
- write_method_name(klass,index,output);
- fprintf(output,"( ");
- write_method_parameters(char* parameters, FILE* output);
- fprintf(output,") ");
- write_method_impl_attributes(klass,index,output);
-}
-
-int write_method_parameters(char* parameters, FILE* output)
-{
-}
-
-int write_method_type(klass,index,output)
-{
-}
-
-int write_method_name(klass,index,output);
-{
-}
-
-int write_method_impl_attributes(klass,index,output)
-{
-}
-
-int write_call_convention(JVClass* klass,UInt16 index,FILE* output)
-{
-}
-
-int write_method_attributes(UInt16 acc_flags,FILE* output)
-{
-}
-
-int write_method_body(JVClass* klass,UInt16 index,FILE* output)
-{
-}
-
-int jilc_statement(JVClass* klass, int* count, int* line_count, FILE* output)
-{
-}
-
-int jilc_instruction(jopcode_map opcode, FILE* output)
-{
-}
-
-
-/* Auxiliary methods */
-
-char* jilc_method_descriptor(char* desriptor)
-{
-}
-
-char* jilc_field_descriptor(char* descriptor)
-{
- int done=0,pos=0,arrCount=0,i=0;
- char* retVal=(char *)calloc(1000,sizeof(char));
- while(!done)
- {
- switch(descriptor[pos]){
- case 'B':
- strcat(retVal,"byte ");
- done=1;
- break;
- case 'C':
- strcat(retVal,"char ");
- done=1;
- break;
- case 'D':
- strcat(retVal,"double ");
- done=1;
- break;
- case 'F':
- strcat(retVal,"float ");
- done=1;
- break;
- case 'I':
- strcat(retVal,"int ");
- done=1;
- break;
- case 'J':
- strcat(retVal,"long ");
- done=1;
- break;
- case 'S':
- strcat(retVal,"short ");
- done=1;
- break;
- case 'Z':
- strcat(retVal,"boolean ");
- done=1;
- break;
- case 'L':
-
strncat(retVal,descriptor+pos+1,strcspn(descriptor+pos+1,";"));
- strcat(retVal," ");
- done=1;
- break;
- case '[':
- arrCount++;
- pos++;
- break;
- }
- }
- for(i=0;i<arrCount;i++)
- strcat(retVal,"[]");
- strcat(retVal," ");
-
- //retVal = (char *)realloc(retVal, strlen(retVal));
-
- return retVal;
-}
-
-ilopcode_map jilc_opcode(jopcode_map opcode)
-{
-}
-
-int jilc_extra_code(JVClass* klass, int* count, int* line_count, FILE* output)
-{
-}
+/**
+ * codegen.c -- Implementing the Code Generation
+ *
+ * Author: Abhaya Agarwal ( address@hidden )
+ * Gaurav Vaish ( address@hidden )
+ *
+ * (C) Abhaya Agarwal, Gaurav Vaish : 2002
+ *
+ */
+
+#include <codegen.h>
+#include <jdasm.h>
+
+int write_class(JVClass* klass, FILE* output)
+{
+ int i=0;
+ fprintf(output,".assembly extern mscorlib { }\n");
+ fprintf(output,".assembly %s.dll { }\n", (strrchr(klass->full_name,
'/') + sizeof(char)));
+ write_class_head(klass, output);
+ fprintf(output,"{\n");
+ write_class_members(klass,output);
+ fprintf(output,"} // Generated by jilc\n");
+}
+
+int write_class_head(JVClass* klass, FILE* output)
+{
+ fprintf(output,".class ");
+ write_class_attributes(klass->acc_flags, output);
+ write_class_name(convert_class_name(klass->full_name), output);
+ write_super_class(klass->full_super,output);
+ if(klass->interface_count>0)
+ write_implemented_interfaces(klass,output);
+ fprintf(output,"\n");
+}
+
+int write_class_attributes(UInt16 acc_flags,FILE* output)
+{
+ fprintf(output,"auto unicode beforefieldinit
%s",jilc_access_flags(acc_flags,CLASS));
+}
+
+char* jilc_access_flags(UInt16 flags,UInt32 type)
+{
+ char *retVal = (char *)calloc(101, sizeof(char));
+ if(flags == 0x0000)
+ strcat(retVal, "");
+ if(is_set(flags, ACCESS_PUBLIC))
+ strcat(retVal, "public ");
+ if(is_set(flags, ACCESS_PRIVATE))
+ strcat(retVal, "private ");
+ if(is_set(flags, ACCESS_PROTECTED))
+ strcat(retVal, "famorassem ");
+ if(!is_set(flags,0x0007))
+ strcat(retVal,"assembly ");
+ if(is_set(flags, ACCESS_STATIC))
+ strcat(retVal, "static ");
+ if(is_set(flags, ACCESS_FINAL)){
+ if(type==CLASS)
+ strcat(retVal, "sealed ");
+ else if(type==FIELD)
+ strcat(retVal, "initonly ");
+ else if(type==METHOD)
+ strcat(retVal, "final ");
+ }
+ if(is_set(flags, ACCESS_SYNCHRONIZED))
+ if(type==CLASS)
+ strcat(retVal,"specialname ");
+ if(is_set(flags, ACCESS_VOLATILE))
+ strcat(retVal, "volatile ");
+ if(is_set(flags, ACCESS_TRANSIENT))
+ strcat(retVal, "transient ");
+ if(is_set(flags, ACCESS_ABSTRACT))
+ strcat(retVal, "abstract ");
+
+ retVal = (char *)realloc(retVal, strlen(retVal));
+
+ return retVal;
+}
+
+int write_class_name(char * name, FILE * output)
+{
+ fprintf(output,"%s ",name);
+}
+
+int write_super_class(char * super, FILE * output)
+{
+ //Todo: Handle System.object
+ //fprintf(output,"extends %s ", super);
+ fprintf(output,"extends %s ", convert_class_name(super));
+}
+
+int write_implemented_interfaces(JVClass* klass, FILE* output)
+{
+ fprintf(output,"implements %s",
convert_class_name(jilc_interface(klass)));
+}
+
+char * jilc_interface(JVClass* klass)
+{
+ int i=0;
+ char * retVal=(char *)calloc(101,sizeof(char));
+ for(i=0;i<klass->interface_count;i++){
+ strcat(retVal,klass->interface_entries[i].full_name);
+ strcat(retVal," ");
+ }
+ retVal = (char *)realloc(retVal, strlen(retVal));
+ return retVal;
+}
+
+int write_class_members(JVClass* klass, FILE* output)
+{
+ UInt16 i;
+ for(i=0;i<klass->field_count;i++)
+ write_field(klass,i,output);
+ for(i=0;i<klass->method_count;i++)
+ write_method(klass,i,output);
+}
+
+int write_field_attributes(UInt16 acc_flags,FILE* output)
+{
+ fprintf(output,"%s",jilc_access_flags(acc_flags,FIELD));
+}
+
+int write_field_type(char* descriptor,FILE* output)
+{
+ UInt16 count=0;
+ fprintf(output,"%s",jilc_field_descriptor(descriptor,&count));
+}
+
+int write_field_name(char* full_name,FILE* output)
+{
+ fprintf(output,"%s ",full_name);
+}
+
+int write_field( JVClass* klass, UInt16 index, FILE* output)
+{
+ fprintf(output,".field ");
+ write_field_attributes(klass->field_entries[index].acc_flags,output);
+ write_field_type(klass->field_entries[index].full_type,output);
+ write_field_name(klass->field_entries[index].full_name,output);
+ fprintf(output,"\n");
+}
+
+int write_method(JVClass* klass, UInt16 index, FILE* output)
+{
+ //printf("going to write method\n");
+ fprintf(output,".method ");
+ write_method_head(klass,index,output);
+// printf("Wrote the head\n");
+ fprintf(output,"{\n");
+
write_method_body(&(klass->method_entries[index]),klass->cp_entries,output);
+ fprintf(output,"}\n");
+// printf("wrote the body\n");
+}
+
+int write_method_head(JVClass* klass,UInt16 index,FILE* output)
+{
+ write_method_attributes(klass,index,output);
+ write_call_convention(klass,index,output);
+ //printf("Going to write type\n");
+ write_method_type(klass,index,output);
+ //printf("Going to write name\n");
+ write_method_name(klass,index,output);
+ fprintf(output,"( ");
+ //printf("going to get parameters\n");
+ write_method_parameters(klass,index,output);
+ fprintf(output,") ");
+ write_method_impl_attributes(klass,index,output);
+ fprintf(output,"\n");
+}
+
+int write_method_attributes(JVClass* klass,UInt16 index,FILE* output)
+{
+ fprintf(output,"virtual hidebysig ");
+
fprintf(output,"%s",jilc_access_flags(klass->method_entries[index].acc_flags,METHOD));
+ if(!strcmp(klass->method_entries[index].full_name,"<clinit>") ||
!strcmp(klass->method_entries[index].full_name,"<init>")) {
+ fprintf(output,"specialname rtspecialname ");
+ }
+
+}
+
+int write_call_convention(JVClass* klass,UInt16 index,FILE* output)
+{
+ if(!is_set(klass->method_entries[index].acc_flags,ACCESS_STATIC))
+ fprintf(output,"instance ");
+}
+
+int write_method_parameters(JVClass* klass, UInt16 index, FILE* output)
+{
+ char* parameters=(char *)calloc(100,sizeof(char));
+ char * full_type=klass->method_entries[index].full_type;
+ strncat(parameters,full_type+1,strcspn(full_type+1,")"));
+ //printf("going for jilc\n%s\n",parameters);//getchar();
+
fprintf(output,"%s",jilc_field_descriptor(parameters,&(klass->method_entries[index].parameter_count)));
+ if(!is_set(klass->method_entries[index].acc_flags,ACCESS_STATIC)){
+ (klass->method_entries[index].parameter_count)++;
+ //printf("changed parameter count\n");
+ }
+ free(parameters);
+}
+
+int write_method_type(JVClass* klass,UInt16 index,FILE* output)
+{
+ char * type=(char *)strpbrk(klass->method_entries[index].full_type,")");
+ UInt16 count=0;
+ //printf("called jilc\n");
+ fprintf(output,"%s",jilc_field_descriptor(type+1,&count));
+}
+
+int write_method_name(JVClass* klass,UInt16 index,FILE* output)
+{
+ if(!strcmp(klass->method_entries[index].full_name,"<init>")){
+ fprintf(output,".ctor ");
+ }
+ else if(!strcmp(klass->method_entries[index].full_name,"<clinit>")){
+ fprintf(output,".cctor ");
+ }
+ else{
+ fprintf(output,"%s ",klass->method_entries[index].full_name);
+ }
+}
+
+int write_method_impl_attributes(JVClass* klass,UInt16 index,FILE* output)
+{
+ char * retVal=(char *)calloc(100,sizeof(char));
+ if(is_set(klass->method_entries[index].acc_flags, ACCESS_NATIVE))
+ strcat(retVal, "native ");
+ else
+ strcat(retVal,"cil managed ");
+ if(is_set(klass->method_entries[index].acc_flags,ACCESS_SYNCHRONIZED))
+ strcat(retVal,"synchronized ");
+ fprintf(output,"%s ",retVal);
+ free(retVal);
+}
+
+int write_method_body(JVMethodEntry* method,JVCPEntry* cp_entry,FILE* output)
+{
+ char * locals=(char *)calloc(100,sizeof(char));
+ int i=0,start=0;
+ byte *code =
method->attr_entries[method->code_index].attributes.code.code;
+ int
code_len=method->attr_entries[method->code_index].attributes.code.code_count;
+printf("writing method body\n");
+ method->local_vars_type=get_local_types(method,output);
+
+ if(!strcmp(method->full_name,"main"))
+ fprintf(output,".entrypoint\n");
+
+ fprintf(output,".maxstack
%d\n",method->attr_entries[method->code_index].attributes.code.max_stack);
+
+ strcat(locals,".locals (");
+
+
for(i=method->parameter_count;i<method->attr_entries[method->code_index].attributes.code.max_locals;i++){
+ if(method->local_vars_type[i]!=NULL){
+ strcat(locals,method->local_vars_type[i]);
+ if(!strcmp(method->local_vars_type[i],"double") ||
!strcmp(method->local_vars_type[i],"long")){
+
if(i<method->attr_entries[method->code_index].attributes.code.max_locals-2)
+ strcat(locals,",");
+ i++;
+ }
+ else
if(i<method->attr_entries[method->code_index].attributes.code.max_locals-1)
+ strcat(locals,",");
+ }
+ }
+ if(strcmp(locals,".locals "))
+ fprintf(output,"%s )\n",locals);
+ free(locals);
+
+ jilc_code(method,cp_entry,output);
+}
+
+int jilc_statement(JVClass* klass, int* count, int* line_count, FILE* output)
+{
+}
+
+int jilc_instruction(jopcode_map opcode, FILE* output)
+{
+}
+
+int jilc_code(JVMethodEntry* method, JVCPEntry* cp_entry, FILE* output)
+{
+ byte*
code=method->attr_entries[method->code_index].attributes.code.code;
+ int
code_len=method->attr_entries[method->code_index].attributes.code.code_count;
+ int wide=0;
+ int start=0,i,low,high,j,count;
+ Int32* jump_points=method->jump_points;
+ int insn_offset = 0,new=0;
+ jopcode_map found;
+ while(start<code_len)
+ {
+ i=search_jopcode_map(code[start]);
+ insn_offset=start;
+ if(i>=0)
+ found = get_jopcode_map(i);
+ else
+ continue;
+ if((jump_points[insn_offset/32] & (UInt32)(1L << (insn_offset
%32)))!=0)
+ fprintf(output,"il_%04d: ",insn_offset);
+ else
+ fprintf(output,"\t");
+ switch(found.opcode)
+ {
+ case 0x00:
+ start++;
+ break;
+ case 0x01:
+ fprintf(output,"ldnull\n");
+ start++;
+ break;
+ case 0x02:
+ fprintf(output,"ldc.i4.m1\n");
+ start++;
+ break;
+ case 0x03:
+ case 0x04:
+ case 0x05:
+ case 0x06:
+ case 0x07:
+ case 0x08:
+
fprintf(output,"ldc.i4.%d\n",(found.opcode-0x03));
+ start++;
+ break;
+ case 0x09:
+ case 0x0A:
+ fprintf(output,"ldc.i8
%d\n",(found.opcode-0x09));
+ start++;
+ break;
+ case 0x0B:
+ case 0x0C:
+ case 0x0D:
+ fprintf(output,"ldc.r4
%f\n",(float)(found.opcode-0x0B));
+ start++;
+ break;
+ case 0x0E:
+ case 0x0F:
+ fprintf(output,"ldc.r8
%f\n",(double)(found.opcode-0x0E));
+ start++;
+ break;
+ case 0x10:
+ start++;
+ fprintf(output,"ldc.i4 %d\n",(signed
char)code[start]);
+ start++;
+ break;
+ case 0x11:
+ start++;
+ fprintf(output,"ldc.i4
%d\n",(int)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0x12:
+ start++;
+ fprintf(output,"ldstr \"CPEntry\"\n");
+ start++;
+ break;
+ case 0x13:
+ start++;
+ fprintf(output,"ldc Wide : not handeled\n");
+ start+=2;
+ break;
+ case 0x14:
+ start++;
+ fprintf(output,"ldc Wide : not handeled\n");
+ start+=2;
+ break;
+ case 0x15:
+ case 0x16:
+ case 0x17:
+ case 0x18:
+ case 0x19:
+ start++;
+ if(wide==1)
+ {
+ i=(UInt16)READ_UINT16(code,start);
+ if(i<method->parameter_count)
+ fprintf(output,"ldarg %d\n",i);
+ else
+ fprintf(output,"ldloc
%d\n",i-method->parameter_count);
+ start+=2;
+ }
+ else{
+ i=(unsigned char)code[start];
+ if(i<method->parameter_count)
+ fprintf(output,"ldarg %d\n",i);
+ else
+ fprintf(output,"ldloc
%d\n",i-method->parameter_count);
+ start+=1;
+ }
+ //exit(0);
+ break;
+ case 0x1a:
+ case 0x1b:
+ case 0x1c:
+ case 0x1d:
+ start++;
+ i=found.opcode-0x1a;
+ if(i<method->parameter_count)
+ fprintf(output,"ldarg.%d\n",i);
+ else
+ fprintf(output,"ldloc.%d\n",i);
+ break;
+ case 0x1e:
+ case 0x1f:
+ case 0x20:
+ case 0x21:
+ start++;
+ i=found.opcode-0x1e;
+ if(i<method->parameter_count)
+ fprintf(output,"ldarg.%d\n",i);
+ else
+ fprintf(output,"ldloc.%d\n",i);
+ break;
+ case 0x22:
+ case 0x23:
+ case 0x24:
+ case 0x25:
+ start++;
+ i=found.opcode-0x22;
+ if(i<method->parameter_count)
+ fprintf(output,"ldarg.%d\n",i);
+ else
+ fprintf(output,"ldloc.%d\n",i);
+ break;
+ case 0x26:
+ case 0x27:
+ case 0x28:
+ case 0x29:
+ start++;
+ i=found.opcode-0x26;
+ if(i<method->parameter_count)
+ fprintf(output,"ldarg.%d\n",i);
+ else
+ fprintf(output,"ldloc.%d\n",i);
+ break;
+ case 0x2a:
+ case 0x2b:
+ case 0x2c:
+ case 0x2d:
+ start++;
+ i=found.opcode-0x2a;
+ if(i<method->parameter_count)
+ fprintf(output,"ldarg.%d\n",i);
+ else
+ fprintf(output,"ldloc.%d\n",i);
+ break;
+ case 0x2e:
+ start++;
+ fprintf(output,"ldelem.i4\n");
+ break;
+ case 0x2f:
+ start++;
+ fprintf(output,"ldelem.i8\n");
+ break;
+ case 0x30:
+ start++;
+ fprintf(output,"ldelem.r4\n");
+ break;
+ case 0x31:
+ start++;
+ fprintf(output,"ldelem.r8\n");
+ break;
+ case 0x32:
+ start++;
+ fprintf(output,"ldelem.ref\n");
+ break;
+ case 0x33:
+ start++;
+ fprintf(output,"ldelem.i1\n");
+ break;
+ case 0x34:
+ start++;
+ fprintf(output,"ldelem.i2\n");
+ break;
+ case 0x35:
+ start++;
+ fprintf(output,"ldelem.i2\n");
+ break;
+ case 0x36:
+ case 0x37:
+ case 0x38:
+ case 0x39:
+ case 0x3a:
+ start++;
+ if(wide==1)
+ {
+ i=(UInt16)READ_UINT16(code,start);
+ if(i<method->parameter_count)
+ fprintf(output,"starg %d\n",i);
+ else
+ fprintf(output,"stloc
%d\n",i-method->parameter_count);
+ start+=2;
+ }
+ else{
+ i=(unsigned char)code[start];
+ if(i<method->parameter_count)
+ fprintf(output,"starg %d\n",i);
+ else
+ fprintf(output,"stloc
%d\n",i-method->parameter_count);
+ start+=1;
+ //printf("done it\n");
+ }
+ //exit(0);
+ break;
+ case 0x3b:
+ case 0x3c:
+ case 0x3d:
+ case 0x3e:
+ start++;
+ i=found.opcode-0x3b;
+ if(i<method->parameter_count)
+ fprintf(output,"starg.%d\n",i);
+ else
+ fprintf(output,"stloc.%d\n",i);
+ break;
+ case 0x3f:
+ case 0x40:
+ case 0x41:
+ case 0x42:
+ start++;
+ i=found.opcode-0x3f;
+ if(i<method->parameter_count)
+ fprintf(output,"starg.%d\n",i);
+ else
+ fprintf(output,"stloc.%d\n",i);
+ break;
+ case 0x43:
+ case 0x44:
+ case 0x45:
+ case 0x46:
+ start++;
+ i=found.opcode-0x43;
+ if(i<method->parameter_count)
+ fprintf(output,"starg.%d\n",i);
+ else
+ fprintf(output,"stloc.%d\n",i);
+ break;
+ case 0x47:
+ case 0x48:
+ case 0x49:
+ case 0x4a:
+ start++;
+ i=found.opcode-0x47;
+ if(i<method->parameter_count)
+ fprintf(output,"starg.%d\n",i);
+ else
+ fprintf(output,"stloc.%d\n",i);
+ break;
+ case 0x4b:
+ case 0x4c:
+ case 0x4d:
+ case 0x4e:
+ start++;
+ i=found.opcode-0x4b;
+ if(i<method->parameter_count)
+ fprintf(output,"starg.%d\n",i);
+ else
+ fprintf(output,"stloc.%d\n",i);
+ break;
+ case 0x4f:
+ start++;
+ fprintf(output,"stelem.i4\n");
+ break;
+ case 0x50:
+ start++;
+ fprintf(output,"stelem.i8\n");
+ break;
+ case 0x51:
+ start++;
+ fprintf(output,"stelem.r4\n");
+ break;
+ case 0x52:
+ start++;
+ fprintf(output,"stelem.r8\n");
+ break;
+ case 0x53:
+ start++;
+ fprintf(output,"stelem.ref\n");
+ break;
+ case 0x54:
+ start++;
+ fprintf(output,"stelem.i1\n");
+ break;
+ case 0x55:
+ start++;
+ fprintf(output,"stelem.i2\n");
+ break;
+ case 0x56:
+ start++;
+ fprintf(output,"stelem.i2\n");
+ break;
+ case 0x57:
+ start++;
+ fprintf(output,"pop\n");
+ break;
+ case 0x58:
+ start++;
+ fprintf(output,"pop2 //not handeled\n");
+ break;
+ case 0x59:
+ start++;
+ fprintf(output,"dup\n");
+ break;
+ case 0x5a:
+ start++;
+ fprintf(output," dup var//not handeled\n");
+ break;
+ case 0x5b:
+ start++;
+ fprintf(output," dup var//not handeled\n");
+ break;
+ case 0x5c:
+ start++;
+ fprintf(output," dup var//not handeled\n");
+ break;
+ case 0x5d:
+ start++;
+ fprintf(output," dup var//not handeled\n");
+ break;
+ case 0x5e:
+ start++;
+ fprintf(output," dup var//not handeled\n");
+ break;
+ case 0x5f:
+ start++;
+ fprintf(output," swap //not handeled\n");
+ break;
+ case 0x60:
+ case 0x61:
+ case 0x62:
+ case 0x63:
+ start++;
+ fprintf(output,"add\n"); //
exceptions
+ break;
+ case 0x64:
+ case 0x65:
+ case 0x66:
+ case 0x67:
+ start++;
+ fprintf(output,"sub\n"); //
exceptions
+ break;
+ case 0x68:
+ case 0x69:
+ case 0x6a:
+ case 0x6b:
+ start++;
+ fprintf(output,"mul\n");
//exceptions
+ break;
+ case 0x6c:
+ case 0x6d:
+ case 0x6e:
+ case 0x6f:
+ start++;
+ fprintf(output,"div\n");
//exceptions
+ break;
+ case 0x70:
+ case 0x71:
+ case 0x72:
+ case 0x73:
+ start++;
+ fprintf(output,"rem\n");
//exceptions
+ break;
+ case 0x74:
+ case 0x75:
+ case 0x76:
+ case 0x77:
+ start++;
+ fprintf(output,"neg\n");
+ break;
+ case 0x78:
+ start++;
+ fprintf(output,"shifting op\n");
+ break;
+ case 0x79:
+ start++;
+ fprintf(output,"shifting op\n");
+ break;
+ case 0x7a:
+ start++;
+ fprintf(output,"shifting op\n");
+ break;
+ case 0x7b:
+ start++;
+ fprintf(output,"shifting op\n");
+ break;
+ case 0x7c:
+ start++;
+ fprintf(output,"shifting op\n");
+ break;
+ case 0x7d:
+ start++;
+ fprintf(output,"shifting op\n");
+ break;
+ case 0x7e:
+ case 0x7f:
+ start++;
+ fprintf(output,"and\n");
+ break;
+ case 0x80:
+ case 0x81:
+ start++;
+ fprintf(output,"or\n");
+ break;
+ case 0x82:
+ case 0x83:
+ start++;
+ fprintf(output,"xor\n");
+ break;
+ case 0x84:
+ start++;
+ if(wide==1)
+ {
+ i=READ_UINT16(code,start);
+ start+=2;
+ fprintf(output,"ldloc.s
%d\n",i-method->parameter_count);
+ fprintf(output,"\tldc.i4 %d\n",(signed
char)code[start]);
+ start++;
+ fprintf(output,"\tadd\n");
+ fprintf(output,"\tstloc
%d\n",i-method->parameter_count);
+ }
+ else{
+ i=(unsigned char)code[start];
+ fprintf(output,"ldloc.s
%d\n",i-method->parameter_count);
+ start++;
+ fprintf(output,"\tldc.i4 %d\n",(signed
char)code[start]);
+ start++;
+ fprintf(output,"\tadd\n");
+ fprintf(output,"\tstloc
%d\n",i-method->parameter_count);
+ }
+ break;
+ case 0x85:
+ start++;
+ fprintf(output,"conv.i8\n");
+ break;
+ case 0x86:
+ start++;
+ fprintf(output,"conv.r4\n");
+ break;
+ case 0x87:
+ start++;
+ fprintf(output,"conv.r8\n");
+ break;
+ case 0x88:
+ start++;
+ fprintf(output,"conv.i4\n");
+ break;
+ case 0x89:
+ start++;
+ fprintf(output,"conv.r4\n");
+ break;
+ case 0x8a:
+ start++;
+ fprintf(output,"conv.r8\n");
+ break;
+ case 0x8b:
+ start++;
+ fprintf(output,"conv.i4\n");
+ break;
+ case 0x8c:
+ start++;
+ fprintf(output,"conv.i8\n");
+ break;
+ case 0x8d:
+ start++;
+ fprintf(output,"conv.r8\n");
+ break;
+ case 0x8e:
+ start++;
+ fprintf(output,"conv.i4\n");
+ break;
+ case 0x8f:
+ start++;
+ fprintf(output,"conv.i8\n");
+ break;
+ case 0x90:
+ start++;
+ fprintf(output,"conv.r4\n");
+ break;
+ case 0x91:
+ start++;
+ fprintf(output,"conv.i1\n");
+ break;
+ case 0x92:
+ start++;
+ fprintf(output,"conv.u2\n");
+ break;
+ case 0x93:
+ start++;
+ fprintf(output,"conv.i2\n");
+ break;
+ case 0x94:
+ start++;
+ fprintf(output,"compare //not
handeled\n");
+ break;
+ case 0x95:
+ start++;
+ fprintf(output,"compare //not
handeled\n");
+ break;
+ case 0x96:
+ start++;
+ fprintf(output,"compare //not
handeled\n");
+ break;
+ case 0x97:
+ start++;
+ fprintf(output,"compare //not
handeled\n");
+ break;
+ case 0x98:
+ start++;
+ fprintf(output,"compare //not
handeled\n");
+ break;
+ case 0x99:
+ start++;
+ fprintf(output,"ldc.i4.0 \n");
+ fprintf(output,"beq il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0x9a:
+ start++;
+ fprintf(output,"jump //not handeled\n");
+ start+=2;
+ break;
+ case 0x9b:
+ start++;
+ fprintf(output,"ldc.i4.0 \n");
+ fprintf(output,"blt il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0x9c:
+ start++;
+ fprintf(output,"ldc.i4.0 \n");
+ fprintf(output,"bge.un il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0x9d:
+ start++;
+ fprintf(output,"ldc.i4.0 \n");
+ fprintf(output,"bgt.un il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0x9e:
+ start++;
+ fprintf(output,"ldc.i4.0 \n");
+ fprintf(output,"ble il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0x9f:
+ start++;
+ fprintf(output,"beq il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0xa0:
+ start++;
+ fprintf(output,"jump //not handeled\n");
+ start+=2;
+ break;
+ case 0xa1:
+ start++;
+ //fprintf(output,"blt il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ fprintf(output,"blt il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0xa2:
+ start++;
+ fprintf(output,"bge.un il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0xa3:
+ start++;
+ fprintf(output,"bgt.un il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0xa4:
+ start++;
+ fprintf(output,"ble il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0xa5:
+ start++;
+ fprintf(output,"beq il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0xa6:
+ start++;
+ fprintf(output,"bne.un il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0xa7:
+ start++;
+ fprintf(output,"br il_%04d\n",insn_offset +
(Int16)READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0xa8:
+ start++;
+ fprintf(output,"//finally not
handelled\n");
+ start+=2;
+ break;
+ case 0xa9:
+ start++;
+ fprintf(output,"//finally not
handeled\n");
+ start+=1;
+ break;
+ case 0xaa:
+ start++;
+ while( (start % 4) != 0)
+ {
+ start++;
+ }
+ start += 4;
+ low = READ_INT32(code,start);
+ start+= 4;
+ high = READ_INT32(code,start);
+ start+= 4;
+ for(j=low;j<=high;j++)
+ {
+ start+=4;
+ }
+ break;
+ case 0xab:
+ start++;
+ while( (start % 4) != 0)
+ {
+ start++;
+ }
+ start += 4;
+ count = READ_INT32(code,start);
+ start += 4;
+ for(j = 0; j < count; j++)
+ {
+ start += 4;//skip key
+ start += 4;
+ }
+ break;
+ case 0xac:
+ case 0xad:
+ case 0xae:
+ case 0xaf:
+ case 0xb0:
+ case 0xb1:
+ start++;
+ fprintf(output,"ret\n");
+ break;
+ case 0xb2:
+ start++;
+ fprintf(output,"ldsfld \"Metadata\"\n");
+ start+=2;
+ break;
+ case 0xb3:
+ start++;
+ fprintf(output,"stsfld \"Metadata\"\n");
+ start+=2;
+ break;
+ case 0xb4:
+ start++;
+ fprintf(output,"ldfld \"Metadata\"\n");
+ start+=2;
+ break;
+ case 0xb5:
+ start++;
+ fprintf(output,"stfld \"Metadata\"\n");
+ start+=2;
+ break;
+ case 0xb6:
+ start++;
+ fprintf(output,"callvirt \"Metadata\"\n");
+ start+=2;
+ //exit(0);
+ break;
+ case 0xb7:
+ start++;
+ if(new>0)
+ fprintf(output,"newobj \"Metadata\"\n");
+ else
+ fprintf(output,"call \"Metadata\"\n");
+ start+=2;
+ if(new>0)
+ new--;
+ break;
+ case 0xb8:
+ start++;
+ fprintf(output,"call \"Metadata\"\n");
+ start+=2;
+ break;
+ case 0xb9:
+ start++;
+ fprintf(output,"call \"Metadata\"\n");
+ start+=4;
+ break;
+ case 0xba:
+ //unused
+ break;
+ case 0xbb:
+ start++;
+ // printf("Enterd new\n");
+ i=READ_INT16(code,start);
//handle class name
+ start+=2;
+ start++;
+ new++;
+ break;
+ case 0xbc:
+ start++;
+ fprintf(output,"newarr \"Metadata\"\n");
+ start+=1;
+ break;
+ case 0xbd:
+ start++;
+ fprintf(output,"newarr \"Metadata\"\n");
+ start+=2;
+ break;
+ case 0xbe:
+ start++;
+ fprintf(output,"ldlen\n");
+ break;
+ case 0xbf:
+ start++;
+ fprintf(output,"throw // huge differences\n");
+ break;
+ case 0xc0:
+ start++;
+ fprintf(output,"castclass //huge
differences\n");
+ start+=2;
+ break;
+ case 0xc1:
+ start++;
+ fprintf(output,"isinst \"Metadata\"\n");
+ start+=2;
+ break;
+ case 0xc2:
+ start++;
+ fprintf(output,"//MonitoeEnter not
handelled\n");
+ break;
+ case 0xc3:
+ start++;
+ fprintf(output,"//MonitorExit not
handelled\n");
+ break;
+ case 0xc4:
+ start++;
+ wide=1;
+ break;
+ case 0xc5:
+ start++;
+ fprintf(output,"//yet to figure out\n");
+ start+=3;
+ break;
+ case 0xc6:
+ start++;
+ fprintf(output,"brnull
il_%04d\n",READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0xc7:
+ start++;
+ fprintf(output,"brinst
il_%04d\n",READ_INT16(code,start));
+ start+=2;
+ break;
+ case 0xc8:
+ start++;
+ fprintf(output,"br il_%04d\n",insn_offset +
(Int16)READ_INT32(code,start));
+ start+=4;
+ break;
+ case 0xc9:
+ start++;
+ fprintf(output,"//finally not
handelled\n");
+ start+=4;
+ break;
+ case 0xca:
+ start++;
+ fprintf(output,"//debugging symbols\n");
+ break;
+ }
+ }
+
+}
+
+/* Auxiliary methods */
+
+char* jilc_field_descriptor(char* descriptor,UInt16* param_count)
+{
+ int done=0,pos=0,arrCount=0,i=0;
+ int len;
+ char* retVal;
+ *param_count=0;
+ //printf("going into loop\n");//getchar();
+ retVal=(char *)calloc(100,sizeof(char));
+ len=strlen(descriptor);
+ while(pos<len)
+ {
+ //printf("%d %d\n",pos,len);
+ switch(descriptor[pos]){
+ case 'B':
+ strcat(retVal,",byte");
+ for(i=0;i<arrCount;i++)
+ strcat(retVal,"[]");
+ arrCount=0;
+ (*param_count)++;
+ pos++;
+ break;
+ case 'C':
+ strcat(retVal,",char");
+ for(i=0;i<arrCount;i++)
+ strcat(retVal,"[]");
+ arrCount=0;
+ (*param_count)++;
+ pos++;
+ break;
+ case 'D':
+ strcat(retVal,",double");
+ for(i=0;i<arrCount;i++)
+ strcat(retVal,"[]");
+ arrCount=0;
+ (*param_count)++;
+ pos++;
+ break;
+ case 'F':
+ strcat(retVal,",float");
+ for(i=0;i<arrCount;i++)
+ strcat(retVal,"[]");
+ arrCount=0;
+ (*param_count)++;
+ pos++;
+ break;
+ case 'I':
+ strcat(retVal,",int");
+ for(i=0;i<arrCount;i++)
+ strcat(retVal,"[]");
+ arrCount=0;
+ (*param_count)++;
+ pos++;
+ break;
+ case 'J':
+ strcat(retVal,",long");
+ for(i=0;i<arrCount;i++)
+ strcat(retVal,"[]");
+ arrCount=0;
+ (*param_count)++;
+ pos++;
+ break;
+ case 'S':
+ strcat(retVal,",short");
+ for(i=0;i<arrCount;i++)
+ strcat(retVal,"[]");
+ arrCount=0;
+ (*param_count)++;
+ pos++;
+ break;
+ case 'Z':
+ strcat(retVal,",boolean");
+ for(i=0;i<arrCount;i++)
+ strcat(retVal,"[]");
+ arrCount=0;
+ (*param_count)++;
+ pos++;
+ break;
+ case 'L':
+ strcat(retVal,",");
+
strncat(retVal,descriptor+pos+1,strcspn(descriptor+pos+1,";"));
+ for(i=0;i<arrCount;i++)
+ strcat(retVal,"[]");
+ arrCount=0;
+ (*param_count)++;
+ pos+=(strcspn(descriptor+pos+1,";")+2);
+ break;
+ case '[':
+ arrCount++;
+ pos++;
+ break;
+ case 'V':
+ strcat(retVal,",void ");
+ pos++;
+ break;
+ }
+ }
+ strcat(retVal," ");
+ return retVal+1;
+}
+
+char ** get_local_types(JVMethodEntry* method,FILE* output)
+{
+ int
no_locals=method->attr_entries[method->code_index].attributes.code.max_locals;
+ char ** ltypes;
+ int
code_len=method->attr_entries[method->code_index].attributes.code.code_count;
+ int start=0,count=0,low,high,j,i,dest=0,insn_offset=0;
+ int *wide;
+ jopcode_map found;
+ char *
code=method->attr_entries[method->code_index].attributes.code.code;
+ method->jump_points=(UInt32*)calloc(code_len >> 5,sizeof(UInt32));
+ //printf("getting types\n");
+ ltypes=(char **)calloc(no_locals,sizeof(char *));
+ while(start<code_len)
+ {
+ i=search_jopcode_map(code[start]);
+ insn_offset=start;
+ if(i>=0)
+ found = get_jopcode_map(i);
+ else
+ continue;
+ //printf("here\n");
+ //printf("%x ",found.opcode);
+ if(code[start]>=0x1A && code[start]<=0x1D){
+ if(ltypes[code[start]-0x1A]==NULL)
+ ltypes[code[start]-0x1A]="int32";
+ start++;
+ }
+ else if(code[start]>=0x3B && code[start]<=0x3E){
+ if(ltypes[code[start]-0x3B]==NULL)
+ ltypes[code[start]-0x3B]="int32";
+ start++;
+ }
+ else if(code[start]>=0x1E && code[start]<=0x21){
+ if(ltypes[code[start]-0x1E]==NULL)
+ ltypes[code[start]-0x1E]="int64";
+ start++;
+ }
+ else if(code[start]>=0x3F && code[start]<=0x42){
+ if(ltypes[code[start]-0x3F]==NULL)
+ ltypes[code[start]-0x3F]="int64";
+ start++;
+ }
+ else if(code[start]>=0x22 && code[start]<=0x25){
+ if(ltypes[code[start]-0x22]==NULL)
+ ltypes[code[start]-0x22]="float";
+ start++;
+ }
+ else if(code[start]>=0x43 && code[start]<=0x46){
+ if(ltypes[code[start]-0x43]==NULL)
+ ltypes[code[start]-0x43]="float";
+ start++;
+ }
+ else if(code[start]>=0x26 && code[start]<=0x29){
+ if(ltypes[code[start]-0x26]==NULL)
+ ltypes[code[start]-0x26]="double";
+ start++;
+ }
+ else if(code[start]>=0x47 && code[start]<=0x4A){
+ if(ltypes[code[start]-0x47]==NULL)
+ ltypes[code[start]-0x47]="double";
+ start++;
+ }
+ else if(code[start]>=0x2A && code[start]<=0x2D){
+ if(ltypes[code[start]-0x2A]==NULL)
+ ltypes[code[start]-0x2A]="ref";
+ start++;
+ }
+ else if(code[start]>=0x4B && code[start]<=0x4E){
+ if(ltypes[code[start]-0x4B]== NULL)
+ ltypes[code[start]-0x4B]="ref";
+ start++;
+ }
+ else if(code[start]==0x15 || code[start]==0x36){
+ start++;
+ ltypes[(unsigned char)code[start]]="int32";
+ start++;
+ }
+ else if(code[start]==0x16 || code[start]==0x37){
+ start++;
+ ltypes[(unsigned char)code[start]]="int64";
+ start++;
+ }
+ else if(code[start]==0x17 || code[start]==0x38){
+ start++;
+ ltypes[(unsigned char)code[start]]="float";
+ start++;
+ }
+ else if(code[start]==0x18 || code[start]==0x39){
+ start++;
+ ltypes[(unsigned char)code[start]]="double";
+ start++;
+ }
+ else if(code[start]==0x19 || code[start]==0x3A){
+ start++;
+ ltypes[(unsigned char)code[start]]="ref";
+ start++;
+ }
+ else{
+
+ switch(found.args)
+ {
+ case I_U1:
+ start++;
+ if(*wide==1)
+ {
+ start += 2;
+ }
+ else
+ {
+ start += 1;
+ }
+ break;
+ case I_S1:
+ case CONSTANT_U1:
+ case ARRAYTYPE_U1:
+ start++;
+ start+=1;
+ break;
+ case I_U2:
+ case I_S2:
+ case FIELD_U2:
+ case METHOD_U2:
+ case CLASS_U2:
+ case CONSTANT_U2:
+ case BIGCONSTANT_U2:
+ start++;
+ start+=2;
+ break;
+ case LABEL_S2:
+ start++;
+
dest=insn_offset+READ_INT16(code,start);
+ if(dest<code_len)
+
method->jump_points[dest/32]|=(UInt32)(1L << \
+
(dest%32));
+ else
+
fprintf(stderr,"illegal jump offset %ld\n"\
+
,dest);
+ start += 2;
+ break;
+ case II_U1_S1:
+ start++;
+ if(*wide ==1)
+ {
+ start+=4;
+ }
+ else
+ {
+ start += 2;
+ }
+ break;
+ case LOOKUP_SWITCH:
+ start++;
+ while( (start % 4) != 0)
+ {
+ start++;
+ }
+ dest =
insn_offset+READ_INT32(code,start);
+ if(dest<code_len) //
default offset
+
method->jump_points[dest/32]|=(UInt32)(1L << \
+
(dest%32));
+ else
+
fprintf(stderr,"illegal jump offset %ld\n",\
+
dest);
+ start += 4;
+ count =
READ_INT32(code,start);
+ start += 4;
+ for(j = 0; j < count;
j++)
+ {
+ start += 4;//skip key
+
dest=insn_offset+READ_INT32(code,start);
+
if(dest<code_len)
+
method->jump_points[dest/32]|=(UInt32)(1L <<\
+
(dest%32));
+ else
fprintf(stderr,"illegal jump offset");
+ start += 4;
+ }
+ break;
+ case TABLE_SWITCH:
+ start++;
+ while( (start % 4) != 0)
+ {
+ start++;
+ }
+ dest =
insn_offset+READ_INT32(code,start);
+ if(dest<code_len) //
default offset
+
method->jump_points[dest/32]|=(UInt32)(1L << \
+
(dest%32));
+ else
+
fprintf(stderr,"illegal jump offset %ld\n",\
+
dest);
+ start += 4;
+ low =
READ_INT32(code,start);
+ start+= 4;
+ high =
READ_INT32(code,start);
+ start+= 4;
+ if(low>high)
+ {
+
fprintf(stderr,"Error !\n");
+ return NULL;
+ }
+ for(j=low;j<=high;j++)
+ {
+
dest=insn_offset+READ_INT32(code,start);
+
if(dest<code_len)
+
method->jump_points[dest/32]|=(UInt32)(1L <<\
+
(dest%32));
+ else
fprintf(stderr,"illegal jump offset");
+ start+=4;
+ }
+ break;
+ case LABEL_S4:
+ start++;
+
dest=insn_offset+READ_INT32(code,start);
+ if(dest<code_len)
+
method->jump_points[dest/32]|=(UInt32)(1L << \
+
(dest%32));
+ else
+
fprintf(stderr,"illegal jump offset %ld\n"\
+
,dest);
+ start+=4;
+ break;
+
+ case INTERFACE_U2_U1_X1:
+ start++;
+ start+=4;//skip one
byte coz SUN says so
+ break;
+ case MARRAY_U2_U1:
+ start++;
+ start+=3;
+ break;
+ case IGNORE: // wide opcode !
+ start++;
+ *wide=1;
+ // printf("WIDE\n");
+ break;
+ default:
+ start++;
+ }
+ }
+ }
+ return ltypes;
+}
+
+ilopcode_map jilc_opcode(jopcode_map opcode)
+{
+}
+
+int jilc_extra_code(JVClass* klass, int* count, int* line_count, FILE* output)
+{
+}
+
+char* convert_class_name(char *full_name)
+{
+ char *retVal;
+ char *ptr;
+ int i = 0;
+ int len;
+
+ len = strlen(full_name);
+ retVal = (char *)malloc(len + 1);
+
+ for(i=0; i < len; i++)
+ {
+ if(full_name[i] == '/')
+ {
+ retVal[i] = '.';
+ } else
+ {
+ retVal[i] = full_name[i];
+ }
+ }
+ retVal[len] = '\0';
+ return retVal;
+}
Index: codegen.h
===================================================================
RCS file: /cvsroot/jilc/jilc/src/codegen.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- codegen.h 12 Apr 2002 15:47:12 -0000 1.4
+++ codegen.h 30 May 2002 03:13:28 -0000 1.5
@@ -10,28 +10,59 @@
#ifndef __JILC_CODEGEN_H
#define __JILC_CODEGEN_H
-#include "defines.h"
-#include "jparser.h"
-#include "jopcodes.h"
-#include "ilopcodes.h"
-
+#include <defines.h>
+#include <jparser.h>
+#include <jopcodes.h>
+#include <ilopcodes.h>
+
int write_class(JVClass* klass, FILE* output);
-int write_class_head(JVClass* klass,FILE* output);
-int write_class_attributes(UInt16 acc_flag, FILE* output);
-int write_class_name(char* name,FILE* output);
-int write_super_class(char* name,FILE* output);
-int write_implemented_interfaces(JVClass* klass,FILE* output);
-
-int jilc_field(JVClass* klass, int index, FILE* output);
-int jilc_method(JVClass* klass,int index, FILE* output);
+
+/* Methods for writing the header */
+
+int write_class_head(JVClass* klass,FILE* output);
+int write_class_attributes(UInt16 acc_flag, FILE* output);
+int write_class_name(char* name,FILE* output);
+int write_super_class(char* name,FILE* output);
+int write_implemented_interfaces(JVClass* klass,FILE* output);
+
+/* Methods to write the field declarations */
+
+int write_field(JVClass* klass, UInt16 index, FILE* output);
+int write_field_attributes(UInt16 acc_flags,FILE* output);
+int write_field_type(char* descriptor,FILE* output);
+int write_field_name(char* name,FILE* output);
+
+
+int write_method(JVClass* klass, UInt16 index, FILE* output);
+//int write_method_head(JVMethodEntry* e, UInt16 index, FILE* output);
+int write_method_head(JVClass* e, UInt16 index, FILE* output);
+//int write_method_body(JVClass* klass, FILE* output);
+int write_method_body(JVMethodEntry* method, JVCPEntry* cp_entry, FILE*
output);
+//int write_method_attributes(UInt16 acc_flags,FILE* output);
+int write_method_attributes(JVClass* klass , UInt16 index, FILE* output);
+int write_method_type(JVClass* klass, UInt16 index, FILE* output);
+int write_method_name(JVClass* klass, UInt16 index, FILE* output);
+//int write_method_parameters(char* parameters, FILE* output);
+int write_method_parameters(JVClass* klass, UInt16 index, FILE* output);
+int write_method_impl_attributes(JVClass* klass, UInt16 index, FILE* output);
+
+
int jilc_statement(JVClass* klass, int* count, int* line_count, FILE* output);
-int jilc_instruction(jopcode_map opcode, FILE* output);
+int jilc_instruction(jopcode_map opcode, FILE* output);
+
+char * jilc_access_flags(UInt16 access_flag,UInt32 type);
+char * jilc_interface(JVClass* klass);
-char * jilc_access_flag(UInt16 access_flag,int type);
-char * jilc_interface(JVClass* klass);
-
/* Auxiliary methods */
+char* jilc_field_descriptor(char* descriptor, UInt16* count);
ilopcode_map jilc_opcode(jopcode_map opcode);
int jilc_extra_code(JVClass* klass, int* count, int* line_count, FILE* output);
-#endif
\ No newline at end of file
+/* Covert the package style class name to namespace style */
+
+char* convert_class_name(char *full_name);
+
+int write_call_convention(JVClass* klass, UInt16 index, FILE* output);
+char ** get_local_types(JVMethodEntry* method, FILE* output);
+
+#endif
Index: defines.h
===================================================================
RCS file: /cvsroot/jilc/jilc/src/defines.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- defines.h 25 Feb 2002 12:51:10 -0000 1.1
+++ defines.h 30 May 2002 03:13:28 -0000 1.2
@@ -1,9 +1,22 @@
-/**
- * defines.h -- Hash-defines, required for all files, are defined here.
+/*
+ * jdasm.c Deassembler implementation file.
*
- * Author: Gaurav Vaish <address@hidden>
+ * Copyright (C) 2002 Gopal.V
+ * Copyright (C) 2002 Gaurav Vaish
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
- * (C) Gaurav Vaish, Gopal V; 2002
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __DEFINES_H
@@ -12,6 +25,10 @@
#define OK 0
#define ERROR 1
+#define BOOL int
+#define TRUE 0x01
+#define FALSE 0x02
+
typedef unsigned char byte;
typedef unsigned char UInt8;
typedef unsigned short UInt16;
@@ -22,4 +39,4 @@
typedef int Int32;
typedef long long Int64;
-#endif
\ No newline at end of file
+#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Jilc-patches] CVS: jilc/src makefile,1.2,1.3 codegen.c,1.2,1.3 codegen.h,1.4,1.5 defines.h,1.1,1.2,
Gopal.V <address@hidden> <=