use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangWorkerSend workerSendStmt) {
WorkerDataChannelInfo workerDataChannelInfo = this.getWorkerDataChannelInfo(this.currentCallableUnitInfo, this.currentWorkerInfo.getWorkerName(), workerSendStmt.workerIdentifier.value);
WorkerDataChannelRefCPEntry wrkrInvRefCPEntry = new WorkerDataChannelRefCPEntry(workerDataChannelInfo.getUniqueNameCPIndex(), workerDataChannelInfo.getUniqueName());
wrkrInvRefCPEntry.setWorkerDataChannelInfo(workerDataChannelInfo);
Operand wrkrInvRefCPIndex = getOperand(currentPkgInfo.addCPEntry(wrkrInvRefCPEntry));
if (workerSendStmt.isForkJoinSend) {
this.currentWorkerInfo.setWrkrDtChnlRefCPIndex(wrkrInvRefCPIndex.value);
this.currentWorkerInfo.setWorkerDataChannelInfoForForkJoin(workerDataChannelInfo);
}
workerDataChannelInfo.setDataChannelRefIndex(wrkrInvRefCPIndex.value);
int nArgExprs = workerSendStmt.exprs.size();
RegIndex[] argRegs = new RegIndex[nArgExprs];
BType[] bTypes = new BType[nArgExprs];
for (int i = 0; i < nArgExprs; i++) {
BLangExpression argExpr = workerSendStmt.exprs.get(i);
genNode(argExpr, this.env);
argRegs[i] = argExpr.regIndex;
bTypes[i] = argExpr.type;
}
UTF8CPEntry sigCPEntry = new UTF8CPEntry(this.generateSig(bTypes));
Operand sigCPIndex = getOperand(this.currentPkgInfo.addCPEntry(sigCPEntry));
// WRKSEND wrkrInvRefCPIndex typesCPIndex nRegIndexes, regIndexes[nRegIndexes]
Operand[] wrkSendArgRegs = new Operand[nArgExprs + 3];
wrkSendArgRegs[0] = wrkrInvRefCPIndex;
wrkSendArgRegs[1] = sigCPIndex;
wrkSendArgRegs[2] = getOperand(nArgExprs);
System.arraycopy(argRegs, 0, wrkSendArgRegs, 3, argRegs.length);
this.emit(InstructionCodes.WRKSEND, wrkSendArgRegs);
}
use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.
the class CodeGenerator method visitOrExpression.
private void visitOrExpression(BLangBinaryExpr binaryExpr) {
// short-circuit evaluation
// Code address to jump if the lhs expression gets evaluated to 'true'.
Operand lExprTrueJumpAddr = getOperand(-1);
// Code address to jump if the rhs expression gets evaluated to 'false'.
Operand rExprFalseJumpAddr = getOperand(-1);
// Generate code for the left hand side
genNode(binaryExpr.lhsExpr, this.env);
emit(InstructionCodes.BR_TRUE, binaryExpr.lhsExpr.regIndex, lExprTrueJumpAddr);
// Generate code for the right hand side
genNode(binaryExpr.rhsExpr, this.env);
emit(InstructionCodes.BR_FALSE, binaryExpr.rhsExpr.regIndex, rExprFalseJumpAddr);
lExprTrueJumpAddr.value = nextIP();
RegIndex exprRegIndex = calcAndGetExprRegIndex(binaryExpr);
emit(InstructionCodes.BCONST_1, exprRegIndex);
Operand gotoAddr = getOperand(-1);
emit(InstructionCodes.GOTO, gotoAddr);
rExprFalseJumpAddr.value = nextIP();
// Load 'false' if the both conditions are false;
emit(InstructionCodes.BCONST_0, exprRegIndex);
gotoAddr.value = nextIP();
}
use of org.wso2.ballerinalang.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.
the class CodeGenerator method createLHSRegIndex.
private RegIndex createLHSRegIndex(RegIndex regIndex) {
if (regIndex.isVarIndex || regIndex.isLHSIndex) {
return regIndex;
}
RegIndex lhsRegIndex = new RegIndex(regIndex.value, regIndex.typeTag, true);
addToRegIndexList(lhsRegIndex);
return lhsRegIndex;
}
use of org.wso2.ballerinalang.programfile.Instruction.RegIndex 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.programfile.Instruction.RegIndex in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangFieldVarRef fieldVarRef) {
RegIndex fieldIndex = fieldVarRef.symbol.varIndex;
// This is a connector field.
// the connector reference must be stored in the current reference register index.
Operand varRegIndex = getOperand(0);
if (varAssignment) {
int opcode = getOpcode(fieldVarRef.type.tag, InstructionCodes.IFIELDSTORE);
emit(opcode, varRegIndex, fieldIndex, fieldVarRef.regIndex);
return;
}
int opcode = getOpcode(fieldVarRef.type.tag, InstructionCodes.IFIELDLOAD);
RegIndex exprRegIndex = calcAndGetExprRegIndex(fieldVarRef);
emit(opcode, varRegIndex, fieldIndex, exprRegIndex);
}
Aggregations