import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
import org.simantics.scl.compiler.types.util.MultiFunction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import gnu.trove.procedure.TObjectObjectProcedure;
import gnu.trove.procedure.TObjectProcedure;
public class CodeGeneration {
-
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CodeGeneration.class);
+
public static final int OPTIMIZATION_PHASES = 2;
CompilationContext compilationContext;
}
public void simplifyValues() {
- //System.out.println("===== Simplify values =====");
+ //LOGGER.info("===== Simplify values =====");
Collection<SCLValue> values = module.getValues();
SimplificationContext simplificationContext = new SimplificationContext(compilationContext, validator);
- //System.out.println("-----------------------------------------------");
+ //LOGGER.info("-----------------------------------------------");
SCLValue[] valueArray = values.toArray(new SCLValue[values.size()]);
for(SCLValue value : valueArray) {
// Simplify
for(SCLValue value : valueArray) {
- //System.out.println("BEFORE " + value.getName() + " = " + value.getExpression());
+ //LOGGER.info("BEFORE " + value.getName() + " = " + value.getExpression());
value.getSimplifiedExpression(simplificationContext);
- //System.out.println("AFTER " + value.getName() + " = " + value.getExpression());
+ //LOGGER.info("AFTER " + value.getName() + " = " + value.getExpression());
}
}
public void convertToSSA() {
ModuleWriter mw = new ModuleWriter(compilationContext.namingPolicy.getModuleClassName(), compilationContext.lineLocator);
for(SCLValue value : module.getValues()) {
- //System.out.println(value.getName().name + " :: " + value.getType());
+ //LOGGER.info(value.getName().name + " :: " + value.getType());
Expression expression = value.getExpression();
if(expression == null)
continue;
if(constant.getTypeParameters().length > 0)
continue;
- //System.out.println(value.getName() + " <- " + constant.getValue().getName());
+ //LOGGER.info(value.getName() + " <- " + constant.getValue().getName());
value.setValue(constant.getValue().getValue());
value.setExpression(null); // HMM??
}*/
public void optimizeSSA() {
if(SCLCompilerConfiguration.SHOW_SSA_BEFORE_OPTIMIZATION && SCLCompilerConfiguration.debugFilter(module.getName())) {
- System.out.println("=== SSA before optimization ====================================");
- System.out.println(ssaModule);
+ LOGGER.info("=== SSA before optimization ====================================");
+ LOGGER.info("{}", ssaModule);
}
if(SCLCompilerConfiguration.DEBUG)
ssaModule.validate();
int optCount = 0;
for(int phase=0;phase<OPTIMIZATION_PHASES;++phase) {
while(optCount++ < 100 && ssaModule.simplify(compilationContext.environment, phase)) {
- //System.out.println("simplify " + optCount);
- //System.out.println("================================================================");
- //System.out.println(ssaModule);
+ //LOGGER.info("simplify " + optCount);
+ //LOGGER.info("================================================================");
+ //LOGGER.info(ssaModule);
}
if(phase == 0)
ssaModule.saveInlinableDefinitions();
}
if(SCLCompilerConfiguration.SHOW_SSA_BEFORE_LAMBDA_LIFTING && SCLCompilerConfiguration.debugFilter(module.getName())) {
- System.out.println("=== SSA before lambda lifting ==================================");
- System.out.println(ssaModule);
+ LOGGER.info("=== SSA before lambda lifting ==================================");
+ LOGGER.info("{}", ssaModule);
}
ssaModule.lambdaLift(errorLog);
//ssaModule.validate();
public void generateCode() {
if(SCLCompilerConfiguration.SHOW_FINAL_SSA && SCLCompilerConfiguration.debugFilter(module.getName())) {
- System.out.println("=== Final SSA ==================================================");
- System.out.println(ssaModule);
+ LOGGER.info("=== Final SSA ==================================================");
+ LOGGER.info("{}", ssaModule);
}
try {
ssaModule.generateCode(moduleBuilder);
errorLog.log(e.getMessage());
}
if(SCLCompilerConfiguration.TRACE_MAX_METHOD_SIZE && moduleBuilder.getMethodSizeCounter() != null)
- System.out.println("[Max method size] " + module.getName() + ": " + moduleBuilder.getMethodSizeCounter());
+ LOGGER.info("[Max method size] " + module.getName() + ": " + moduleBuilder.getMethodSizeCounter());
classes = moduleBuilder.getClasses();
}
if(constructor.parameterTypes.length != 1) {
String javaName = MethodBuilderBase.getClassName(dataType.getTypeDesc());
if(SCLCompilerConfiguration.TRACE_METHOD_CREATION)
- System.out.println("Create class " + javaName);
+ LOGGER.info("Create class " + javaName);
ClassBuilder cf = new ClassBuilder(moduleBuilder, Opcodes.ACC_PUBLIC, javaName, "java/lang/Object");
cf.setSourceFile("_SCL_DataType");
CodeBuilderUtils.makeRecord(cf, constructor.name.name,
// Create supertype
{
if(SCLCompilerConfiguration.TRACE_METHOD_CREATION)
- System.out.println("Create class " + javaName);
+ LOGGER.info("Create class " + javaName);
ClassBuilder cf = new ClassBuilder(moduleBuilder,
Opcodes.ACC_ABSTRACT | Opcodes.ACC_PUBLIC,
javaName, "java/lang/Object");
// Create constructors
for(Constructor constructor : dataType.constructors) {
if(SCLCompilerConfiguration.TRACE_METHOD_CREATION)
- System.out.println("Create class " + constructor.javaName);
+ LOGGER.info("Create class " + constructor.javaName);
ClassBuilder cf = new ClassBuilder(moduleBuilder, Opcodes.ACC_PUBLIC, constructor.javaName, javaName);
cf.setSourceFile("_SCL_DataType");
CodeBuilderUtils.makeRecord(cf, constructor.name.name,
final JavaTypeTranslator javaTypeTranslator = moduleBuilder.getJavaTypeTranslator();
if(SCLCompilerConfiguration.TRACE_METHOD_CREATION)
- System.out.println("Create class " + typeClass.javaName);
+ LOGGER.info("Create class " + typeClass.javaName);
final ClassBuilder cf = new ClassBuilder(moduleBuilder,
Opcodes.ACC_INTERFACE | Opcodes.ACC_PUBLIC,
typeClass.javaName, "java/lang/Object");
final JavaTypeTranslator javaTypeTranslator = moduleBuilder.getJavaTypeTranslator();
if(SCLCompilerConfiguration.TRACE_METHOD_CREATION)
- System.out.println("Create class " + instance.javaName);
+ LOGGER.info("Create class " + instance.javaName);
final ClassBuilder cb = new ClassBuilder(moduleBuilder, Opcodes.ACC_PUBLIC, instance.javaName, "java/lang/Object",
instance.typeClass.javaName);
cb.setSourceFile("_SCL_TypeClassInstance");
} catch (MatchException e) {
throw new InternalCompilerError("Method " + method.getName() + " has too high arity.");
}
- //System.out.println("Interface types: " + Arrays.toString(types));
+ //LOGGER.info("Interface types: " + Arrays.toString(types));
TypeDesc[] parameterTypeDescs = javaTypeTranslator.toTypeDescs(mfun.parameterTypes);
TypeDesc returnTypeDesc = javaTypeTranslator.toTypeDesc(mfun.returnType);
MethodBuilder mb = cb.addMethod(Opcodes.ACC_PUBLIC, method.getJavaName(),
MultiFunction mfun2;
try {
mfun2 = Types.matchFunction(Types.removeForAll(function.getType()), parameters.length);
- //System.out.println("Implementation types: " + Arrays.toString(functionTypes));
+ //LOGGER.info("Implementation types: " + Arrays.toString(functionTypes));
} catch (MatchException e) {
throw new InternalCompilerError(e);
}
import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
import org.simantics.scl.compiler.types.TVar;
import org.simantics.scl.compiler.types.Type;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import gnu.trove.map.hash.THashMap;
*/
public abstract class Constant extends Val {
+ private static final Logger LOGGER = LoggerFactory.getLogger(Constant.class);
+
public static boolean TRACE_REALIZATION = false;
protected Type type;
ModuleBuilder moduleBuilder = new ModuleBuilder(policy, builder.javaTypeTranslator);
if(SCLCompilerConfiguration.TRACE_METHOD_CREATION)
- System.out.println("Create class " + policy.getModuleClassName());
+ LOGGER.info("Create class " + policy.getModuleClassName());
ClassBuilder classFile = new ClassBuilder(moduleBuilder, Opcodes.ACC_PUBLIC, policy.getModuleClassName(), "java/lang/Object");
classFile.setSourceFile("_SCL_RealizedValue");
if(valueCache != null) {
valueCache.put(this, result);
if(TRACE_REALIZATION)
- System.out.println("/REALIZED/ " + this + " " + getClass().getSimpleName());
+ LOGGER.info("/REALIZED/ " + this + " " + getClass().getSimpleName());
}
return result;
} catch (IllegalAccessException e) {
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import gnu.trove.map.hash.THashMap;
public abstract class FunctionValue extends Constant {
+ private static final Logger LOGGER = LoggerFactory.getLogger(FunctionValue.class);
+
TVar[] typeParameters;
Type returnType;
protected Type[] parameterTypes;
public Type apply(MethodBuilder mb, Type[] typeParameters, Val... parameters) {
int arity = getArity();
- /*System.out.println("MONADIC APPLICATION " + this);
- System.out.println(" call arity: " + parameters.length);
- System.out.println(" func arity: " + arity);
- System.out.println(" func monadic: " + isMonadic());
+ /*LOGGER.info("MONADIC APPLICATION " + this);
+ LOGGER.info(" call arity: " + parameters.length);
+ LOGGER.info(" func arity: " + arity);
+ LOGGER.info(" func monadic: " + isMonadic());
*/
if(parameters.length < arity) {
ModuleBuilder moduleBuilder = mb.getModuleBuilder();
ClassBuilder classFile;
if(arity <= Constants.MAX_FUNCTION_PARAMETER_COUNT) {
if(SCLCompilerConfiguration.TRACE_METHOD_CREATION)
- System.out.println("Create class " + policy.getModuleClassName());
+ LOGGER.info("Create class " + policy.getModuleClassName());
classFile = new ClassBuilder(moduleBuilder, Opcodes.ACC_PUBLIC, policy.getModuleClassName(),
MethodBuilderBase.getClassName(Constants.FUNCTION_IMPL[arity]));
classFile.setSourceFile("_SCL_FunctionValue");
}
else {
if(SCLCompilerConfiguration.TRACE_METHOD_CREATION)
- System.out.println("Create class " + policy.getModuleClassName());
+ LOGGER.info("Create class " + policy.getModuleClassName());
classFile = new ClassBuilder(moduleBuilder, Opcodes.ACC_PUBLIC, policy.getModuleClassName(),
MethodBuilderBase.getClassName(Constants.FUNCTION_N_IMPL));
classFile.setSourceFile("_SCL_FunctionValue");
if(valueCache != null) {
valueCache.put(this, result);
if(TRACE_REALIZATION)
- System.out.println("/REALIZED/ " + this + " " + getClass().getSimpleName());
+ LOGGER.info("/REALIZED/ " + this + " " + getClass().getSimpleName());
}
return result;
} catch (InstantiationException e) {
import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.exceptions.MatchException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ETransformation extends SimplifiableExpression {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ETransformation.class);
+
public static final Object TRANSFORMATION_RULES_TYPECHECKED = new Object();
public final String name;
Expression expression = tb.compileRules();
if(SCLCompilerConfiguration.SHOW_COMPILED_RULES)
- System.out.println(expression);
+ LOGGER.info("{}", expression);
return expression;
}
import org.simantics.scl.compiler.internal.codegen.utils.SSASimplificationContext;
import org.simantics.scl.compiler.internal.codegen.utils.SSAValidationContext;
import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import gnu.trove.map.hash.THashMap;
import gnu.trove.procedure.TObjectObjectProcedure;
import gnu.trove.procedure.TObjectProcedure;
public class SSAModule {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(SSAModule.class);
+
THashMap<Name, SCLConstant> functions = new THashMap<Name, SCLConstant>();
ArrayList<StaticField> staticFields = new ArrayList<StaticField>();
public ArrayList<SSAClosure> closuresToGenerate = new ArrayList<SSAClosure>();
try {
function.getDefinition().validate(context);
} catch(RuntimeException e) {
- System.out.println("-- VALIDATE " + function.getName() + " ----------------");
+ LOGGER.info("-- VALIDATE " + function.getName() + " ----------------");
PrintingContext printingContext = new PrintingContext();
printingContext.setErrorMarker(context.errorMarker);
function.getDefinition().toString(printingContext);
- System.out.println(printingContext.toString());
+ LOGGER.info(printingContext.toString());
throw e;
}
}
public void generateCode(final ModuleBuilder moduleBuilder) throws CodeBuildingException {
final String moduleClassName = moduleBuilder.getNamingPolicy().getModuleClassName();
if(SCLCompilerConfiguration.TRACE_METHOD_CREATION)
- System.out.println("Create class " + moduleClassName);
+ LOGGER.info("Create class " + moduleClassName);
final ClassBuilder classFile = new ClassBuilder(moduleBuilder, Opcodes.ACC_PUBLIC, moduleClassName,
"java/lang/Object");
classFile.setSourceFile(moduleBuilder.getNamingPolicy().getModuleName());
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.CodeSizeEvaluator;
import org.objectweb.asm.util.TraceClassVisitor;
+import org.simantics.scl.compiler.internal.codegen.utils.LoggingOutputStream.LogLevel;
import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ClassBuilder {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ClassBuilder.class);
+
ModuleBuilder moduleBuilder;
String className;
String superClassName;
this.classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
this.classVisitor = SCLCompilerConfiguration.SHOW_COMPILED_BYTECODE
&& SCLCompilerConfiguration.debugFilter(moduleBuilder.namingPolicy.getModuleName())
- ? new TraceClassVisitor(classWriter, new PrintWriter(System.out))
+ ? new TraceClassVisitor(classWriter, new PrintWriter(new LoggingOutputStream(LOGGER, LogLevel.INFO)))
: classWriter;
classVisitor.visit(Opcodes.V1_5, access, className, null, superClassName, interfaces);
}
--- /dev/null
+package org.simantics.scl.compiler.internal.codegen.utils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+
+import org.slf4j.Logger;
+
+public class LoggingOutputStream extends OutputStream {
+
+ private final ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
+ private final Logger logger;
+ private final LogLevel level;
+
+ public enum LogLevel {
+ TRACE, DEBUG, INFO, WARN, ERROR,
+ }
+
+ public LoggingOutputStream(Logger logger, LogLevel level) {
+ this.logger = logger;
+ this.level = level;
+ }
+
+ @Override
+ public void write(int b) {
+ if (b == '\n') {
+ String line = baos.toString();
+ baos.reset();
+
+ switch (level) {
+ case TRACE:
+ logger.trace(line);
+ break;
+ case DEBUG:
+ logger.debug(line);
+ break;
+ case ERROR:
+ logger.error(line);
+ break;
+ case INFO:
+ logger.info(line);
+ break;
+ case WARN:
+ logger.warn(line);
+ break;
+ }
+ } else {
+ baos.write(b);
+ }
+ }
+}
import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator;
import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
import org.simantics.scl.compiler.types.Type;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import gnu.trove.map.hash.THashMap;
public class ModuleBuilder {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ModuleBuilder.class);
+
JavaNamingPolicy namingPolicy;
JavaTypeTranslator javaTypeTranslator;
public void addClass(ClassBuilder cb) {
byte[] bytecode = cb.finishClass();
classes.put(cb.getClassName(), bytecode);
- //System.out.println("Added " + cb.getClassName());
+ //LOGGER.info("Added " + cb.getClassName());
}
public JavaTypeTranslator getJavaTypeTranslator() {
ClassBuilder classBuilder;
if(remainingArity <= Constants.MAX_FUNCTION_PARAMETER_COUNT) {
if(SCLCompilerConfiguration.TRACE_METHOD_CREATION)
- System.out.println("Create class " + className);
+ LOGGER.info("Create class " + className);
classBuilder = new ClassBuilder(this, Opcodes.ACC_PUBLIC, className, MethodBuilderBase.getClassName(Constants.FUNCTION_IMPL[remainingArity]));
classBuilder.setSourceFile("_SCL_Closure");
}
else {
if(SCLCompilerConfiguration.TRACE_METHOD_CREATION)
- System.out.println("Create class " + className);
+ LOGGER.info("Create class " + className);
classBuilder = new ClassBuilder(this, Opcodes.ACC_PUBLIC, className, MethodBuilderBase.getClassName(Constants.FUNCTION_N_IMPL));
classBuilder.setSourceFile("_SCL_Closure");
public void markModified(String description) {
if(SCLCompilerConfiguration.PRINT_OPTIMIZATION_TRANSFORMATIONS)
- System.out.println("(" + modiId + ") DID " + description);
+ LOGGER.info("(" + modiId + ") DID " + description);
modified = true;
if(SCLCompilerConfiguration.VALIDATE_AFTER_OPTIMIZATIONS)
module.validate();
}
public void printConstant(Name name) {
- System.out.println("--- " + name + " ---------------------------");
- System.out.println(module.get(name));
+ LOGGER.info("--- " + name + " ---------------------------");
+ LOGGER.info("{}", module.get(name));
}
public void validate() {
import org.simantics.scl.compiler.types.exceptions.UnificationException;
import org.simantics.scl.compiler.types.util.TConComparator;
import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet;
public class ConstraintSolver {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ConstraintSolver.class);
+
public static THashSet<TCon> DEFAULTS_IGNORE = new THashSet<TCon>();
public static THashMap<List<TCon>, Type> DEFAULTS = new THashMap<List<TCon>, Type>();
TypeUnparsingContext tuc = SCLCompilerConfiguration.TRACE_CONSTRAINT_SOLVER ?
new TypeUnparsingContext() : null;
if(SCLCompilerConfiguration.TRACE_CONSTRAINT_SOLVER) {
- System.out.println();
- System.out.println("GIVEN:");
+ LOGGER.info("");
+ LOGGER.info("GIVEN:");
for(TPred g : given)
- System.out.println(" " + g.toString(tuc));
- System.out.println("DEMANDS:");
+ LOGGER.info(" " + g.toString(tuc));
+ LOGGER.info("DEMANDS:");
for(EVariable demand : demands)
- System.out.println(" " + demand.getType().toString(tuc));
- System.out.println("==>");
+ LOGGER.info(" " + demand.getType().toString(tuc));
+ LOGGER.info("==>");
}
ConstraintSet cs = new ConstraintSet(environment);
ArrayList<ArrayList<Constraint>> groups =
groupConstraintsByCommonMetavars(unsolvedConstraints);
if(SCLCompilerConfiguration.TRACE_CONSTRAINT_SOLVER) {
- System.out.println("DEFAULT GROUPS:");
+ LOGGER.info("DEFAULT GROUPS:");
for(ArrayList<Constraint> group : groups) {
for(Constraint c : group)
- System.out.println(" " + c.constraint.toString(tuc));
- System.out.println(" --");
+ LOGGER.info(" " + c.constraint.toString(tuc));
+ LOGGER.info(" --");
}
}
}
if(SCLCompilerConfiguration.TRACE_CONSTRAINT_SOLVER) {
- System.out.println("UNSOLVED:");
+ LOGGER.info("UNSOLVED:");
for(Constraint c : unsolvedConstraints)
- System.out.println(" " + c.constraint.toString(tuc));
- System.out.println("SOLVED:");
+ LOGGER.info(" " + c.constraint.toString(tuc));
+ LOGGER.info("SOLVED:");
for(Constraint c : solvedConstraints)
- System.out.println(" " + c.constraint.toString(tuc) + " <= " + c.generator);
- //System.out.println("APPLY DEFAULTS: " + applyDefaults);
+ LOGGER.info(" " + c.constraint.toString(tuc) + " <= " + c.generator);
+ //LOGGER.info("APPLY DEFAULTS: " + applyDefaults);
}
return new ReducedConstraints(givenConstraints,
import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
import org.simantics.scl.compiler.top.ValueNotFound;
import org.simantics.scl.compiler.types.Types;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import gnu.trove.map.hash.THashMap;
import gnu.trove.map.hash.TObjectLongHashMap;
* @author Hannu Niemistö
*/
public class ModuleRepository {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ModuleRepository.class);
+
private final ModuleRepository parentRepository;
private final ModuleSourceRepository sourceRepository;
private ConcurrentHashMap<String, ModuleEntry> moduleCache = new ConcurrentHashMap<String, ModuleEntry>();
if(moduleCache.get(moduleName) == this) {
moduleCache.remove(moduleName);
if(SCLCompilerConfiguration.TRACE_MODULE_UPDATE) {
- System.out.println("Invalidate " + moduleName);
+ LOGGER.info("Invalidate " + moduleName);
for(UpdateListener l : listenersCopy)
- System.out.println(" " + l);
+ LOGGER.info(" " + l);
}
for(UpdateListener l : listenersCopy)
if(!l.stopListening())
compilationResult = DoesNotExist.getInstance();
else {
if(SCLCompilerConfiguration.TRACE_MODULE_UPDATE)
- System.out.println("Compile " + source);
+ LOGGER.info("Compile " + source);
beginModuleCompilation(moduleName);
compilationResult = source.compileModule(ModuleRepository.this, this, advisor == null ? null : advisor.getOptions(moduleName));
finishModuleCompilation(moduleName);
import org.simantics.scl.compiler.environment.GlobalOnlyEnvironment;
import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator;
import org.simantics.scl.compiler.internal.codegen.utils.JavaNamingPolicy;
+import org.simantics.scl.compiler.internal.codegen.utils.LoggingOutputStream;
+import org.simantics.scl.compiler.internal.codegen.utils.LoggingOutputStream.LogLevel;
import org.simantics.scl.compiler.internal.codegen.utils.TransientClassBuilder;
import org.simantics.scl.compiler.internal.decompilation.DecompilerFactory;
import org.simantics.scl.compiler.internal.decompilation.IDecompiler;
public synchronized void addClass(String name, byte[] class_) {
if(TRACE_CLASS_CREATION)
- System.out.println("addClass " + name + " (" + class_.length + " bytes)");
+ LOGGER.info("addClass " + name + " (" + class_.length + " bytes)");
if(VALIDATE_CLASS_NAMES)
validateClassName(name);
localClasses.put(name, class_);
public synchronized void addClasses(Map<String, byte[]> classes) {
if(TRACE_CLASS_CREATION)
for(String name : classes.keySet())
- System.out.println("addClass " + name + " (" + classes.get(name).length + " bytes)");
+ LOGGER.info("addClass " + name + " (" + classes.get(name).length + " bytes)");
if(VALIDATE_CLASS_NAMES)
for(String name : classes.keySet())
validateClassName(name);
}
private void validateClassName(String name) {
- //System.out.println(name);
+ //LOGGER.info(name);
/*if(!name.startsWith(SCL_PACKAGE_PREFIX) || !extractClassLoaderId(name).equals(moduleName))
throw new IllegalArgumentException("Class name " + name + " does not start with '" +
SCL_PACKAGE_PREFIX + moduleName + "$'.");
}
private Class<?> getClass(String name) throws ClassNotFoundException {
- //System.out.println("getClass " + name);
+ //LOGGER.info("getClass " + name);
// If the class is not generated from SCL, use parent class loader
if(!name.startsWith(SCL_PACKAGE_PREFIX)) {
}
public Module getModule(String moduleName) {
- //System.out.println("ModuleClassLoader.getModule(" + moduleName + ")");
+ //LOGGER.info("ModuleClassLoader.getModule(" + moduleName + ")");
if(moduleName.equals(this.moduleName))
return module;
else {
IDecompiler decompiler = DecompilerFactory.getDecompiler();
if(decompiler == null)
return;
- decompiler.decompile(this, className, new OutputStreamWriter(System.out));
+ decompiler.decompile(this, className, new OutputStreamWriter(new LoggingOutputStream(LOGGER, LogLevel.INFO)));
}
}
import org.simantics.scl.compiler.types.util.ProcedureType;
import org.simantics.scl.runtime.function.FunctionImpl1;
import org.simantics.scl.runtime.tuple.Tuple0;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
import gnu.trove.set.hash.THashSet;
public class ExpressionEvaluator {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ExpressionEvaluator.class);
+
public static final boolean TRACE_INTERPRETATION_VS_COMPILATION = false;
private static final String COMPUTATION_METHOD_NAME = "main";
}
} catch(SCLSyntaxErrorException e) {
errorLog.log(e.location, e.getMessage());
- //System.out.println(errorLog.getErrorsAsString());
+ //LOGGER.info(errorLog.getErrorsAsString());
throw new SCLExpressionCompilationException(errorLog.getErrors());
} catch(Exception e) {
errorLog.log(e);
throw new SCLExpressionCompilationException(errorLog.getErrors());
if(SCLCompilerConfiguration.SHOW_EXPRESSION_BEFORE_EVALUATION)
- System.out.println(expression);
+ LOGGER.info("{}", expression);
if(interpretIfPossible) {
// Try to interpret
new TransientClassBuilder(classLoader, javaTypeTranslator));
IExpression iexp = expression.toIExpression(expressionInterpretationContext);
if(TRACE_INTERPRETATION_VS_COMPILATION)
- System.out.println("INTERPRETED " + expressionText);
+ LOGGER.info("INTERPRETED " + expressionText);
if(SCLCompilerConfiguration.SHOW_INTERPRETED_EXPRESSION)
- System.out.println("INTERPRETED AS: " + iexp);
+ LOGGER.info("INTERPRETED AS: " + iexp);
return iexp.execute(new Object[expressionInterpretationContext.getMaxVariableId()]);
} catch(UnsupportedOperationException e) {
// This is normal when expression cannot be interpreted. We compile it instead.
SSAModule ssaModule = mw.getModule();
if(SCLCompilerConfiguration.SHOW_SSA_BEFORE_OPTIMIZATION) {
- System.out.println("=== SSA before optimization ==================================");
- System.out.println(ssaModule);
+ LOGGER.info("=== SSA before optimization ==================================");
+ LOGGER.info("{}", ssaModule);
}
if(SCLCompilerConfiguration.DEBUG)
ssaModule.validate();
for(int phase=0;phase<CodeGeneration.OPTIMIZATION_PHASES;++phase) {
int optCount = 0;
while(optCount++ < 4 && ssaModule.simplify(environment, phase)) {
- //System.out.println("simplify " + optCount);
+ //LOGGER.info("simplify " + optCount);
}
}
if(SCLCompilerConfiguration.SHOW_SSA_BEFORE_LAMBDA_LIFTING) {
- System.out.println("=== SSA before lambda lifting ==================================");
- System.out.println(ssaModule);
+ LOGGER.info("=== SSA before lambda lifting ==================================");
+ LOGGER.info("{}", ssaModule);
}
//ssaModule.saveInlinableDefinitions();
ssaModule.lambdaLift(errorLog);
// Generate code
if(SCLCompilerConfiguration.SHOW_FINAL_SSA)
- System.out.println(ssaModule);
+ LOGGER.info("{}", ssaModule);
try {
ssaModule.generateCode(moduleBuilder);
} catch (CodeBuildingException e) {
public interface SCLCompilerConfiguration {
- public static final boolean DEBUG = false;
- public static final boolean ENABLE_TIMING = false;
+ static final String KEY_PREFIX = "org.simantics.scl.compiler.";
- public static final boolean SHOW_SSA_BEFORE_OPTIMIZATION = false;
- public static final boolean SHOW_SSA_BEFORE_LAMBDA_LIFTING = false;
- public static final boolean SHOW_FINAL_SSA = false;
- public static final boolean SHOW_COMPILED_BYTECODE = false;
- public static final boolean SHOW_DECOMPILED_BYTECODE = false;
+ public static final boolean DEBUG = parseBoolean("debug", false);
+ public static final boolean ENABLE_TIMING = parseBoolean("enableTiming", false);
- public static final boolean SHOW_EXPRESSION_BEFORE_EVALUATION = false;
- public static final boolean SHOW_INTERPRETED_EXPRESSION = false;
+ public static final boolean SHOW_SSA_BEFORE_OPTIMIZATION = parseBoolean("showSsaBeforeOptimization", false);
+ public static final boolean SHOW_SSA_BEFORE_LAMBDA_LIFTING = parseBoolean("showSsaBeforeLambdaLifting", false);
+ public static final boolean SHOW_FINAL_SSA = parseBoolean("showFinalSsa", false);
+ public static final boolean SHOW_COMPILED_BYTECODE = parseBoolean("showCompiledBytecode", false);
+ public static final boolean SHOW_DECOMPILED_BYTECODE = parseBoolean("showDecompiledBytecode", false);
- public static final boolean SHOW_COMPILED_RULES = false;
+ public static final boolean SHOW_EXPRESSION_BEFORE_EVALUATION = parseBoolean("showExpressionBeforeEvaluation", false);
+ public static final boolean SHOW_INTERPRETED_EXPRESSION = parseBoolean("showInterpretedExpression", false);
- public static final boolean VALIDATE_AFTER_OPTIMIZATIONS = false;
- public static final boolean TRACE_CONSTRAINT_SOLVER = false;
- public static final boolean PRINT_OPTIMIZATION_TRANSFORMATIONS = false;
+ public static final boolean SHOW_COMPILED_RULES = parseBoolean("showCompiledRules", false);
- public static final boolean NULL_CHECK_THREAD_LOCAL_VARIABLES = false;
+ public static final boolean VALIDATE_AFTER_OPTIMIZATIONS = parseBoolean("validateAfterOptimizations", false);
+ public static final boolean TRACE_CONSTRAINT_SOLVER = parseBoolean("traceConstraintSolver", false);
+ public static final boolean PRINT_OPTIMIZATION_TRANSFORMATIONS = parseBoolean("printOptimizationTransformations", false);
- public static final boolean TRACE_METHOD_CREATION = false;
+ public static final boolean NULL_CHECK_THREAD_LOCAL_VARIABLES = parseBoolean("nullCheckThreadLocalVariables", false);
- public static final boolean TRACE_MODULE_UPDATE = false;
+ public static final boolean TRACE_METHOD_CREATION = parseBoolean("traceMethodCreation", false);
+
+ public static final boolean TRACE_MODULE_UPDATE = parseBoolean("traceModuleUpdate", false);
// Flags related to too long method sizes
- public static final boolean TRACE_MAX_METHOD_SIZE = false;
- public static final boolean EVERY_RULE_ENFORCEMENT_IN_SEPARATE_METHOD = true;
- public static final boolean EVERY_DATALOG_STRATUM_IN_SEPARATE_METHOD = true;
+ public static final boolean TRACE_MAX_METHOD_SIZE = parseBoolean("traceMaxMethodSize", false);
+ public static final boolean EVERY_RULE_ENFORCEMENT_IN_SEPARATE_METHOD = parseBoolean("everyRuleEnforcementInSeparateMethod", true);
+ public static final boolean EVERY_DATALOG_STRATUM_IN_SEPARATE_METHOD = parseBoolean("everyDatalogStratumInSeparateMethod", true);
- public static final boolean ALLOW_OVERLOADING = true;
+ public static final boolean ALLOW_OVERLOADING = parseBoolean("allowOverloading", true);
public static boolean debugFilter(String name) {
return true;
}
-
+
+ static boolean parseBoolean(String property, boolean defaultValue) {
+ return defaultValue || Boolean.parseBoolean(System.getProperty(KEY_PREFIX + property));
+ }
}