use of org.robovm.compiler.llvm.Variable in project robovm by robovm.
the class BroMethodCompiler method createStackCopy.
protected Value createStackCopy(Function fn, Value value) {
Variable stackCopy = fn.newVariable(new PointerType(value.getType()));
fn.add(new Alloca(stackCopy, value.getType()));
fn.add(new Store(value, stackCopy.ref()));
return stackCopy.ref();
}
use of org.robovm.compiler.llvm.Variable in project robovm by robovm.
the class BroMethodCompiler method marshalDoubleToMachineSizedFloat.
protected Value marshalDoubleToMachineSizedFloat(Function fn, Value value) {
if (config.getArch().is32Bit()) {
Variable result = fn.newVariable(FLOAT);
fn.add(new Fptrunc(result, value, FLOAT));
return result.ref();
} else {
return value;
}
}
use of org.robovm.compiler.llvm.Variable in project robovm by robovm.
the class BroMethodCompiler method marshalObjectToNative.
protected Value marshalObjectToNative(Function fn, MarshalerMethod marshalerMethod, MarshaledArg marshaledArg, Type nativeType, Value env, Value object, long flags) {
Invokestatic invokestatic = marshalerMethod.getInvokeStatic(sootMethod.getDeclaringClass());
trampolines.add(invokestatic);
Value handle = call(fn, invokestatic.getFunctionRef(), env, object, new IntegerConstant(flags));
Variable nativeValue = fn.newVariable(nativeType);
if (nativeType instanceof StructureType || nativeType instanceof ArrayType) {
Variable tmp = fn.newVariable(new PointerType(nativeType));
fn.add(new Inttoptr(tmp, handle, tmp.getType()));
fn.add(new Load(nativeValue, tmp.ref()));
} else {
fn.add(new Inttoptr(nativeValue, handle, nativeType));
}
if (marshaledArg != null) {
marshaledArg.handle = handle;
marshaledArg.object = object;
}
return nativeValue.ref();
}
use of org.robovm.compiler.llvm.Variable in project robovm by robovm.
the class ClassCompiler method createLookupFunction.
private void createLookupFunction(SootMethod m) {
Function function = FunctionBuilder.lookup(m, true);
mb.addFunction(function);
Variable reserved0 = function.newVariable(I8_PTR_PTR);
function.add(new Getelementptr(reserved0, function.getParameterRef(0), 0, 4));
Variable reserved1 = function.newVariable(I8_PTR_PTR);
function.add(new Getelementptr(reserved1, function.getParameterRef(0), 0, 5));
function.add(new Store(getString(m.getName()), reserved0.ref()));
function.add(new Store(getString(getDescriptor(m)), reserved1.ref()));
if (!sootClass.isInterface()) {
int vtableIndex = 0;
try {
VTable vtable = config.getVTableCache().get(sootClass);
vtableIndex = vtable.getEntry(m).getIndex();
} catch (IllegalArgumentException e) {
// VTable throws this if any of the superclasses of the class is actually an interface.
// Shouldn't happen frequently but the DRLVM test suite has some tests for this.
// Use 0 as vtableIndex since this lookup function will never be called anyway.
}
Value classPtr = call(function, OBJECT_CLASS, function.getParameterRef(1));
Value vtablePtr = call(function, CLASS_VITABLE, classPtr);
Variable funcPtrPtr = function.newVariable(I8_PTR_PTR);
function.add(new Getelementptr(funcPtrPtr, vtablePtr, 0, 1, vtableIndex));
Variable funcPtr = function.newVariable(I8_PTR);
function.add(new Load(funcPtr, funcPtrPtr.ref()));
Variable f = function.newVariable(function.getType());
function.add(new Bitcast(f, funcPtr.ref(), f.getType()));
Value result = tailcall(function, f.ref(), function.getParameterRefs());
function.add(new Ret(result));
} else {
ITable itable = config.getITableCache().get(sootClass);
ITable.Entry entry = itable.getEntry(m);
List<Value> args = new ArrayList<Value>();
args.add(function.getParameterRef(0));
args.add(getInfoStruct(function, sootClass));
args.add(function.getParameterRef(1));
args.add(new IntegerConstant(entry.getIndex()));
Value fptr = call(function, BC_LOOKUP_INTERFACE_METHOD_IMPL, args);
Variable f = function.newVariable(function.getType());
function.add(new Bitcast(f, fptr, f.getType()));
Value result = tailcall(function, f.ref(), function.getParameterRefs());
function.add(new Ret(result));
}
}
use of org.robovm.compiler.llvm.Variable in project robovm by robovm.
the class Functions method callWithArguments.
public static Value callWithArguments(Function currentFunction, Value fn, Argument... args) {
Variable result = null;
Type returnType = ((FunctionType) fn.getType()).getReturnType();
if (returnType != VOID) {
result = currentFunction.newVariable(returnType);
}
currentFunction.add(new Call(result, fn, args));
return result == null ? null : result.ref();
}
Aggregations