Search in sources :

Example 16 with Variable

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

the class BroMethodCompiler method createStackCopy.

protected Value createStackCopy(Function fn, Value value) {
    Variable stackCopy = fn.newVariable(new PointerType(value.getType()));
    fn.add(new Alloca(stackCopy, value.getType()));
    fn.add(new Store(value, stackCopy.ref()));
    return stackCopy.ref();
}
Also used : Variable(org.robovm.compiler.llvm.Variable) Alloca(org.robovm.compiler.llvm.Alloca) Store(org.robovm.compiler.llvm.Store) PointerType(org.robovm.compiler.llvm.PointerType)

Example 17 with Variable

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

the class BroMethodCompiler method marshalDoubleToMachineSizedFloat.

protected Value marshalDoubleToMachineSizedFloat(Function fn, Value value) {
    if (config.getArch().is32Bit()) {
        Variable result = fn.newVariable(FLOAT);
        fn.add(new Fptrunc(result, value, FLOAT));
        return result.ref();
    } else {
        return value;
    }
}
Also used : Variable(org.robovm.compiler.llvm.Variable) Fptrunc(org.robovm.compiler.llvm.Fptrunc)

Example 18 with Variable

use of org.robovm.compiler.llvm.Variable 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 19 with Variable

use of org.robovm.compiler.llvm.Variable 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 20 with Variable

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

the class Functions method callWithArguments.

public static Value callWithArguments(Function currentFunction, Value fn, Argument... 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)

Aggregations

Variable (org.robovm.compiler.llvm.Variable)38 PointerType (org.robovm.compiler.llvm.PointerType)18 Value (org.robovm.compiler.llvm.Value)18 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)14 Load (org.robovm.compiler.llvm.Load)12 Type (org.robovm.compiler.llvm.Type)11 FunctionType (org.robovm.compiler.llvm.FunctionType)10 Bitcast (org.robovm.compiler.llvm.Bitcast)9 ConstantBitcast (org.robovm.compiler.llvm.ConstantBitcast)8 Ret (org.robovm.compiler.llvm.Ret)8 VariableRef (org.robovm.compiler.llvm.VariableRef)8 Getelementptr (org.robovm.compiler.llvm.Getelementptr)7 ArrayType (org.robovm.compiler.llvm.ArrayType)6 Br (org.robovm.compiler.llvm.Br)6 Function (org.robovm.compiler.llvm.Function)6 Icmp (org.robovm.compiler.llvm.Icmp)6 IntegerType (org.robovm.compiler.llvm.IntegerType)6 Label (org.robovm.compiler.llvm.Label)6 StructureType (org.robovm.compiler.llvm.StructureType)6 ArrayList (java.util.ArrayList)5