Search in sources :

Example 6 with Value

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

the class MethodCompiler method invokeExpr.

private Value invokeExpr(Stmt stmt, InvokeExpr expr) {
    SootMethodRef methodRef = expr.getMethodRef();
    ArrayList<Value> args = new ArrayList<Value>();
    args.add(env);
    if (!(expr instanceof StaticInvokeExpr)) {
        Value base = immediate(stmt, (Immediate) ((InstanceInvokeExpr) expr).getBase());
        checkNull(stmt, base);
        args.add(base);
    }
    int i = 0;
    for (soot.Value sootArg : (List<soot.Value>) expr.getArgs()) {
        Value arg = immediate(stmt, (Immediate) sootArg);
        args.add(narrowFromI32Value(stmt, getType(methodRef.parameterType(i)), arg));
        i++;
    }
    Value result = null;
    FunctionRef functionRef = config.isDebug() ? null : Intrinsics.getIntrinsic(sootMethod, stmt, expr);
    if (functionRef == null) {
        Trampoline trampoline = null;
        String targetClassName = getInternalName(methodRef.declaringClass());
        String methodName = methodRef.name();
        String methodDesc = getDescriptor(methodRef);
        if (expr instanceof SpecialInvokeExpr) {
            soot.Type runtimeType = ((SpecialInvokeExpr) expr).getBase().getType();
            String runtimeClassName = runtimeType == NullType.v() ? targetClassName : getInternalName(runtimeType);
            trampoline = new Invokespecial(this.className, targetClassName, methodName, methodDesc, runtimeClassName);
        } else if (expr instanceof StaticInvokeExpr) {
            trampoline = new Invokestatic(this.className, targetClassName, methodName, methodDesc);
        } else if (expr instanceof VirtualInvokeExpr) {
            soot.Type runtimeType = ((VirtualInvokeExpr) expr).getBase().getType();
            String runtimeClassName = runtimeType == NullType.v() ? targetClassName : getInternalName(runtimeType);
            trampoline = new Invokevirtual(this.className, targetClassName, methodName, methodDesc, runtimeClassName);
        } else if (expr instanceof InterfaceInvokeExpr) {
            trampoline = new Invokeinterface(this.className, targetClassName, methodName, methodDesc);
        }
        trampolines.add(trampoline);
        if (canCallDirectly(expr)) {
            SootMethod method = this.sootMethod.getDeclaringClass().getMethod(methodRef.name(), methodRef.parameterTypes(), methodRef.returnType());
            if (method.isSynchronized()) {
                functionRef = FunctionBuilder.synchronizedWrapper(method).ref();
            } else {
                functionRef = createMethodFunction(method).ref();
            }
        } else {
            functionRef = trampoline.getFunctionRef();
        }
    }
    result = call(stmt, functionRef, args.toArray(new Value[0]));
    if (result != null) {
        return widenToI32Value(stmt, result, methodRef.returnType().equals(CharType.v()));
    } else {
        return null;
    }
}
Also used : Trampoline(org.robovm.compiler.trampoline.Trampoline) SootMethodRef(soot.SootMethodRef) SpecialInvokeExpr(soot.jimple.SpecialInvokeExpr) ArrayList(java.util.ArrayList) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) InterfaceInvokeExpr(soot.jimple.InterfaceInvokeExpr) Invokeinterface(org.robovm.compiler.trampoline.Invokeinterface) Invokespecial(org.robovm.compiler.trampoline.Invokespecial) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) Invokestatic(org.robovm.compiler.trampoline.Invokestatic) Value(org.robovm.compiler.llvm.Value) SootMethod(soot.SootMethod) ArrayList(java.util.ArrayList) List(java.util.List) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) Invokevirtual(org.robovm.compiler.trampoline.Invokevirtual) FunctionRef(org.robovm.compiler.llvm.FunctionRef)

Example 7 with Value

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

the class MethodCompiler method tableSwitch.

private void tableSwitch(TableSwitchStmt stmt) {
    Map<IntegerConstant, BasicBlockRef> targets = new HashMap<IntegerConstant, BasicBlockRef>();
    for (int i = stmt.getLowIndex(); i <= stmt.getHighIndex(); i++) {
        Unit target = stmt.getTarget(i - stmt.getLowIndex());
        targets.put(new IntegerConstant(i), function.newBasicBlockRef(new Label(target)));
    }
    BasicBlockRef def = function.newBasicBlockRef(new Label(stmt.getDefaultTarget()));
    Value key = immediate(stmt, (Immediate) stmt.getKey());
    function.add(new Switch(key, def, targets)).attach(stmt);
}
Also used : BasicBlockRef(org.robovm.compiler.llvm.BasicBlockRef) Switch(org.robovm.compiler.llvm.Switch) HashMap(java.util.HashMap) Label(org.robovm.compiler.llvm.Label) Value(org.robovm.compiler.llvm.Value) Unit(soot.Unit) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant)

