Package soot

Examples of soot.SootClass


     * @param type The type to be checked.
     * @return True if the type is required.
     */
    public static boolean isRequired(Type type) {
        if (type instanceof RefType) {
            SootClass sootClass = ((RefType) type).getSootClass();

            if (isRequired(sootClass)) {
                return true;
            } else {
                return false;
View Full Code Here


     prune-level 1 analysis is called.
     @param classPath The classpath.
     @param className The name of the class.
     */
    private static void _pruneLevel1(String classPath, String className) {
        SootClass source = Scene.v().getSootClass(className);

        CallGraphPruner pruner = new CallGraphPruner(source);
        _requiredMethods = pruner.getReachableMethods();
        _requiredClasses = pruner.getReachableClasses();
        _requiredFields = pruner.getReachableFields();
View Full Code Here

        CodeFileGenerator cGenerator = new CodeFileGenerator();

        String code;
        boolean verbose = Options.v().getBoolean("verbose");

        SootClass sootClass = Scene.v().getSootClass(className);
        CNames.setup();

        // Make changes in the filename.
        String fileName = CNames.classNameToFileName(className);
View Full Code Here

        String code;

        Scene.v().loadClassAndSupport(className);

        SootClass sootClass = Scene.v().getSootClass(className);
        CNames.setup();

        // Make changes in the filename.
        String fileName = CNames.classNameToFileName(className);
View Full Code Here

     *  All other requests are ignored. Duplicate requests are also ignored.
     *  @param type The type.
     */
    protected void _updateRequiredTypes(Type type) {
        if (!_context.getDisableImports()) {
            SootClass source = null;

            if (type instanceof RefType) {
                source = ((RefType) type).getSootClass();
            } else if ((type instanceof ArrayType)
                    && (((ArrayType) type).baseType instanceof RefType)) {
View Full Code Here

    /** Generate code for a reference to a static field.
     *  @param v The static field reference.
     */
    public void caseStaticFieldRef(StaticFieldRef v) {
        SootField field = v.getField();
        SootClass className = field.getDeclaringClass();
        _push(CNames.classStructureNameOf(className) + ".classvars."
                + CNames.fieldNameOf(field));
        _context.addIncludeFile("\"" + CNames.includeFileNameOf(className)
                + "\"");
    }
View Full Code Here

     @param expression The instance invoke expression.
     */
    protected void _generateInstanceInvokeExpression(
            InstanceInvokeExpr expression) {
        SootMethod method = expression.getMethod();
        SootClass declaringClass = method.getDeclaringClass();

        // If the declaring class is an interface extending a method in
        // Object, then the first argument to non-static methods will be
        // the interface, not Object.
        if ((expression instanceof VirtualInvokeExpr)
View Full Code Here

        classList.add(Scene.v().getMainClass());

        StringBuffer sourcesList = new StringBuffer();

        for (Iterator sootClasses = classList.iterator(); sootClasses.hasNext();) {
            SootClass sootClass = (SootClass) sootClasses.next();

            // Determine the base of the source code file names.
            String fileName;

            /* FIXME: Changed this to enable code generation in correct
             * directory.
             if (!outDir.equals("")) {
             File outDirFile = new File(outDir);
             if (!outDirFile.isDirectory()) {
             outDirFile.mkdirs();
             }
             fileName = outDir + System.getProperty("file.separator");
             } else {
             fileName = "";
             }
             */
            fileName = CNames.classNameToFileName(sootClass.getName());

            //fileName += sootClass.getName();
            // FIXME: move these out of the loop?
            /*HeaderFileGenerator hGenerator = */new HeaderFileGenerator();

            /*CodeFileGenerator cGenerator = */new CodeFileGenerator();

            /*StubFileGenerator sGenerator = */new StubFileGenerator();
            CNames.setup();

            RequiredFileGenerator RFG = new RequiredFileGenerator();

            String classPath = Scene.v().getSootClassPath();
            System.out.println("CWriter: soot class path = " + classPath);

            // Options for fast minimal code generation.
            Options.v().put("pruneLevel", "1");
            Options.v().put("compileMode", "full");
            Options.v().put("verbose", "true");
            Options.v().put("runtimeDir", "../../runtime");

            //Options.v().put("gcDir", null);
            RFG.init(classPath, sootClass.getName());

            // Figure out if this is the main class
            System.out.println("Main file: " + mainFile);
            System.out.println("Class name:" + sootClass.getName());

            boolean isMainClass = false;
            MainFileGenerator mGenerator = null;

            // FIXME: Testing purposes.
            if (true) {
                //if (mainFile.equals(sootClass.getName())) {
                isMainClass = true;
                mGenerator = new MainFileGenerator();
            }

            //generate the .i.h, .h, and .c files
            System.out.println("Generating C code files for " + fileName);

            String code = null;

            /* FIXME: Remove this code.
             * Not needed because RequiredFileGenerator will take care of
             * it.

             code = sGenerator.generate(sootClass);
             FileHandler.write(fileName
             + StubFileGenerator.stubFileNameSuffix(),
             code);
             code = hGenerator.generate(sootClass);
             FileHandler.write(fileName + ".h", code);
             code = cGenerator.generate(sootClass);
             FileHandler.write(fileName + ".c", code);
             sourcesList.append(" " + fileName + ".c");
             */

            // Generate all required files, including the files for the
            // main class.
            try {
                RequiredFileGenerator.generateTransitiveClosureOf(classPath,
                        sootClass.getName());
            } catch (IOException exception) {
                throw new RuntimeException("Could not generate transitive "
                        + "closure during required file generation");
            }

            // Generate a main file, containing a C main function,
            // if this is the main class.
            if (isMainClass) {
                code = mGenerator.generate(sootClass);
                FileHandler.write(fileName + "_main.c", code);
            }

            // Generate a makefile.
            MakeFileGenerator.generateMakeFile(classPath, sootClass.getName());

            System.out.println("Done generating C code files for " + fileName);
        }

        MakefileWriter.addMakefileSubstitution("@cFiles@", sourcesList
View Full Code Here

     @param type The type.
     *  Same as the corresponding method in CodeGenerator
     */
    protected void _updateRequiredTypes(Type type) {
        if (!_context.getDisableImports()) {
            SootClass source = null;

            if (type instanceof RefType) {
                source = ((RefType) type).getSootClass();
            } else if ((type instanceof ArrayType)
                    && (((ArrayType) type).baseType instanceof RefType)) {
View Full Code Here

                    // Note: The control path that causes this to be
                    // null should never occur in practice.
                    return;
                }

                SootClass baseClass = ((RefType) type).getSootClass();

                // FIXME: match better.
                // If we are invoking a method on a token, then...
                if (SootUtilities.derivesFrom(baseClass,
                        PtolemyUtilities.tokenClass)) {
                    if (r.getMethod().equals(
                            PtolemyUtilities.arrayTokenConstructor)) {
                        // The arrayToken constructor depends on the type
                        // of its constructor argument.
                        //     System.out.println("found array invoke: " + r);
                        //     System.out.println("Argument type is : " + in.get(r.getArg(0)));
                        ptolemy.data.type.Type argType = (ptolemy.data.type.Type) in
                                .get(r.getArg(0));

                        if (argType == null) {
                            argType = BaseType.UNKNOWN;
                        }

                        out.put(r.getBase(), new ArrayType(argType));
                    } else if (r.getMethod().equals(
                            PtolemyUtilities.arrayTokenWithTypeConstructor)) {
                        // The arrayToken constructor depends on the type
                        // of its constructor argument.
                        //     System.out.println("found array invoke: " + r);
                        //     System.out.println("Argument type is : " + in.get(r.getArg(0)));

                        ptolemy.data.type.Type argType = (ptolemy.data.type.Type) in
                                .get(r.getArg(0));

                        if (argType == null) {
                            argType = BaseType.UNKNOWN;
                        }

                        out.put(r.getBase(), new ArrayType(argType));
                    }
                }
            }
        } else if (stmt instanceof AssignStmt) {
            Value leftOp = ((AssignStmt) stmt).getLeftOp();

            if (!_isTokenType(leftOp.getType())) {
                //     System.out.println("type " + leftOp.getType()
                //             + " is not a token");
                return;
            }

            //  System.out.println("from " + in);
            Value rightOp = ((AssignStmt) stmt).getRightOp();

            if (rightOp instanceof StaticInvokeExpr) {
                StaticInvokeExpr r = (StaticInvokeExpr) rightOp;

                if (r.getMethod().equals(PtolemyUtilities.arraycopyMethod)) {
                    out.put(r.getArg(0), in.get(r.getArg(2)));
                }
            } else if (rightOp instanceof InstanceInvokeExpr
                    || rightOp instanceof InterfaceInvokeExpr) {
                InstanceInvokeExpr r = (InstanceInvokeExpr) rightOp;
                String methodName = r.getMethod().getName();

                Type type = r.getBase().getType();

                //   System.out.println("baseType = " + type);
                //  System.out.println("methodName = " + methodName);
                if (type instanceof NullType) {
                    // Note: The control path that causes this to be
                    // null should never occur in practice.
                    return;
                }

                SootClass baseClass = ((RefType) type).getSootClass();

                // FIXME: match better.
                // If we are invoking a method on a token, then...
                if (SootUtilities.derivesFrom(baseClass,
                        PtolemyUtilities.tokenClass)) {
                    if (methodName.equals("one") || methodName.equals("zero")
                            || methodName.equals("not")
                            || methodName.equals("bitwiseNot")
                            || methodName.equals("leftShift")
                            || methodName.equals("rightShift")
                            || methodName.equals("logicalRightShift")
                            || methodName.equals("pow")) {
                        // The returned type must be equal to the type
                        // we are calling the method on.
                        _updateTypeInAssignment(leftOp, in.get(r.getBase()),
                                out);
                    } else if (methodName.equals("add")
                            || methodName.equals("addReverse")
                            || methodName.equals("subtract")
                            || methodName.equals("subtractReverse")
                            || methodName.equals("multiply")
                            || methodName.equals("multiplyReverse")
                            || methodName.equals("divide")
                            || methodName.equals("divideReverse")
                            || methodName.equals("modulo")
                            || methodName.equals("moduloReverse")
                            || methodName.equals("bitwiseAnd")
                            || methodName.equals("bitwiseOr")
                            || methodName.equals("bitwiseXor")) {
                        //                         System.out.println("methodName = " + methodName);
                        //                         System.out.println("r.getBase() = " + r.getBase());
                        //                         System.out.println("r.getArg(0) = " + r.getArg(0));
                        //                         System.out.println("type(r.getBase()) = " + in.get(r.getBase()));
                        //                         System.out.println("type(r.getArg(0)) = " + in.get(r.getArg(0)));
                        ptolemy.data.type.Type baseType = (ptolemy.data.type.Type) in
                                .get(r.getBase());
                        ptolemy.data.type.Type argType = (ptolemy.data.type.Type) in
                                .get(r.getArg(0));

                        if ((baseType == null) || (argType == null)) {
                            out.put(leftOp, null);
                        } else {
                            _updateTypeInAssignment(leftOp, TypeLattice
                                    .lattice().leastUpperBound(baseType,
                                            argType), out);
                        }
                    } else if (methodName.equals("convert")) {
                        // The return rightOp type is equal to the base type.
                        // The first argument type is less than or equal to the base type.
                        _updateTypeInAssignment(leftOp, in.get(r.getBase()),
                                out);
                    } else if (methodName.equals("getElement")
                            || methodName.equals("arrayValue")) {
                        ptolemy.data.type.Type arrayType = (ptolemy.data.type.Type) in
                                .get(r.getBase());

                        if ((arrayType != null)
                                && arrayType instanceof ArrayType) {
                            _updateTypeInAssignment(leftOp,
                                    ((ArrayType) arrayType).getElementType(),
                                    out);
                        }
                    } else if (methodName.equals("getElementAsToken")) {
                        ptolemy.data.type.Type matrixType = (ptolemy.data.type.Type) in
                                .get(r.getBase());

                        if ((matrixType != null)
                                && matrixType instanceof MatrixType) {
                            _updateTypeInAssignment(leftOp,
                                    ((MatrixType) matrixType).getElementType(),
                                    out);
                        }
                    } else if (methodName.equals("absolute")) {
                        // Return the same as the input type, unless complex,
                        // in which case, return double.
                        ptolemy.data.type.Type inType = (ptolemy.data.type.Type) in
                                .get(r.getBase());

                        if (inType.equals(BaseType.COMPLEX)) {
                            _updateTypeInAssignment(leftOp, BaseType.DOUBLE,
                                    out);
                        } else {
                            _updateTypeInAssignment(leftOp, inType, out);
                        }
                    }
                } else if (SootUtilities.derivesFrom(baseClass,
                        PtolemyUtilities.componentPortClass)) {
                    // If we are invoking a method on a port.
                    TypedIOPort port = (TypedIOPort) _namedObjAnalysis
                            .getObject((Local) r.getBase());

                    //System.out.println("port for " + r.getBase() + " = " + port);
                    if (methodName.equals("broadcast")) {
                        // The type of the argument must be less than the
                        // type of the port.
                    } else if (methodName.equals("get")) {
                        // The port here may be null if the model does not
                        // actually contain the port...  This happens, for
                        // instance, in MathFunction
                        if (port != null) {
                            _updateTypeInAssignment(leftOp, port.getType(), out);
                        }
                    } else if (methodName.equals("send")) {
                        if (r.getArgCount() == 3) {
                            // The type of the argument must be less than the
                            // type of the port.
                            //r.getArg(1));
                        } else if (r.getArgCount() == 2) {
                            // The type of the argument must be less than the
                            // type of the port.
                            //            r.getArg(1));
                        }
                    }
                } else if (SootUtilities.derivesFrom(baseClass,
                        PtolemyUtilities.attributeClass)) {
                    // If we are invoking a method on a parameter.
                    Attribute attribute = (Attribute) _namedObjAnalysis
                            .getObject((Local) r.getBase());

                    if (attribute == null) {
                        // A method invocation with a null base is bogus,
                        // so don't create a type constraint.
                    }

                    if (attribute instanceof Variable) {
                        Variable parameter = (Variable) attribute;

                        if (methodName.equals("setToken")) {
                            // The type of the argument must be less than the
                            // type of the parameter.
                            // r.getArg(0));
                        } else if (methodName.equals("getToken")) {
                            // Return the type of the parameter.
                            _updateTypeInAssignment(leftOp,
                                    parameter.getType(), out);
                        }
                    }
                }
            } else if (rightOp instanceof ArrayRef) {
                //  System.out.println("arrayRef stmt = " + stmt);
                //                 System.out.println("right type = " + in.get(((ArrayRef)rightOp).getBase()));
                _updateTypeInAssignment(leftOp, in.get(((ArrayRef) rightOp)
                        .getBase()), out);
            } else if (rightOp instanceof CastExpr) {
                CastExpr castExpr = (CastExpr) rightOp;
                Type type = castExpr.getType();

                // FIXME: what if downcast???
                /*RefType tokenType =*/PtolemyUtilities.getBaseTokenType(type);

                //       System.out.println("castType = " + tokenType);
                //                 System.out.println("castOp = " + castExpr.getOp());
                //                 System.out.println("currentType = " + in.get(castExpr.getOp()));
                //if (tokenType != null) {
                _updateTypeInAssignment(leftOp, in.get(castExpr.getOp()), out);

                // } else {
                // Otherwise there is nothing to be done.
                //}
            } else if (rightOp instanceof Local) {
                Local local = (Local) rightOp;

                _updateTypeInAssignment(leftOp, in.get(local), out);
            } else if (rightOp instanceof NewExpr) {
                NewExpr newExpr = (NewExpr) rightOp;
                RefType type = newExpr.getBaseType();
                SootClass castClass = type.getSootClass();

                // If we are creating a Token type...
                if (SootUtilities.derivesFrom(castClass,
                        PtolemyUtilities.tokenClass)) {
                    // Then the rightOp of the expression is the type of the
View Full Code Here

TOP

Related Classes of soot.SootClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.