Search in sources :

Example 11 with Type

use of org.robovm.compiler.llvm.Type in project robovm by robovm.

the class BroMethodCompiler method getLoType.

protected static String getLoType(final Type type, String base, int index, Map<String, String> structs) {
    if (type instanceof StructureType) {
        StringBuilder sb = new StringBuilder();
        StructureType st = (StructureType) type;
        sb.append("{");
        String name = String.format("%s_%04d", base, index);
        for (int i = 0; i < st.getTypeCount(); i++) {
            Type t = st.getTypeAt(i);
            if (i == 0 && t instanceof StructureType) {
                if (((StructureType) t).getTypeCount() == 0) {
                    // Skip empty structs as first member
                    continue;
                }
            }
            // Only support arrays embedded in structs
            StringBuilder dims = new StringBuilder();
            while (t instanceof ArrayType) {
                ArrayType at = (ArrayType) t;
                dims.append('[').append(at.getSize()).append(']');
                t = ((ArrayType) t).getElementType();
            }
            sb.append(getLoType(t, name, i, structs)).append(" m" + i).append(dims).append(";");
        }
        sb.append("}");
        structs.put(name, sb.toString());
        return "struct " + name;
    } else {
        return getHiType(type);
    }
}
Also used : ArrayType(org.robovm.compiler.llvm.ArrayType) RefType(soot.RefType) IntegerType(org.robovm.compiler.llvm.IntegerType) StructureType(org.robovm.compiler.llvm.StructureType) ArrayType(org.robovm.compiler.llvm.ArrayType) PointerType(org.robovm.compiler.llvm.PointerType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) LongType(soot.LongType) Type(org.robovm.compiler.llvm.Type) AggregateType(org.robovm.compiler.llvm.AggregateType) PrimitiveType(org.robovm.compiler.llvm.PrimitiveType) PrimType(soot.PrimType) VoidType(soot.VoidType) FunctionType(org.robovm.compiler.llvm.FunctionType) StructureType(org.robovm.compiler.llvm.StructureType) Ptrtoint(org.robovm.compiler.llvm.Ptrtoint)

Example 12 with Type

use of org.robovm.compiler.llvm.Type in project robovm by robovm.

the class Functions method call.

public static Value call(Function currentFunction, Value fn, Value... args) {
    Variable result = null;
    Type returnType = ((FunctionType) fn.getType()).getReturnType();
    if (returnType != VOID) {
        result = currentFunction.newVariable(returnType);
    }
    currentFunction.add(new Call(result, fn, args));
    return result == null ? null : result.ref();
}
Also used : TailCall(org.robovm.compiler.llvm.TailCall) Call(org.robovm.compiler.llvm.Call) PointerType(org.robovm.compiler.llvm.PointerType) Type(org.robovm.compiler.llvm.Type) FunctionType(org.robovm.compiler.llvm.FunctionType) Variable(org.robovm.compiler.llvm.Variable) FunctionType(org.robovm.compiler.llvm.FunctionType)

Example 13 with Type

use of org.robovm.compiler.llvm.Type in project robovm by robovm.

the class Functions method tailcall.

public static Value tailcall(Function currentFunction, Value fn, Value... args) {
    Variable result = null;
    Type returnType = ((FunctionType) fn.getType()).getReturnType();
    if (returnType != VOID) {
        result = currentFunction.newVariable(returnType);
    }
    currentFunction.add(new TailCall(result, fn, args));
    return result == null ? null : result.ref();
}
Also used : PointerType(org.robovm.compiler.llvm.PointerType) Type(org.robovm.compiler.llvm.Type) FunctionType(org.robovm.compiler.llvm.FunctionType) Variable(org.robovm.compiler.llvm.Variable) TailCall(org.robovm.compiler.llvm.TailCall) FunctionType(org.robovm.compiler.llvm.FunctionType)

Example 14 with Type

use of org.robovm.compiler.llvm.Type in project robovm by robovm.

the class BroMethodCompiler method mergeStructMemberTypes.

