1 package org.simantics.scl.compiler.internal.codegen.ssa;
3 import java.util.ArrayList;
5 import org.simantics.scl.compiler.internal.codegen.references.BoundVar;
6 import org.simantics.scl.compiler.internal.codegen.references.Val;
7 import org.simantics.scl.compiler.internal.codegen.references.ValRef;
8 import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetApply;
9 import org.simantics.scl.compiler.internal.codegen.utils.CopyContext;
10 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
11 import org.simantics.scl.compiler.internal.codegen.utils.Printable;
12 import org.simantics.scl.compiler.internal.codegen.utils.PrintingContext;
13 import org.simantics.scl.compiler.internal.codegen.utils.SSALambdaLiftingContext;
14 import org.simantics.scl.compiler.internal.codegen.utils.SSASimplificationContext;
15 import org.simantics.scl.compiler.internal.codegen.utils.SSAValidationContext;
16 import org.simantics.scl.compiler.internal.codegen.utils.ValRefVisitor;
17 import org.simantics.scl.compiler.types.TVar;
18 import org.simantics.scl.compiler.types.Type;
19 import org.simantics.scl.compiler.types.Types;
22 public abstract class SSAStatement implements Printable {
28 public void detach() {
30 parent.firstStatement = next;
34 parent.lastStatement = prev;
39 public abstract void generateCode(MethodBuilder mb);
41 public abstract void validate(SSAValidationContext context);
43 public void simplify(SSASimplificationContext context) {
46 public abstract void destroy();
48 public SSABlock getParent() {
52 public SSAStatement getPrev() {
56 public void setAsLastStatement() {
58 parent.lastStatement = this;
61 public SSAStatement getNext() {
65 public void remove() {
71 public String toString() {
72 PrintingContext context = new PrintingContext();
74 return context.toString();
77 public void markGenerateOnFly() {
80 public abstract SSAStatement copy(CopyContext context);
81 public abstract void replace(TVar[] vars, Type[] replacements);
83 public abstract void addBoundVariablesTo(SSAValidationContext context);
85 public abstract void collectFreeVariables(SSAFunction function, ArrayList<ValRef> vars);
87 public SSAFunction getParentFunction() {
91 public void lambdaLift(SSALambdaLiftingContext context) {
94 public void insertBefore(SSAStatement statement) {
96 prev = statement.prev;
97 parent = statement.parent;
99 parent.firstStatement = this;
102 statement.prev = this;
105 public void insertAfter(SSAStatement statement) {
107 next = statement.next;
108 parent = statement.parent;
110 parent.lastStatement = this;
113 statement.next = this;
116 public void replaceByApply(ValRef valRef, Val function, Type[] typeParameters, Val[] parameters) {
117 BoundVar target = new BoundVar(valRef.getBinding().getType());
118 new LetApply(target, Types.NO_EFFECTS, function.createOccurrence(typeParameters), ValRef.createOccurrences(parameters)).insertBefore(this);
119 valRef.replaceBy(target);
122 public void prepare(MethodBuilder mb) {
125 public abstract void forValRefs(ValRefVisitor visitor);
127 public abstract void cleanup();