Search in sources :

Example 21 with Type

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

the class StructMemberMethodCompiler method structMember.

private Function structMember(ModuleBuilder moduleBuilder, SootMethod method) {
    Function function = createMethodFunction(method);
    moduleBuilder.addFunction(function);
    // Get the value of the handle field in the Struct base class and cast it to a <structType>*
    Variable handleI64 = function.newVariable(I64);
    function.add(new Load(handleI64, getFieldPtr(function, function.getParameterRef(1), offsetof(new StructureType(DATA_OBJECT, new StructureType(I64)), 1, 0), I64)));
    Variable handlePtr = function.newVariable(new PointerType(structType));
    function.add(new Inttoptr(handlePtr, handleI64.ref(), handlePtr.getType()));
    // Add 1 since the first type in structType is the superclass type or {}.      
    int offset = getStructMemberOffset(method) + 1;
    Type memberType = getStructMemberType(method);
    Variable memberPtr = function.newVariable(new PointerType(memberType));
    if (memberType != structType.getTypeAt(offset)) {
        // Several @StructMembers of different types have this offset (union)
        Variable tmp = function.newVariable(new PointerType(structType.getTypeAt(offset)));
        function.add(new Getelementptr(tmp, handlePtr.ref(), 0, offset));
        function.add(new Bitcast(memberPtr, tmp.ref(), memberPtr.getType()));
    } else {
        function.add(new Getelementptr(memberPtr, handlePtr.ref(), 0, offset));
    }
    VariableRef env = function.getParameterRef(0);
    if (method.getParameterCount() == 0) {
        // Getter
        Value result = loadValueForGetter(method, function, memberType, memberPtr.ref(), function.getParameterRef(0), true, MarshalerFlags.CALL_TYPE_STRUCT_MEMBER);
        function.add(new Ret(result));
    } else {
        // Setter
        // 'env' is parameter 0, 'this' is at 1, the value we're interested in is at index 2
        Value value = function.getParameterRef(2);
        storeValueForSetter(method, function, memberType, memberPtr.ref(), env, value, MarshalerFlags.CALL_TYPE_STRUCT_MEMBER);
        if (method.getReturnType().equals(VoidType.v())) {
            function.add(new Ret());
        } else {
            function.add(new Ret(function.getParameterRef(1)));
        }
    }
    return function;
}
Also used : Ret(org.robovm.compiler.llvm.Ret) Load(org.robovm.compiler.llvm.Load) VariableRef(org.robovm.compiler.llvm.VariableRef) Variable(org.robovm.compiler.llvm.Variable) Inttoptr(org.robovm.compiler.llvm.Inttoptr) PointerType(org.robovm.compiler.llvm.PointerType) Getelementptr(org.robovm.compiler.llvm.Getelementptr) Function(org.robovm.compiler.llvm.Function) StructureType(org.robovm.compiler.llvm.StructureType) PointerType(org.robovm.compiler.llvm.PointerType) Type(org.robovm.compiler.llvm.Type) VoidType(soot.VoidType) Bitcast(org.robovm.compiler.llvm.Bitcast) StructureType(org.robovm.compiler.llvm.StructureType) Value(org.robovm.compiler.llvm.Value)

Example 22 with Type

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

the class Types method getFunctionType.

private static FunctionType getFunctionType(String methodDesc, boolean ztatic, boolean nativ) {
    List<Type> paramTypes = new ArrayList<Type>();
    paramTypes.add(ENV_PTR);
    if (!ztatic) {
        paramTypes.add(OBJECT_PTR);
    } else if (nativ) {
        paramTypes.add(OBJECT_PTR);
    }
    CharBuffer buffer = CharBuffer.wrap(methodDesc);
    // Skip initial (
    buffer.get();
    while (buffer.get(buffer.position()) != ')') {
        paramTypes.add(getType(buffer));
    }
    // Skip ending )
    buffer.get();
    Type returnType = getType(buffer);
    return new FunctionType(returnType, paramTypes.toArray(new Type[paramTypes.size()]));
}
Also used : PointerType(org.robovm.compiler.llvm.PointerType) RefType(soot.RefType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) ShortType(soot.ShortType) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType) CharType(soot.CharType) LongType(soot.LongType) IntegerType(org.robovm.compiler.llvm.IntegerType) BooleanType(soot.BooleanType) OpaqueType(org.robovm.compiler.llvm.OpaqueType) StructureType(org.robovm.compiler.llvm.StructureType) RefLikeType(soot.RefLikeType) ByteType(soot.ByteType) Type(org.robovm.compiler.llvm.Type) BottomType(soot.jimple.toolkits.typing.fast.BottomType) AggregateType(org.robovm.compiler.llvm.AggregateType) PrimType(soot.PrimType) VoidType(soot.VoidType) FunctionType(org.robovm.compiler.llvm.FunctionType) FunctionType(org.robovm.compiler.llvm.FunctionType) ArrayList(java.util.ArrayList) CharBuffer(java.nio.CharBuffer)

Example 23 with Type

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

the class Types method getFunctionType.

