Search in sources :

Example 41 with Value

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

the class AttributesEncoder method encodeAnnotationElementValue.

private PackedStructureConstant encodeAnnotationElementValue(AnnotationElem ae) {
    PackedStructureType type = getAnnotationElementType(ae);
    Value kind = new IntegerConstant((byte) ae.getKind());
    if (ae instanceof AnnotationIntElem) {
        AnnotationIntElem aie = (AnnotationIntElem) ae;
        return new PackedStructureConstant(type, kind, new IntegerConstant(aie.getValue()));
    } else if (ae instanceof AnnotationLongElem) {
        AnnotationLongElem ale = (AnnotationLongElem) ae;
        return new PackedStructureConstant(type, kind, new IntegerConstant(ale.getValue()));
    } else if (ae instanceof AnnotationFloatElem) {
        AnnotationFloatElem afe = (AnnotationFloatElem) ae;
        return new PackedStructureConstant(type, kind, new FloatingPointConstant(afe.getValue()));
    } else if (ae instanceof AnnotationDoubleElem) {
        AnnotationDoubleElem ade = (AnnotationDoubleElem) ae;
        return new PackedStructureConstant(type, kind, new FloatingPointConstant(ade.getValue()));
    } else if (ae instanceof AnnotationStringElem) {
        AnnotationStringElem ase = (AnnotationStringElem) ae;
        return new PackedStructureConstant(type, kind, getStringOrNull(ase.getValue()));
    } else if (ae instanceof AnnotationClassElem) {
        AnnotationClassElem ace = (AnnotationClassElem) ae;
        addDependencyIfNeeded(ace.getDesc());
        return new PackedStructureConstant(type, kind, getStringOrNull(ace.getDesc()));
    } else if (ae instanceof AnnotationEnumElem) {
        AnnotationEnumElem aee = (AnnotationEnumElem) ae;
        addDependencyIfNeeded(aee.getTypeName());
        return new PackedStructureConstant(type, kind, getStringOrNull(aee.getTypeName()), getStringOrNull(aee.getConstantName()));
    } else if (ae instanceof AnnotationArrayElem) {
        AnnotationArrayElem aae = (AnnotationArrayElem) ae;
        Value[] values = new Value[aae.getNumValues() + 2];
        values[0] = kind;
        values[1] = new IntegerConstant((char) aae.getNumValues());
        for (int i = 0; i < aae.getNumValues(); i++) {
            values[i + 2] = encodeAnnotationElementValue(aae.getValueAt(i));
        }
        return new PackedStructureConstant(type, values);
    } else if (ae instanceof AnnotationAnnotationElem) {
        AnnotationAnnotationElem aae = (AnnotationAnnotationElem) ae;
        return new PackedStructureConstant(type, kind, encodeAnnotationTagValue(aae.getValue()));
    }
    throw new IllegalArgumentException("Unknown AnnotationElem type: " + ae.getClass());
}
Also used : AnnotationStringElem(soot.tagkit.AnnotationStringElem) AnnotationAnnotationElem(soot.tagkit.AnnotationAnnotationElem) FloatingPointConstant(org.robovm.compiler.llvm.FloatingPointConstant) AnnotationLongElem(soot.tagkit.AnnotationLongElem) AnnotationArrayElem(soot.tagkit.AnnotationArrayElem) PackedStructureType(org.robovm.compiler.llvm.PackedStructureType) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant) PackedStructureConstant(org.robovm.compiler.llvm.PackedStructureConstant) AnnotationEnumElem(soot.tagkit.AnnotationEnumElem) AnnotationDoubleElem(soot.tagkit.AnnotationDoubleElem) AnnotationIntElem(soot.tagkit.AnnotationIntElem) AnnotationFloatElem(soot.tagkit.AnnotationFloatElem) AnnotationClassElem(soot.tagkit.AnnotationClassElem) Value(org.robovm.compiler.llvm.Value)

Example 42 with Value

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

the class AttributesEncoder method encodeAnnotationTagValue.

private PackedStructureConstant encodeAnnotationTagValue(AnnotationTag tag) {
    Value[] values = new Value[tag.getNumElems() * 2 + 2];
    values[0] = getString(tag.getType());
    addDependencyIfNeeded(tag.getType());
    values[1] = new IntegerConstant(tag.getNumElems());
    for (int i = 0; i < tag.getNumElems(); i++) {
        values[i * 2 + 2] = getString(tag.getElemAt(i).getName());
        values[i * 2 + 2 + 1] = encodeAnnotationElementValue(tag.getElemAt(i));
    }
    return new PackedStructureConstant(getAnnotationTagType(tag), values);
}
Also used : Value(org.robovm.compiler.llvm.Value) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant) PackedStructureConstant(org.robovm.compiler.llvm.PackedStructureConstant)

