use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class Function method createAtomicReadModifyWrite.
private void createAtomicReadModifyWrite(long[] args) {
int i = 0;
final int ptr = getIndex(args[i++]);
final Type ptrType;
if (scope.isValueForwardRef(ptr)) {
ptrType = types.get(args[i++]);
} else {
ptrType = scope.getValueType(ptr);
}
final int value = getIndex(args[i++]);
final int opcode = (int) args[i++];
final boolean isVolatile = args[i++] != 0;
final long atomicOrdering = args[i++];
final long synchronizationScope = args[i];
final Type type = ((PointerType) ptrType).getPointeeType();
emit(ReadModifyWriteInstruction.fromSymbols(scope.getSymbols(), type, ptr, value, opcode, isVolatile, atomicOrdering, synchronizationScope));
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class Module method createGlobalVariable.
private void createGlobalVariable(long[] args) {
final int recordOffset = useStrTab() ? STRTAB_RECORD_OFFSET : 0;
final long typeField = args[GLOBALVAR_TYPE + recordOffset];
final long flagField = args[GLOBALVAR_FLAGS + recordOffset];
Type type = types.get(typeField);
if ((flagField & GLOBALVAR_EXPLICICTTYPE_MASK) != 0) {
type = new PointerType(type);
}
final boolean isConstant = (flagField & GLOBALVAR_ISCONSTANT_MASK) != 0;
final int initialiser = (int) args[GLOBALVAR_INTITIALIZER + recordOffset];
final long linkage = args[GLOBALVAR_LINKAGE + recordOffset];
final int align = (int) args[GLOBALVAR_ALIGN + recordOffset];
long visibility = Visibility.DEFAULT.getEncodedValue();
if (GLOBALVAR_VISIBILITY + recordOffset < args.length) {
visibility = args[GLOBALVAR_VISIBILITY + recordOffset];
}
final GlobalValueSymbol global;
if (isConstant) {
global = GlobalConstant.create(type, align, linkage, visibility, scope.getSymbols(), initialiser);
} else {
global = GlobalVariable.create(type, align, linkage, visibility, scope.getSymbols(), initialiser);
}
if (useStrTab()) {
readNameFromStrTab(args, global);
}
module.addGlobalSymbol(global);
scope.addSymbol(global, global.getType());
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class Module method createGlobalAliasNew.
private void createGlobalAliasNew(long[] args) {
final int recordOffset = useStrTab() ? STRTAB_RECORD_OFFSET : 0;
final Type type = new PointerType(types.get(args[GLOBALALIAS_TYPE + recordOffset]));
// idx = 1 is address space information
final int value = (int) args[GLOBALALIAS_NEW_VALUE + recordOffset];
final long linkage = args[GLOBALALIAS_NEW_LINKAGE + recordOffset];
final GlobalAlias global = GlobalAlias.create(type, linkage, Visibility.DEFAULT.ordinal(), scope.getSymbols(), value);
if (useStrTab()) {
readNameFromStrTab(args, global);
}
module.addGlobalSymbol(global);
scope.addSymbol(global, global.getType());
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class BasicNodeFactory method createArrayLiteral.
@Override
public LLVMExpressionNode createArrayLiteral(LLVMParserRuntime runtime, List<LLVMExpressionNode> arrayValues, ArrayType arrayType) {
assert arrayType.getNumberOfElements() == arrayValues.size();
LLVMExpressionNode arrayAlloc = createAlloca(runtime, arrayType);
int nrElements = arrayValues.size();
Type elementType = arrayType.getElementType();
int elementSize = runtime.getContext().getByteSize(elementType);
if (elementSize == 0) {
throw new AssertionError(elementType + " has size of 0!");
}
if (elementType instanceof PrimitiveType) {
switch(((PrimitiveType) elementType).getPrimitiveKind()) {
case I8:
return LLVMI8ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
case I16:
return LLVMI16ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
case I32:
return LLVMI32ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
case I64:
return LLVMI64ArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
case FLOAT:
return LLVMFloatArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
case DOUBLE:
return LLVMDoubleArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
case X86_FP80:
return LLVM80BitFloatArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
default:
throw new AssertionError(elementType);
}
} else if (Type.isFunctionOrFunctionPointer(elementType)) {
return LLVMFunctionArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
} else if (elementType instanceof PointerType) {
return LLVMAddressArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), elementSize, arrayAlloc);
} else if (elementType instanceof ArrayType || elementType instanceof StructureType) {
return LLVMStructArrayLiteralNodeGen.create(arrayValues.toArray(new LLVMExpressionNode[nrElements]), createMemMove(), elementSize, arrayAlloc);
}
throw new AssertionError(elementType);
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class LLVMBitcodeInstructionVisitor method visit.
@Override
public void visit(ExtractValueInstruction extract) {
if (!(extract.getAggregate().getType() instanceof ArrayType || extract.getAggregate().getType() instanceof StructureType || extract.getAggregate().getType() instanceof PointerType)) {
throw new IllegalStateException("\'extractvalue\' can only extract elements of arrays and structs!");
}
final LLVMExpressionNode baseAddress = symbols.resolve(extract.getAggregate());
final Type baseType = extract.getAggregate().getType();
final int targetIndex = extract.getIndex();
final Type resultType = extract.getType();
LLVMExpressionNode targetAddress = baseAddress;
final AggregateType aggregateType = (AggregateType) baseType;
long offset = runtime.getContext().getIndexOffset(targetIndex, aggregateType);
final Type targetType = aggregateType.getElementType(targetIndex);
if (targetType != null && !((targetType instanceof StructureType) && (((StructureType) targetType).isPacked()))) {
offset += runtime.getContext().getBytePadding(offset, targetType);
}
if (offset != 0) {
final LLVMExpressionNode oneLiteralNode = nodeFactory.createLiteral(runtime, 1, PrimitiveType.I32);
targetAddress = nodeFactory.createTypedElementPointer(runtime, targetAddress, oneLiteralNode, offset, extract.getType());
}
final LLVMExpressionNode result = nodeFactory.createExtractValue(runtime, resultType, targetAddress);
createFrameWrite(result, extract);
}
Aggregations