Search in sources :

Example 41 with SootField

use of soot.SootField in project robovm by robovm.

the class TrampolineCompiler method createInlinedAccessorForInstanceField.

private void createInlinedAccessorForInstanceField(FieldAccessor t, SootField field) {
    Function fn = new FunctionBuilder(t).linkage(aliasLinkage()).attribs(shouldInline(), optsize).build();
    List<SootField> classFields = Collections.emptyList();
    StructureType classType = new StructureType();
    List<SootField> instanceFields = getInstanceFields(config.getOs(), config.getArch(), field.getDeclaringClass());
    StructureType instanceType = getInstanceType(config.getOs(), config.getArch(), field.getDeclaringClass());
    if (t.isGetter()) {
        ClassCompiler.createFieldGetter(fn, field, classFields, classType, instanceFields, instanceType);
    } else {
        ClassCompiler.createFieldSetter(fn, field, classFields, classType, instanceFields, instanceType);
    }
    mb.addFunction(fn);
}
Also used : Function(org.robovm.compiler.llvm.Function) StructureType(org.robovm.compiler.llvm.StructureType) SootField(soot.SootField)

Example 42 with SootField

use of soot.SootField 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 43 with SootField

use of soot.SootField 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)

Example 44 with SootField

use of soot.SootField in project robovm by robovm.

the class MethodCompiler method initializeClassFields.

private void initializeClassFields() {
    for (SootField field : sootMethod.getDeclaringClass().getFields()) {
        if (!field.isStatic()) {
            continue;
        }
        for (Tag tag : field.getTags()) {
            Value value = null;
            if (tag instanceof DoubleConstantValueTag) {
                DoubleConstantValueTag dtag = (DoubleConstantValueTag) tag;
                value = new FloatingPointConstant(dtag.getDoubleValue());
            } else if (tag instanceof FloatConstantValueTag) {
                FloatConstantValueTag ftag = (FloatConstantValueTag) tag;
                value = new FloatingPointConstant(ftag.getFloatValue());
            } else if (tag instanceof IntegerConstantValueTag) {
                IntegerConstantValueTag itag = (IntegerConstantValueTag) tag;
                value = new IntegerConstant(itag.getIntValue());
                IntegerType type = (IntegerType) getType(field.getType());
                if (type.getBits() < 32) {
                    value = new ConstantTrunc((Constant) value, type);
                }
            } else if (tag instanceof LongConstantValueTag) {
                LongConstantValueTag ltag = (LongConstantValueTag) tag;
                value = new IntegerConstant(ltag.getLongValue());
            } else if (tag instanceof StringConstantValueTag) {
                String s = ((StringConstantValueTag) tag).getStringValue();
                value = call(ldcString(s), env);
            }
            if (value != null) {
                FunctionRef fn = FunctionBuilder.setter(field).ref();
                call(fn, env, value);
            }
        }
    }
}
Also used : FloatingPointConstant(org.robovm.compiler.llvm.FloatingPointConstant) FloatingPointConstant(org.robovm.compiler.llvm.FloatingPointConstant) Constant(org.robovm.compiler.llvm.Constant) NullConstant(org.robovm.compiler.llvm.NullConstant) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant) IntegerConstantValueTag(soot.tagkit.IntegerConstantValueTag) DoubleConstantValueTag(soot.tagkit.DoubleConstantValueTag) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant) IntegerType(org.robovm.compiler.llvm.IntegerType) ConstantTrunc(org.robovm.compiler.llvm.ConstantTrunc) Value(org.robovm.compiler.llvm.Value) LongConstantValueTag(soot.tagkit.LongConstantValueTag) SootField(soot.SootField) ArrayCheckTag(soot.jimple.toolkits.annotation.tags.ArrayCheckTag) NullCheckTag(soot.jimple.toolkits.annotation.tags.NullCheckTag) FloatConstantValueTag(soot.tagkit.FloatConstantValueTag) IntegerConstantValueTag(soot.tagkit.IntegerConstantValueTag) Tag(soot.tagkit.Tag) DoubleConstantValueTag(soot.tagkit.DoubleConstantValueTag) LongConstantValueTag(soot.tagkit.LongConstantValueTag) StringConstantValueTag(soot.tagkit.StringConstantValueTag) StringConstantValueTag(soot.tagkit.StringConstantValueTag) FloatConstantValueTag(soot.tagkit.FloatConstantValueTag) FunctionRef(org.robovm.compiler.llvm.FunctionRef)

Example 45 with SootField

use of soot.SootField in project robovm by robovm.

the class ObjCMemberPlugin method registerSelectors.

private void registerSelectors(SootClass sootClass, Set<String> selectors) {
    Jimple j = Jimple.v();
    SootMethod clinit = getOrCreateStaticInitializer(sootClass);
    Body body = clinit.retrieveActiveBody();
    Local sel = Jimple.v().newLocal("$sel", org_robovm_objc_Selector.getType());
    body.getLocals().add(sel);
    Chain<Unit> units = body.getUnits();
    for (String selectorName : selectors) {
        SootField f = getSelectorField(selectorName);
        sootClass.addField(f);
        units.insertBefore(Arrays.<Unit>asList(j.newAssignStmt(sel, j.newStaticInvokeExpr(org_robovm_objc_Selector_register, StringConstant.v(selectorName))), j.newAssignStmt(j.newStaticFieldRef(f.makeRef()), sel)), units.getLast());
    }
}
Also used : SootMethod(soot.SootMethod) Local(soot.Local) Jimple(soot.jimple.Jimple) SootField(soot.SootField) Unit(soot.Unit) Body(soot.Body)

Aggregations

SootField (soot.SootField)73 SootMethod (soot.SootMethod)29 SootClass (soot.SootClass)26 RefType (soot.RefType)22 ArrayList (java.util.ArrayList)19 Value (soot.Value)17 Iterator (java.util.Iterator)15 Local (soot.Local)14 Type (soot.Type)14 Unit (soot.Unit)13 FieldRef (soot.jimple.FieldRef)12 BooleanType (soot.BooleanType)10 PrimType (soot.PrimType)10 VoidType (soot.VoidType)10 Stmt (soot.jimple.Stmt)10 ByteType (soot.ByteType)8 CharType (soot.CharType)8 DoubleType (soot.DoubleType)8 FloatType (soot.FloatType)8 IntType (soot.IntType)8