static Type mergeStructMemberTypes(DataLayout dataLayout, Type t1, Type t2) {
    int align1 = dataLayout.getAlignment(t1);
    int align2 = dataLayout.getAlignment(t2);
    int size1 = dataLayout.getStoreSize(t1);
    int size2 = dataLayout.getStoreSize(t2);
    Type result = align1 < align2 ? t2 : t1;
    int size = align1 < align2 ? size2 : size1;
    int pad = Math.max(size1, size2) - size;
    if (pad > 0) {
        return new StructureType(result, new ArrayType(pad, I8));
    } else {
        return result;
    }
}
Also used : ArrayType(org.robovm.compiler.llvm.ArrayType) RefType(soot.RefType) IntegerType(org.robovm.compiler.llvm.IntegerType) StructureType(org.robovm.compiler.llvm.StructureType) ArrayType(org.robovm.compiler.llvm.ArrayType) PointerType(org.robovm.compiler.llvm.PointerType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) LongType(soot.LongType) Type(org.robovm.compiler.llvm.Type) AggregateType(org.robovm.compiler.llvm.AggregateType) PrimitiveType(org.robovm.compiler.llvm.PrimitiveType) PrimType(soot.PrimType) VoidType(soot.VoidType) FunctionType(org.robovm.compiler.llvm.FunctionType) StructureType(org.robovm.compiler.llvm.StructureType) Ptrtoint(org.robovm.compiler.llvm.Ptrtoint)

Example 15 with Type

use of org.robovm.compiler.llvm.Type in project robovm by robovm.

the class BroMethodCompiler method getStructMemberType.

