use of com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException in project graal by oracle.
the class CommonNodeFactory method createNestedElementPointerNode.
public static LLVMExpressionNode createNestedElementPointerNode(NodeFactory nodeFactory, DataLayout dataLayout, LLVMExpressionNode[] indexNodes, Long[] indexConstants, Type[] indexTypes, LLVMExpressionNode curAddress, Type curType) {
try {
ElementPointerFactory factory = new ElementPointerFactory(nodeFactory, curAddress, curType);
for (int i = 0; i < indexNodes.length; i++) {
Type indexType = indexTypes[i];
Long indexInteger = indexConstants[i];
if (indexInteger == null) {
// the index is determined at runtime
if (factory.currentType instanceof StructureType) {
// according to http://llvm.org/docs/LangRef.html#getelementptr-instruction
throw new LLVMParserException("Indices on structs must be constant integers!");
}
AggregateType aggregate = (AggregateType) factory.currentType;
long indexedTypeLength = aggregate.getOffsetOf(1, dataLayout);
factory.currentType = aggregate.getElementType(1);
factory.addIndex(indexedTypeLength, indexNodes[i], indexType);
} else {
// the index is a constant integer
AggregateType aggregate = (AggregateType) factory.currentType;
long addressOffset = aggregate.getOffsetOf(indexInteger, dataLayout);
factory.currentType = aggregate.getElementType(indexInteger);
// address computed by getelementptr even if it is the same as the basepointer
if (addressOffset != 0 || i == indexNodes.length - 1) {
LLVMExpressionNode indexNode;
if (indexType == PrimitiveType.I32) {
indexNode = CommonNodeFactory.createLiteral(1, PrimitiveType.I32);
} else if (indexType == PrimitiveType.I64) {
indexNode = CommonNodeFactory.createLiteral(1L, PrimitiveType.I64);
} else {
throw new AssertionError(indexType);
}
factory.addIndex(addressOffset, indexNode, indexType);
}
}
}
return factory.currentAddress;
} catch (TypeOverflowException e) {
return Type.handleOverflowExpression(e);
}
}
use of com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException in project graal by oracle.
the class BasicNodeFactory method createPrimitiveArrayLiteral.
@Override
public LLVMExpressionNode createPrimitiveArrayLiteral(Object arrayValues, ArrayType arrayType, GetStackSpaceFactory arrayGetStackSpaceFactory) {
assert arrayType.getNumberOfElements() == Array.getLength(arrayValues);
LLVMExpressionNode arrayGetStackSpace = arrayGetStackSpaceFactory.createGetStackSpace(this, arrayType);
Type elementType = arrayType.getElementType();
try {
long elementSize = getByteSize(elementType);
if (elementSize == 0) {
throw new TypeOverflowException(elementType + " has size of 0!");
}
if (elementType instanceof PrimitiveType) {
PrimitiveType primitiveType = (PrimitiveType) elementType;
if (primitiveType.getPrimitiveKind() == PrimitiveKind.I8 && arrayValues instanceof byte[] && elementSize == 1) {
return LLVMI8ArrayLiteralNodeGen.create((byte[]) arrayValues, arrayGetStackSpace);
}
}
} catch (TypeOverflowException e) {
return Type.handleOverflowExpression(e);
}
throw new AssertionError(elementType);
}
use of com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException 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);
}
use of com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException in project graal by oracle.
the class LLVMBitcodeInstructionVisitor method capsuleAddressByValue.
private LLVMExpressionNode capsuleAddressByValue(LLVMExpressionNode child, Type type, AttributesGroup paramAttr) {
try {
final Type pointee = ((PointerType) type).getPointeeType();
final long size = pointee.getSize(dataLayout);
int alignment = pointee.getAlignment(dataLayout);
for (Attribute attr : paramAttr.getAttributes()) {
if (attr instanceof Attribute.KnownIntegerValueAttribute && ((Attribute.KnownIntegerValueAttribute) attr).getAttr() == Attribute.Kind.ALIGN) {
alignment = ((Attribute.KnownIntegerValueAttribute) attr).getValue();
}
}
return nodeFactory.createVarArgCompoundValue(size, alignment, type, child);
} catch (TypeOverflowException e) {
return Type.handleOverflowExpression(e);
}
}
use of com.oracle.truffle.llvm.runtime.types.Type.TypeOverflowException in project graal by oracle.
the class LLVMForeignCallNode method execute.
@Override
public Object execute(VirtualFrame frame) {
Object result;
LLVMThreadingStack threadingStack = LLVMContext.get(this).getThreadingStack();
LLVMStack stack = getStack.executeWithTarget(threadingStack, Thread.currentThread());
try {
result = doCall(frame, stack);
} catch (ArityException ex) {
throw silenceException(RuntimeException.class, ex);
} catch (TypeOverflowException ex) {
throw silenceException(RuntimeException.class, ex);
}
return prepareValueForEscape.executeWithType(result, returnBaseType);
}
Aggregations