Search in sources :

Example 6 with BasicBlockRef

use of org.robovm.compiler.llvm.BasicBlockRef 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

BasicBlockRef (org.robovm.compiler.llvm.BasicBlockRef)6 Label (org.robovm.compiler.llvm.Label)6 Value (org.robovm.compiler.llvm.Value)6 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)5 FunctionType (org.robovm.compiler.llvm.FunctionType)4 Ret (org.robovm.compiler.llvm.Ret)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Function (org.robovm.compiler.llvm.Function)3 FunctionRef (org.robovm.compiler.llvm.FunctionRef)3 Switch (org.robovm.compiler.llvm.Switch)3 Type (org.robovm.compiler.llvm.Type)3 Unreachable (org.robovm.compiler.llvm.Unreachable)3 Unit (soot.Unit)3 MarshalSite (org.robovm.compiler.MarshalerLookup.MarshalSite)2 MarshalerMethod (org.robovm.compiler.MarshalerLookup.MarshalerMethod)2 PointerMarshalerMethod (org.robovm.compiler.MarshalerLookup.PointerMarshalerMethod)2 Alloca (org.robovm.compiler.llvm.Alloca)2 Bitcast (org.robovm.compiler.llvm.Bitcast)2 Br (org.robovm.compiler.llvm.Br)2