Skip to content

Commit

Permalink
[lang] Add optimization level parameter to the SARL batch compiler.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Aug 19, 2018
1 parent df661f6 commit ecc5fd3
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
@@ -0,0 +1,83 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2018 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.lang.compiler.batch;

import com.google.common.base.Strings;

/** Level of optimization of the Java code.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.8
*/
public enum OptimizationLevel {

/**
* No optimization, debugging information included.
*/
G0,

/**
* No optimization, no debugging information included.
*/
G1,

/**
* Optimization, no debugging information included.
*/
G2;

/** Replies the default optimization level.
*
* @return the default optimization level.
*/
public static OptimizationLevel getDefault() {
return G0;
}

/** Parse the given case insensitive string for obtaining the optimization level.
*
* @param name the string to parse.
* @return the optimization level, or {@code null} if the string cannot be parsed.
*/
public static OptimizationLevel valueOfCaseInsensitive(String name) {
if (Strings.isNullOrEmpty(name)) {
return null;
}
try {
return valueOf(name.toUpperCase());
} catch (Exception exception) {
return null;
}
}

/** Replies the string representation of this optimization level.
*
* @return the string representation.
*/
public String getCaseInsensitiveName() {
return name().toLowerCase();
}

}
Expand Up @@ -254,6 +254,8 @@ public boolean accept(File pathname) {

private boolean reportInternalProblemsAsIssues;

private OptimizationLevel optimizationLevel;

/** Constructor the batch compiler.
*/
public SarlBatchCompiler() {
Expand Down Expand Up @@ -305,6 +307,27 @@ public IJavaBatchCompiler getJavaCompiler() {
return this.javaCompiler;
}

/** Change the optimization level that should be applied to the generated Java byte code.
*
* @param level the optimization level.
* @since 0.8
*/
public void setOptimizationLevel(OptimizationLevel level) {
this.optimizationLevel = level;
}

/** Replies the optimization level that should be applied to the generated Java byte code.
*
* @return the optimization level.
* @since 0.8
*/
public OptimizationLevel getOptimizationLevel() {
if (this.optimizationLevel == null) {
this.optimizationLevel = OptimizationLevel.getDefault();
}
return this.optimizationLevel;
}

/** Change the flag that permits to report the compiler's internal problems as issues.
*
* @param reportAsIssues {@code true} if the internal errors are reported as issues.
Expand Down

0 comments on commit ecc5fd3

Please sign in to comment.