Search in sources :

Example 36 with SootMethod

use of soot.SootMethod in project robovm by robovm.

the class MarshalerLookupTest method testFindMarshalerStructMemberPrimitiveArray3D.

@Test
public void testFindMarshalerStructMemberPrimitiveArray3D() {
    MarshalerLookup lookup = new MarshalerLookup(config).searchBuiltins(false);
    SootMethod getter = toSootClass(TestStruct.class).getMethodByName("getV4");
    SootMethod setter = toSootClass(TestStruct.class).getMethodByName("setV4");
    assertEquals(toSootClass(M2.class).getMethodByName("byteArray3DToObject"), lookup.findMarshalerMethod(new MarshalSite(getter)).getMethod());
    assertEquals(toSootClass(M2.class).getMethodByName("byteArray3DToNative"), lookup.findMarshalerMethod(new MarshalSite(setter, 0)).getMethod());
}
Also used : MarshalSite(org.robovm.compiler.MarshalerLookup.MarshalSite) SootMethod(soot.SootMethod) Test(org.junit.Test)

Example 37 with SootMethod

use of soot.SootMethod in project robovm by robovm.

the class MarshalerLookupTest method testFindMarshalerMethodInterfaceMatchPointer.

@Test
public void testFindMarshalerMethodInterfaceMatchPointer() {
    MarshalerLookup lookup = new MarshalerLookup(config).searchBuiltins(false);
    SootMethod method = toSootClass(Foo4.class).getMethodByName("foo3");
    assertEquals(toSootClass(M2.class).getMethodByName("charSequenceToObject"), lookup.findMarshalerMethod(new MarshalSite(method)).getMethod());
    assertEquals(toSootClass(M2.class).getMethodByName("charSequenceToNative"), lookup.findMarshalerMethod(new MarshalSite(method, 0)).getMethod());
}
Also used : MarshalSite(org.robovm.compiler.MarshalerLookup.MarshalSite) SootMethod(soot.SootMethod) Test(org.junit.Test)

Example 38 with SootMethod

use of soot.SootMethod in project robovm by robovm.

the class MarshalerLookupTest method testFindMarshalerStructMemberPrimitiveArray2D.

@Test
public void testFindMarshalerStructMemberPrimitiveArray2D() {
    MarshalerLookup lookup = new MarshalerLookup(config).searchBuiltins(false);
    SootMethod getter = toSootClass(TestStruct.class).getMethodByName("getV3");
    SootMethod setter = toSootClass(TestStruct.class).getMethodByName("setV3");
    assertEquals(toSootClass(M2.class).getMethodByName("byteArray2DToObject"), lookup.findMarshalerMethod(new MarshalSite(getter)).getMethod());
    assertEquals(toSootClass(M2.class).getMethodByName("byteArray2DToNative"), lookup.findMarshalerMethod(new MarshalSite(setter, 0)).getMethod());
}
Also used : MarshalSite(org.robovm.compiler.MarshalerLookup.MarshalSite) SootMethod(soot.SootMethod) Test(org.junit.Test)

Example 39 with SootMethod

use of soot.SootMethod in project robovm by robovm.

the class ClassCompiler method getOverriddenMethods.

private Map<SootMethod, Set<SootMethod>> getOverriddenMethods(SootClass sc) {
    Map<SootMethod, Set<SootMethod>> result = new HashMap<>();
    for (SootMethod m : sc.getMethods()) {
        if (!m.isStatic() && !m.isPrivate() && !m.getName().equals("<init>")) {
            result.put(m, new HashSet<SootMethod>());
        }
    }
    findOverriddenSuperMethods(sc, sc, result);
    return result;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) SootMethod(soot.SootMethod)

Example 40 with SootMethod

use of soot.SootMethod in project robovm by robovm.

the class ClassCompiler method patchAsmWithFunctionSizes.

private static void patchAsmWithFunctionSizes(Config config, Clazz clazz, InputStream inStream, OutputStream outStream) throws IOException {
    String labelPrefix = config.getOs().getFamily() == OS.Family.darwin ? "_" : "";
    String localLabelPrefix = config.getOs().getFamily() == OS.Family.darwin ? "L" : ".L";
    Set<String> functionNames = new HashSet<String>();
    for (SootMethod method : clazz.getSootClass().getMethods()) {
        if (!method.isAbstract()) {
            String name = labelPrefix + Symbols.methodSymbol(method);
            functionNames.add(name);
        }
    }
    String infoStructLabel = labelPrefix + Symbols.infoStructSymbol(clazz.getInternalName());
    Pattern methodImplPattern = Pattern.compile("\\s*\\.(?:quad|long)\\s+\"?(" + Pattern.quote(labelPrefix + Symbols.methodSymbolPrefix(clazz.getInternalName())) + "[^\\s\"]+)\"?.*");
    BufferedReader in = null;
    BufferedWriter out = null;
    try {
        in = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));
        out = new BufferedWriter(new OutputStreamWriter(outStream, "UTF-8"));
        String line = null;
        String currentFunction = null;
        while ((line = in.readLine()) != null) {
            if (currentFunction == null) {
                out.write(line);
                out.write('\n');
                int colon = line.indexOf(':');
                if (colon != -1) {
                    String label = line.substring(0, colon);
                    if (label.startsWith("\"") && label.endsWith("\"")) {
                        label = label.substring(1, label.length() - 1);
                    }
                    if (functionNames.contains(label)) {
                        currentFunction = label;
                    } else if (label.equals(infoStructLabel)) {
                        break;
                    }
                }
            } else if (line.trim().equals(".cfi_endproc") || line.trim().startsWith(".section") || line.trim().startsWith(".globl")) {
                out.write("\"");
                out.write(localLabelPrefix);
                out.write(currentFunction);
                out.write("_end\":\n\n");
                currentFunction = null;
                out.write(line);
                out.write('\n');
            } else {
                out.write(line);
                out.write('\n');
            }
        }
        while ((line = in.readLine()) != null) {
            out.write(line);
            out.write('\n');
            Matcher matcher = methodImplPattern.matcher(line);
            if (matcher.matches()) {
                String functionName = matcher.group(1);
                if (functionNames.contains(functionName)) {
                    line = in.readLine();
                    if (line.contains(String.valueOf(DUMMY_METHOD_SIZE))) {
                        out.write("\t.long\t");
                        out.write("\"" + localLabelPrefix + functionName + "_end\" - \"" + functionName + "\"");
                        out.write('\n');
                    } else {
                        out.write(line);
                        out.write('\n');
                    }
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
    }
}
Also used : Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) SootMethod(soot.SootMethod) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet) BufferedWriter(java.io.BufferedWriter)

Aggregations

SootMethod (soot.SootMethod)82 Test (org.junit.Test)34 SootClass (soot.SootClass)30 MarshalSite (org.robovm.compiler.MarshalerLookup.MarshalSite)21 PrimType (soot.PrimType)15 RefType (soot.RefType)14 VoidType (soot.VoidType)13 SootMethodType (org.robovm.compiler.util.generic.SootMethodType)11 DoubleType (soot.DoubleType)11 FloatType (soot.FloatType)11 LongType (soot.LongType)11 ArrayList (java.util.ArrayList)9 BooleanType (soot.BooleanType)9 SootField (soot.SootField)8 Type (soot.Type)8 Body (soot.Body)7 RefLikeType (soot.RefLikeType)7 CompilerException (org.robovm.compiler.CompilerException)6 Unit (soot.Unit)6 MethodVisitor (org.objectweb.asm.MethodVisitor)5