@SuppressWarnings("unchecked")
public static FunctionType getFunctionType(SootMethodRef methodRef) {
    Type returnType = getType(methodRef.returnType());
    Type[] paramTypes = new Type[(methodRef.isStatic() ? 1 : 2) + methodRef.parameterTypes().size()];
    int i = 0;
    paramTypes[i++] = ENV_PTR;
    if (!methodRef.isStatic()) {
        paramTypes[i++] = OBJECT_PTR;
    }
    for (soot.Type t : (List<soot.Type>) methodRef.parameterTypes()) {
        paramTypes[i++] = getType(t);
    }
    return new FunctionType(returnType, paramTypes);
}
Also used : PointerType(org.robovm.compiler.llvm.PointerType) RefType(soot.RefType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) ShortType(soot.ShortType) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType) CharType(soot.CharType) LongType(soot.LongType) IntegerType(org.robovm.compiler.llvm.IntegerType) BooleanType(soot.BooleanType) OpaqueType(org.robovm.compiler.llvm.OpaqueType) StructureType(org.robovm.compiler.llvm.StructureType) RefLikeType(soot.RefLikeType) ByteType(soot.ByteType) Type(org.robovm.compiler.llvm.Type) BottomType(soot.jimple.toolkits.typing.fast.BottomType) AggregateType(org.robovm.compiler.llvm.AggregateType) PrimType(soot.PrimType) VoidType(soot.VoidType) FunctionType(org.robovm.compiler.llvm.FunctionType) FunctionType(org.robovm.compiler.llvm.FunctionType) ArrayList(java.util.ArrayList) List(java.util.List) ConstantPtrtoint(org.robovm.compiler.llvm.ConstantPtrtoint)

Example 24 with Type

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

the class Types method getInstanceType0.

private static PackedStructureType getInstanceType0(OS os, Arch arch, SootClass clazz, int subClassAlignment, int[] superSize) {
    List<Type> types = new ArrayList<Type>();
    List<SootField> fields = getInstanceFields(os, arch, clazz);
    int superAlignment = 1;
    if (!fields.isEmpty()) {
        // Pad the super type so that the first field is aligned properly
        SootField field = fields.get(0);
        superAlignment = getFieldAlignment(os, arch, field);
    }
    if (clazz.hasSuperclass()) {
        types.add(getInstanceType0(os, arch, clazz.getSuperclass(), superAlignment, superSize));
    }
    int offset = superSize[0];
    for (SootField field : fields) {
        int falign = getFieldAlignment(os, arch, field);
        int padding = (offset & (falign - 1)) != 0 ? (falign - (offset & (falign - 1))) : 0;
        types.add(padType(getType(field.getType()), padding));
        offset += padding + getFieldSize(arch, field);
    }
    int padding = (offset & (subClassAlignment - 1)) != 0 ? (subClassAlignment - (offset & (subClassAlignment - 1))) : 0;
    for (int i = 0; i < padding; i++) {
        types.add(I8);
        offset++;
    }
    superSize[0] = offset;
    return new PackedStructureType(types.toArray(new Type[types.size()]));
}
Also used : PointerType(org.robovm.compiler.llvm.PointerType) RefType(soot.RefType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) ShortType(soot.ShortType) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType) CharType(soot.CharType) LongType(soot.LongType) IntegerType(org.robovm.compiler.llvm.IntegerType) BooleanType(soot.BooleanType) OpaqueType(org.robovm.compiler.llvm.OpaqueType) StructureType(org.robovm.compiler.llvm.StructureType) RefLikeType(soot.RefLikeType) ByteType(soot.ByteType) Type(org.robovm.compiler.llvm.Type) BottomType(soot.jimple.toolkits.typing.fast.BottomType) AggregateType(org.robovm.compiler.llvm.AggregateType) PrimType(soot.PrimType) VoidType(soot.VoidType) FunctionType(org.robovm.compiler.llvm.FunctionType) ArrayList(java.util.ArrayList) SootField(soot.SootField) ConstantPtrtoint(org.robovm.compiler.llvm.ConstantPtrtoint) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType)

Example 25 with Type

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

the class Types method getClassType.

public static StructureType getClassType(OS os, Arch arch, SootClass clazz) {
    List<Type> types = new ArrayList<Type>();
    int offset = 0;
    for (SootField field : getClassFields(os, arch, clazz)) {
        int falign = getFieldAlignment(os, arch, field);
        int padding = (offset & (falign - 1)) != 0 ? (falign - (offset & (falign - 1))) : 0;
        types.add(padType(getType(field.getType()), padding));
        offset += padding + getFieldSize(arch, field);
    }
    return new StructureType(CLASS, new StructureType(types.toArray(new Type[types.size()])));
}
Also used : PointerType(org.robovm.compiler.llvm.PointerType) RefType(soot.RefType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) ShortType(soot.ShortType) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType) CharType(soot.CharType) LongType(soot.LongType) IntegerType(org.robovm.compiler.llvm.IntegerType) BooleanType(soot.BooleanType) OpaqueType(org.robovm.compiler.llvm.OpaqueType) StructureType(org.robovm.compiler.llvm.StructureType) RefLikeType(soot.RefLikeType) ByteType(soot.ByteType) Type(org.robovm.compiler.llvm.Type) BottomType(soot.jimple.toolkits.typing.fast.BottomType) AggregateType(org.robovm.compiler.llvm.AggregateType) PrimType(soot.PrimType) VoidType(soot.VoidType) FunctionType(org.robovm.compiler.llvm.FunctionType) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType) StructureType(org.robovm.compiler.llvm.StructureType) ArrayList(java.util.ArrayList) SootField(soot.SootField) ConstantPtrtoint(org.robovm.compiler.llvm.ConstantPtrtoint)

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