Search in sources :

Example 26 with FunctionRef

use of org.robovm.compiler.llvm.FunctionRef in project robovm by robovm.

the class AbstractMethodCompiler method compileSynchronizedWrapper.

private void compileSynchronizedWrapper(ModuleBuilder moduleBuilder, SootMethod method) {
    String targetName = Symbols.methodSymbol(method);
    Function syncFn = FunctionBuilder.synchronizedWrapper(method);
    moduleBuilder.addFunction(syncFn);
    FunctionType functionType = syncFn.getType();
    FunctionRef target = new FunctionRef(targetName, functionType);
    Value monitor = null;
    if (method.isStatic()) {
        FunctionRef fn = FunctionBuilder.ldcInternal(sootMethod.getDeclaringClass()).ref();
        monitor = call(syncFn, fn, syncFn.getParameterRef(0));
    } else {
        monitor = syncFn.getParameterRef(1);
    }
    call(syncFn, MONITORENTER, syncFn.getParameterRef(0), monitor);
    BasicBlockRef bbSuccess = syncFn.newBasicBlockRef(new Label("success"));
    BasicBlockRef bbFailure = syncFn.newBasicBlockRef(new Label("failure"));
    trycatchAllEnter(syncFn, bbSuccess, bbFailure);
    syncFn.newBasicBlock(bbSuccess.getLabel());
    Value result = call(syncFn, target, syncFn.getParameterRefs());
    trycatchLeave(syncFn);
    call(syncFn, MONITOREXIT, syncFn.getParameterRef(0), monitor);
    syncFn.add(new Ret(result));
    syncFn.newBasicBlock(bbFailure.getLabel());
    trycatchLeave(syncFn);
    call(syncFn, MONITOREXIT, syncFn.getParameterRef(0), monitor);
    call(syncFn, BC_THROW_IF_EXCEPTION_OCCURRED, syncFn.getParameterRef(0));
    syncFn.add(new Unreachable());
}
Also used : Ret(org.robovm.compiler.llvm.Ret) Function(org.robovm.compiler.llvm.Function) BasicBlockRef(org.robovm.compiler.llvm.BasicBlockRef) Unreachable(org.robovm.compiler.llvm.Unreachable) FunctionType(org.robovm.compiler.llvm.FunctionType) Value(org.robovm.compiler.llvm.Value) Label(org.robovm.compiler.llvm.Label) FunctionRef(org.robovm.compiler.llvm.FunctionRef)

Aggregations

FunctionRef (org.robovm.compiler.llvm.FunctionRef)26 Function (org.robovm.compiler.llvm.Function)16 Value (org.robovm.compiler.llvm.Value)16 Ret (org.robovm.compiler.llvm.Ret)14 FunctionType (org.robovm.compiler.llvm.FunctionType)11 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)10 ConstantBitcast (org.robovm.compiler.llvm.ConstantBitcast)9 Global (org.robovm.compiler.llvm.Global)8 NullConstant (org.robovm.compiler.llvm.NullConstant)8 ArrayList (java.util.ArrayList)7 FunctionDeclaration (org.robovm.compiler.llvm.FunctionDeclaration)7 PointerType (org.robovm.compiler.llvm.PointerType)7 Type (org.robovm.compiler.llvm.Type)6 Unreachable (org.robovm.compiler.llvm.Unreachable)5 Variable (org.robovm.compiler.llvm.Variable)5 Trampoline (org.robovm.compiler.trampoline.Trampoline)5 FloatingPointConstant (org.robovm.compiler.llvm.FloatingPointConstant)4 GlobalRef (org.robovm.compiler.llvm.GlobalRef)4 Load (org.robovm.compiler.llvm.Load)4 StructureType (org.robovm.compiler.llvm.StructureType)4