X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fcodegen%2Fssa%2FSSAFunction.java;h=68dd82f15f4bb1c76d5b68c07f58cfc501e3f66c;hp=c812db7c4476a3b8078847ad045d359cf618afc3;hb=a8758de5bc19e5adb3f618d3038743a164f09912;hpb=12d9af17384d960b75d58c3935d2b7b46d93e87b diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/SSAFunction.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/SSAFunction.java index c812db7c4..68dd82f15 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/SSAFunction.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/SSAFunction.java @@ -11,35 +11,27 @@ import org.simantics.scl.compiler.internal.codegen.continuations.ReturnCont; import org.simantics.scl.compiler.internal.codegen.references.BoundVar; import org.simantics.scl.compiler.internal.codegen.references.Val; import org.simantics.scl.compiler.internal.codegen.references.ValRef; -import org.simantics.scl.compiler.internal.codegen.ssa.binders.BoundVarBinder; -import org.simantics.scl.compiler.internal.codegen.ssa.binders.FunctionBinder; import org.simantics.scl.compiler.internal.codegen.ssa.exits.Jump; import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetApply; import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetFunctions; import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator; import org.simantics.scl.compiler.internal.codegen.utils.CopyContext; import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder; -import org.simantics.scl.compiler.internal.codegen.utils.Printable; import org.simantics.scl.compiler.internal.codegen.utils.PrintingContext; import org.simantics.scl.compiler.internal.codegen.utils.SSALambdaLiftingContext; import org.simantics.scl.compiler.internal.codegen.utils.SSASimplificationContext; import org.simantics.scl.compiler.internal.codegen.utils.SSAValidationContext; +import org.simantics.scl.compiler.internal.codegen.utils.ValRefVisitor; import org.simantics.scl.compiler.types.TVar; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; -public final class SSAFunction implements Printable, BoundVarBinder { - Val target; - +public final class SSAFunction extends SSAClosure { TVar[] typeParameters; Type effect; SSABlock firstBlock; SSABlock lastBlock; - ReturnCont returnCont; - - FunctionBinder parent; - SSAFunction prev; - SSAFunction next; + ReturnCont returnCont; public SSAFunction(TVar[] typeParameters, Type effect, Type returnType) { this(typeParameters, effect, new ReturnCont(returnType)); @@ -51,21 +43,6 @@ public final class SSAFunction implements Printable, BoundVarBinder { this.effect = Types.canonical(effect); returnCont.setParent(this); } - - public Val getTarget() { - return target; - } - - public void setTarget(Val target) { - this.target = target; - if(target instanceof BoundVar) - ((BoundVar) target).parent = this; - } - - public void setTarget(BoundVar target) { - this.target = target; - target.parent = this; - } public boolean hasEffect() { return effect != Types.NO_EFFECTS; @@ -116,6 +93,10 @@ public final class SSAFunction implements Printable, BoundVarBinder { for(int i=0,j=0;i 0) @@ -309,12 +242,14 @@ public final class SSAFunction implements Printable, BoundVarBinder { return firstBlock.parameters.length; } + @Override public void markGenerateOnFly() { for(SSABlock block = firstBlock; block != null; block = block.next) block.markGenerateOnFly(); } - public SSAFunction copy(CopyContext context) { + @Override + public SSAClosure copy(CopyContext context) { TVar[] newTypeParameters = context.copyParameters(typeParameters); SSAFunction newFunction = new SSAFunction(newTypeParameters, effect, context.copy(returnCont)); for(SSABlock block = firstBlock; @@ -322,11 +257,8 @@ public final class SSAFunction implements Printable, BoundVarBinder { newFunction.addBlock(context.copy(block)); return newFunction; } - - public SSAFunction copy() { - return copy(new CopyContext()); - } - + + @Override public void replace(TVar[] vars, Type[] replacements) { returnCont.replace(vars, replacements); for(SSABlock block = firstBlock; @@ -338,6 +270,7 @@ public final class SSAFunction implements Printable, BoundVarBinder { this.typeParameters = typeParameters; } + @Override public Type getType() { Type type = returnCont.getType(); type = Types.functionE( @@ -361,73 +294,29 @@ public final class SSAFunction implements Printable, BoundVarBinder { return returnCont.getType(); } + @Override public void destroy() { for(SSABlock block = firstBlock; block != null; block = block.next) block.destroy(); } - public void detach() { - if(prev == null) - parent.setFirstFunction(next); - else - prev.next = next; - if(next != null) - next.prev = prev; - } - - public void remove() { - destroy(); - detach(); - } - - public void addSibling(SSAFunction function) { - function.parent = parent; - function.next = next; - function.prev = this; - - next.prev = function; - next = function; - } - - public SSAFunction getNext() { - return next; - } - - public void setParent(FunctionBinder parent) { - this.parent = parent; - } - - public void setPrev(SSAFunction function) { - this.prev = function; - } - - public void setNext(SSAFunction function) { - this.next = function; - } - + @Override public void collectFreeVariables(ArrayList vars) { for(SSABlock block = firstBlock; block != null; block = block.next) block.collectFreeVariables(this, vars); } - - @Override - public SSAFunction getParentFunction() { - return parent.getParentFunction(); - } - - public FunctionBinder getParent() { - return parent; - } + @Override public void lambdaLift(SSALambdaLiftingContext context) { for(SSABlock block = firstBlock; block != null; block = block.next) block.lambdaLift(context); } - public void addParametersInFront(BoundVar[] parameters) { + @Override + public void parametrize(BoundVar[] parameters) { Cont proxy = null; for(ContRef ref = firstBlock.getOccurrence(); ref != null; ref = ref.getNext()) proxy = ref.addParametersInFront(parameters, firstBlock.parameters, proxy); @@ -481,11 +370,16 @@ public final class SSAFunction implements Printable, BoundVarBinder { return effect; } - public int getBlockCount() { - int count = 0; - for(SSABlock block = firstBlock;block != null;block = block.next) - ++count; - return count; + @Override + public boolean isValue() { + return getArity() == 0; + } + + @Override + public void forValRefs(ValRefVisitor visitor) { + for(SSABlock block = firstBlock; + block != null; block = block.next) + block.forValRefs(visitor); } }