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);
}
}
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;
}
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;
}
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));
}
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;
}
}
Aggregations