use of org.robovm.compiler.llvm.Type 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;
}
use of org.robovm.compiler.llvm.Type in project robovm by robovm.
the class Types method getFunctionType.
private static FunctionType getFunctionType(String methodDesc, boolean ztatic, boolean nativ) {
List<Type> paramTypes = new ArrayList<Type>();
paramTypes.add(ENV_PTR);
if (!ztatic) {
paramTypes.add(OBJECT_PTR);
} else if (nativ) {
paramTypes.add(OBJECT_PTR);
}
CharBuffer buffer = CharBuffer.wrap(methodDesc);
// Skip initial (
buffer.get();
while (buffer.get(buffer.position()) != ')') {
paramTypes.add(getType(buffer));
}
// Skip ending )
buffer.get();
Type returnType = getType(buffer);
return new FunctionType(returnType, paramTypes.toArray(new Type[paramTypes.size()]));
}
use of org.robovm.compiler.llvm.Type in project robovm by robovm.
the class Types method getFunctionType.
@SuppressWarnings("unchecked")
public static FunctionType getFunctionType(SootMethodRef methodRef) {
Type returnType = getType(methodRef.returnType());
Type[] paramTypes = new Type[(methodRef.isStatic() ? 1 : 2) + methodRef.parameterTypes().size()];
int i = 0;
paramTypes[i++] = ENV_PTR;
if (!methodRef.isStatic()) {
paramTypes[i++] = OBJECT_PTR;
}
for (soot.Type t : (List<soot.Type>) methodRef.parameterTypes()) {
paramTypes[i++] = getType(t);
}
return new FunctionType(returnType, paramTypes);
}
use of org.robovm.compiler.llvm.Type 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 org.robovm.compiler.llvm.Type 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()])));
}
Aggregations