Search in sources :

Example 6 with Load

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

the class ClassCompiler method createFieldGetter.

static Function createFieldGetter(Function fn, SootField field, List<SootField> classFields, StructureType classType, List<SootField> instanceFields, StructureType instanceType) {
    Value fieldPtr = null;
    if (field.isStatic()) {
        fieldPtr = getClassFieldPtr(fn, field, classFields, classType);
    } else {
        fieldPtr = getInstanceFieldPtr(fn, fn.getParameterRef(1), field, instanceFields, instanceType);
    }
    Variable result = fn.newVariable(getType(field.getType()));
    if (Modifier.isVolatile(field.getModifiers())) {
        fn.add(new Fence(Ordering.seq_cst));
        if (LongType.v().equals(field.getType())) {
            fn.add(new Load(result, fieldPtr, false, Ordering.unordered, 8));
        } else {
            fn.add(new Load(result, fieldPtr));
        }
    } else {
        fn.add(new Load(result, fieldPtr));
    }
    fn.add(new Ret(new VariableRef(result)));
    return fn;
}
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) Value(org.robovm.compiler.llvm.Value) Fence(org.robovm.compiler.llvm.Fence)

Example 7 with Load

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

the class BroMethodCompiler method marshalObjectToNative.

protected Value marshalObjectToNative(Function fn, MarshalerMethod marshalerMethod, MarshaledArg marshaledArg, Type nativeType, Value env, Value object, long flags) {
    Invokestatic invokestatic = marshalerMethod.getInvokeStatic(sootMethod.getDeclaringClass());
    trampolines.add(invokestatic);
    Value handle = call(fn, invokestatic.getFunctionRef(), env, object, new IntegerConstant(flags));
    Variable nativeValue = fn.newVariable(nativeType);
    if (nativeType instanceof StructureType || nativeType instanceof ArrayType) {
        Variable tmp = fn.newVariable(new PointerType(nativeType));
        fn.add(new Inttoptr(tmp, handle, tmp.getType()));
        fn.add(new Load(nativeValue, tmp.ref()));
    } else {
        fn.add(new Inttoptr(nativeValue, handle, nativeType));
    }
    if (marshaledArg != null) {
        marshaledArg.handle = handle;
        marshaledArg.object = object;
    }
    return nativeValue.ref();
}
Also used : ArrayType(org.robovm.compiler.llvm.ArrayType) Invokestatic(org.robovm.compiler.trampoline.Invokestatic) Load(org.robovm.compiler.llvm.Load) Variable(org.robovm.compiler.llvm.Variable) StructureType(org.robovm.compiler.llvm.StructureType) Value(org.robovm.compiler.llvm.Value) Inttoptr(org.robovm.compiler.llvm.Inttoptr) PointerType(org.robovm.compiler.llvm.PointerType) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant)

Example 8 with Load

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

the class ClassCompiler method createLookupFunction.

private void createLookupFunction(SootMethod m) {
    Function function = FunctionBuilder.lookup(m, true);
    mb.addFunction(function);
    Variable reserved0 = function.newVariable(I8_PTR_PTR);
    function.add(new Getelementptr(reserved0, function.getParameterRef(0), 0, 4));
    Variable reserved1 = function.newVariable(I8_PTR_PTR);
    function.add(new Getelementptr(reserved1, function.getParameterRef(0), 0, 5));
    function.add(new Store(getString(m.getName()), reserved0.ref()));
    function.add(new Store(getString(getDescriptor(m)), reserved1.ref()));
    if (!sootClass.isInterface()) {
        int vtableIndex = 0;
        try {
            VTable vtable = config.getVTableCache().get(sootClass);
            vtableIndex = vtable.getEntry(m).getIndex();
        } catch (IllegalArgumentException e) {
        // VTable throws this if any of the superclasses of the class is actually an interface.
        // Shouldn't happen frequently but the DRLVM test suite has some tests for this.
        // Use 0 as vtableIndex since this lookup function will never be called anyway.
        }
        Value classPtr = call(function, OBJECT_CLASS, function.getParameterRef(1));
        Value vtablePtr = call(function, CLASS_VITABLE, classPtr);
        Variable funcPtrPtr = function.newVariable(I8_PTR_PTR);
        function.add(new Getelementptr(funcPtrPtr, vtablePtr, 0, 1, vtableIndex));
        Variable funcPtr = function.newVariable(I8_PTR);
        function.add(new Load(funcPtr, funcPtrPtr.ref()));
        Variable f = function.newVariable(function.getType());
        function.add(new Bitcast(f, funcPtr.ref(), f.getType()));
        Value result = tailcall(function, f.ref(), function.getParameterRefs());
        function.add(new Ret(result));
    } else {
        ITable itable = config.getITableCache().get(sootClass);
        ITable.Entry entry = itable.getEntry(m);
        List<Value> args = new ArrayList<Value>();
        args.add(function.getParameterRef(0));
        args.add(getInfoStruct(function, sootClass));
        args.add(function.getParameterRef(1));
        args.add(new IntegerConstant(entry.getIndex()));
        Value fptr = call(function, BC_LOOKUP_INTERFACE_METHOD_IMPL, args);
        Variable f = function.newVariable(function.getType());
        function.add(new Bitcast(f, fptr, f.getType()));
        Value result = tailcall(function, f.ref(), function.getParameterRefs());
        function.add(new Ret(result));
    }
}
Also used : Ret(org.robovm.compiler.llvm.Ret) Load(org.robovm.compiler.llvm.Load) Variable(org.robovm.compiler.llvm.Variable) ArrayList(java.util.ArrayList) Store(org.robovm.compiler.llvm.Store) Getelementptr(org.robovm.compiler.llvm.Getelementptr) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant) Function(org.robovm.compiler.llvm.Function) Bitcast(org.robovm.compiler.llvm.Bitcast) ConstantBitcast(org.robovm.compiler.llvm.ConstantBitcast) Value(org.robovm.compiler.llvm.Value)

