mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 08:18:03 +00:00
Finish Compiler for Multiple Classes
This commit is contained in:
parent
e97b9e55c8
commit
36f3d2755a
@ -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"));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user