X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fcompilation%2FCodeGeneration.java;h=f0b9f735e68b7b6522b46423e188f7a0ca95feba;hb=f2b480b85db5e35cd18329ccdcd28ab1e0663094;hp=9c7c77470c55b57a91c7dc768d49ff3408e2c9ff;hpb=bf540e621923947f9d6f4d5eeef5d05f08373125;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/CodeGeneration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/CodeGeneration.java index 9c7c77470..f0b9f735e 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/CodeGeneration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/CodeGeneration.java @@ -17,6 +17,7 @@ import org.simantics.scl.compiler.constants.ThisConstant; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.macros.StandardMacroRule; +import org.simantics.scl.compiler.elaboration.modules.DerivedProperty; import org.simantics.scl.compiler.elaboration.modules.InlineProperty; import org.simantics.scl.compiler.elaboration.modules.MethodImplementation; import org.simantics.scl.compiler.elaboration.modules.PrivateProperty; @@ -52,12 +53,16 @@ import org.simantics.scl.compiler.types.Type; 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; @@ -84,11 +89,11 @@ public class CodeGeneration { } public void simplifyValues() { - //System.out.println("===== Simplify values ====="); + //LOGGER.info("===== Simplify values ====="); Collection 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) { @@ -100,16 +105,16 @@ public class CodeGeneration { // 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()); + 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; @@ -124,13 +129,18 @@ public class CodeGeneration { decomposed.typeParameters, decomposed.returnType, decomposed.parameterTypes));*/ + boolean isDerived = false; for(SCLValueProperty prop : value.getProperties()) { if(prop instanceof InlineProperty) { InlineProperty inlineProperty = (InlineProperty)prop; constant.setInlineArity(inlineProperty.arity, inlineProperty.phaseMask); } else if(prop == PrivateProperty.INSTANCE) - constant.setPrivate(true); + constant.setPrivate(!isDerived); + else if(prop == DerivedProperty.INSTANCE) { + constant.setPrivate(false); + isDerived = true; + } } } // This is quite hackish optimization that can be possibly removed when @@ -143,7 +153,7 @@ public class CodeGeneration { 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?? }*/ @@ -154,7 +164,7 @@ public class CodeGeneration { continue; DecomposedExpression decomposed = - DecomposedExpression.decompose(expression); + DecomposedExpression.decompose(errorLog, expression); CodeWriter w = mw.createFunction((SCLConstant)value.getValue(), decomposed.typeParameters, @@ -166,7 +176,7 @@ public class CodeGeneration { IVal[] parameterVals = w.getParameters(); for(int i=0;i