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