mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 01: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) {
|
public static TypedProgram generateTypedASTFromAst(Program ast) {
|
||||||
TypedClass typedAST = new TypedClass();
|
TypedProgram typedAST = new TypedProgram(ast);
|
||||||
TypedProgram typedProgram = new TypedProgram(ast);
|
return typedAST;
|
||||||
return typedProgram;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] generateByteCodeArrayFromTypedAst(TypedProgram typedAST) {
|
public static byte[] generateByteCodeArrayFromTypedAst(TypedClass typedAST) {
|
||||||
return typedAST.codeGen();
|
return typedAST.codeGen();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] generateByteCodeArray(List<String> fromSources) {
|
public static List<byte[]> generateByteCodeArray(List<String> fromSources) {
|
||||||
Program ast = generateAST(fromSources);
|
Program ast = generateAST(fromSources);
|
||||||
TypedProgram typedAST = generateTypedASTFromAst(ast);
|
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<>();
|
List<Class> classes = new ArrayList<>();
|
||||||
for (String sourcePath : sourcePaths) {
|
for (String sourcePath : sourcePaths) {
|
||||||
ANTLRInputStream antlrInputStream;
|
ANTLRInputStream antlrInputStream;
|
||||||
@ -81,17 +84,21 @@ public class Compiler {
|
|||||||
}
|
}
|
||||||
Program program = new Program(classes);
|
Program program = new Program(classes);
|
||||||
TypedProgram typedAST = generateTypedASTFromAst(program);
|
TypedProgram typedAST = generateTypedASTFromAst(program);
|
||||||
//TODO: Für jede Klasse einzeln Bytecode generieren
|
List<byte[]> byteCode = new ArrayList<>();
|
||||||
return generateByteCodeArrayFromTypedAst(typedAST);
|
for (TypedClass c : typedAST.getTypedClasses()) {
|
||||||
|
byteCode.add(generateByteCodeArrayFromTypedAst(c));
|
||||||
|
}
|
||||||
|
return byteCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateByteCodeFileFromFile(List<String> sourcePath, String classname) {
|
public static void generateByteCodeFileFromFile(List<String> sourcePath, List<String> classname) {
|
||||||
byte[] bytes = generateByteCodeArrayFromFile(sourcePath);
|
List<byte[]> bytes = generateByteCodeArrayFromFile(sourcePath);
|
||||||
//TODO: Für jede Klasse einzeln Bytecode schreiben
|
for (int i = 0; i < bytes.size(); i++) {
|
||||||
CodeGenUtils.writeClassfile(bytes, classname);
|
CodeGenUtils.writeClassfile(bytes.get(i), classname.get(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
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.ast.records.Program;
|
||||||
import de.maishai.typedast.ClassContext;
|
import de.maishai.typedast.ClassContext;
|
||||||
|
import lombok.Getter;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class TypedProgram {
|
public class TypedProgram {
|
||||||
private List<TypedClass> typedClasses = new ArrayList<>();
|
private List<TypedClass> typedClasses = new ArrayList<>();
|
||||||
|
|
||||||
@ -16,18 +18,8 @@ public class TypedProgram {
|
|||||||
startConversion(program);
|
startConversion(program);
|
||||||
}
|
}
|
||||||
public void startConversion(Program program){
|
public void startConversion(Program program){
|
||||||
|
//TODO: implement
|
||||||
program.classes().toString();
|
program.classes().toString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public byte[] codeGen() {
|
|
||||||
//TODO: implement this quickly
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user