From 157c83d9a4d9fb06a9e4e55d1465da1304e97e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 24 Mar 2014 15:32:13 +0100 Subject: [PATCH] Anpassungen fuer jvmdisassembler --- .classpath | 1 + src/mycompiler/mybytecode/ClassFile.java | 103 ++++--------------- src/mycompiler/mybytecode/CodeAttribute.java | 29 ++++-- src/mycompiler/mybytecode/SignatureInfo.java | 9 +- 4 files changed, 46 insertions(+), 96 deletions(-) diff --git a/.classpath b/.classpath index 20f5e915..8799920f 100755 --- a/.classpath +++ b/.classpath @@ -6,5 +6,6 @@ + diff --git a/src/mycompiler/mybytecode/ClassFile.java b/src/mycompiler/mybytecode/ClassFile.java index 661eae1b..e77d959c 100755 --- a/src/mycompiler/mybytecode/ClassFile.java +++ b/src/mycompiler/mybytecode/ClassFile.java @@ -1,15 +1,16 @@ +//key_vector funktioniert nicht PL 14-03-21 +//muss angeschaut werden + + // ino.module.ClassFile.8531.package package mycompiler.mybytecode; // ino.end // ino.module.ClassFile.8531.import -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.lang.reflect.Array; import java.util.Vector; - import mycompiler.myclass.ParameterList; import mycompiler.myclass.UsedId; import mycompiler.MyCompiler; @@ -19,7 +20,6 @@ import mycompiler.mystatement.Assign; import mycompiler.mystatement.Block; import mycompiler.mytype.Type; import mycompiler.SourceFile; - import org.apache.log4j.Logger; // ino.end @@ -38,7 +38,6 @@ public class ClassFile // ino.end // ino.class.ClassFile.21492.body { - //Beschreibung des Classfiles: http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4 public boolean hamaAload0 = false; //hama: f�gt in Konstruktor und set Methode ein aload_0 ein wird f�r StoreSomethingParmCon ben�tigt // ino.attribute.codegenlog.21495.decldescription type=line @@ -55,10 +54,10 @@ public class ClassFile private static int magic = 0xcafebabe; // ino.end // ino.attribute.minor_version.21501.declaration - private static short minor_version = 0; + public static short minor_version = 0; // ino.end // ino.attribute.major_version.21504.declaration - private static short major_version = 0x31; + public static short major_version = 0x31; // ino.end // ino.attribute.constant_pool.21507.declaration @@ -92,7 +91,7 @@ public class ClassFile private Vector class_block = new Vector(); // ino.end // ino.attribute.class_name.21537.declaration - private String class_name = new String(); + private String class_name = new String("OUTPUT");//DEFAULTWERT PL 14-03-21 eingefuegt // ino.end // ino.attribute.super_class_name.21540.declaration private String super_class_name = new String(); @@ -638,6 +637,11 @@ public class ClassFile // ino.method.set_attributes.21624.body { this.attributes = t; } // ino.end + + public void set_class_name(String cn) { + this.class_name = cn; + } + // ino.method.set_constructor_founded.21627.definition public void set_constructor_founded(boolean t) // ino.end @@ -729,7 +733,8 @@ public class ClassFile codegenlog.info("Generieren der Klasse: " + class_name); // Datei vorbereiten - File file = new File(MyCompiler.getAPI().getOutputDir() + //File file = new File(MyCompiler.getAPI().getOutputDir() + File file = new File ("/Users/pl/forschung/PIZZA+/JVM_Generics/Testfiles/" + class_name + ".class"); FileOutputStream f = new FileOutputStream(file); @@ -799,7 +804,7 @@ public class ClassFile // ino.end // ino.method.writeInt.21669.definition - public void writeInt(OutputStream f, int i) + public void writeInt(FileOutputStream f, int i) throws IOException // ino.end // ino.method.writeInt.21669.body @@ -812,7 +817,7 @@ public class ClassFile // ino.end // ino.method.writeShort.21672.definition - public void writeShort(OutputStream f, short i) + public void writeShort(FileOutputStream f, short i) throws IOException // ino.end // ino.method.writeShort.21672.body @@ -823,7 +828,7 @@ public class ClassFile // ino.end // ino.method.writeByte.21675.definition - public void writeByte(OutputStream f, byte i) + public void writeByte(FileOutputStream f, byte i) throws IOException // ino.end // ino.method.writeByte.21675.body @@ -833,7 +838,7 @@ public class ClassFile // ino.end // ino.method.writeByteArray.21678.definition - public void writeByteArray(OutputStream f, byte[] b) + public void writeByteArray(FileOutputStream f, byte[] b) throws IOException // ino.end // ino.method.writeByteArray.21678.body @@ -841,78 +846,6 @@ public class ClassFile for(int i = 0; i < Array.getLength(b); i++) f.write(b[i]); } // ino.end - - public byte[] getBytecode() { - ByteArrayOutputStream f = new ByteArrayOutputStream(); - try { - // Schreiben der Header-Infos - writeInt(f, magic); - - writeShort(f, minor_version); - writeShort(f, major_version); - codegenlog.debug("Header: magic=" + Integer.toHexString(magic)); - codegenlog.debug("Header: minor_version=" + minor_version); - codegenlog.debug("Header: major_version=" + major_version); - codegenlog.info("Verarbeite Konstanten-Pool: " + (constant_pool.size()+1)); - - // Constant-Pool verarbeiten - writeShort(f, (short)(constant_pool.size() + 1)); - for(int i = 0; i < constant_pool.size(); i++) - { - codegenlog.debug((i+1) +". " + - constant_pool.elementAt(i).toString()); - constant_pool.elementAt(i).codegen(this, f); - } - - // Informationen ueber die Klasse selbst verarbeiten - writeShort(f, access_flags); - writeShort(f, this_class); - writeShort(f, super_class); - codegenlog.debug("Klasseninfos: access_flags=" + access_flags); - codegenlog.debug("Klasseninfos: this_class=" + this_class); - codegenlog.debug("Klasseninfos: super_class=" + super_class); - - // Interfaces verarbeiten - codegenlog.info("Verarbeite Interfaces: " + interfaces.size()); - writeShort(f, (short)interfaces.size()); - for (int i=0; i local_type_vector = new Vector(); // ino.end + + short max_stack; + public CodeAttribute() { + super(); + } + // ino.method.CodeAttribute.21700.definition public CodeAttribute(String class_name, short acc_flags) // ino.end @@ -204,9 +213,11 @@ public class CodeAttribute extends Attribute // ino.end // ino.method.get_attributes_length.21748.body { - int ret = 12; + int ret = 8;//2(max_stack)+2(max_locals)+4(code_length) ret += code_vector.size(); + ret += 2; //exception table length ret += (exception_tables.size() * 8); + ret += 2; //Attribute_count for (int i = 0; i < attributes.size(); i++) ret += attributes.elementAt(i) .get_attributes_length(); @@ -232,15 +243,20 @@ public class CodeAttribute extends Attribute } // ino.end + public void set_max_stack(short ms) { + max_stack = ms; + } + + // ino.method.codegen.21757.definition - @Override - public void codegen(ClassFile classfile, OutputStream f) + public void codegen(ClassFile classfile, FileOutputStream f) throws JVMCodeException, IOException // ino.end // ino.method.codegen.21757.body { int attributes_length = this.get_attributes_length(); - short max_stack = calculate_max_stack(); + //PL 14-03-21: muss wieder einkommentiert werden + //short max_stack = calculate_max_stack(); classfile.writeShort(f, get_attribute_name_index()); classfile.writeInt(f, attributes_length); classfile.writeShort(f, max_stack); @@ -281,6 +297,7 @@ public class CodeAttribute extends Attribute // ino.end // ino.method.calculate_max_stack.21760.definition + //PL 14-03-21: Diese Methode duerfte nicht stimmen private short calculate_max_stack() throws JVMCodeException // ino.end diff --git a/src/mycompiler/mybytecode/SignatureInfo.java b/src/mycompiler/mybytecode/SignatureInfo.java index 049665eb..bb684269 100755 --- a/src/mycompiler/mybytecode/SignatureInfo.java +++ b/src/mycompiler/mybytecode/SignatureInfo.java @@ -5,9 +5,7 @@ package mycompiler.mybytecode; // ino.module.SignatureInfo.8550.import import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.util.Vector; - import mycompiler.myclass.ParameterList; import mycompiler.myclass.UsedId; import mycompiler.myexception.JVMCodeException; @@ -15,7 +13,6 @@ import mycompiler.mytype.BoundedGenericTypeVar; import mycompiler.mytype.GenericTypeVar; import mycompiler.mytype.RefType; import mycompiler.mytype.Type; - import org.apache.log4j.Logger; // ino.end @@ -46,6 +43,9 @@ public class SignatureInfo extends Attribute // ino.end + public SignatureInfo(short sid) { + signatureID = sid; + } // ino.method.SignatureInfo.22978.defdescription type=javadoc /** * Konstruktor fuer die Signatur einer Klasse bzw. eines Interfaces. @@ -178,8 +178,7 @@ public class SignatureInfo extends Attribute // ino.end // ino.method.codegen.22987.definition - @Override - public void codegen(ClassFile classfile, OutputStream f) + public void codegen(ClassFile classfile, FileOutputStream f) throws JVMCodeException, IOException // ino.end // ino.method.codegen.22987.body