-package org.simantics.scl.compiler.internal.codegen.ssa;\r
-\r
-import java.util.ArrayList;\r
-\r
-import org.simantics.scl.compiler.internal.codegen.references.BoundVar;\r
-import org.simantics.scl.compiler.internal.codegen.references.ValRef;\r
-import org.simantics.scl.compiler.internal.codegen.ssa.binders.ClosureBinder;\r
-import org.simantics.scl.compiler.internal.codegen.utils.CopyContext;\r
-import org.simantics.scl.compiler.internal.codegen.utils.PrintingContext;\r
-import org.simantics.scl.compiler.internal.codegen.utils.SSALambdaLiftingContext;\r
-import org.simantics.scl.compiler.internal.codegen.utils.SSASimplificationContext;\r
-import org.simantics.scl.compiler.internal.codegen.utils.SSAValidationContext;\r
-import org.simantics.scl.compiler.internal.codegen.utils.ValRefVisitor;\r
-import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;\r
-import org.simantics.scl.compiler.internal.codegen.writer.ModuleWriter;\r
-import org.simantics.scl.compiler.types.TVar;\r
-import org.simantics.scl.compiler.types.Type;\r
-\r
-public class SSAObject extends SSAClosure implements ClosureBinder {\r
- Type type;\r
- SSAClosure firstClosure;\r
- \r
- public SSAObject(Type type) {\r
- this.type = type;\r
- }\r
-\r
- @Override\r
- public void toString(PrintingContext context) {\r
- for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext()) {\r
- context.indentation();\r
- context.append(closure.getTarget());\r
- context.append("(" + closure.getTarget().occurrenceCount() + ")");\r
- context.append(" :: ");\r
- context.append(closure.getTarget().getType());\r
- context.append(" = \n");\r
- context.indent();\r
- closure.toString(context);\r
- context.dedent();\r
- }\r
- }\r
-\r
- @Override\r
- public SSAClosure getFirstClosure() {\r
- return firstClosure;\r
- }\r
- \r
- @Override\r
- public void setFirstClosure(SSAClosure function) {\r
- this.firstClosure = function; \r
- if(function == null)\r
- detach();\r
- }\r
- \r
- @Override\r
- public void destroy() {\r
- for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())\r
- closure.destroy();\r
- }\r
-\r
- @Override\r
- public SSAClosure copy(CopyContext context) {\r
- SSAObject result = new SSAObject(context.copyType(type));\r
- for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext()) {\r
- SSAClosure newFunction = closure.copy(context);\r
- newFunction.setTarget(context.copy(closure.getTarget()));\r
- result.addClosure(newFunction);\r
- }\r
- return result; \r
- }\r
-\r
- public void addClosure(SSAClosure closure) {\r
- closure.setParent(this); \r
- closure.setNext(firstClosure);\r
- if(firstClosure != null)\r
- firstClosure.setPrev(closure);\r
- firstClosure = closure;\r
- }\r
- \r
- @Override\r
- public void markGenerateOnFly() {\r
- for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())\r
- closure.markGenerateOnFly();\r
- }\r
-\r
- @Override\r
- public void replace(TVar[] vars, Type[] replacements) {\r
- for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())\r
- closure.replace(vars, replacements);\r
- }\r
-\r
- @Override\r
- public void collectFreeVariables(ArrayList<ValRef> freeVars) {\r
- for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())\r
- closure.collectFreeVariables(freeVars);\r
- }\r
-\r
- @Override\r
- public void simplify(SSASimplificationContext context) {\r
- for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())\r
- closure.simplify(context);\r
- }\r
-\r
- @Override\r
- public void validate(SSAValidationContext context) {\r
- for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())\r
- closure.validate(context);\r
- }\r
-\r
- @Override\r
- public void lambdaLift(SSALambdaLiftingContext context) {\r
- for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())\r
- closure.lambdaLift(context);\r
- }\r
-\r
- @Override\r
- public boolean isValue() {\r
- return false;\r
- }\r
-\r
- @Override\r
- public void parametrize(BoundVar[] parameters) {\r
- // TODO Auto-generated method stub\r
- \r
- }\r
-\r
- @Override\r
- public Type getType() {\r
- return type;\r
- }\r
- \r
- public CodeWriter createMethod(ModuleWriter moduleWriter, TVar[] typeParameters, Type effect, Type returnType, Type[] parameterTypes) {\r
- SSAFunction function = new SSAFunction(typeParameters, effect, returnType);\r
- SSABlock block = new SSABlock(parameterTypes);\r
- function.addBlock(block);\r
- BoundVar target = new BoundVar(function.getType());\r
- function.setTarget(target);\r
- addClosure(function);\r
- return new CodeWriter(moduleWriter, block);\r
- }\r
-\r
- @Override\r
- public void forValRefs(ValRefVisitor visitor) {\r
- for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())\r
- closure.forValRefs(visitor);\r
- }\r
-\r
-}\r
+package org.simantics.scl.compiler.internal.codegen.ssa;
+
+import java.util.ArrayList;
+
+import org.simantics.scl.compiler.internal.codegen.references.BoundVar;
+import org.simantics.scl.compiler.internal.codegen.references.ValRef;
+import org.simantics.scl.compiler.internal.codegen.ssa.binders.ClosureBinder;
+import org.simantics.scl.compiler.internal.codegen.utils.CopyContext;
+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.internal.codegen.writer.CodeWriter;
+import org.simantics.scl.compiler.internal.codegen.writer.ModuleWriter;
+import org.simantics.scl.compiler.types.TVar;
+import org.simantics.scl.compiler.types.Type;
+
+public class SSAObject extends SSAClosure implements ClosureBinder {
+ Type type;
+ SSAClosure firstClosure;
+
+ public SSAObject(Type type) {
+ this.type = type;
+ }
+
+ @Override
+ public void toString(PrintingContext context) {
+ for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext()) {
+ context.indentation();
+ context.append(closure.getTarget());
+ context.append("(" + closure.getTarget().occurrenceCount() + ")");
+ context.append(" :: ");
+ context.append(closure.getTarget().getType());
+ context.append(" = \n");
+ context.indent();
+ closure.toString(context);
+ context.dedent();
+ }
+ }
+
+ @Override
+ public SSAClosure getFirstClosure() {
+ return firstClosure;
+ }
+
+ @Override
+ public void setFirstClosure(SSAClosure function) {
+ this.firstClosure = function;
+ if(function == null)
+ detach();
+ }
+
+ @Override
+ public void destroy() {
+ for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())
+ closure.destroy();
+ }
+
+ @Override
+ public SSAClosure copy(CopyContext context) {
+ SSAObject result = new SSAObject(context.copyType(type));
+ for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext()) {
+ SSAClosure newFunction = closure.copy(context);
+ newFunction.setTarget(context.copy(closure.getTarget()));
+ result.addClosure(newFunction);
+ }
+ return result;
+ }
+
+ public void addClosure(SSAClosure closure) {
+ closure.setParent(this);
+ closure.setNext(firstClosure);
+ if(firstClosure != null)
+ firstClosure.setPrev(closure);
+ firstClosure = closure;
+ }
+
+ @Override
+ public void markGenerateOnFly() {
+ for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())
+ closure.markGenerateOnFly();
+ }
+
+ @Override
+ public void replace(TVar[] vars, Type[] replacements) {
+ for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())
+ closure.replace(vars, replacements);
+ }
+
+ @Override
+ public void collectFreeVariables(ArrayList<ValRef> freeVars) {
+ for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())
+ closure.collectFreeVariables(freeVars);
+ }
+
+ @Override
+ public void simplify(SSASimplificationContext context) {
+ for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())
+ closure.simplify(context);
+ }
+
+ @Override
+ public void validate(SSAValidationContext context) {
+ for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())
+ closure.validate(context);
+ }
+
+ @Override
+ public void lambdaLift(SSALambdaLiftingContext context) {
+ for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())
+ closure.lambdaLift(context);
+ }
+
+ @Override
+ public boolean isValue() {
+ return false;
+ }
+
+ @Override
+ public void parametrize(BoundVar[] parameters) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Type getType() {
+ return type;
+ }
+
+ public CodeWriter createMethod(ModuleWriter moduleWriter, TVar[] typeParameters, Type effect, Type returnType, Type[] parameterTypes) {
+ SSAFunction function = new SSAFunction(typeParameters, effect, returnType);
+ SSABlock block = new SSABlock(parameterTypes);
+ function.addBlock(block);
+ BoundVar target = new BoundVar(function.getType());
+ function.setTarget(target);
+ addClosure(function);
+ return new CodeWriter(moduleWriter, block);
+ }
+
+ @Override
+ public void forValRefs(ValRefVisitor visitor) {
+ for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())
+ closure.forValRefs(visitor);
+ }
+
+ @Override
+ public void cleanup() {
+ for(SSAClosure closure = firstClosure; closure != null; closure = closure.getNext())
+ closure.cleanup();
+ }
+
+}