Example 8 with Value

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

the class MethodCompiler method exitMonitor.

private void exitMonitor(ExitMonitorStmt stmt) {
    Value op = immediate(stmt, (Immediate) stmt.getOp());
    checkNull(stmt, op);
    call(stmt, MONITOREXIT, env, op);
}
Also used : Value(org.robovm.compiler.llvm.Value)

Example 9 with Value

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

the class Linker method createLookup.

private Function createLookup(ModuleBuilder mb, ClazzInfo ci, MethodInfo mi) {
    Function function = FunctionBuilder.lookup(ci, mi, false);
    String targetFnName = mi.isSynchronized() ? Symbols.synchronizedWrapperSymbol(ci.getInternalName(), mi.getName(), mi.getDesc()) : Symbols.methodSymbol(ci.getInternalName(), mi.getName(), mi.getDesc());
    FunctionRef fn = new FunctionRef(targetFnName, function.getType());
    if (!mb.hasSymbol(fn.getName())) {
        mb.addFunctionDeclaration(new FunctionDeclaration(fn));
    }
    Value result = tailcall(function, fn, function.getParameterRefs());
    function.add(new Ret(result));
    return function;
}
Also used : Ret(org.robovm.compiler.llvm.Ret) ModifiedUtf8HashFunction(org.robovm.compiler.hash.ModifiedUtf8HashFunction) Function(org.robovm.compiler.llvm.Function) FunctionDeclaration(org.robovm.compiler.llvm.FunctionDeclaration) Value(org.robovm.compiler.llvm.Value) FunctionRef(org.robovm.compiler.llvm.FunctionRef)

Example 10 with Value

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

the class Linker method createInstanceof.

private Function createInstanceof(ModuleBuilder mb, Clazz clazz, TypeInfo typeInfo) {
    Function fn = FunctionBuilder.instanceOf(clazz);
    Value info = getInfoStruct(mb, fn, clazz);
    if (typeInfo.error) {
        // This will trigger an exception
        call(fn, BC_LDC_CLASS, fn.getParameterRef(0), info);
        fn.add(new Ret(new IntegerConstant(0)));
    } else if (!clazz.getClazzInfo().isInterface()) {
        Value result = call(fn, INSTANCEOF_CLASS, fn.getParameterRef(0), info, fn.getParameterRef(1), new IntegerConstant((typeInfo.classTypes.length - 1) * 4 + 5 * 4), new IntegerConstant(typeInfo.id));
        fn.add(new Ret(result));
    } else {
        Value result = call(fn, INSTANCEOF_INTERFACE, fn.getParameterRef(0), info, fn.getParameterRef(1), new IntegerConstant(typeInfo.id));
        fn.add(new Ret(result));
    }
    return fn;
}
Also used : Ret(org.robovm.compiler.llvm.Ret) ModifiedUtf8HashFunction(org.robovm.compiler.hash.ModifiedUtf8HashFunction) Function(org.robovm.compiler.llvm.Function) Value(org.robovm.compiler.llvm.Value) IntegerConstant(org.robovm.compiler.llvm.IntegerConstant)

Aggregations

Value (org.robovm.compiler.llvm.Value)48 Ret (org.robovm.compiler.llvm.Ret)26 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)24 Function (org.robovm.compiler.llvm.Function)22 Variable (org.robovm.compiler.llvm.Variable)18 FunctionRef (org.robovm.compiler.llvm.FunctionRef)16 Label (org.robovm.compiler.llvm.Label)10 Load (org.robovm.compiler.llvm.Load)10 ArrayList (java.util.ArrayList)9 PointerType (org.robovm.compiler.llvm.PointerType)9 Bitcast (org.robovm.compiler.llvm.Bitcast)8 FunctionType (org.robovm.compiler.llvm.FunctionType)8 NullConstant (org.robovm.compiler.llvm.NullConstant)8 ConstantBitcast (org.robovm.compiler.llvm.ConstantBitcast)7 StructureType (org.robovm.compiler.llvm.StructureType)7 Type (org.robovm.compiler.llvm.Type)7 VariableRef (org.robovm.compiler.llvm.VariableRef)7 Invokestatic (org.robovm.compiler.trampoline.Invokestatic)7 BasicBlockRef (org.robovm.compiler.llvm.BasicBlockRef)6 Br (org.robovm.compiler.llvm.Br)6