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);
}
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()]));
}
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()])));
}
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);
}
}
}
}
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());
}
}
Aggregations