Search in sources :

Example 1 with NullConstant

use of com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant in project sulong by graalvm.

the class ParseUtil method asLong.

public static long asLong(long[] args, int index, Metadata md) {
    final int typeIndex = index << 1;
    if (typeIndex >= args.length) {
        return DEFAULT_NUMBER;
    }
    final Type type = md.getTypeById(args[typeIndex]);
    if (type == MetaType.METADATA || VoidType.INSTANCE.equals(type)) {
        return DEFAULT_NUMBER;
    }
    final int valueIndex = typeIndex + 1;
    final SymbolImpl value = md.getScope().getSymbols().getOrNull((int) args[valueIndex]);
    if (value instanceof IntegerConstant) {
        return ((IntegerConstant) value).getValue();
    } else if (value instanceof BigIntegerConstant) {
        return ((BigIntegerConstant) value).getValue().longValue();
    } else if (value instanceof NullConstant || value instanceof UndefinedConstant) {
        return 0L;
    } else {
        return DEFAULT_NUMBER;
    }
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) Type(com.oracle.truffle.llvm.runtime.types.Type) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) UndefinedConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.UndefinedConstant) BigIntegerConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.integer.BigIntegerConstant) NullConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant) IntegerConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.integer.IntegerConstant) BigIntegerConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.integer.BigIntegerConstant)

Example 2 with NullConstant

use of com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant in project sulong by graalvm.

the class LLVMBitcodeInstructionVisitor method visit.

@Override
public void visit(AllocateInstruction allocate) {
    final Type type = allocate.getPointeeType();
    int alignment;
    if (allocate.getAlign() == 0) {
        alignment = runtime.getContext().getByteAlignment(type);
    } else {
        alignment = 1 << (allocate.getAlign() - 1);
    }
    if (alignment == 0) {
        alignment = LLVMStack.NO_ALIGNMENT_REQUIREMENTS;
    }
    final SymbolImpl count = allocate.getCount();
    final LLVMExpressionNode result;
    if (count instanceof NullConstant) {
        result = nodeFactory.createAlloca(runtime, type, alignment);
    } else if (count instanceof IntegerConstant) {
        long numElements = (int) ((IntegerConstant) count).getValue();
        if (numElements == 1) {
            result = nodeFactory.createAlloca(runtime, type, alignment);
        } else {
            assert numElements == (int) numElements;
            ArrayType arrayType = new ArrayType(type, (int) numElements);
            result = nodeFactory.createAlloca(runtime, arrayType, alignment);
        }
    } else {
        LLVMExpressionNode num = symbols.resolve(count);
        result = nodeFactory.createAllocaArray(runtime, type, num, alignment);
    }
    // we never want to step on allocations, only to actual assignments in the source
    createFrameWrite(result, allocate, null);
}
Also used : ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) LLVMConversionType(com.oracle.truffle.llvm.parser.instructions.LLVMConversionType) PrimitiveType(com.oracle.truffle.llvm.runtime.types.PrimitiveType) StructureType(com.oracle.truffle.llvm.runtime.types.StructureType) ArrayType(com.oracle.truffle.llvm.runtime.types.ArrayType) AggregateType(com.oracle.truffle.llvm.runtime.types.AggregateType) LLVMArithmeticInstructionType(com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType) Type(com.oracle.truffle.llvm.runtime.types.Type) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) FunctionType(com.oracle.truffle.llvm.runtime.types.FunctionType) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) NullConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant) IntegerConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.integer.IntegerConstant)

Example 3 with NullConstant

use of com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant in project sulong by graalvm.

the class ParseUtil method isInteger.

public static boolean isInteger(long[] args, int index, Metadata md) {
    final int typeIndex = index << 1;
    final Type type = md.getTypeById(args[typeIndex]);
    if (type == MetaType.METADATA || VoidType.INSTANCE.equals(type)) {
        return false;
    }
    final int valueIndex = typeIndex + 1;
    final SymbolImpl value = md.getScope().getSymbols().getOrNull((int) args[valueIndex]);
    return value instanceof IntegerConstant || value instanceof BigIntegerConstant || value instanceof NullConstant || value instanceof UndefinedConstant;
}
Also used : SymbolImpl(com.oracle.truffle.llvm.parser.model.SymbolImpl) Type(com.oracle.truffle.llvm.runtime.types.Type) VoidType(com.oracle.truffle.llvm.runtime.types.VoidType) MetaType(com.oracle.truffle.llvm.runtime.types.MetaType) UndefinedConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.UndefinedConstant) BigIntegerConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.integer.BigIntegerConstant) NullConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant) IntegerConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.integer.IntegerConstant) BigIntegerConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.integer.BigIntegerConstant)

