Search in sources :

Example 1 with Interval

use of com.jopdesign.dfa.analyses.Interval in project jop by jop-devel.

the class AllocationWcetModel method getArrayBound.

private long getArrayBound(ExecutionContext context, InstructionHandle ih, int index) {
    int srcLine = context.getMethodInfo().getCode().getLineNumberTable().getSourceLine(ih.getPosition());
    // get annotated size
    LoopBound annotated = null;
    try {
        SourceAnnotations annots = project.getAnnotations(context.getMethodInfo().getClassInfo());
        annotated = annots.annotationsForLine(srcLine);
        if (annotated == null) {
            WCETTool.logger.info("No annotated bound for array at " + context + ":" + srcLine);
        }
    } catch (Exception exc) {
        // TODO: anything else to do?
        WCETTool.logger.warn("Problem reading annotated bound for array at " + context + ":" + srcLine, exc);
    }
    // get analyzed size
    Interval analyzed = null;
    Interval[] sizes = null;
    if (project.getDfaLoopBounds() != null) {
        sizes = project.getDfaLoopBounds().getArraySizes(ih, context.getCallString());
    }
    if (sizes == null) {
        WCETTool.logger.info("No DFA available for array at " + context + ":" + srcLine);
    } else {
        analyzed = sizes[index];
        if (analyzed == null) {
            WCETTool.logger.info("No DFA bound for array at " + context + ":" + srcLine);
        }
    }
    // compute which bound to use
    if (analyzed != null && analyzed.hasUb()) {
        if (annotated != null) {
            if (annotated.getUpperBound(context) > analyzed.getUb()) {
                WCETTool.logger.warn("DFA bound smaller than annotated bound for array at " + context + ":" + srcLine);
            }
            if (annotated.getUpperBound(context) < analyzed.getUb()) {
                WCETTool.logger.warn("DFA bound larger than annotated bound for array at " + context + ":" + srcLine);
            }
            if (annotated.getUpperBound(context) == analyzed.getUb()) {
                WCETTool.logger.info("DFA bound equals annotated bound for array at " + context + ":" + srcLine);
            }
            return Math.max(annotated.getUpperBound(context), analyzed.getUb());
        } else {
            return analyzed.getUb();
        }
    } else {
        if (annotated != null) {
            return annotated.getUpperBound(context);
        } else {
            WCETTool.logger.error("Cannot determine cost of unbounded array " + context.getMethodInfo().getFQMethodName() + ":" + srcLine + ".\nApproximating with 1024 words, but result is not safe anymore.");
            return 1024;
        }
    }
}
Also used : LoopBound(com.jopdesign.common.code.LoopBound) SourceAnnotations(com.jopdesign.wcet.annotations.SourceAnnotations) Interval(com.jopdesign.dfa.analyses.Interval)

Aggregations

LoopBound (com.jopdesign.common.code.LoopBound)1 Interval (com.jopdesign.dfa.analyses.Interval)1 SourceAnnotations (com.jopdesign.wcet.annotations.SourceAnnotations)1