1 package org.simantics.scl.compiler.internal.codegen.ssa;
\r
3 import java.util.ArrayList;
\r
5 import org.simantics.scl.compiler.internal.codegen.references.BoundVar;
\r
6 import org.simantics.scl.compiler.internal.codegen.references.Val;
\r
7 import org.simantics.scl.compiler.internal.codegen.references.ValRef;
\r
8 import org.simantics.scl.compiler.internal.codegen.ssa.statements.LetApply;
\r
9 import org.simantics.scl.compiler.internal.codegen.utils.CopyContext;
\r
10 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
\r
11 import org.simantics.scl.compiler.internal.codegen.utils.Printable;
\r
12 import org.simantics.scl.compiler.internal.codegen.utils.PrintingContext;
\r
13 import org.simantics.scl.compiler.internal.codegen.utils.SSALambdaLiftingContext;
\r
14 import org.simantics.scl.compiler.internal.codegen.utils.SSASimplificationContext;
\r
15 import org.simantics.scl.compiler.internal.codegen.utils.SSAValidationContext;
\r
16 import org.simantics.scl.compiler.types.TVar;
\r
17 import org.simantics.scl.compiler.types.Type;
\r
18 import org.simantics.scl.compiler.types.Types;
\r
21 public abstract class SSAStatement implements Printable {
\r
25 public long location;
\r
27 public void detach() {
\r
29 parent.firstStatement = next;
\r
33 parent.lastStatement = prev;
\r
38 public abstract void generateCode(MethodBuilder mb);
\r
40 public abstract void validate(SSAValidationContext context);
\r
42 public void simplify(SSASimplificationContext context) {
\r
45 public abstract void destroy();
\r
47 public SSABlock getParent() {
\r
51 public SSAStatement getPrev() {
\r
55 public void setAsLastStatement() {
\r
57 parent.lastStatement = this;
\r
60 public SSAStatement getNext() {
\r
64 public void remove() {
\r
70 public String toString() {
\r
71 PrintingContext context = new PrintingContext();
\r
73 return context.toString();
\r
76 public void markGenerateOnFly() {
\r
79 public abstract SSAStatement copy(CopyContext context);
\r
80 public abstract void replace(TVar[] vars, Type[] replacements);
\r
82 public abstract void addBoundVariablesTo(SSAValidationContext context);
\r
84 public abstract void collectFreeVariables(SSAFunction function, ArrayList<ValRef> vars);
\r
86 public SSAFunction getParentFunction() {
\r
87 return parent.parent;
\r
90 public void lambdaLift(SSALambdaLiftingContext context) {
\r
93 public void insertBefore(SSAStatement statement) {
\r
95 prev = statement.prev;
\r
96 parent = statement.parent;
\r
98 parent.firstStatement = this;
\r
101 statement.prev = this;
\r
104 public void insertAfter(SSAStatement statement) {
\r
106 next = statement.next;
\r
107 parent = statement.parent;
\r
109 parent.lastStatement = this;
\r
112 statement.next = this;
\r
115 public void replaceByApply(ValRef valRef, Val function, Type[] typeParameters, Val[] parameters) {
\r
116 BoundVar target = new BoundVar(valRef.getBinding().getType());
\r
117 new LetApply(target, Types.NO_EFFECTS, function.createOccurrence(typeParameters), ValRef.createOccurrences(parameters)).insertBefore(this);
\r
118 valRef.replaceBy(target);
\r
121 public void prepare(MethodBuilder mb) {
\r