Example 4 with NullConstant

use of com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant in project sulong by graalvm.

the class LLVMRuntimeDebugInformation method handleDebugIntrinsic.

LLVMExpressionNode handleDebugIntrinsic(SymbolImpl value, SourceVariable variable, MDExpression expression, long index, boolean isDeclaration) {
    if (!isEnabled || variable.hasStaticAllocation()) {
        return null;
    }
    LLVMExpressionNode valueRead = null;
    if (isDeclaration) {
        if (value instanceof UndefinedConstant) {
            if (variable.hasValue()) {
                // know this from the presence of the value
                return null;
            }
            valueRead = symbols.resolve(new NullConstant(MetaType.DEBUG));
        } else if (value instanceof NullConstant) {
            valueRead = symbols.resolve(new NullConstant(MetaType.DEBUG));
        } else if (value instanceof GlobalValueSymbol || value.getType() instanceof PointerType) {
            valueRead = symbols.resolve(value);
        }
    } else {
        valueRead = symbols.resolve(value);
        if (index != 0) {
            // this is unsupported, it doesn't appear in LLVM 3.8+
            return null;
        }
    }
    if (valueRead == null) {
        return null;
    }
    int partIndex = -1;
    int[] clearParts = null;
    if (ValueFragment.describesFragment(expression)) {
        final ValueFragment fragment = ValueFragment.parse(expression);
        final List<ValueFragment> siblings = variable.getFragments();
        final List<Integer> clearSiblings = new ArrayList<>(siblings.size());
        partIndex = ValueFragment.getPartIndex(fragment, siblings, clearSiblings);
        if (clearSiblings.isEmpty()) {
            // this will be the case most of the time
            clearParts = CLEAR_NONE;
        } else {
            clearParts = clearSiblings.stream().mapToInt(Integer::intValue).toArray();
        }
    }
    if (partIndex < 0 && variable.hasFragments()) {
        partIndex = variable.getFragmentIndex(0, (int) variable.getSymbol().getType().getSize());
        if (partIndex < 0) {
            throw new IllegalStateException("Cannot find index of value fragment!");
        }
        clearParts = new int[variable.getFragments().size() - 1];
        for (int i = 0; i < partIndex; i++) {
            clearParts[i] = i;
        }
        for (int i = partIndex; i < clearParts.length; i++) {
            clearParts[i] = i + 1;
        }
    }
    final boolean mustDereference = isDeclaration || mustDereferenceValue(expression, variable.getSourceType(), value);
    final FrameSlot targetSlot = frame.findOrAddFrameSlot(variable.getSymbol(), MetaType.DEBUG, FrameSlotKind.Object);
    final LLVMExpressionNode containerRead = factory.createFrameRead(runtime, MetaType.DEBUG, targetSlot);
    return factory.createDebugWrite(mustDereference, valueRead, targetSlot, containerRead, partIndex, clearParts);
}
Also used : UndefinedConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.UndefinedConstant) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) ArrayList(java.util.ArrayList) NullConstant(com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant) PointerType(com.oracle.truffle.llvm.runtime.types.PointerType) GlobalValueSymbol(com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol) LLVMExpressionNode(com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode) ValueFragment(com.oracle.truffle.llvm.parser.metadata.debuginfo.ValueFragment)

Aggregations

NullConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.NullConstant)4 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)3 UndefinedConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.UndefinedConstant)3 IntegerConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.integer.IntegerConstant)3 Type (com.oracle.truffle.llvm.runtime.types.Type)3 BigIntegerConstant (com.oracle.truffle.llvm.parser.model.symbols.constants.integer.BigIntegerConstant)2 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)2 MetaType (com.oracle.truffle.llvm.runtime.types.MetaType)2 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)2 VoidType (com.oracle.truffle.llvm.runtime.types.VoidType)2 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)1 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)1 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)1 ValueFragment (com.oracle.truffle.llvm.parser.metadata.debuginfo.ValueFragment)1 GlobalValueSymbol (com.oracle.truffle.llvm.parser.model.symbols.globals.GlobalValueSymbol)1 AggregateType (com.oracle.truffle.llvm.runtime.types.AggregateType)1 ArrayType (com.oracle.truffle.llvm.runtime.types.ArrayType)1 FunctionType (com.oracle.truffle.llvm.runtime.types.FunctionType)1 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)1 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)1