Search in sources :

Example 16 with ContextMap

use of com.jopdesign.dfa.framework.ContextMap in project jop by jop-devel.

the class CallStringReceiverTypes method initial.

public ContextMap<CallString, Set<TypeMapping>> initial(InstructionHandle stmt) {
    ContextMap<CallString, Set<TypeMapping>> init = new ContextMap<CallString, Set<TypeMapping>>(new Context(), new LinkedHashMap<CallString, Set<TypeMapping>>());
    Set<TypeMapping> s = new LinkedHashSet<TypeMapping>();
    s.add(new TypeMapping("com.jopdesign.io.IOFactory.sp", "com.jopdesign.io.SerialPort"));
    s.add(new TypeMapping("com.jopdesign.io.IOFactory.sys", "com.jopdesign.io.SysDevice"));
    init.put(CallString.EMPTY, s);
    return init;
}
Also used : Context(com.jopdesign.dfa.framework.Context) LinkedHashSet(java.util.LinkedHashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ContextMap(com.jopdesign.dfa.framework.ContextMap) CallString(com.jopdesign.common.code.CallString)

Example 17 with ContextMap

use of com.jopdesign.dfa.framework.ContextMap in project jop by jop-devel.

the class LoopBounds method copyResults.

@Override
public void copyResults(MethodInfo newContainer, Map<InstructionHandle, InstructionHandle> newHandles) {
    for (Map.Entry<InstructionHandle, InstructionHandle> entry : newHandles.entrySet()) {
        InstructionHandle oldHandle = entry.getKey();
        InstructionHandle newHandle = entry.getValue();
        if (newHandle == null)
            continue;
        // TODO support updating the callstrings too
        // TODO this does NOT update stackPtr,.. in the new context!
        ContextMap<CallString, Pair<ValueMapping, ValueMapping>> value = bounds.get(oldHandle);
        if (value != null)
            bounds.put(newHandle, value.copy(newContainer));
        ContextMap<CallString, Interval> value1 = arrayIndices.get(oldHandle);
        if (value1 != null)
            arrayIndices.put(newHandle, value1.copy(newContainer));
        ContextMap<CallString, Integer> value2 = scopes.get(oldHandle);
        if (value2 != null)
            scopes.put(newHandle, value2.copy(newContainer));
        ContextMap<CallString, Interval[]> value3 = sizes.get(oldHandle);
        if (value3 != null)
            sizes.put(newHandle, value3.copy(newContainer));
        ContextMap<CallString, Set<FlowEdge>> old = infeasibles.get(oldHandle);
        if (old != null) {
            Map<CallString, Set<FlowEdge>> map = new LinkedHashMap<CallString, Set<FlowEdge>>(old.size());
            for (CallString cs : old.keySet()) {
                Set<FlowEdge> newSet = new LinkedHashSet<FlowEdge>();
                for (FlowEdge edge : old.get(cs)) {
                    InstructionHandle newHead = newHandles.get(edge.getHead());
                    InstructionHandle newTail = newHandles.get(edge.getTail());
                    if (newHead != null && newTail != null) {
                        Context ctx = new Context(edge.getContext());
                        ctx.setMethodInfo(newContainer);
                        newSet.add(new FlowEdge(newTail, newHead, edge.getType(), ctx));
                    }
                }
                map.put(cs, newSet);
            }
            Context c = old.getContext();
            c.setMethodInfo(newContainer);
            ContextMap<CallString, Set<FlowEdge>> edges = new ContextMap<CallString, Set<FlowEdge>>(c, map);
            infeasibles.put(newHandle, edges);
        }
    }
}
Also used : FlowEdge(com.jopdesign.dfa.framework.FlowEdge) SerializedFlowEdge(com.jopdesign.dfa.framework.FlowEdge.SerializedFlowEdge) LinkedHashSet(java.util.LinkedHashSet) Context(com.jopdesign.dfa.framework.Context) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ContextMap(com.jopdesign.dfa.framework.ContextMap) CallString(com.jopdesign.common.code.CallString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ContextMap(com.jopdesign.dfa.framework.ContextMap) Pair(com.jopdesign.common.graphutils.Pair)

Example 18 with ContextMap

use of com.jopdesign.dfa.framework.ContextMap in project jop by jop-devel.

the class SymbolicPointsTo method initial.

public ContextMap<CallString, SymbolicAddressMap> initial(InstructionHandle stmt) {
    ContextMap<CallString, SymbolicAddressMap> retval = new ContextMap<CallString, SymbolicAddressMap>(new Context(), new HashMap<CallString, SymbolicAddressMap>());
    SymbolicAddressMap init = new SymbolicAddressMap(bsFactory);
    // Add symbolic stack names
    int stackPtr = 0;
    if (!entryMethod.isStatic()) {
        init.putStack(stackPtr++, bsFactory.singleton(SymbolicAddress.rootAddress("$this")));
    }
    String[] args = entryMethod.getArgumentNames();
    for (int i = 0; i < args.length; i++) {
        Type ty = entryMethod.getArgumentType(i);
        if (ty instanceof ReferenceType) {
            init.putStack(stackPtr, bsFactory.singleton(SymbolicAddress.rootAddress("$" + args[i])));
        }
        stackPtr += ty.getSize();
    }
    retval.put(initialCallString, init);
    return retval;
}
Also used : Context(com.jopdesign.dfa.framework.Context) ReferenceType(org.apache.bcel.generic.ReferenceType) Type(org.apache.bcel.generic.Type) CallString(com.jopdesign.common.code.CallString) ContextMap(com.jopdesign.dfa.framework.ContextMap) ReferenceType(org.apache.bcel.generic.ReferenceType) CallString(com.jopdesign.common.code.CallString)

Example 19 with ContextMap

use of com.jopdesign.dfa.framework.ContextMap in project jop by jop-devel.

the class SymbolicPointsTo method join.

public ContextMap<CallString, SymbolicAddressMap> join(ContextMap<CallString, SymbolicAddressMap> s1, ContextMap<CallString, SymbolicAddressMap> s2) {
    if (s1 == null) {
        return new ContextMap<CallString, SymbolicAddressMap>(s2);
    }
    if (s2 == null) {
        return new ContextMap<CallString, SymbolicAddressMap>(s1);
    }
    // create empty context map, with s1's context
    ContextMap<CallString, SymbolicAddressMap> result = new ContextMap<CallString, SymbolicAddressMap>(new Context(s1.getContext()), new HashMap<CallString, SymbolicAddressMap>());
    // add both context maps. Note that entries from s2 overwrite those from the s1
    result.putAll(s1);
    result.putAll(s2);
    // a and b are the DF results for the respectively active contexts
    SymbolicAddressMap a = s1.get(s1.getContext().callString);
    SymbolicAddressMap b = s2.get(s2.getContext().callString);
    SymbolicAddressMap merged = a.clone();
    merged.join(b);
    result.put(s2.getContext().callString, merged);
    if (result.getContext().stackPtr < 0) {
        result.getContext().stackPtr = s2.getContext().stackPtr;
    }
    if (result.getContext().syncLevel < 0) {
        result.getContext().syncLevel = s2.getContext().syncLevel;
    }
    result.getContext().threaded = Context.isThreaded();
    return result;
}
Also used : Context(com.jopdesign.dfa.framework.Context) ContextMap(com.jopdesign.dfa.framework.ContextMap) CallString(com.jopdesign.common.code.CallString)

Aggregations

ContextMap (com.jopdesign.dfa.framework.ContextMap)19 CallString (com.jopdesign.common.code.CallString)18 Context (com.jopdesign.dfa.framework.Context)16 Set (java.util.Set)10 InstructionHandle (org.apache.bcel.generic.InstructionHandle)10 LinkedHashSet (java.util.LinkedHashSet)9 DFATool (com.jopdesign.dfa.DFATool)8 LinkedHashMap (java.util.LinkedHashMap)7 MethodInfo (com.jopdesign.common.MethodInfo)6 Map (java.util.Map)6 ReferenceType (org.apache.bcel.generic.ReferenceType)4 Type (org.apache.bcel.generic.Type)4 AppInfoError (com.jopdesign.common.misc.AppInfoError)3 GETFIELD (org.apache.bcel.generic.GETFIELD)3 GETSTATIC (org.apache.bcel.generic.GETSTATIC)3 Instruction (org.apache.bcel.generic.Instruction)3 LDC (org.apache.bcel.generic.LDC)3 LoadInstruction (org.apache.bcel.generic.LoadInstruction)3 PUTFIELD (org.apache.bcel.generic.PUTFIELD)3 PUTSTATIC (org.apache.bcel.generic.PUTSTATIC)3