Search in sources :

Example 26 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

the class ParameterAttributes method decodeCodeEntry.

private void decodeCodeEntry(RecordBuffer buffer) {
    final List<AttributesGroup> attrGroup = new ArrayList<>();
    while (buffer.remaining() > 0) {
        long groupId = buffer.read();
        for (AttributesGroup attr : attributes) {
            if (attr.getGroupId() == groupId) {
                attrGroup.add(attr);
                break;
            }
        }
    }
    if (attrGroup.size() != buffer.size()) {
        throw new LLVMParserException("Mismatching number of defined and found attributes in AttributesGroup");
    }
    parameterCodeEntry.add(new AttributesCodeEntry(attrGroup));
}
Also used : AttributesGroup(com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup) AttributesCodeEntry(com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry) ArrayList(java.util.ArrayList) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 27 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

the class Function method createInvoke.

private void createInvoke(RecordBuffer buffer) {
    AttributesCodeEntry paramAttr = paramAttributes.getCodeEntry(buffer.read());
    long ccInfo = buffer.read();
    InstructionBlock normalSuccessor = function.getBlock(buffer.read());
    InstructionBlock unwindSuccessor = function.getBlock(buffer.read());
    FunctionType functionType = null;
    if (((ccInfo >> INVOKE_HASEXPLICITFUNCTIONTYPE_SHIFT) & 1) != 0) {
        functionType = Types.castToFunction(readType(buffer));
    }
    int target = readIndex(buffer);
    Type calleeType = readValueType(buffer, target);
    if (functionType == null) {
        if (calleeType instanceof PointerType) {
            functionType = Types.castToFunction(((PointerType) calleeType).getPointeeType());
        } else if (calleeType instanceof FunctionType) {
            functionType = (FunctionType) calleeType;
        } else {
            throw new LLVMParserException("Cannot find Type of invoked function: " + calleeType);
        }
    }
    int[] args = new int[buffer.remaining()];
    int j = 0;
    // the formal parameters are read without forward types
    while (j < functionType.getNumberOfArguments() && buffer.remaining() > 0) {
        args[j++] = readIndex(buffer);
    }
    // now varargs are read with forward types
    while (buffer.remaining() > 0) {
        args[j++] = readIndexSkipType(buffer);
    }
    if (args.length != j) {
        args = Arrays.copyOf(args, j);
    }
    final Type returnType = functionType.getReturnType();
    if (returnType == VoidType.INSTANCE) {
        emit(VoidInvokeInstruction.fromSymbols(scope, target, args, normalSuccessor, unwindSuccessor, paramAttr, operandBundle));
    } else {
        emit(InvokeInstruction.fromSymbols(scope, returnType, target, args, normalSuccessor, unwindSuccessor, paramAttr, operandBundle));
    }
    operandBundle = null;
    isLastBlockTerminated = true;
}
Also used : PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) AttributesCodeEntry(com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) InstructionBlock(com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 28 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

the class RecursiveTypesTest method createConfig.

private static void createConfig(ArrayList<Object[]> configs, TypeFactory rootFactory, List<TypeFactory> otherFactories) {
    try {
        String name = Stream.concat(Stream.of(rootFactory), otherFactories.stream()).map(TypeFactory::toString).collect(Collectors.joining("-"));
        Type rootType = createRecursiveType(rootFactory, otherFactories);
        Type copyType = createRecursiveType(rootFactory, otherFactories);
        configs.add(new Object[] { name, rootType, copyType });
        Type indirectRootType = rootFactory.create(rootType);
        Type indirectCopyType = rootFactory.create(copyType);
        configs.add(new Object[] { name + "_indirect", indirectRootType, indirectCopyType });
    } catch (LLVMParserException | AssertionError e) {
    // cannot create type
    }
}
Also used : AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) Type(com.oracle.truffle.llvm.runtime.types.Type) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 29 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(InsertValueInstruction insert) {
    if (!(insert.getAggregate().getType() instanceof StructureType || insert.getAggregate().getType() instanceof ArrayType)) {
        throw new LLVMParserException("\'insertvalue\' can only insert values into arrays and structs!");
    }
    final AggregateType sourceType = (AggregateType) insert.getAggregate().getType();
    final LLVMExpressionNode sourceAggregate = symbols.resolve(insert.getAggregate());
    final LLVMExpressionNode valueToInsert = symbols.resolve(insert.getValue());
    final Type valueType = insert.getValue().getType();
    final int targetIndex = insert.getIndex();
    final LLVMExpressionNode resultAggregate = nodeFactory.createGetUniqueStackSpace(sourceType, uniquesRegion);
    LLVMExpressionNode result;
    try {
        final long offset = sourceType.getOffsetOf(targetIndex, dataLayout);
        result = nodeFactory.createInsertValue(resultAggregate, sourceAggregate, sourceType.getSize(dataLayout), offset, valueToInsert, valueType);
    } catch (TypeOverflowException e) {
        // FIXME is that the right thing to do?
        result = Type.handleOverflowExpression(e);
    }
    createFrameWrite(result, insert);
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) Type(com.oracle.truffle.llvm.runtime.types.Type) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) TypeOverflowException(com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 30 with LLVMParserException

use of com.oracle.truffle.llvm.runtime.except.LLVMParserException in project graal by oracle.

the class LLVMBitcodeInstructionVisitor method assignSourceLocation.

private void assignSourceLocation(LLVMInstrumentableNode node, Instruction sourceInstruction, SourceInstrumentationStrategy instrumentationStrategy) {
    if (node == null) {
        return;
    }
    final LLVMSourceLocation location = sourceInstruction.getSourceLocation();
    if (location == null) {
        return;
    }
    node.setSourceLocation(location);
    assert instrumentationStrategy != null;
    switch(instrumentationStrategy) {
        case FORCED:
            node.setHasStatementTag(true);
            lastLocation = location;
            break;
        case ONLY_FIRST_STATEMENT_ON_LOCATION:
            if (lastLocation == location) {
                // shortcut for locations assigned by DEBUG_LOC_AGAIN
                break;
            } else if (lastLocation != null && Objects.equals(lastLocation.describeFile(), location.describeFile()) && lastLocation.getLine() == location.getLine()) {
                // though llvm debug information does not actually describe statement boundaries
                break;
            } else {
                node.setHasStatementTag(true);
                lastLocation = location;
            }
            break;
        case DISABLED:
            break;
        default:
            throw new LLVMParserException("Unknown instrumentation strategy: " + instrumentationStrategy);
    }
}
Also used : LLVMSourceLocation(com.oracle.truffle.llvm.runtime.debug.scope.LLVMSourceLocation) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Aggregations

LLVMParserException (com.oracle.truffle.llvm.runtime.except.LLVMParserException)32 Type (com.oracle.truffle.llvm.runtime.types.Type)12 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)11 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)11 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)10 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)10 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)9 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)9 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)7 AttributesGroup (com.oracle.truffle.llvm.parser.model.attributes.AttributesGroup)6 VectorType (com.oracle.truffle.llvm.runtime.types.VectorType)6 ArrayList (java.util.ArrayList)6 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)5 LLVMSourceType (com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType)5 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)5 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)4 TypeArrayBuilder (com.oracle.truffle.llvm.runtime.types.Type.TypeArrayBuilder)3 Matcher (java.util.regex.Matcher)3 CallTarget (com.oracle.truffle.api.CallTarget)2 TruffleFile (com.oracle.truffle.api.TruffleFile)2