48 lines
1.5 KiB
Java
48 lines
1.5 KiB
Java
package bytecode;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
|
|
import com.google.common.io.Files;
|
|
|
|
import junit.framework.TestCase;
|
|
import de.dhbwstuttgart.core.MyCompiler;
|
|
import de.dhbwstuttgart.core.MyCompilerAPI;
|
|
import de.dhbwstuttgart.logger.Logger;
|
|
import de.dhbwstuttgart.logger.LoggerConfiguration;
|
|
import de.dhbwstuttgart.logger.Section;
|
|
import de.dhbwstuttgart.logger.Timewatch;
|
|
import de.dhbwstuttgart.parser.JavaParser.yyException;
|
|
import de.dhbwstuttgart.typeinference.ByteCodeResult;
|
|
import de.dhbwstuttgart.typeinference.Menge;
|
|
|
|
public class SingleClassTester {
|
|
|
|
public static void compileToBytecode(String inputFile, String outputFile){
|
|
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
|
|
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
|
|
try {
|
|
compiler.parse(new File(inputFile));
|
|
Menge<ByteCodeResult> bytecode = compiler.generateBytecode(compiler.typeReconstruction().firstElement());
|
|
System.out.println(bytecode);
|
|
bytecode.firstElement().getByteCode().getJavaClass().dump(new File(outputFile));
|
|
} catch (IOException | yyException e) {
|
|
e.printStackTrace();
|
|
TestCase.fail();
|
|
}finally{
|
|
writeLog(outputFile+".log");
|
|
}
|
|
}
|
|
|
|
private static void writeLog(String toFile){
|
|
String log = Logger.getWholeLog()+"\n";
|
|
log+=Timewatch.getTimewatch().dumpTimeData();
|
|
try {
|
|
Files.write(log.getBytes(),new File(toFile));
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
TestCase.fail();
|
|
}
|
|
}
|
|
}
|