Example 43 with Value

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

the class BroMethodCompiler method loadValueForGetter.

protected Value loadValueForGetter(SootMethod method, Function fn, Type memberType, Value memberPtr, Value env, boolean dereference, long flags) {
    soot.Type type = method.getReturnType();
    Value result = null;
    if (memberType instanceof StructureType) {
        // The member is a child struct contained in the current struct
        result = memberPtr;
    } else if (memberType instanceof ArrayType) {
        // The member is an array contained in the current struct
        result = memberPtr;
    } else if (dereference) {
        Variable tmp = fn.newVariable(memberType);
        fn.add(new Load(tmp, memberPtr));
        result = tmp.ref();
    } else {
        // Do not dereference the pointer but use it as is. This is needed for
        // global values such as _dispatch_main_q which is a struct and not a
        // pointer which we should load. We want the address of the struct.
        Variable tmp = fn.newVariable(memberType);
        fn.add(new Bitcast(tmp, memberPtr, tmp.getType()));
        result = tmp.ref();
    }
    if (needsMarshaler(type)) {
        MarshalerMethod marshalerMethod = config.getMarshalerLookup().findMarshalerMethod(new MarshalSite(method));
        String targetClassName = getInternalName(type);
        if (memberType instanceof PrimitiveType) {
            // Value type wrapping a primitive value (e.g. Enum, Integer and Bits)
            result = marshalNativeToValueObject(fn, marshalerMethod, env, targetClassName, result, flags);
        } else {
            if (memberType instanceof ArrayType) {
                // Array
                result = marshalNativeToArray(fn, marshalerMethod, env, targetClassName, result, flags, getArrayDimensions(method));
            } else {
                result = marshalNativeToObject(fn, marshalerMethod, null, env, targetClassName, result, flags);
            }
        }
    } else {
        result = marshalNativeToPrimitive(fn, method, result);
    }
    return result;
}
Also used : ArrayType(org.robovm.compiler.llvm.ArrayType) MarshalSite(org.robovm.compiler.MarshalerLookup.MarshalSite) Load(org.robovm.compiler.llvm.Load) Variable(org.robovm.compiler.llvm.Variable) Bitcast(org.robovm.compiler.llvm.Bitcast) ConstantBitcast(org.robovm.compiler.llvm.ConstantBitcast) StructureType(org.robovm.compiler.llvm.StructureType) Value(org.robovm.compiler.llvm.Value) PrimitiveType(org.robovm.compiler.llvm.PrimitiveType) MarshalerMethod(org.robovm.compiler.MarshalerLookup.MarshalerMethod) ValueMarshalerMethod(org.robovm.compiler.MarshalerLookup.ValueMarshalerMethod) ArrayMarshalerMethod(org.robovm.compiler.MarshalerLookup.ArrayMarshalerMethod)

Example 44 with Value

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

Example 45 with Value

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

the class ClassCompiler method createLdcClass.

private Function createLdcClass() {
    Function fn = FunctionBuilder.ldcInternal(sootClass);
    Value info = getInfoStruct(fn, sootClass);
    Value result = call(fn, BC_LDC_CLASS, fn.getParameterRef(0), info);
    fn.add(new Ret(result));
    return fn;
}
Also used : Ret(org.robovm.compiler.llvm.Ret) Function(org.robovm.compiler.llvm.Function) Value(org.robovm.compiler.llvm.Value)

Aggregations

Value (org.robovm.compiler.llvm.Value)48 Ret (org.robovm.compiler.llvm.Ret)26 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)24 Function (org.robovm.compiler.llvm.Function)22 Variable (org.robovm.compiler.llvm.Variable)18 FunctionRef (org.robovm.compiler.llvm.FunctionRef)16 Label (org.robovm.compiler.llvm.Label)10 Load (org.robovm.compiler.llvm.Load)10 ArrayList (java.util.ArrayList)9 PointerType (org.robovm.compiler.llvm.PointerType)9 Bitcast (org.robovm.compiler.llvm.Bitcast)8 FunctionType (org.robovm.compiler.llvm.FunctionType)8 NullConstant (org.robovm.compiler.llvm.NullConstant)8 ConstantBitcast (org.robovm.compiler.llvm.ConstantBitcast)7 StructureType (org.robovm.compiler.llvm.StructureType)7 Type (org.robovm.compiler.llvm.Type)7 VariableRef (org.robovm.compiler.llvm.VariableRef)7 Invokestatic (org.robovm.compiler.trampoline.Invokestatic)7 BasicBlockRef (org.robovm.compiler.llvm.BasicBlockRef)6 Br (org.robovm.compiler.llvm.Br)6