Merge branch 'refs/heads/MultipleClasses' into testsuites

This commit is contained in:
JonathanFleischmann 2024-05-14 15:05:12 +02:00
commit 131264d27e
2 changed files with 24 additions and 25 deletions

View File

@ -47,22 +47,25 @@ public class Compiler {
}
public static TypedProgram generateTypedASTFromAst(Program ast) {
TypedClass typedAST = new TypedClass();
TypedProgram typedProgram = new TypedProgram(ast);
return typedProgram;
TypedProgram typedAST = new TypedProgram(ast);
return typedAST;
}
public static byte[] generateByteCodeArrayFromTypedAst(TypedProgram typedAST) {
public static byte[] generateByteCodeArrayFromTypedAst(TypedClass typedAST) {
return typedAST.codeGen();
}
public static byte[] generateByteCodeArray(List<String> fromSources) {
public static List<byte[]> generateByteCodeArray(List<String> fromSources) {
Program ast = generateAST(fromSources);
TypedProgram typedAST = generateTypedASTFromAst(ast);
return generateByteCodeArrayFromTypedAst(typedAST);
List<byte[]> byteCode = new ArrayList<>();
for (TypedClass c : typedAST.getTypedClasses()) {
byteCode.add(generateByteCodeArrayFromTypedAst(c));
}
return byteCode;
}
public static byte[] generateByteCodeArrayFromFile(List<String> sourcePaths) {
public static List<byte[]> generateByteCodeArrayFromFile(List<String> sourcePaths) {
List<Class> classes = new ArrayList<>();
for (String sourcePath : sourcePaths) {
ANTLRInputStream antlrInputStream;
@ -81,17 +84,21 @@ public class Compiler {
}
Program program = new Program(classes);
TypedProgram typedAST = generateTypedASTFromAst(program);
//TODO: Für jede Klasse einzeln Bytecode generieren
return generateByteCodeArrayFromTypedAst(typedAST);
List<byte[]> byteCode = new ArrayList<>();
for (TypedClass c : typedAST.getTypedClasses()) {
byteCode.add(generateByteCodeArrayFromTypedAst(c));
}
return byteCode;
}
public static void generateByteCodeFileFromFile(List<String> sourcePath, String classname) {
byte[] bytes = generateByteCodeArrayFromFile(sourcePath);
//TODO: Für jede Klasse einzeln Bytecode schreiben
CodeGenUtils.writeClassfile(bytes, classname);
public static void generateByteCodeFileFromFile(List<String> sourcePath, List<String> classname) {
List<byte[]> bytes = generateByteCodeArrayFromFile(sourcePath);
for (int i = 0; i < bytes.size(); i++) {
CodeGenUtils.writeClassfile(bytes.get(i), classname.get(i));
}
}
public static void main(String[] args) {
generateByteCodeFileFromFile(List.of("src/main/resources/JavaTestfiles/ClassCanBeTyped.java"), "ClassCanBeTyped");
generateByteCodeFileFromFile(List.of("src/main/resources/JavaTestfiles/ClassCanBeTyped.java"), List.of("ClassCanBeTyped"));
}
}

View File

@ -2,12 +2,14 @@ package de.maishai.typedast.typedclass;
import de.maishai.ast.records.Program;
import de.maishai.typedast.ClassContext;
import lombok.Getter;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import java.util.ArrayList;
import java.util.List;
@Getter
public class TypedProgram {
private List<TypedClass> typedClasses = new ArrayList<>();
@ -16,18 +18,8 @@ public class TypedProgram {
startConversion(program);
}
public void startConversion(Program program){
//TODO: implement
program.classes().toString();
}
public byte[] codeGen() {
//TODO: implement this quickly
return null;
}
}