Search in sources :

Example 11 with LLVMParserException

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

the class IntegerConstant method createNode.

@Override
public LLVMExpressionNode createNode(LLVMParserRuntime runtime, DataLayout dataLayout, GetStackSpaceFactory stackFactory) {
    Type type = getType();
    long lVal = getValue();
    if (type instanceof PrimitiveType) {
        switch(((PrimitiveType) type).getPrimitiveKind()) {
            case I1:
                return CommonNodeFactory.createSimpleConstantNoArray(lVal != 0, type);
            case I8:
                return CommonNodeFactory.createSimpleConstantNoArray((byte) lVal, type);
            case I16:
                return CommonNodeFactory.createSimpleConstantNoArray((short) lVal, type);
            case I32:
                return CommonNodeFactory.createSimpleConstantNoArray((int) lVal, type);
            case I64:
                return CommonNodeFactory.createSimpleConstantNoArray(lVal, type);
            default:
                throw new LLVMParserException("Unsupported IntegerConstant: " + type);
        }
    } else if (type instanceof VariableBitWidthType) {
        return CommonNodeFactory.createSimpleConstantNoArray(lVal, type);
    } else {
        throw new LLVMParserException("Unsupported IntegerConstant: " + type);
    }
}
Also used : PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) VariableBitWidthType(com.oracle.truffle.llvm.runtime.types.VariableBitWidthType) Type(com.oracle.truffle.llvm.runtime.types.Type) VariableBitWidthType(com.oracle.truffle.llvm.runtime.types.VariableBitWidthType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 12 with LLVMParserException

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

the class LoadDependencyNode method createDependencySource.

@TruffleBoundary
private Object createDependencySource(String libName, String libPath, TruffleFile file) {
    assert file != null;
    boolean createNative = false;
    try {
        if (!file.isRegularFile()) {
            createNative = true;
        }
    } catch (SecurityException se) {
        createNative = true;
    }
    if (createNative) {
        TruffleFile nativeFile = createNativeTruffleFile(libName, libPath);
        // null is returned if the NFIContextExtension does not exists.
        if (nativeFile == null) {
            return null;
        }
        return createNativeLibraryCallTarget(nativeFile);
    }
    Source source;
    LLVMLanguage language = getLanguage();
    if (language.containsLibrarySource(file.getPath())) {
        source = language.getLibrarySource(file.getPath());
    } else {
        try {
            source = Source.newBuilder("llvm", file).internal(getContext().isInternalLibraryFile(file)).build();
            language.addLibrarySource(file.getPath(), source);
        } catch (IOException | SecurityException | OutOfMemoryError ex) {
            throw new LLVMParserException("Error reading file " + file.getName() + ".");
        }
    }
    return source;
}
Also used : TruffleFile(com.oracle.truffle.api.TruffleFile) IOException(java.io.IOException) Source(com.oracle.truffle.api.source.Source) LLVMLanguage(com.oracle.truffle.llvm.runtime.LLVMLanguage) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 13 with LLVMParserException

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

the class LoadNativeNode method execute.

@Override
@SuppressWarnings("unchecked")
public Object execute(VirtualFrame frame) {
    Object[] arguments = frame.getArguments();
    Object library = null;
    LLVMLoadingPhase phase;
    if (arguments.length > 0 && (arguments[0] instanceof LLVMLoadingPhase)) {
        phase = (LLVMLoadingPhase) arguments[0];
    } else if (arguments.length == 0 || (arguments.length > 0 && (arguments[0] instanceof LLVMDLOpen.RTLDFlags))) {
        if (path == null) {
            throw new LLVMParserException(this, "Toplevel executable %s does not contain bitcode", path);
        }
        phase = LLVMLoadingPhase.INIT_SYMBOLS;
    } else {
        throw new LLVMParserException(this, "LoadNativeNode is called either with unexpected arguments or as a toplevel");
    }
    if (LLVMLoadingPhase.INIT_SYMBOLS.isActive(phase)) {
        LLVMContext context = LLVMContext.get(this);
        library = parseAndInitialiseNativeLib(context);
    }
    if (LLVMLoadingPhase.BUILD_DEPENDENCY.isActive(phase)) {
        ArrayList<CallTarget> dependencies = (ArrayList<CallTarget>) frame.getArguments()[2];
        dependencies.add(this.getCallTarget());
    }
    return library;
}
Also used : LLVMLoadingPhase(com.oracle.truffle.llvm.initialization.LoadModulesNode.LLVMLoadingPhase) LLVMContext(com.oracle.truffle.llvm.runtime.LLVMContext) CallTarget(com.oracle.truffle.api.CallTarget) LLVMDLOpen(com.oracle.truffle.llvm.runtime.nodes.intrinsics.c.LLVMDLOpen) ArrayList(java.util.ArrayList) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 14 with LLVMParserException

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

the class PEFile method create.

public static PEFile create(ByteSequence bytes) {
    ObjectFileReader reader = new ObjectFileReader(bytes, true);
    short machine = reader.getShort();
    if (machine != IMAGE_DOS_SIGNATURE) {
        throw new LLVMParserException("Invalid MS DOS file!");
    }
    reader.setPosition(OFFSET_TO_PE_SIGNATURE);
    int peOffset = reader.getInt();
    reader.setPosition(peOffset);
    int reSignature = reader.getInt();
    if (reSignature != IMAGE_NT_SIGNATURE) {
        throw new LLVMParserException("No PE Signature found in MS DOS Executable!");
    }
    return new PEFile(CoffFile.create(bytes, reader));
}
Also used : ObjectFileReader(com.oracle.truffle.llvm.parser.filereader.ObjectFileReader) LLVMParserException(com.oracle.truffle.llvm.runtime.except.LLVMParserException)

Example 15 with LLVMParserException

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

the class Function method getElementPointerType.

private Type getElementPointerType(Type type, int[] indices) {
    boolean vectorized = type instanceof VectorType;
    int length = vectorized ? ((VectorType) type).getNumberOfElementsInt() : 0;
    Type elementType = vectorized ? ((VectorType) type).getElementType() : type;
    for (int indexIndex : indices) {
        Type indexType = scope.getValueType(indexIndex);
        if (elementType instanceof PointerType) {
            elementType = ((PointerType) elementType).getPointeeType();
        } else if (elementType instanceof ArrayType) {
            elementType = ((ArrayType) elementType).getElementType();
        } else if (elementType instanceof VectorType) {
            elementType = ((VectorType) elementType).getElementType();
        } else if (elementType instanceof StructureType) {
            StructureType structure = (StructureType) elementType;
            if (!(indexType instanceof PrimitiveType)) {
                throw new LLVMParserException("Cannot infer structure element from " + indexType);
            }
            Number indexNumber = (Number) ((PrimitiveType) indexType).getConstant();
            assert ((PrimitiveType) indexType).getPrimitiveKind() == PrimitiveKind.I32;
            elementType = structure.getElementType(indexNumber.intValue());
        } else {
            throw new LLVMParserException("Cannot index type: " + elementType);
        }
        if (indexType instanceof VectorType) {
            int indexVectorLength = ((VectorType) indexType).getNumberOfElementsInt();
            if (vectorized) {
                if (indexVectorLength != length) {
                    throw new LLVMParserException(String.format("Vectors of different lengths are not supported: %d != %d", indexVectorLength, length));
                }
            } else {
                vectorized = true;
                length = indexVectorLength;
            }
        }
    }
    Type pointer = new PointerType(elementType);
    if (vectorized) {
        return new VectorType(pointer, length);
    } else {
        return pointer;
    }
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) 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) VectorType(com.oracle.truffle.llvm.runtime.types.VectorType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) 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