use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class Function method createGetElementPointer.
private void createGetElementPointer(long[] args) {
int i = 0;
boolean isInbounds = args[i++] != 0;
// we do not use this parameter
i++;
int pointer = getIndex(args[i++]);
Type base;
if (scope.isValueForwardRef(pointer)) {
base = types.get(args[i++]);
} else {
base = scope.getValueType(pointer);
}
List<Integer> indices = getIndices(args, i);
Type type = new PointerType(getElementPointerType(base, indices));
emit(GetElementPointerInstruction.fromSymbols(scope.getSymbols(), type, pointer, indices, isInbounds));
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class Module method createFunction.
private void createFunction(long[] args) {
final int recordOffset = useStrTab() ? STRTAB_RECORD_OFFSET : 0;
Type type = types.get(args[FUNCTION_TYPE + recordOffset]);
if (type instanceof PointerType) {
type = ((PointerType) type).getPointeeType();
}
final FunctionType functionType = (FunctionType) type;
final boolean isPrototype = args[FUNCTION_ISPROTOTYPE + recordOffset] != 0;
final Linkage linkage = Linkage.decode(args[FUNCTION_LINKAGE + recordOffset]);
final AttributesCodeEntry paramAttr = paramAttributes.getCodeEntry(args[FUNCTION_PARAMATTR + recordOffset]);
if (isPrototype) {
final FunctionDeclaration function = new FunctionDeclaration(functionType, linkage, paramAttr);
module.addFunctionDeclaration(function);
scope.addSymbol(function, function.getType());
if (useStrTab()) {
readNameFromStrTab(args, function);
}
} else {
final FunctionDefinition function = new FunctionDefinition(functionType, linkage, paramAttr);
module.addFunctionDefinition(function);
scope.addSymbol(function, function.getType());
if (useStrTab()) {
readNameFromStrTab(args, function);
}
functionQueue.addLast(function);
}
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class LLVMParserRuntime method resolveStructor.
private LLVMExpressionNode[] resolveStructor(GlobalValueSymbol globalVar, Comparator<Pair<Integer, ?>> priorityComparator) {
if (!(globalVar.getValue() instanceof ArrayConstant)) {
// array globals of length 0 may be initialized with scalar null
return LLVMExpressionNode.NO_EXPRESSIONS;
}
final Object globalVariableDescriptor = scope.getGlobalVariable(globalVar.getName());
final ArrayConstant arrayConstant = (ArrayConstant) globalVar.getValue();
final int elemCount = arrayConstant.getElementCount();
final StructureType elementType = (StructureType) arrayConstant.getType().getElementType();
final int structSize = getContext().getByteSize(elementType);
final FunctionType functionType = (FunctionType) ((PointerType) elementType.getElementType(1)).getPointeeType();
final int indexedTypeLength = getContext().getByteAlignment(functionType);
final ArrayList<Pair<Integer, LLVMExpressionNode>> structors = new ArrayList<>(elemCount);
for (int i = 0; i < elemCount; i++) {
final LLVMExpressionNode globalVarAddress = nodeFactory.createLiteral(this, globalVariableDescriptor, new PointerType(globalVar.getType()));
final LLVMExpressionNode iNode = nodeFactory.createLiteral(this, i, PrimitiveType.I32);
final LLVMExpressionNode structPointer = nodeFactory.createTypedElementPointer(this, globalVarAddress, iNode, structSize, elementType);
final LLVMExpressionNode loadedStruct = nodeFactory.createLoad(this, elementType, structPointer);
final LLVMExpressionNode oneLiteralNode = nodeFactory.createLiteral(this, 1, PrimitiveType.I32);
final LLVMExpressionNode functionLoadTarget = nodeFactory.createTypedElementPointer(this, loadedStruct, oneLiteralNode, indexedTypeLength, functionType);
final LLVMExpressionNode loadedFunction = nodeFactory.createLoad(this, functionType, functionLoadTarget);
final LLVMExpressionNode[] argNodes = new LLVMExpressionNode[] { nodeFactory.createFrameRead(this, PointerType.VOID, rootFrame.findFrameSlot(LLVMStack.FRAME_ID)) };
final LLVMExpressionNode functionCall = nodeFactory.createFunctionCall(this, loadedFunction, argNodes, functionType, null);
final StructureConstant structorDefinition = (StructureConstant) arrayConstant.getElement(i);
final SymbolImpl prioritySymbol = structorDefinition.getElement(0);
final Integer priority = LLVMSymbolReadResolver.evaluateIntegerConstant(prioritySymbol);
structors.add(new Pair<>(priority != null ? priority : LEAST_CONSTRUCTOR_PRIORITY, functionCall));
}
return structors.stream().sorted(priorityComparator).map(Pair::getSecond).toArray(LLVMExpressionNode[]::new);
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class BasicNodeFactory method createVectorLiteralNode.
@Override
public LLVMExpressionNode createVectorLiteralNode(LLVMParserRuntime runtime, List<LLVMExpressionNode> listValues, Type type) {
LLVMExpressionNode[] vals = listValues.toArray(new LLVMExpressionNode[listValues.size()]);
Type llvmType = ((VectorType) type).getElementType();
if (llvmType instanceof PrimitiveType) {
switch(((PrimitiveType) llvmType).getPrimitiveKind()) {
case I1:
return LLVMVectorI1LiteralNodeGen.create(vals);
case I8:
return LLVMVectorI8LiteralNodeGen.create(vals);
case I16:
return LLVMVectorI16LiteralNodeGen.create(vals);
case I32:
return LLVMVectorI32LiteralNodeGen.create(vals);
case I64:
return LLVMVectorI64LiteralNodeGen.create(vals);
case FLOAT:
return LLVMVectorFloatLiteralNodeGen.create(vals);
case DOUBLE:
return LLVMVectorDoubleLiteralNodeGen.create(vals);
default:
throw new AssertionError();
}
} else if (llvmType instanceof PointerType) {
if (((PointerType) llvmType).getPointeeType() instanceof FunctionType) {
return LLVMVectorFunctionLiteralNodeGen.create(vals);
} else {
return LLVMVectorAddressLiteralNodeGen.create(vals);
}
} else {
throw new AssertionError(llvmType + " not yet supported");
}
}
use of com.oracle.truffle.llvm.runtime.types.PointerType in project sulong by graalvm.
the class BasicNodeFactory method allocateGlobalIntern.
private static Object allocateGlobalIntern(LLVMParserRuntime runtime, final GlobalValueSymbol global, LLVMSourceSymbol sourceSymbol) {
final Type resolvedType = ((PointerType) global.getType()).getPointeeType();
final String name = global.getName();
LLVMContext context = runtime.getContext();
if (global.isExternal()) {
NFIContextExtension nfiContextExtension = context.getContextExtension(NFIContextExtension.class);
return LLVMGlobal.external(context, global, name, resolvedType, LLVMAddress.fromLong(nfiContextExtension.getNativeHandle(context, name)), sourceSymbol);
} else {
return LLVMGlobal.internal(context, global, name, resolvedType, sourceSymbol);
}
}
Aggregations