Search in sources :

Example 26 with RegIndex

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);
}
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 27 with RegIndex

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();
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 28 with RegIndex

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;
}
Also used : RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 29 with RegIndex

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);
}
Also used : RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 30 with RegIndex

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);
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Aggregations

RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)37 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)22 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)20 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)13 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)6 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)5 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)4 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)4 BXMLNSSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol)3 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)3 Stack (java.util.Stack)2 Name (org.ballerinalang.model.Name)2 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)2 BTypeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol)2 BMapType (org.wso2.ballerinalang.compiler.semantics.model.types.BMapType)2 BLangEnumerator (org.wso2.ballerinalang.compiler.tree.BLangEnum.BLangEnumerator)2 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)2 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)2 BLangRecordKeyValue (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKeyValue)2 EnumInfo (org.wso2.ballerinalang.programfile.EnumInfo)2