Search in sources :

Example 6 with AppSetup

use of com.jopdesign.common.AppSetup in project jop by jop-devel.

the class WCETPreprocess method main.

public static void main(String[] args) {
    AppSetup setup = new AppSetup();
    AppInfo ai = setup.initAndLoad(args, false, false, true);
    preprocess(ai);
    // dump the methods
    //	try {
    //		ai.iterate(new Dump(ai, new PrintWriter(new FileOutputStream(ai.outFile+"/dump.txt"))));
    //	} catch (FileNotFoundException e) {
    //		e.printStackTrace();
    //	}
    // write the class files
    setup.writeClasses();
}
Also used : AppSetup(com.jopdesign.common.AppSetup) AppInfo(com.jopdesign.common.AppInfo)

Example 7 with AppSetup

use of com.jopdesign.common.AppSetup in project jop by jop-devel.

the class UppAalAnalysis method main.

public static void main(String[] args) {
    // We set a different output path for this tool if invoked by cmdline
    // Note that WCETTool could also override defaults, but we do not want to change the
    // default value of outdir if WCETTool is invoked from another tool
    Properties defaultProps = new Properties();
    defaultProps.put("outdir", "java/target/wcet/${projectname}");
    AppSetup setup = new AppSetup(defaultProps, false);
    setup.setVersionInfo("1.0 [deprecated]");
    // We do not load a config file automatically, user has to specify it explicitly to avoid
    // unintentional misconfiguration
    //setup.setConfigFilename(CONFIG_FILE_NAME);
    setup.setUsageInfo("UppAllAnalysis", "UppAll WCET Analysis");
    WCETTool wcetTool = new WCETTool();
    DFATool dfaTool = new DFATool();
    setup.registerTool("dfa", dfaTool, true, false);
    setup.registerTool("wcet", wcetTool);
    @SuppressWarnings("unused") AppInfo appInfo = setup.initAndLoad(args, true, false, false);
    if (setup.useTool("dfa")) {
        wcetTool.setDfaTool(dfaTool);
    }
    ExecHelper exec = new ExecHelper(setup.getConfig(), tlLogger);
    exec.dumpConfig();
    UppAalAnalysis inst = new UppAalAnalysis(wcetTool);
    /* run */
    if (!inst.run(exec))
        exec.bail("UppAal translation failed");
    tlLogger.info("UppAal translation finished");
}
Also used : DFATool(com.jopdesign.dfa.DFATool) AppSetup(com.jopdesign.common.AppSetup) Properties(java.util.Properties) AppInfo(com.jopdesign.common.AppInfo)

Example 8 with AppSetup

use of com.jopdesign.common.AppSetup in project jop by jop-devel.

the class HashTest method main.

public static void main(String[] args) {
    TestFramework test = new TestFramework();
    AppSetup setup = test.setupAppSetup();
    AppInfo appInfo = test.setupAppInfo("common.code.HashTest", false);
    ClassInfo testClass = appInfo.loadClass("common.TestFramework");
    MethodInfo mainMethod = appInfo.getMainMethod();
    MethodCode code = mainMethod.getCode();
    InstructionHandle[] ih = code.getInstructionList().getInstructionHandles();
    InvokeSite i1 = code.getInvokeSite(ih[1]);
    InvokeSite i2 = code.getInvokeSite(ih[2]);
    InvokeSite i3 = code.getInvokeSite(ih[3]);
    InvokeSite i11 = code.getInvokeSite(ih[1]);
    check(i1 == i11);
    CallString c1 = new CallString(i1);
    CallString c2 = new CallString(i2);
    CallString c11 = new CallString(i1);
    check(c1.equals(c11));
    check(!c1.equals(c2));
    ExecutionContext e1 = new ExecutionContext(mainMethod, c1);
    ExecutionContext e2 = new ExecutionContext(mainMethod, c2);
    ExecutionContext e11 = new ExecutionContext(mainMethod, c11);
    check(e1.equals(e11));
    check(!e1.equals(e2));
    // TODO put stuff into maps, check contains() and get()
    // modify instruction list, check if everything still works
    InstructionList il = code.getInstructionList();
    il.insert(new ILOAD(0));
    il.insert(ih[2], new ILOAD(1));
    ih = il.getInstructionHandles();
    InvokeSite i12 = code.getInvokeSite(ih[2]);
    InvokeSite i22 = code.getInvokeSite(ih[4]);
    check(i12 == i1);
    check(i22 == i2);
    check(e1.equals(e11));
    check(!e1.equals(e2));
    il.setPositions();
    check(c1.equals(c11));
    check(!c1.equals(c2));
    check(e1.equals(e11));
    check(!e1.equals(e2));
}
Also used : InstructionList(org.apache.bcel.generic.InstructionList) ILOAD(org.apache.bcel.generic.ILOAD) InstructionHandle(org.apache.bcel.generic.InstructionHandle) AppInfo(com.jopdesign.common.AppInfo) TestFramework(com.jopdesign.common.TestFramework) AppSetup(com.jopdesign.common.AppSetup) MethodInfo(com.jopdesign.common.MethodInfo) MethodCode(com.jopdesign.common.MethodCode) ClassInfo(com.jopdesign.common.ClassInfo)

