use of org.wso2.ballerinalang.programfile.WorkerDataChannelInfo in project ballerina by ballerina-lang.
the class CodeGenerator method getWorkerDataChannelInfo.
private WorkerDataChannelInfo getWorkerDataChannelInfo(CallableUnitInfo callableUnit, String source, String target) {
WorkerDataChannelInfo workerDataChannelInfo = callableUnit.getWorkerDataChannelInfo(WorkerDataChannelInfo.generateChannelName(source, target));
if (workerDataChannelInfo == null) {
UTF8CPEntry sourceCPEntry = new UTF8CPEntry(source);
int sourceCPIndex = this.currentPkgInfo.addCPEntry(sourceCPEntry);
UTF8CPEntry targetCPEntry = new UTF8CPEntry(target);
int targetCPIndex = this.currentPkgInfo.addCPEntry(targetCPEntry);
workerDataChannelInfo = new WorkerDataChannelInfo(sourceCPIndex, source, targetCPIndex, target);
workerDataChannelInfo.setUniqueName(workerDataChannelInfo.getChannelName() + this.workerChannelCount);
String uniqueName = workerDataChannelInfo.getUniqueName();
UTF8CPEntry uniqueNameCPEntry = new UTF8CPEntry(uniqueName);
int uniqueNameCPIndex = this.currentPkgInfo.addCPEntry(uniqueNameCPEntry);
workerDataChannelInfo.setUniqueNameCPIndex(uniqueNameCPIndex);
callableUnit.addWorkerDataChannelInfo(workerDataChannelInfo);
this.workerChannelCount++;
}
return workerDataChannelInfo;
}
use of org.wso2.ballerinalang.programfile.WorkerDataChannelInfo 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.WorkerDataChannelInfo in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
public void visit(BLangWorkerReceive workerReceiveStmt) {
WorkerDataChannelInfo workerDataChannelInfo = this.getWorkerDataChannelInfo(this.currentCallableUnitInfo, workerReceiveStmt.workerIdentifier.value, this.currentWorkerInfo.getWorkerName());
WorkerDataChannelRefCPEntry wrkrChnlRefCPEntry = new WorkerDataChannelRefCPEntry(workerDataChannelInfo.getUniqueNameCPIndex(), workerDataChannelInfo.getUniqueName());
wrkrChnlRefCPEntry.setWorkerDataChannelInfo(workerDataChannelInfo);
Operand wrkrRplyRefCPIndex = getOperand(currentPkgInfo.addCPEntry(wrkrChnlRefCPEntry));
workerDataChannelInfo.setDataChannelRefIndex(wrkrRplyRefCPIndex.value);
List<BLangExpression> lhsExprs = workerReceiveStmt.exprs;
int nLHSExprs = lhsExprs.size();
RegIndex[] regIndexes = new RegIndex[nLHSExprs];
BType[] bTypes = new BType[nLHSExprs];
for (int i = 0; i < nLHSExprs; i++) {
BLangExpression lExpr = lhsExprs.get(i);
if (lExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF && lExpr instanceof BLangLocalVarRef) {
lExpr.regIndex = ((BLangLocalVarRef) lExpr).symbol.varIndex;
regIndexes[i] = lExpr.regIndex;
} else {
lExpr.regIndex = getRegIndex(lExpr.type.tag);
lExpr.regIndex.isLHSIndex = true;
regIndexes[i] = lExpr.regIndex;
}
bTypes[i] = lExpr.type;
}
UTF8CPEntry sigCPEntry = new UTF8CPEntry(this.generateSig(bTypes));
Operand sigCPIndex = getOperand(currentPkgInfo.addCPEntry(sigCPEntry));
// WRKRECEIVE wrkrRplyRefCPIndex typesCPIndex nRegIndexes, regIndexes[nRegIndexes]
Operand[] wrkReceiveArgRegs = new Operand[nLHSExprs + 3];
wrkReceiveArgRegs[0] = wrkrRplyRefCPIndex;
wrkReceiveArgRegs[1] = sigCPIndex;
wrkReceiveArgRegs[2] = getOperand(nLHSExprs);
System.arraycopy(regIndexes, 0, wrkReceiveArgRegs, 3, regIndexes.length);
emit(InstructionCodes.WRKRECEIVE, wrkReceiveArgRegs);
for (BLangExpression lExpr : lhsExprs) {
if (lExpr.getKind() == NodeKind.SIMPLE_VARIABLE_REF && lExpr instanceof BLangLocalVarRef) {
continue;
}
this.varAssignment = true;
this.genNode(lExpr, this.env);
this.varAssignment = false;
}
}
Aggregations