Compiler inline on/off flag

This commit is contained in:
Mikhael Bogdanov
2013-11-22 17:12:17 +04:00
parent 4079735bf2
commit 8533fd64ff
21 changed files with 167 additions and 12 deletions
@@ -65,4 +65,7 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
@Argument(value = "kotlinHome", description = "Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery")
public String kotlinHome;
@Argument(value = "inline", description = "Inlining mode: on/off (default is off)")
public String enableInline;
}
@@ -63,6 +63,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
protected boolean parseArguments(@NotNull PrintStream errStream, @NotNull A arguments, @NotNull String[] args) {
try {
arguments.freeArgs = Args.parse(arguments, args);
checkArguments(arguments);
return true;
}
catch (IllegalArgumentException e) {
@@ -76,6 +77,10 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
return false;
}
protected void checkArguments(@NotNull A argument) {
}
/**
* Allow derived classes to add additional command line arguments
*/
@@ -35,4 +35,7 @@ public class JVMConfigurationKeys {
CompilerConfigurationKey.create("generate not-null assertions");
public static final CompilerConfigurationKey<Boolean> GENERATE_NOT_NULL_PARAMETER_ASSERTIONS =
CompilerConfigurationKey.create("generate not-null parameter assertions");
public static final CompilerConfigurationKey<Boolean> ENABLE_INLINE =
CompilerConfigurationKey.create("enable inline");
}
@@ -107,6 +107,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, arguments.notNullAssertions);
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, arguments.notNullParamAssertions);
configuration.put(JVMConfigurationKeys.ENABLE_INLINE, "on".equalsIgnoreCase(arguments.enableInline));
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
@@ -190,4 +191,16 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
}
return annotationsPath;
}
@Override
protected void checkArguments(@NotNull K2JVMCompilerArguments argument) {
super.checkArguments(argument);
String inline = argument.enableInline;
if (inline != null) {
if (!"on".equalsIgnoreCase(inline) && !"off".equalsIgnoreCase(inline)) {
throw new IllegalArgumentException("Wrong value for inline option: '" + inline + "'. Should be 'on' or 'off'");
}
}
}
}
@@ -47,6 +47,7 @@ import org.jetbrains.jet.lang.resolve.ScriptNameUtil;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.types.lang.InlineUtil;
import org.jetbrains.jet.plugin.JetMainDetector;
import org.jetbrains.jet.utils.KotlinPaths;
@@ -293,7 +294,8 @@ public class KotlinToJVMBytecodeCompiler {
project, ClassBuilderFactories.BINARIES, Progress.DEAF, exhaust.getBindingContext(), environment.getSourceFiles(),
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false),
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, false),
/*generateDeclaredClasses = */true
/*generateDeclaredClasses = */true,
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineUtil.DEFAULT_INLINE_FLAG)
);
KotlinCodegenFacade.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION);
@@ -57,6 +57,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
import org.jetbrains.jet.lang.types.lang.InlineUtil;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.plugin.JetLanguage;
import org.jetbrains.jet.utils.ExceptionUtils;
@@ -236,7 +237,7 @@ public class ReplInterpreter {
BindingContext bindingContext = AnalyzeExhaust.success(trace.getBindingContext(), module).getBindingContext();
GenerationState generationState = new GenerationState(psiFile.getProject(), ClassBuilderFactories.BINARIES,
bindingContext, Collections.singletonList(psiFile));
bindingContext, Collections.singletonList(psiFile), InlineUtil.DEFAULT_INLINE_FLAG);
compileScript(psiFile.getScript(), scriptClassType, earlierScripts, generationState,
CompilationErrorHandler.THROW_EXCEPTION);