use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class CallStringReceiverTypes method initialize.
public void initialize(MethodInfo mi, Context context) {
String sig = mi.getFQMethodName();
threads.put(sig, new ContextMap<CallString, Set<TypeMapping>>(context, new LinkedHashMap<CallString, Set<TypeMapping>>()));
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class CallStringReceiverTypes method updateThreads.
private void updateThreads(Map<CallString, Set<TypeMapping>> input, Interpreter<CallString, Set<TypeMapping>> interpreter, Map<InstructionHandle, ContextMap<CallString, Set<TypeMapping>>> state) {
DFATool p = interpreter.getDFATool();
boolean modified = true;
while (modified) {
modified = false;
Map<String, ContextMap<CallString, Set<TypeMapping>>> tmpThreads = new LinkedHashMap<String, ContextMap<CallString, Set<TypeMapping>>>();
for (String methodName : threads.keySet()) {
MethodInfo method = p.getMethod(methodName);
InstructionHandle entry = p.getEntryHandle(method);
Context c = state.get(entry).getContext();
int varPtr = c.stackPtr - MethodHelper.getArgSize(method);
// prepare input information
ContextMap<CallString, Set<TypeMapping>> threadInput = new ContextMap<CallString, Set<TypeMapping>>(c, new LinkedHashMap<CallString, Set<TypeMapping>>());
for (CallString cs : input.keySet()) {
Set<TypeMapping> s = input.get(cs);
Set<TypeMapping> o = new LinkedHashSet<TypeMapping>();
filterSet(s, o, 0);
threadInput.put(cs, o);
}
state.put(entry, join(threadInput, state.get(entry)));
// save information
ContextMap<CallString, Set<TypeMapping>> savedResult = threads.get(methodName);
// interpret thread
Map<InstructionHandle, ContextMap<CallString, Set<TypeMapping>>> r = interpreter.interpret(c, entry, state, false);
// pull out relevant information from thread
InstructionHandle exit = p.getExitHandle(method);
ContextMap<CallString, Set<TypeMapping>> threadResult;
if (r.get(exit) != null) {
threadResult = new ContextMap<CallString, Set<TypeMapping>>(c, new LinkedHashMap<CallString, Set<TypeMapping>>());
threadResult.put(c.callString, new LinkedHashSet<TypeMapping>());
Set<TypeMapping> returned = r.get(exit).get(c.callString);
filterReturnSet(returned, threadResult.get(c.callString), varPtr);
} else {
threadResult = new ContextMap<CallString, Set<TypeMapping>>(c, new LinkedHashMap<CallString, Set<TypeMapping>>());
threadResult.put(c.callString, new LinkedHashSet<TypeMapping>());
}
if (!threadResult.equals(savedResult)) {
modified = true;
}
tmpThreads.put(methodName, threadResult);
}
threads = tmpThreads;
}
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class LoopBounds method initial.
public ContextMap<CallString, Map<Location, ValueMapping>> initial(InstructionHandle stmt) {
ContextMap<CallString, Map<Location, ValueMapping>> retval = new ContextMap<CallString, Map<Location, ValueMapping>>(new Context(), new LinkedHashMap<CallString, Map<Location, ValueMapping>>());
CallString l = CallString.EMPTY;
Map<Location, ValueMapping> init = new LinkedHashMap<Location, ValueMapping>();
ValueMapping value;
value = new ValueMapping();
value.assigned.setLb(0);
value.assigned.setUb(16);
init.put(new Location("com.jopdesign.io.SysDevice.nrCpu"), value);
retval.put(l, init);
return retval;
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class LoopBounds method getBound.
public int getBound(InstructionHandle instr, CallString csSuffix) {
ContextMap<CallString, Pair<ValueMapping, ValueMapping>> r = bounds.get(instr);
if (r == null) {
// no bound at this point
return -1;
}
// merge bound for all contexts
int maxValue = -1;
for (CallString callString : r.keySet()) {
if (!callString.hasSuffix(csSuffix))
continue;
Pair<ValueMapping, ValueMapping> bounds = r.get(callString);
ValueMapping first = bounds.first();
ValueMapping second = bounds.second();
if (first == null || second == null) {
return -1;
}
InstructionHandle target = ((BranchInstruction) instr.getInstruction()).getTarget();
if (scopes.get(target) != null) {
if (scopes.get(target).get(callString) <= first.defscope || scopes.get(target).get(callString) <= second.defscope) {
return -1;
}
}
if (scopes.get(instr).get(callString) <= first.defscope || scopes.get(instr).get(callString) <= second.defscope) {
return -1;
}
// if (first.softinc || second.softinc) {
// return -1;
// }
int val = ValueMapping.computeBound(first, second);
if (val < 0) {
// no bound for some context
return -1;
} else {
// compute the maximum
maxValue = Math.max(maxValue, val);
}
}
return maxValue;
}
use of com.jopdesign.common.code.CallString in project jop by jop-devel.
the class LoopBounds method join.
public ContextMap<CallString, Map<Location, ValueMapping>> join(ContextMap<CallString, Map<Location, ValueMapping>> s1, ContextMap<CallString, Map<Location, ValueMapping>> s2) {
if (s1 == null) {
return new ContextMap<CallString, Map<Location, ValueMapping>>(s2);
}
if (s2 == null) {
return new ContextMap<CallString, Map<Location, ValueMapping>>(s1);
}
ContextMap<CallString, Map<Location, ValueMapping>> result = new ContextMap<CallString, Map<Location, ValueMapping>>(new Context(s1.getContext()), new LinkedHashMap<CallString, Map<Location, ValueMapping>>());
result.putAll(s1);
result.putAll(s2);
Map<Location, ValueMapping> a = s1.get(s2.getContext().callString);
Map<Location, ValueMapping> b = s2.get(s2.getContext().callString);
if (a != null || b != null) {
if (a == null) {
a = new LinkedHashMap<Location, ValueMapping>();
}
if (b == null) {
b = new LinkedHashMap<Location, ValueMapping>();
}
Map<Location, ValueMapping> merged = new LinkedHashMap<Location, ValueMapping>(a);
for (Location l : b.keySet()) {
ValueMapping x = a.get(l);
ValueMapping y = b.get(l);
if (x != null) {
if (!x.equals(y)) {
ValueMapping r = new ValueMapping(x, true);
r.join(y);
merged.put(l, r);
} else {
merged.put(l, x);
}
} else {
merged.put(l, y);
}
}
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;
}
Aggregations