Example 9 with Load

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

the class GlobalValueMethodCompiler method doCompile.

protected Function doCompile(ModuleBuilder moduleBuilder, SootMethod method) {
    AnnotationTag globalValueAnnotation = getAnnotation(method, GLOBAL_VALUE);
    validateGlobalValueMethod(method, globalValueAnnotation);
    boolean optional = readBooleanElem(globalValueAnnotation, "optional", false);
    boolean dereference = readBooleanElem(globalValueAnnotation, "dereference", true);
    Function fn = createMethodFunction(method);
    moduleBuilder.addFunction(fn);
    Type valueType = getStructMemberType(method);
    // Load the address of the resolved @GlobalValue method
    Variable valuePtr = fn.newVariable(new PointerType(valueType));
    Global valuePtrPtr = new Global(Symbols.globalValuePtrSymbol(method), _private, new NullConstant(I8_PTR));
    moduleBuilder.addGlobal(valuePtrPtr);
    fn.add(new Load(valuePtr, new ConstantBitcast(valuePtrPtr.ref(), new PointerType(valuePtr.getType()))));
    Label nullLabel = new Label();
    Label notNullLabel = new Label();
    Variable nullCheck = fn.newVariable(I1);
    fn.add(new Icmp(nullCheck, Condition.eq, valuePtr.ref(), new NullConstant(valuePtr.getType())));
    fn.add(new Br(nullCheck.ref(), fn.newBasicBlockRef(nullLabel), fn.newBasicBlockRef(notNullLabel)));
    fn.newBasicBlock(nullLabel);
    VariableRef env = fn.getParameterRef(0);
    call(fn, BC_THROW_UNSATISIFED_LINK_ERROR, env, moduleBuilder.getString(String.format((optional ? "Optional " : "") + "@GlobalValue method %s.%s%s not bound", className, method.getName(), getDescriptor(method))));
    fn.add(new Unreachable());
    fn.newBasicBlock(notNullLabel);
    if (method.getParameterCount() == 0) {
        // Getter
        Value result = loadValueForGetter(method, fn, valueType, valuePtr.ref(), env, dereference, MarshalerFlags.CALL_TYPE_GLOBAL_VALUE);
        fn.add(new Ret(result));
    } else {
        // Setter
        // 'env' is parameter 0, the value we're interested in is at index 1
        Value value = fn.getParameterRef(1);
        storeValueForSetter(method, fn, valueType, valuePtr.ref(), env, value, MarshalerFlags.CALL_TYPE_GLOBAL_VALUE);
        fn.add(new Ret());
    }
    return fn;
}
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) ConstantBitcast(org.robovm.compiler.llvm.ConstantBitcast) Label(org.robovm.compiler.llvm.Label) NullConstant(org.robovm.compiler.llvm.NullConstant) PointerType(org.robovm.compiler.llvm.PointerType) Global(org.robovm.compiler.llvm.Global) Br(org.robovm.compiler.llvm.Br) AnnotationTag(soot.tagkit.AnnotationTag) Function(org.robovm.compiler.llvm.Function) PointerType(org.robovm.compiler.llvm.PointerType) Type(org.robovm.compiler.llvm.Type) VoidType(soot.VoidType) Unreachable(org.robovm.compiler.llvm.Unreachable) Value(org.robovm.compiler.llvm.Value) Icmp(org.robovm.compiler.llvm.Icmp)

Example 10 with Load

use of org.robovm.compiler.llvm.Load 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)

Aggregations

Load (org.robovm.compiler.llvm.Load)12 Variable (org.robovm.compiler.llvm.Variable)12 Value (org.robovm.compiler.llvm.Value)10 PointerType (org.robovm.compiler.llvm.PointerType)8 ConstantBitcast (org.robovm.compiler.llvm.ConstantBitcast)7 VariableRef (org.robovm.compiler.llvm.VariableRef)7 Bitcast (org.robovm.compiler.llvm.Bitcast)6 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)6 Ret (org.robovm.compiler.llvm.Ret)6 Function (org.robovm.compiler.llvm.Function)5 StructureType (org.robovm.compiler.llvm.StructureType)5 Type (org.robovm.compiler.llvm.Type)5 ArrayType (org.robovm.compiler.llvm.ArrayType)4 FunctionRef (org.robovm.compiler.llvm.FunctionRef)4 Getelementptr (org.robovm.compiler.llvm.Getelementptr)4 Icmp (org.robovm.compiler.llvm.Icmp)4 Br (org.robovm.compiler.llvm.Br)3 FunctionType (org.robovm.compiler.llvm.FunctionType)3 GlobalRef (org.robovm.compiler.llvm.GlobalRef)3 Inttoptr (org.robovm.compiler.llvm.Inttoptr)3