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%2Fwriter%2FCodeWriter.java;h=1125a4bde9f41c52f372adcd22c9c627dc6f9010;hp=6bed9f0661fc854b86afa24738bc3eb6dc032f91;hb=a8758de5bc19e5adb3f618d3038743a164f09912;hpb=12d9af17384d960b75d58c3935d2b7b46d93e87b diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/writer/CodeWriter.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/writer/CodeWriter.java index 6bed9f066..1125a4bde 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/writer/CodeWriter.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/writer/CodeWriter.java @@ -10,6 +10,7 @@ import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.references.ValRef; import org.simantics.scl.compiler.internal.codegen.ssa.SSABlock; import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction; +import org.simantics.scl.compiler.internal.codegen.ssa.SSAObject; import org.simantics.scl.compiler.internal.codegen.ssa.exits.If; import org.simantics.scl.compiler.internal.codegen.ssa.exits.Jump; import org.simantics.scl.compiler.internal.codegen.ssa.exits.Switch; @@ -28,12 +29,12 @@ public class CodeWriter { ModuleWriter moduleWriter; SSABlock block; - CodeWriter(ModuleWriter moduleWriter, SSABlock block) { + public CodeWriter(ModuleWriter moduleWriter, SSABlock block) { this.moduleWriter = moduleWriter; this.block = block; } - public IVal apply(int lineNumber, IVal function, IVal ... parameters) { + public IVal apply(long lineNumber, IVal function, IVal ... parameters) { try { MultiFunction mfun = Types.matchFunction(function.getType(), parameters.length); return applyWithEffect(lineNumber, @@ -45,7 +46,7 @@ public class CodeWriter { } } - public IVal applyWithEffectChecked(int lineNumber, Type effect, Type returnType, IVal function, IVal ... parameters) { + public IVal applyWithEffectChecked(long lineNumber, Type effect, Type returnType, IVal function, IVal ... parameters) { try { MultiFunction mfun = Types.matchFunction(function.getType(), parameters.length); if(!Types.equals(effect, mfun.effect)) @@ -69,6 +70,12 @@ public class CodeWriter { return var; } + public CodeWriter createBlock() { + SSABlock newBlock = new SSABlock(Type.EMPTY_ARRAY); + block.getParent().addBlock(newBlock); + return new CodeWriter(moduleWriter, newBlock); + } + public CodeWriter createBlock(Type ... parameterTypes) { SSABlock newBlock = new SSABlock(parameterTypes); block.getParent().addBlock(newBlock); @@ -120,6 +127,24 @@ public class CodeWriter { elseTarget.createOccurrence())); block = null; } + + public void branchAwayIf(IVal condition, ICont target) { + SSABlock newBlock = new SSABlock(Type.EMPTY_ARRAY); + block.getParent().addBlock(newBlock); + block.setExit(new If(condition.createOccurrence(), + target.createOccurrence(), + newBlock.createOccurrence())); + this.block = newBlock; + } + + public void branchAwayUnless(IVal condition, ICont target) { + SSABlock newBlock = new SSABlock(Type.EMPTY_ARRAY); + block.getParent().addBlock(newBlock); + block.setExit(new If(condition.createOccurrence(), + newBlock.createOccurrence(), + target.createOccurrence())); + this.block = newBlock; + } public void return_(IVal val) { jump(block.getParent().getReturnCont(), val); @@ -143,5 +168,13 @@ public class CodeWriter { public SSAFunction getFunction() { return block.getParent(); - } + } + + public boolean isUnfinished() { + return block != null; + } + + public void defineObject(SSAObject object) { + this.block.addStatement(new LetFunctions(object)); + } }