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;
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,
}
}
- 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))
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);
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);
public SSAFunction getFunction() {
return block.getParent();
- }
+ }
+
+ public boolean isUnfinished() {
+ return block != null;
+ }
+
+ public void defineObject(SSAObject object) {
+ this.block.addStatement(new LetFunctions(object));
+ }
}