mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 08:38:03 +00:00
accurately depicted stack size
This commit is contained in:
parent
f1b366e157
commit
02039a5334
Binary file not shown.
@ -98,9 +98,7 @@ public class Compiler {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
generateByteCodeFileFromFile(List.of("src/main/resources/JavaTestfiles/ClassWithConstructor.java",
|
||||
"src/main/resources/JavaTestfiles/ClassWithConstructorAndMethodCall.java",
|
||||
"src/main/resources/JavaTestfiles/ComplexClass.java"),
|
||||
List.of("ClassWithConstructor","ClassWithConstructorAndMethodCall","ComplexClass"));
|
||||
generateByteCodeFileFromFile(List.of("src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java"),
|
||||
List.of("ClassCanBeBytecoded"));
|
||||
}
|
||||
}
|
||||
|
@ -85,13 +85,11 @@ public class TypedAssignment implements TypedStatement {
|
||||
value.codeGen(ctx);
|
||||
getOwnerChain(ctx);
|
||||
} else {
|
||||
ctx.pushStack("this");
|
||||
getOwnerChain(ctx);
|
||||
value.codeGen(ctx);
|
||||
}
|
||||
|
||||
|
||||
//save value in field
|
||||
//save value
|
||||
if (location.getField()) {
|
||||
|
||||
String receiver = ctx.getClassContext().getName();
|
||||
@ -100,6 +98,7 @@ public class TypedAssignment implements TypedStatement {
|
||||
}
|
||||
ctx.getMv().visitFieldInsn(Opcodes.PUTFIELD, receiver, location.getName(), value.getType().getDescriptor());
|
||||
System.out.println("PUTFIELD: " + receiver + " " + location.getName() + " " + value.getType().getDescriptor());
|
||||
|
||||
} else {
|
||||
if(value.getType().getKind() == Type.Kind.REFERENCE) {
|
||||
System.out.println("ASTORE " + ctx.getLocalVar(location.getName()).get().index());
|
||||
@ -108,8 +107,7 @@ public class TypedAssignment implements TypedStatement {
|
||||
ctx.getMv().visitVarInsn(Opcodes.ISTORE, ctx.getLocalVar(location.getName()).get().index());
|
||||
}
|
||||
}
|
||||
//ctx.popStack();
|
||||
//ctx.popStack();
|
||||
ctx.popStack();
|
||||
}
|
||||
|
||||
private void getOwnerChain(MethodContext ctx) {
|
||||
|
@ -206,5 +206,7 @@ public class TypedBinary implements TypedExpression {
|
||||
}
|
||||
}
|
||||
ctx.popStack();
|
||||
ctx.popStack();
|
||||
ctx.pushAnonToStack();
|
||||
}
|
||||
}
|
||||
|
@ -119,5 +119,6 @@ public class TypedFieldVarAccess implements TypedExpression {
|
||||
ctx.getMv().visitVarInsn(loadOpcode, ctx.getLocalVar(name).get().index());
|
||||
System.out.println(loadOpcode == Opcodes.ALOAD ? "ALOAD " + ctx.getLocalVar(name).get().index() : "ILOAD " + ctx.getLocalVar(name).get().index());
|
||||
}
|
||||
ctx.pushAnonToStack();
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ public class TypedIfElse implements TypedStatement {
|
||||
Label end = new Label();
|
||||
typedCon.codeGen(ctx);
|
||||
ctx.getMv().visitJumpInsn(Opcodes.IFEQ, falseLabel);
|
||||
ctx.popStack();
|
||||
ifTypedBlock.codeGen(ctx);
|
||||
ctx.getMv().visitJumpInsn(Opcodes.GOTO, end);
|
||||
|
||||
|
@ -55,11 +55,6 @@ public class TypedNew implements TypedExpression, TypedStatement {
|
||||
|
||||
@Override
|
||||
public void codeGen(MethodContext ctx) {
|
||||
//pop the stack
|
||||
//ctx.popStack();
|
||||
//ctx.getMv().visitInsn(Opcodes.POP);
|
||||
//System.out.println("Popped stack");
|
||||
|
||||
ctx.getMv().visitTypeInsn(Opcodes.NEW, type.getReference());
|
||||
System.out.println("NEW " + type.getReference());
|
||||
ctx.pushAnonToStack();
|
||||
@ -70,6 +65,9 @@ public class TypedNew implements TypedExpression, TypedStatement {
|
||||
arg.codeGen(ctx);
|
||||
}
|
||||
ctx.getMv().visitMethodInsn(Opcodes.INVOKESPECIAL, type.getReference(), "<init>", CodeGenUtils.generateDescriptor(args.stream().map(TypedExpression::getType).toList(), Type.VOID), false);
|
||||
for (TypedExpression arg : args) {
|
||||
ctx.popStack();
|
||||
}
|
||||
System.out.println("INVOKESPECIAL " + type.getReference() + "<init> " + CodeGenUtils.generateDescriptor(args.stream().map(TypedExpression::getType).toList(), Type.VOID));
|
||||
}
|
||||
}
|
||||
|
20
src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java
Normal file
20
src/main/resources/JavaTestfiles/ClassCanBeBytecoded.java
Normal file
@ -0,0 +1,20 @@
|
||||
public class ClassCanBeBytecoded {
|
||||
public ClassCanBeBytecoded() {
|
||||
}
|
||||
|
||||
public ClassCanBeBytecoded(int var1) {
|
||||
}
|
||||
|
||||
public ClassCanBeBytecoded test(int var1) {
|
||||
int result;
|
||||
if (var1 > 10) {
|
||||
result = var1 - 10;
|
||||
} else {
|
||||
result = var1 + 10;
|
||||
}
|
||||
ClassCanBeBytecoded c;
|
||||
c = new ClassCanBeBytecoded(result);
|
||||
result = var1 + var1;
|
||||
return c;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user