Introduced IR CodegenFactory, added configuration key to enable it

This commit is contained in:
Michael Bogdanov
2016-09-20 10:27:25 +03:00
committed by Dmitry Petrov
parent 0c60b21cca
commit 978a4db07b
8 changed files with 73 additions and 14 deletions
@@ -133,7 +133,11 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
configuration.put(JVMConfigurationKeys.JVM_TARGET, JvmTarget.JVM_1_8);
}
return getBytecodeForFile(ktFile, configuration, ir.isSelected());
if (ir.isSelected()) {
configuration.put(JVMConfigurationKeys.IR, true);
}
return getBytecodeForFile(ktFile, configuration);
}
@Override
@@ -241,10 +245,10 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
// public for tests
@NotNull
public static String getBytecodeForFile(@NotNull KtFile ktFile, @NotNull CompilerConfiguration configuration, boolean newIRGenerator) {
public static String getBytecodeForFile(@NotNull KtFile ktFile, @NotNull CompilerConfiguration configuration) {
GenerationState state;
try {
state = compileSingleFile(ktFile, configuration, newIRGenerator);
state = compileSingleFile(ktFile, configuration);
}
catch (ProcessCanceledException e) {
throw e;
@@ -284,8 +288,7 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
@NotNull
public static GenerationState compileSingleFile(
@NotNull final KtFile ktFile,
@NotNull CompilerConfiguration configuration,
boolean newIRGenerator
@NotNull CompilerConfiguration configuration
) {
ResolutionFacade resolutionFacade = ResolutionUtils.getResolutionFacade(ktFile);
@@ -324,11 +327,9 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
ktFile.getProject(), ClassBuilderFactories.TEST, resolutionFacade.getModuleDescriptor(), bindingContext, toProcess,
configuration, generateClassFilter
);
if (newIRGenerator) {
JvmBackendFacade.INSTANCE.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
} else {
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
}
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
return state;
}
@@ -72,7 +72,7 @@ class KotlinDecompilerServiceImpl : KotlinDecompilerService {
}
fun bytecodeMapForSourceFile(file: KtFile): Map<File, () -> ByteArray> {
val generationState = KotlinBytecodeToolWindow.compileSingleFile(file, CompilerConfiguration.EMPTY, false)
val generationState = KotlinBytecodeToolWindow.compileSingleFile(file, CompilerConfiguration.EMPTY)
val bytecodeMap = hashMapOf<File, () -> ByteArray>()
generationState.factory.asList().filter { FileUtilRt.extensionEquals(it.relativePath, "class") }.forEach {
@@ -44,7 +44,7 @@ abstract class AbstractBytecodeToolWindowTest: KotlinLightCodeInsightFixtureTest
if (InTextDirectivesUtils.getPrefixedBoolean(mainFileText, "// INLINE:") == false) {
configuration.put(CommonConfigurationKeys.DISABLE_INLINE, true)
}
val bytecodes = KotlinBytecodeToolWindow.getBytecodeForFile(file, configuration, false)
val bytecodes = KotlinBytecodeToolWindow.getBytecodeForFile(file, configuration)
assert(bytecodes.contains("// ================")) {
"The header \"// ================\" is missing.\n This means that there is an exception failed during compilation:\n$bytecodes"
}