use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.REG in project ballerina by ballerina-lang.
the class CodeGenerator method getRegIndexInternal.
private RegIndex getRegIndexInternal(int typeTag, VariableIndex.Kind varIndexKind) {
int index;
switch(varIndexKind) {
case REG:
return new RegIndex(getNextIndex(typeTag, regIndexes), typeTag);
case PACKAGE:
index = getNextIndex(typeTag, pvIndexes);
break;
case FIELD:
index = getNextIndex(typeTag, fieldIndexes);
break;
default:
index = getNextIndex(typeTag, lvIndexes);
break;
}
RegIndex regIndex = new RegIndex(index, typeTag);
regIndex.isVarIndex = true;
return regIndex;
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.REG in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangTernaryExpr ternaryExpr) {
// Determine the reg index of the ternary expression and this reg index will be used by both then and else
// expressions to store their result
RegIndex ternaryExprRegIndex = calcAndGetExprRegIndex(ternaryExpr);
// Generate code for the condition
this.genNode(ternaryExpr.expr, this.env);
Operand ifFalseJumpAddr = getOperand(-1);
this.emit(InstructionCodes.BR_FALSE, ternaryExpr.expr.regIndex, ifFalseJumpAddr);
// Generate code for the then expression
ternaryExpr.thenExpr.regIndex = createLHSRegIndex(ternaryExprRegIndex);
this.genNode(ternaryExpr.thenExpr, this.env);
Operand endJumpAddr = getOperand(-1);
this.emit(InstructionCodes.GOTO, endJumpAddr);
ifFalseJumpAddr.value = nextIP();
// Generate code for the then expression
ternaryExpr.elseExpr.regIndex = createLHSRegIndex(ternaryExprRegIndex);
this.genNode(ternaryExpr.elseExpr, this.env);
endJumpAddr.value = nextIP();
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.REG in project ballerina by ballerina-lang.
the class CodeGenerator method getRegIndex.
private RegIndex getRegIndex(int typeTag) {
RegIndex regIndex = getRegIndexInternal(typeTag, REG);
addToRegIndexList(regIndex);
return regIndex;
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.REG in project ballerina by ballerina-lang.
the class CodeGenerator method endWorkerInfoUnit.
private void endWorkerInfoUnit(CodeAttributeInfo codeAttributeInfo) {
codeAttributeInfo.maxLongLocalVars = lvIndexes.tInt + 1;
codeAttributeInfo.maxDoubleLocalVars = lvIndexes.tFloat + 1;
codeAttributeInfo.maxStringLocalVars = lvIndexes.tString + 1;
codeAttributeInfo.maxIntLocalVars = lvIndexes.tBoolean + 1;
codeAttributeInfo.maxByteLocalVars = lvIndexes.tBlob + 1;
codeAttributeInfo.maxRefLocalVars = lvIndexes.tRef + 1;
codeAttributeInfo.maxLongRegs = codeAttributeInfo.maxLongLocalVars + maxRegIndexes.tInt + 1;
codeAttributeInfo.maxDoubleRegs = codeAttributeInfo.maxDoubleLocalVars + maxRegIndexes.tFloat + 1;
codeAttributeInfo.maxStringRegs = codeAttributeInfo.maxStringLocalVars + maxRegIndexes.tString + 1;
codeAttributeInfo.maxIntRegs = codeAttributeInfo.maxIntLocalVars + maxRegIndexes.tBoolean + 1;
codeAttributeInfo.maxByteRegs = codeAttributeInfo.maxByteLocalVars + maxRegIndexes.tBlob + 1;
codeAttributeInfo.maxRefRegs = codeAttributeInfo.maxRefLocalVars + maxRegIndexes.tRef + 1;
// Update register indexes.
for (RegIndex regIndex : regIndexList) {
switch(regIndex.typeTag) {
case TypeTags.INT:
regIndex.value = regIndex.value + codeAttributeInfo.maxLongLocalVars;
break;
case TypeTags.FLOAT:
regIndex.value = regIndex.value + codeAttributeInfo.maxDoubleLocalVars;
break;
case TypeTags.STRING:
regIndex.value = regIndex.value + codeAttributeInfo.maxStringLocalVars;
break;
case TypeTags.BOOLEAN:
regIndex.value = regIndex.value + codeAttributeInfo.maxIntLocalVars;
break;
case TypeTags.BLOB:
regIndex.value = regIndex.value + codeAttributeInfo.maxByteLocalVars;
break;
default:
regIndex.value = regIndex.value + codeAttributeInfo.maxRefLocalVars;
break;
}
}
regIndexList = new ArrayList<>();
lvIndexes = new VariableIndex(LOCAL);
regIndexes = new VariableIndex(REG);
maxRegIndexes = new VariableIndex(REG);
}
use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.REG in project ballerina by ballerina-lang.
the class CodeGenerator method processJoinWorkers.
/* visit the workers within fork-join block */
private void processJoinWorkers(BLangForkJoin forkJoin, ForkjoinInfo forkjoinInfo, SymbolEnv forkJoinEnv) {
UTF8CPEntry codeUTF8CPEntry = new UTF8CPEntry(AttributeInfo.Kind.CODE_ATTRIBUTE.toString());
int codeAttribNameIndex = this.currentPkgInfo.addCPEntry(codeUTF8CPEntry);
for (BLangWorker worker : forkJoin.workers) {
VariableIndex lvIndexesCopy = copyVarIndex(this.lvIndexes);
this.regIndexes = new VariableIndex(REG);
VariableIndex regIndexesCopy = this.regIndexes;
this.regIndexes = new VariableIndex(REG);
VariableIndex maxRegIndexesCopy = this.maxRegIndexes;
this.maxRegIndexes = new VariableIndex(REG);
List<RegIndex> regIndexListCopy = this.regIndexList;
this.regIndexList = new ArrayList<>();
WorkerInfo workerInfo = forkjoinInfo.getWorkerInfo(worker.name.value);
workerInfo.codeAttributeInfo.attributeNameIndex = codeAttribNameIndex;
workerInfo.codeAttributeInfo.codeAddrs = this.nextIP();
this.currentWorkerInfo = workerInfo;
this.genNode(worker.body, forkJoinEnv);
this.endWorkerInfoUnit(workerInfo.codeAttributeInfo);
this.emit(InstructionCodes.HALT);
this.lvIndexes = lvIndexesCopy;
this.regIndexes = regIndexesCopy;
this.maxRegIndexes = maxRegIndexesCopy;
this.regIndexList = regIndexListCopy;
}
}
Aggregations