Search in sources :

Example 1 with WorkerDataChannelRefCPEntry

use of org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry in project ballerina by ballerina-lang.

the class PackageInfoWriter method writeCP.

public static void writeCP(DataOutputStream dataOutStream, ConstantPoolEntry[] constPool) throws IOException {
    dataOutStream.writeInt(constPool.length);
    for (ConstantPoolEntry cpEntry : constPool) {
        // Emitting the kind of the constant pool entry.
        dataOutStream.writeByte(cpEntry.getEntryType().getValue());
        int nameCPIndex;
        switch(cpEntry.getEntryType()) {
            case CP_ENTRY_UTF8:
                String stringVal = ((UTF8CPEntry) cpEntry).getValue();
                if (stringVal != null) {
                    byte[] bytes = toUTF(stringVal);
                    dataOutStream.writeShort(bytes.length);
                    dataOutStream.write(bytes);
                } else {
                    // If the string value is null, we write the size as -1.
                    // This marks that the value followed by -1 size is a null value.
                    dataOutStream.writeShort(NULL_VALUE_FIELD_SIZE_TAG);
                }
                break;
            case CP_ENTRY_INTEGER:
                long longVal = ((IntegerCPEntry) cpEntry).getValue();
                dataOutStream.writeLong(longVal);
                break;
            case CP_ENTRY_FLOAT:
                double doubleVal = ((FloatCPEntry) cpEntry).getValue();
                dataOutStream.writeDouble(doubleVal);
                break;
            case CP_ENTRY_STRING:
                nameCPIndex = ((StringCPEntry) cpEntry).getStringCPIndex();
                dataOutStream.writeInt(nameCPIndex);
                break;
            case CP_ENTRY_PACKAGE:
                nameCPIndex = ((PackageRefCPEntry) cpEntry).nameCPIndex;
                dataOutStream.writeInt(nameCPIndex);
                break;
            case CP_ENTRY_FUNCTION_REF:
                FunctionRefCPEntry funcRefEntry = (FunctionRefCPEntry) cpEntry;
                dataOutStream.writeInt(funcRefEntry.packageCPIndex);
                dataOutStream.writeInt(funcRefEntry.nameCPIndex);
                break;
            case CP_ENTRY_ACTION_REF:
                ActionRefCPEntry actionRefEntry = (ActionRefCPEntry) cpEntry;
                dataOutStream.writeInt(actionRefEntry.getPackageCPIndex());
                dataOutStream.writeInt(actionRefEntry.getNameCPIndex());
                break;
            case CP_ENTRY_STRUCTURE_REF:
                StructureRefCPEntry structureRefCPEntry = (StructureRefCPEntry) cpEntry;
                dataOutStream.writeInt(structureRefCPEntry.packageCPIndex);
                dataOutStream.writeInt(structureRefCPEntry.nameCPIndex);
                break;
            case CP_ENTRY_TYPE_REF:
                TypeRefCPEntry typeRefCPEntry = (TypeRefCPEntry) cpEntry;
                dataOutStream.writeInt(typeRefCPEntry.typeSigCPIndex);
                break;
            case CP_ENTRY_FORK_JOIN:
                ForkJoinCPEntry forkJoinCPEntry = (ForkJoinCPEntry) cpEntry;
                dataOutStream.writeInt(forkJoinCPEntry.forkJoinInfoIndex);
                break;
            case CP_ENTRY_WRKR_DATA_CHNL_REF:
                WorkerDataChannelRefCPEntry workerDataChannelCPEntry = (WorkerDataChannelRefCPEntry) cpEntry;
                dataOutStream.writeInt(workerDataChannelCPEntry.getUniqueNameCPIndex());
                break;
            case CP_ENTRY_TRANSFORMER_REF:
                TransformerRefCPEntry transformerRefEntry = (TransformerRefCPEntry) cpEntry;
                dataOutStream.writeInt(transformerRefEntry.packageCPIndex);
                dataOutStream.writeInt(transformerRefEntry.nameCPIndex);
                break;
        }
    }
}
Also used : TransformerRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TransformerRefCPEntry) TypeRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry) ActionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.ActionRefCPEntry) FloatCPEntry(org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry) WorkerDataChannelRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry) ConstantPoolEntry(org.wso2.ballerinalang.programfile.cpentries.ConstantPoolEntry) UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) FunctionRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.FunctionRefCPEntry) ForkJoinCPEntry(org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry) StructureRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry) IntegerCPEntry(org.wso2.ballerinalang.programfile.cpentries.IntegerCPEntry)

Example 2 with WorkerDataChannelRefCPEntry

use of org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry 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);
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) WorkerDataChannelRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry) WorkerDataChannelInfo(org.wso2.ballerinalang.programfile.WorkerDataChannelInfo) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 3 with WorkerDataChannelRefCPEntry

use of org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry 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;
    }
}
Also used : BLangLocalVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangLocalVarRef) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) WorkerDataChannelRefCPEntry(org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex) UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) WorkerDataChannelInfo(org.wso2.ballerinalang.programfile.WorkerDataChannelInfo) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Aggregations

UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)3 WorkerDataChannelRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry)3 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)2 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)2 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)2 WorkerDataChannelInfo (org.wso2.ballerinalang.programfile.WorkerDataChannelInfo)2 BLangLocalVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangLocalVarRef)1 ActionRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.ActionRefCPEntry)1 ConstantPoolEntry (org.wso2.ballerinalang.programfile.cpentries.ConstantPoolEntry)1 FloatCPEntry (org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry)1 ForkJoinCPEntry (org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry)1 FunctionRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.FunctionRefCPEntry)1 IntegerCPEntry (org.wso2.ballerinalang.programfile.cpentries.IntegerCPEntry)1 StructureRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.StructureRefCPEntry)1 TransformerRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.TransformerRefCPEntry)1 TypeRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.TypeRefCPEntry)1