Search in sources :

Example 1 with UTF8CPEntry

use of org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry 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 UTF8CPEntry

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

the class CodeGenerator method visit.

public void visit(BLangForkJoin forkJoin) {
    SymbolEnv forkJoinEnv = SymbolEnv.createForkJoinSymbolEnv(forkJoin, this.env);
    ForkjoinInfo forkjoinInfo = new ForkjoinInfo(this.lvIndexes.toArray());
    this.populateForkJoinWorkerInfo(forkJoin, forkjoinInfo);
    int forkJoinInfoIndex = this.forkJoinCount++;
    /* was I already inside a fork/join */
    if (this.env.forkJoin != null) {
        this.currentWorkerInfo.addForkJoinInfo(forkjoinInfo);
    } else {
        this.currentCallableUnitInfo.defaultWorkerInfo.addForkJoinInfo(forkjoinInfo);
    }
    ForkJoinCPEntry forkJoinCPEntry = new ForkJoinCPEntry(forkJoinInfoIndex);
    Operand forkJoinCPIndex = getOperand(this.currentPkgInfo.addCPEntry(forkJoinCPEntry));
    forkjoinInfo.setIndexCPIndex(forkJoinCPIndex.value);
    RegIndex timeoutRegIndex = new RegIndex(-1, TypeTags.INT);
    addToRegIndexList(timeoutRegIndex);
    if (forkJoin.timeoutExpression != null) {
        forkjoinInfo.setTimeoutAvailable(true);
        this.genNode(forkJoin.timeoutExpression, forkJoinEnv);
        timeoutRegIndex.value = forkJoin.timeoutExpression.regIndex.value;
    }
    // FORKJOIN forkJoinCPIndex timeoutRegIndex joinVarRegIndex joinBlockAddr timeoutVarRegIndex timeoutBlockAddr
    RegIndex joinVarRegIndex = new RegIndex(-1, TypeTags.MAP);
    Operand joinBlockAddr = getOperand(-1);
    RegIndex timeoutVarRegIndex = new RegIndex(-1, TypeTags.MAP);
    Operand timeoutBlockAddr = getOperand(-1);
    this.emit(InstructionCodes.FORKJOIN, forkJoinCPIndex, timeoutRegIndex, joinVarRegIndex, joinBlockAddr, timeoutVarRegIndex, timeoutBlockAddr);
    this.processJoinWorkers(forkJoin, forkjoinInfo, forkJoinEnv);
    int i = 0;
    int[] joinWrkrNameCPIndexes = new int[forkJoin.joinedWorkers.size()];
    String[] joinWrkrNames = new String[joinWrkrNameCPIndexes.length];
    for (BLangIdentifier workerName : forkJoin.joinedWorkers) {
        UTF8CPEntry workerNameCPEntry = new UTF8CPEntry(workerName.value);
        int workerNameCPIndex = this.currentPkgInfo.addCPEntry(workerNameCPEntry);
        joinWrkrNameCPIndexes[i] = workerNameCPIndex;
        joinWrkrNames[i] = workerName.value;
        i++;
    }
    forkjoinInfo.setJoinWrkrNameIndexes(joinWrkrNameCPIndexes);
    forkjoinInfo.setJoinWorkerNames(joinWrkrNames);
    forkjoinInfo.setWorkerCount(forkJoin.joinedWorkerCount);
    this.processJoinBlock(forkJoin, forkjoinInfo, forkJoinEnv, joinVarRegIndex, joinBlockAddr);
    this.processTimeoutBlock(forkJoin, forkJoinEnv, timeoutVarRegIndex, timeoutBlockAddr);
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) ForkjoinInfo(org.wso2.ballerinalang.programfile.ForkjoinInfo) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) ForkJoinCPEntry(org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 3 with UTF8CPEntry

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

the class CodeGenerator method getDefaultValueAttributeInfo.

private DefaultValueAttributeInfo getDefaultValueAttributeInfo(BLangLiteral literalExpr) {
    DefaultValue defaultValue = getDefaultValue(literalExpr);
    UTF8CPEntry defaultValueAttribUTF8CPEntry = new UTF8CPEntry(AttributeInfo.Kind.DEFAULT_VALUE_ATTRIBUTE.toString());
    int defaultValueAttribNameIndex = currentPkgInfo.addCPEntry(defaultValueAttribUTF8CPEntry);
    return new DefaultValueAttributeInfo(defaultValueAttribNameIndex, defaultValue);
}
Also used : DefaultValue(org.wso2.ballerinalang.programfile.DefaultValue) UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) ParamDefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.ParamDefaultValueAttributeInfo) DefaultValueAttributeInfo(org.wso2.ballerinalang.programfile.attributes.DefaultValueAttributeInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 4 with UTF8CPEntry

use of org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry 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;
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) WorkerDataChannelInfo(org.wso2.ballerinalang.programfile.WorkerDataChannelInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 5 with UTF8CPEntry

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

the class CodeGenerator method processJoinBlock.

/* generate code for Join block */
private void processJoinBlock(BLangForkJoin forkJoin, ForkjoinInfo forkjoinInfo, SymbolEnv forkJoinEnv, RegIndex joinVarRegIndex, Operand joinBlockAddr) {
    UTF8CPEntry joinType = new UTF8CPEntry(forkJoin.joinType.name());
    int joinTypeCPIndex = this.currentPkgInfo.addCPEntry(joinType);
    forkjoinInfo.setJoinType(forkJoin.joinType.name());
    forkjoinInfo.setJoinTypeCPIndex(joinTypeCPIndex);
    joinBlockAddr.value = nextIP();
    if (forkJoin.joinResultVar != null) {
        visitForkJoinParameterDefs(forkJoin.joinResultVar, forkJoinEnv);
        joinVarRegIndex.value = forkJoin.joinResultVar.symbol.varIndex.value;
    }
    if (forkJoin.joinedBody != null) {
        this.genNode(forkJoin.joinedBody, forkJoinEnv);
    }
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Aggregations

UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)14 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)13 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)4 BLangWorker (org.wso2.ballerinalang.compiler.tree.BLangWorker)3 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)3 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)3 WorkerDataChannelInfo (org.wso2.ballerinalang.programfile.WorkerDataChannelInfo)3 WorkerInfo (org.wso2.ballerinalang.programfile.WorkerInfo)3 WorkerDataChannelRefCPEntry (org.wso2.ballerinalang.programfile.cpentries.WorkerDataChannelRefCPEntry)3 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)2 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)2 DefaultValue (org.wso2.ballerinalang.programfile.DefaultValue)2 FloatCPEntry (org.wso2.ballerinalang.programfile.cpentries.FloatCPEntry)2 ForkJoinCPEntry (org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry)2 IntegerCPEntry (org.wso2.ballerinalang.programfile.cpentries.IntegerCPEntry)2 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)1 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)1 BLangLocalVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef.BLangLocalVarRef)1 ForkjoinInfo (org.wso2.ballerinalang.programfile.ForkjoinInfo)1 LineNumberInfo (org.wso2.ballerinalang.programfile.LineNumberInfo)1