Search in sources :

Example 6 with REG

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

Example 7 with REG

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

Example 8 with REG

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

Example 9 with REG

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

Example 10 with 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;
    }
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Aggregations

RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)7 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)4 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)3 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)2 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)2 BLangStatement (org.wso2.ballerinalang.compiler.tree.statements.BLangStatement)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Stack (java.util.Stack)1 Collectors (java.util.stream.Collectors)1 XMLConstants (javax.xml.XMLConstants)1 AxisFault (org.apache.axis2.AxisFault)1 Policy (org.apache.neethi.Policy)1 CompilerPhase (org.ballerinalang.compiler.CompilerPhase)1