Search in sources :

Example 6 with VariableRef

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

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

the class MethodCompiler method if_.

private void if_(IfStmt stmt) {
    ConditionExpr condition = (ConditionExpr) stmt.getCondition();
    Value op1 = immediate(stmt, (Immediate) condition.getOp1());
    Value op2 = immediate(stmt, (Immediate) condition.getOp2());
    Icmp.Condition c = null;
    if (condition instanceof EqExpr) {
        c = Icmp.Condition.eq;
    } else if (condition instanceof NeExpr) {
        c = Icmp.Condition.ne;
    } else if (condition instanceof GtExpr) {
        c = Icmp.Condition.sgt;
    } else if (condition instanceof LtExpr) {
        c = Icmp.Condition.slt;
    } else if (condition instanceof GeExpr) {
        c = Icmp.Condition.sge;
    } else if (condition instanceof LeExpr) {
        c = Icmp.Condition.sle;
    }
    Variable result = function.newVariable(Type.I1);
    function.add(new Icmp(result, c, op1, op2)).attach(stmt);
    Unit nextUnit = sootMethod.getActiveBody().getUnits().getSuccOf(stmt);
    function.add(new Br(new VariableRef(result), function.newBasicBlockRef(new Label(stmt.getTarget())), function.newBasicBlockRef(new Label(nextUnit)))).attach(stmt);
}
Also used : VariableRef(org.robovm.compiler.llvm.VariableRef) Condition(org.robovm.compiler.llvm.Icmp.Condition) Variable(org.robovm.compiler.llvm.Variable) NeExpr(soot.jimple.NeExpr) Label(org.robovm.compiler.llvm.Label) GtExpr(soot.jimple.GtExpr) LtExpr(soot.jimple.LtExpr) GeExpr(soot.jimple.GeExpr) Unit(soot.Unit) LeExpr(soot.jimple.LeExpr) Br(org.robovm.compiler.llvm.Br) EqExpr(soot.jimple.EqExpr) ConditionExpr(soot.jimple.ConditionExpr) Value(org.robovm.compiler.llvm.Value) Icmp(org.robovm.compiler.llvm.Icmp)

Example 8 with VariableRef

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

the class ClassCompiler method getClassFieldPtr.

static Value getClassFieldPtr(Function f, SootField field, List<SootField> classFields, StructureType classType) {
    Value info = getInfoStruct(f, field.getDeclaringClass());
    Variable base = f.newVariable(I8_PTR);
    f.add(new Load(base, info));
    return getFieldPtr(f, new VariableRef(base), offsetof(classType, 1, classFields.indexOf(field), 1), getType(field.getType()));
}
Also used : Load(org.robovm.compiler.llvm.Load) VariableRef(org.robovm.compiler.llvm.VariableRef) Variable(org.robovm.compiler.llvm.Variable) Value(org.robovm.compiler.llvm.Value)

Aggregations

Variable (org.robovm.compiler.llvm.Variable)8 VariableRef (org.robovm.compiler.llvm.VariableRef)8 Load (org.robovm.compiler.llvm.Load)7 Value (org.robovm.compiler.llvm.Value)7 PointerType (org.robovm.compiler.llvm.PointerType)5 Type (org.robovm.compiler.llvm.Type)5 Icmp (org.robovm.compiler.llvm.Icmp)4 Ret (org.robovm.compiler.llvm.Ret)4 Bitcast (org.robovm.compiler.llvm.Bitcast)3 Br (org.robovm.compiler.llvm.Br)3 ConstantBitcast (org.robovm.compiler.llvm.ConstantBitcast)3 FunctionRef (org.robovm.compiler.llvm.FunctionRef)3 FunctionType (org.robovm.compiler.llvm.FunctionType)3 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)3 NullConstant (org.robovm.compiler.llvm.NullConstant)3 ArrayType (org.robovm.compiler.llvm.ArrayType)2 FloatingPointConstant (org.robovm.compiler.llvm.FloatingPointConstant)2 FloatingPointType (org.robovm.compiler.llvm.FloatingPointType)2 Function (org.robovm.compiler.llvm.Function)2 GlobalRef (org.robovm.compiler.llvm.GlobalRef)2