public Type getStructMemberType(SootMethod method) {
    String methodType = hasStructMemberAnnotation(method) ? "@StructMember" : "@GlobalValue";
    SootMethod getter = method.getParameterCount() == 0 ? method : null;
    SootMethod setter = getter == null ? method : null;
    soot.Type type = getter != null ? getter.getReturnType() : setter.getParameterType(0);
    Type memberType = null;
    if (getter != null && hasPointerAnnotation(getter) || setter != null && hasPointerAnnotation(setter, 0)) {
        memberType = I8_PTR;
    } else if (getter != null && hasMachineSizedFloatAnnotation(getter) || setter != null && hasMachineSizedFloatAnnotation(setter, 0)) {
        memberType = config.getArch().is32Bit() ? FLOAT : DOUBLE;
    } else if (getter != null && (hasMachineSizedSIntAnnotation(getter) || hasMachineSizedUIntAnnotation(getter)) || setter != null && (hasMachineSizedSIntAnnotation(setter, 0) || hasMachineSizedUIntAnnotation(setter, 0))) {
        memberType = config.getArch().is32Bit() ? I32 : I64;
    } else if (type instanceof PrimType) {
        memberType = getType(type);
    } else if (getter != null && hasArrayAnnotation(getter) || setter != null && hasArrayAnnotation(setter, 0)) {
        int[] dimensions = getter != null ? getArrayDimensions(getter) : getArrayDimensions(setter, 0);
        if (dimensions == null || dimensions.length == 0) {
            throw new IllegalArgumentException("No dimensions specified for @Array annotation on " + methodType + " " + (getter != null ? "getter" : "setter") + " " + method);
        }
        if (type instanceof soot.ArrayType && ((soot.ArrayType) type).numDimensions != dimensions.length) {
            throw new IllegalArgumentException("Mismatch in number of dimennsions for @Array annotation " + "and type on " + methodType + " " + (getter != null ? "getter" : "setter") + " " + method);
        }
        Type baseType = null;
        if (type instanceof soot.ArrayType) {
            soot.ArrayType arrayType = (soot.ArrayType) type;
            if (isStruct(arrayType.baseType)) {
                // ByVal is implied for arrays of structs
                try {
                    baseType = getStructType(arrayType.baseType);
                } catch (StackOverflowError e) {
                    throw new IllegalArgumentException("Struct type " + type + " refers to itself");
                }
            } else {
                baseType = getType(arrayType.baseType);
            }
        } else if (isStruct(type)) {
            // ByVal is implied
            try {
                baseType = getStructType(type);
            } catch (StackOverflowError e) {
                throw new IllegalArgumentException("Struct type " + type + " refers to itself");
            }
        } else if (type instanceof RefType) {
            MarshalerMethod marshalerMethod = config.getMarshalerLookup().findMarshalerMethod(getter != null ? new MarshalSite(getter) : new MarshalSite(setter, 0));
            baseType = getType(((ArrayMarshalerMethod) marshalerMethod).getBaseType());
        }
        if (baseType == null) {
            throw new IllegalArgumentException("Arrays of " + type + " is not supported");
        }
        long total = dimensions[0];
        for (int i = 1; i < dimensions.length; i++) {
            total *= dimensions[i];
        }
        memberType = new ArrayType(total, baseType);
    } else if (isStruct(type)) {
        boolean byVal = getter != null ? isPassByValue(getter) : isPassByValue(setter, 0);
        if (!byVal) {
            // NOTE: We use i8* instead of <StructType>* to support pointers to recursive structs
            memberType = I8_PTR;
        } else {
            try {
                memberType = getStructType(type);
            } catch (StackOverflowError e) {
                throw new IllegalArgumentException("Struct type " + type + " refers to itself");
            }
        }
    } else if (isNativeObject(type)) {
        memberType = I8_PTR;
    } else {
        MarshalerMethod marshalerMethod = config.getMarshalerLookup().findMarshalerMethod(getter != null ? new MarshalSite(getter) : new MarshalSite(setter, 0));
        if (marshalerMethod instanceof ValueMarshalerMethod) {
            memberType = ((ValueMarshalerMethod) marshalerMethod).getNativeType(config.getArch());
        } else {
            memberType = I8_PTR;
        }
    }
    return memberType;
}
Also used : MarshalSite(org.robovm.compiler.MarshalerLookup.MarshalSite) ValueMarshalerMethod(org.robovm.compiler.MarshalerLookup.ValueMarshalerMethod) Ptrtoint(org.robovm.compiler.llvm.Ptrtoint) ArrayType(org.robovm.compiler.llvm.ArrayType) RefType(soot.RefType) RefType(soot.RefType) IntegerType(org.robovm.compiler.llvm.IntegerType) StructureType(org.robovm.compiler.llvm.StructureType) ArrayType(org.robovm.compiler.llvm.ArrayType) PointerType(org.robovm.compiler.llvm.PointerType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) LongType(soot.LongType) Type(org.robovm.compiler.llvm.Type) AggregateType(org.robovm.compiler.llvm.AggregateType) PrimitiveType(org.robovm.compiler.llvm.PrimitiveType) PrimType(soot.PrimType) VoidType(soot.VoidType) FunctionType(org.robovm.compiler.llvm.FunctionType) SootMethod(soot.SootMethod) PrimType(soot.PrimType) MarshalerMethod(org.robovm.compiler.MarshalerLookup.MarshalerMethod) ValueMarshalerMethod(org.robovm.compiler.MarshalerLookup.ValueMarshalerMethod) ArrayMarshalerMethod(org.robovm.compiler.MarshalerLookup.ArrayMarshalerMethod) ArrayMarshalerMethod(org.robovm.compiler.MarshalerLookup.ArrayMarshalerMethod)

Aggregations

Type (org.robovm.compiler.llvm.Type)25 PointerType (org.robovm.compiler.llvm.PointerType)23 FunctionType (org.robovm.compiler.llvm.FunctionType)21 StructureType (org.robovm.compiler.llvm.StructureType)15 PrimType (soot.PrimType)15 IntegerType (org.robovm.compiler.llvm.IntegerType)14 LongType (soot.LongType)13 VoidType (soot.VoidType)13 ArrayList (java.util.ArrayList)12 Variable (org.robovm.compiler.llvm.Variable)11 DoubleType (soot.DoubleType)11 FloatType (soot.FloatType)11 ArrayType (org.robovm.compiler.llvm.ArrayType)10 CharType (soot.CharType)10 RefLikeType (soot.RefLikeType)10 AggregateType (org.robovm.compiler.llvm.AggregateType)8 PrimitiveType (org.robovm.compiler.llvm.PrimitiveType)8 RefType (soot.RefType)8 Value (org.robovm.compiler.llvm.Value)7 FunctionRef (org.robovm.compiler.llvm.FunctionRef)6