forked from JavaTX/JavaCompilerCore
Anpassungen fuer jvmdisassembler
This commit is contained in:
parent
9990892e5b
commit
157c83d9a4
@ -6,5 +6,6 @@
|
|||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
<classpathentry kind="lib" path="lib/log4j-1.2.12.jar"/>
|
<classpathentry kind="lib" path="lib/log4j-1.2.12.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/junit-4.0.jar"/>
|
<classpathentry kind="lib" path="lib/junit-4.0.jar"/>
|
||||||
|
<classpathentry kind="lib" path="/Users/pl/workspaceV3_3_2/de.ba.horb.typeinference.plugin.updateSite/plugins/org.apache.log4j_1.2.15.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
|
//key_vector funktioniert nicht PL 14-03-21
|
||||||
|
//muss angeschaut werden
|
||||||
|
|
||||||
|
|
||||||
// ino.module.ClassFile.8531.package
|
// ino.module.ClassFile.8531.package
|
||||||
package mycompiler.mybytecode;
|
package mycompiler.mybytecode;
|
||||||
// ino.end
|
// ino.end
|
||||||
// ino.module.ClassFile.8531.import
|
// ino.module.ClassFile.8531.import
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import mycompiler.myclass.ParameterList;
|
import mycompiler.myclass.ParameterList;
|
||||||
import mycompiler.myclass.UsedId;
|
import mycompiler.myclass.UsedId;
|
||||||
import mycompiler.MyCompiler;
|
import mycompiler.MyCompiler;
|
||||||
@ -19,7 +20,6 @@ import mycompiler.mystatement.Assign;
|
|||||||
import mycompiler.mystatement.Block;
|
import mycompiler.mystatement.Block;
|
||||||
import mycompiler.mytype.Type;
|
import mycompiler.mytype.Type;
|
||||||
import mycompiler.SourceFile;
|
import mycompiler.SourceFile;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
@ -38,7 +38,6 @@ public class ClassFile
|
|||||||
// ino.end
|
// ino.end
|
||||||
// ino.class.ClassFile.21492.body
|
// 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<EFBFBD>gt in Konstruktor und set Methode ein aload_0 ein wird f<EFBFBD>r StoreSomethingParmCon ben<EFBFBD>tigt
|
public boolean hamaAload0 = false; //hama: f<EFBFBD>gt in Konstruktor und set Methode ein aload_0 ein wird f<EFBFBD>r StoreSomethingParmCon ben<EFBFBD>tigt
|
||||||
|
|
||||||
// ino.attribute.codegenlog.21495.decldescription type=line
|
// ino.attribute.codegenlog.21495.decldescription type=line
|
||||||
@ -55,10 +54,10 @@ public class ClassFile
|
|||||||
private static int magic = 0xcafebabe;
|
private static int magic = 0xcafebabe;
|
||||||
// ino.end
|
// ino.end
|
||||||
// ino.attribute.minor_version.21501.declaration
|
// ino.attribute.minor_version.21501.declaration
|
||||||
private static short minor_version = 0;
|
public static short minor_version = 0;
|
||||||
// ino.end
|
// ino.end
|
||||||
// ino.attribute.major_version.21504.declaration
|
// ino.attribute.major_version.21504.declaration
|
||||||
private static short major_version = 0x31;
|
public static short major_version = 0x31;
|
||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
// ino.attribute.constant_pool.21507.declaration
|
// ino.attribute.constant_pool.21507.declaration
|
||||||
@ -92,7 +91,7 @@ public class ClassFile
|
|||||||
private Vector<Assign> class_block = new Vector<Assign>();
|
private Vector<Assign> class_block = new Vector<Assign>();
|
||||||
// ino.end
|
// ino.end
|
||||||
// ino.attribute.class_name.21537.declaration
|
// 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.end
|
||||||
// ino.attribute.super_class_name.21540.declaration
|
// ino.attribute.super_class_name.21540.declaration
|
||||||
private String super_class_name = new String();
|
private String super_class_name = new String();
|
||||||
@ -638,6 +637,11 @@ public class ClassFile
|
|||||||
// ino.method.set_attributes.21624.body
|
// ino.method.set_attributes.21624.body
|
||||||
{ this.attributes = t; }
|
{ this.attributes = t; }
|
||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
|
public void set_class_name(String cn) {
|
||||||
|
this.class_name = cn;
|
||||||
|
}
|
||||||
|
|
||||||
// ino.method.set_constructor_founded.21627.definition
|
// ino.method.set_constructor_founded.21627.definition
|
||||||
public void set_constructor_founded(boolean t)
|
public void set_constructor_founded(boolean t)
|
||||||
// ino.end
|
// ino.end
|
||||||
@ -729,7 +733,8 @@ public class ClassFile
|
|||||||
codegenlog.info("Generieren der Klasse: " + class_name);
|
codegenlog.info("Generieren der Klasse: " + class_name);
|
||||||
|
|
||||||
// Datei vorbereiten
|
// 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");
|
+ class_name + ".class");
|
||||||
FileOutputStream f = new FileOutputStream(file);
|
FileOutputStream f = new FileOutputStream(file);
|
||||||
|
|
||||||
@ -799,7 +804,7 @@ public class ClassFile
|
|||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
// ino.method.writeInt.21669.definition
|
// ino.method.writeInt.21669.definition
|
||||||
public void writeInt(OutputStream f, int i)
|
public void writeInt(FileOutputStream f, int i)
|
||||||
throws IOException
|
throws IOException
|
||||||
// ino.end
|
// ino.end
|
||||||
// ino.method.writeInt.21669.body
|
// ino.method.writeInt.21669.body
|
||||||
@ -812,7 +817,7 @@ public class ClassFile
|
|||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
// ino.method.writeShort.21672.definition
|
// ino.method.writeShort.21672.definition
|
||||||
public void writeShort(OutputStream f, short i)
|
public void writeShort(FileOutputStream f, short i)
|
||||||
throws IOException
|
throws IOException
|
||||||
// ino.end
|
// ino.end
|
||||||
// ino.method.writeShort.21672.body
|
// ino.method.writeShort.21672.body
|
||||||
@ -823,7 +828,7 @@ public class ClassFile
|
|||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
// ino.method.writeByte.21675.definition
|
// ino.method.writeByte.21675.definition
|
||||||
public void writeByte(OutputStream f, byte i)
|
public void writeByte(FileOutputStream f, byte i)
|
||||||
throws IOException
|
throws IOException
|
||||||
// ino.end
|
// ino.end
|
||||||
// ino.method.writeByte.21675.body
|
// ino.method.writeByte.21675.body
|
||||||
@ -833,7 +838,7 @@ public class ClassFile
|
|||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
// ino.method.writeByteArray.21678.definition
|
// ino.method.writeByteArray.21678.definition
|
||||||
public void writeByteArray(OutputStream f, byte[] b)
|
public void writeByteArray(FileOutputStream f, byte[] b)
|
||||||
throws IOException
|
throws IOException
|
||||||
// ino.end
|
// ino.end
|
||||||
// ino.method.writeByteArray.21678.body
|
// ino.method.writeByteArray.21678.body
|
||||||
@ -842,77 +847,5 @@ public class ClassFile
|
|||||||
}
|
}
|
||||||
// ino.end
|
// 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<interfaces.size(); i++) {
|
|
||||||
writeShort(f, interfaces.elementAt(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Felder verarbeiten
|
|
||||||
codegenlog.info("Verarbeite Fields: " + fields.size());
|
|
||||||
writeShort(f, (short)fields.size());
|
|
||||||
for(int i = 0; i < fields.size(); i++)
|
|
||||||
{
|
|
||||||
fields.elementAt(i).codegen(this, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Methodenvektor
|
|
||||||
codegenlog.info("Verarbeite Methodenliste: " + methods.size());
|
|
||||||
writeShort(f, (short)methods.size());
|
|
||||||
for(int i = 0; i < methods.size(); i++)
|
|
||||||
{
|
|
||||||
codegenlog.debug("Verarbeite Methode " + (i+1));
|
|
||||||
methods.elementAt(i).codegen(this, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attribut-Vektor
|
|
||||||
codegenlog.info("Verarbeite Attribute: " + attributes.size());
|
|
||||||
writeShort(f, (short)attributes.size());
|
|
||||||
for(int i = 0; i < attributes.size(); i++)
|
|
||||||
{
|
|
||||||
attributes.elementAt(i).codegen(this, f);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JVMCodeException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return f.toByteArray();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
//PL 14-03-21: calculate_max_stack() duerfte nicht stimmen
|
||||||
|
//vorübergehend max_stack und set_max_stack eingeführt
|
||||||
|
//in codegen "short max_stack = calculate_max_stack();" auskommentiert
|
||||||
|
//muss wieder einkommentiert werden
|
||||||
|
|
||||||
// ino.module.CodeAttribute.8532.package
|
// ino.module.CodeAttribute.8532.package
|
||||||
package mycompiler.mybytecode;
|
package mycompiler.mybytecode;
|
||||||
// ino.end
|
// ino.end
|
||||||
@ -5,10 +10,8 @@ package mycompiler.mybytecode;
|
|||||||
// ino.module.CodeAttribute.8532.import
|
// ino.module.CodeAttribute.8532.import
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import mycompiler.myexception.JVMCodeException;
|
import mycompiler.myexception.JVMCodeException;
|
||||||
import mycompiler.mytype.Type;
|
import mycompiler.mytype.Type;
|
||||||
// ino.end
|
// ino.end
|
||||||
@ -34,6 +37,12 @@ public class CodeAttribute extends Attribute
|
|||||||
private Vector<Type> local_type_vector = new Vector<Type>();
|
private Vector<Type> local_type_vector = new Vector<Type>();
|
||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
|
short max_stack;
|
||||||
|
|
||||||
|
public CodeAttribute() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
// ino.method.CodeAttribute.21700.definition
|
// ino.method.CodeAttribute.21700.definition
|
||||||
public CodeAttribute(String class_name, short acc_flags)
|
public CodeAttribute(String class_name, short acc_flags)
|
||||||
// ino.end
|
// ino.end
|
||||||
@ -204,9 +213,11 @@ public class CodeAttribute extends Attribute
|
|||||||
// ino.end
|
// ino.end
|
||||||
// ino.method.get_attributes_length.21748.body
|
// 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 += code_vector.size();
|
||||||
|
ret += 2; //exception table length
|
||||||
ret += (exception_tables.size() * 8);
|
ret += (exception_tables.size() * 8);
|
||||||
|
ret += 2; //Attribute_count
|
||||||
for (int i = 0; i < attributes.size(); i++)
|
for (int i = 0; i < attributes.size(); i++)
|
||||||
ret += attributes.elementAt(i)
|
ret += attributes.elementAt(i)
|
||||||
.get_attributes_length();
|
.get_attributes_length();
|
||||||
@ -232,15 +243,20 @@ public class CodeAttribute extends Attribute
|
|||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
|
public void set_max_stack(short ms) {
|
||||||
|
max_stack = ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ino.method.codegen.21757.definition
|
// ino.method.codegen.21757.definition
|
||||||
@Override
|
public void codegen(ClassFile classfile, FileOutputStream f)
|
||||||
public void codegen(ClassFile classfile, OutputStream f)
|
|
||||||
throws JVMCodeException, IOException
|
throws JVMCodeException, IOException
|
||||||
// ino.end
|
// ino.end
|
||||||
// ino.method.codegen.21757.body
|
// ino.method.codegen.21757.body
|
||||||
{
|
{
|
||||||
int attributes_length = this.get_attributes_length();
|
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.writeShort(f, get_attribute_name_index());
|
||||||
classfile.writeInt(f, attributes_length);
|
classfile.writeInt(f, attributes_length);
|
||||||
classfile.writeShort(f, max_stack);
|
classfile.writeShort(f, max_stack);
|
||||||
@ -281,6 +297,7 @@ public class CodeAttribute extends Attribute
|
|||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
// ino.method.calculate_max_stack.21760.definition
|
// ino.method.calculate_max_stack.21760.definition
|
||||||
|
//PL 14-03-21: Diese Methode duerfte nicht stimmen
|
||||||
private short calculate_max_stack()
|
private short calculate_max_stack()
|
||||||
throws JVMCodeException
|
throws JVMCodeException
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -5,9 +5,7 @@ package mycompiler.mybytecode;
|
|||||||
// ino.module.SignatureInfo.8550.import
|
// ino.module.SignatureInfo.8550.import
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import mycompiler.myclass.ParameterList;
|
import mycompiler.myclass.ParameterList;
|
||||||
import mycompiler.myclass.UsedId;
|
import mycompiler.myclass.UsedId;
|
||||||
import mycompiler.myexception.JVMCodeException;
|
import mycompiler.myexception.JVMCodeException;
|
||||||
@ -15,7 +13,6 @@ import mycompiler.mytype.BoundedGenericTypeVar;
|
|||||||
import mycompiler.mytype.GenericTypeVar;
|
import mycompiler.mytype.GenericTypeVar;
|
||||||
import mycompiler.mytype.RefType;
|
import mycompiler.mytype.RefType;
|
||||||
import mycompiler.mytype.Type;
|
import mycompiler.mytype.Type;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
@ -46,6 +43,9 @@ public class SignatureInfo extends Attribute
|
|||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
|
|
||||||
|
public SignatureInfo(short sid) {
|
||||||
|
signatureID = sid;
|
||||||
|
}
|
||||||
// ino.method.SignatureInfo.22978.defdescription type=javadoc
|
// ino.method.SignatureInfo.22978.defdescription type=javadoc
|
||||||
/**
|
/**
|
||||||
* Konstruktor fuer die Signatur einer Klasse bzw. eines Interfaces.
|
* Konstruktor fuer die Signatur einer Klasse bzw. eines Interfaces.
|
||||||
@ -178,8 +178,7 @@ public class SignatureInfo extends Attribute
|
|||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
// ino.method.codegen.22987.definition
|
// ino.method.codegen.22987.definition
|
||||||
@Override
|
public void codegen(ClassFile classfile, FileOutputStream f)
|
||||||
public void codegen(ClassFile classfile, OutputStream f)
|
|
||||||
throws JVMCodeException, IOException
|
throws JVMCodeException, IOException
|
||||||
// ino.end
|
// ino.end
|
||||||
// ino.method.codegen.22987.body
|
// ino.method.codegen.22987.body
|
||||||
|
Loading…
Reference in New Issue
Block a user