Example 9 with AppSetup

use of com.jopdesign.common.AppSetup in project jop by jop-devel.

the class SegmentTest method main.

public static void main(String[] args) {
    TestFramework testFramework = new TestFramework();
    AppSetup setup = testFramework.setupAppSetup("java/tools/test/test/cg1.zip", null);
    AppInfo appInfo = testFramework.setupAppInfo("wcet.devel.CallGraph1.run", true);
    SegmentTest testInst = new SegmentTest();
    testInst.appInfo = appInfo;
    MethodInfo mainMethod = appInfo.getMainMethod();
    /* count total number of CFG nodes */
    SuperGraph superGraph = new SuperGraph(testInst, testInst.getFlowGraph(mainMethod), 2);
    Segment segment = Segment.methodSegment(mainMethod, CallString.EMPTY, testInst, 2, superGraph.getInfeasibleEdgeProvider());
    int count = 0;
    for (ContextCFG cgNode : superGraph.getCallGraphNodes()) {
        try {
            cgNode.getCfg().exportDOT(new File("/tmp/cfg-" + cgNode.getCfg().getMethodInfo().getClassName() + "_" + cgNode.getCfg().getMethodInfo().getShortName() + ".dot"));
        } catch (IOException e) {
        }
        count += cgNode.getCfg().vertexSet().size();
    }
    checkEquals("[Segment 1] Expected node count", (count - 2), Iterators.size(segment.getNodes()));
    try {
        segment.exportDOT(new File("/tmp/cg1-segment.dot"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    /* root */
    ContextCFG root = superGraph.getRootNode();
    /* Build a segment cuts all invokes in those methods invoked by run() */
    Segment segment2;
    /* root entries */
    Set<SuperGraphEdge> entries = new HashSet<SuperGraphEdge>();
    Iterators.addAll(entries, superGraph.liftCFGEdges(root, root.getCfg().outgoingEdgesOf(root.getCfg().getEntry())));
    Set<SuperGraphEdge> exits = new HashSet<SuperGraphEdge>();
    int cfgNodeCandidateCount = root.getCfg().vertexSet().size();
    /* find callees */
    for (SuperEdge superEdge : superGraph.getCallGraph().outgoingEdgesOf(root)) {
        if (!(superEdge instanceof SuperInvokeEdge))
            continue;
        ContextCFG callee1 = superGraph.getCallGraph().getEdgeTarget(superEdge);
        cfgNodeCandidateCount += callee1.getCfg().vertexSet().size();
        /* find all edges from invoke nodes */
        for (CFGNode cfgNode : callee1.getCfg().vertexSet()) {
            if (cfgNode instanceof InvokeNode) {
                Iterators.addAll(exits, superGraph.outgoingEdgesOf(new SuperGraphNode(callee1, cfgNode)));
            }
        }
    }
    segment2 = new Segment(superGraph, entries, exits);
    exits = segment2.getExitEdges();
    /* reachable exits */
    try {
        segment2.exportDOT(new File("/tmp/cg1-segment2.dot"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    checkEquals("[Segment 2] Expected node count", 14, Iterators.size(segment2.getNodes()) + 2);
    checkLessEqual("[Segment 2] Expected node count <= |root + directly invoked|", Iterators.size(segment2.getNodes()) + 2, cfgNodeCandidateCount);
    /* Another segment, with entries the exits of the last segment, and exits all invokes in methods the entries */
    Segment segment3;
    entries = segment2.getExitEdges();
    exits = new HashSet<SuperGraphEdge>();
    cfgNodeCandidateCount = 0;
    for (SuperGraphEdge superEdge : entries) {
        SuperGraphNode node1 = superEdge.getTarget();
        for (SuperEdge superEdge2 : superGraph.getCallGraph().outgoingEdgesOf(node1.getContextCFG())) {
            if (!(superEdge2 instanceof SuperInvokeEdge))
                continue;
            ContextCFG callee2 = superGraph.getCallGraph().getEdgeTarget(superEdge2);
            /* find all edges from invoke nodes */
            for (CFGNode cfgNode : callee2.getCfg().vertexSet()) {
                if (cfgNode instanceof InvokeNode) {
                    Iterators.addAll(exits, superGraph.outgoingEdgesOf(new SuperGraphNode(callee2, cfgNode)));
                }
            }
        }
    }
    segment3 = new Segment(superGraph, entries, exits);
    try {
        segment3.exportDOT(new File("/tmp/cg1-segment3.dot"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    checkEquals("[Segment 2] 3 exits", 3, segment2.getExitEdges().size());
    checkEquals("[Segment 3] 3 entries", 3, segment3.getEntryEdges().size());
    checkEquals("[Segment 3] 4 exits", 4, segment3.getExitEdges().size());
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) IOException(java.io.IOException) SuperEdge(com.jopdesign.common.code.SuperGraph.SuperEdge) AppInfo(com.jopdesign.common.AppInfo) SuperInvokeEdge(com.jopdesign.common.code.SuperGraph.SuperInvokeEdge) TestFramework(com.jopdesign.common.TestFramework) ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) InvokeNode(com.jopdesign.common.code.ControlFlowGraph.InvokeNode) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) AppSetup(com.jopdesign.common.AppSetup) MethodInfo(com.jopdesign.common.MethodInfo) File(java.io.File) HashSet(java.util.HashSet)

Example 10 with AppSetup

use of com.jopdesign.common.AppSetup in project jop by jop-devel.

the class WcetAppInfoTest method main.

/*
     * DEMO
     * ~~~~
     */
/* small demo using the class loader */
public static void main(String[] argv) {
    AppSetup appSetup = new AppSetup();
    WCETTool wcetTool = new WCETTool();
    appSetup.registerTool("wcet", wcetTool);
    Config config = appSetup.getConfig();
    config.setOption(ProjectConfig.PROJECT_NAME, "typegraph");
    AppInfo appInfo = appSetup.initAndLoad(argv, false, false, false);
    ProjectConfig pConfig = wcetTool.getProjectConfig();
    try {
        System.out.println("Classloader Demo: " + pConfig.getAppClassName());
        String rootClass = pConfig.getAppClassName();
        String rootPkg = rootClass.substring(0, rootClass.lastIndexOf("."));
        ClassInfo ci = appInfo.getClassInfo(pConfig.getAppClassName());
        System.out.println("Source file: " + ci.getSourceFileName());
        System.out.println("Root class: " + ci.toString());
        {
            System.out.println("Writing type graph to " + pConfig.getOutFile("typegraph.png"));
            File dotFile = pConfig.getOutFile("typegraph.dot");
            FileWriter dotWriter = new FileWriter(dotFile);
            // FIXME TypeGraph is not used anymore, export ClassInfo/.. graph
            TypeGraph typeGraph = new TypeGraph();
            typeGraph.exportDOT(dotWriter, rootPkg);
            dotWriter.close();
            InvokeDot.invokeDot(wcetTool.getConfig(), dotFile, pConfig.getOutFile("typegraph.png"));
        }
        SuperGraph sg = new SuperGraph(appInfo, pConfig.getTargetMethodInfo().getCode().getControlFlowGraph(false), 0);
        {
            System.out.println("Writing supergraph graph to " + pConfig.getOutFile("supergraph.png"));
            File dotFile = pConfig.getOutFile("callgraph.dot");
            sg.exportDOT(dotFile);
            InvokeDot.invokeDot(wcetTool.getConfig(), dotFile, pConfig.getOutFile("supergraph.png"));
        }
        CallGraph cg = appInfo.buildCallGraph(false);
        {
            System.out.println("Writing call graph to " + pConfig.getOutFile("callgraph.png"));
            File dotFile = pConfig.getOutFile("callgraph.dot");
            FileWriter dotWriter = new FileWriter(dotFile);
            cg.exportDOT(dotWriter);
            dotWriter.close();
            InvokeDot.invokeDot(wcetTool.getConfig(), dotFile, pConfig.getOutFile("callgraph.png"));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Config(com.jopdesign.common.config.Config) SuperGraph(com.jopdesign.common.code.SuperGraph) FileWriter(java.io.FileWriter) TypeGraph(com.jopdesign.common.graphutils.TypeGraph) IOException(java.io.IOException) IOException(java.io.IOException) AppInfo(com.jopdesign.common.AppInfo) CallGraph(com.jopdesign.common.code.CallGraph) AppSetup(com.jopdesign.common.AppSetup) File(java.io.File) ClassInfo(com.jopdesign.common.ClassInfo)

Aggregations

AppSetup (com.jopdesign.common.AppSetup)10 AppInfo (com.jopdesign.common.AppInfo)7 IOException (java.io.IOException)4 MethodInfo (com.jopdesign.common.MethodInfo)3 TestFramework (com.jopdesign.common.TestFramework)3 DFATool (com.jopdesign.dfa.DFATool)3 File (java.io.File)3 ClassInfo (com.jopdesign.common.ClassInfo)2 FileWriter (java.io.FileWriter)2 Properties (java.util.Properties)2 MethodCode (com.jopdesign.common.MethodCode)1 CallGraph (com.jopdesign.common.code.CallGraph)1 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)1 InvokeNode (com.jopdesign.common.code.ControlFlowGraph.InvokeNode)1 SuperGraph (com.jopdesign.common.code.SuperGraph)1 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)1 SuperEdge (com.jopdesign.common.code.SuperGraph.SuperEdge)1 SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)1 SuperGraphNode (com.jopdesign.common.code.SuperGraph.SuperGraphNode)1 SuperInvokeEdge (com.jopdesign.common.code.SuperGraph.SuperInvokeEdge)1