Search in sources :

Example 1 with MalformedProgramException

use of com.dat3m.dartagnan.exception.MalformedProgramException in project Dat3M by hernanponcedeleon.

the class ProgramBuilder method validateLabels.

private void validateLabels(Thread thread) throws MalformedProgramException {
    Map<String, Label> threadLabels = new HashMap<>();
    Set<String> referencedLabels = new HashSet<>();
    Event e = thread.getEntry();
    while (e != null) {
        if (e instanceof CondJump) {
            referencedLabels.add(((CondJump) e).getLabel().getName());
        } else if (e instanceof Label) {
            Label label = labels.remove(((Label) e).getName());
            if (label == null) {
                throw new MalformedProgramException("Duplicated label " + ((Label) e).getName());
            }
            threadLabels.put(label.getName(), label);
        }
        e = e.getSuccessor();
    }
    for (String labelName : referencedLabels) {
        if (!threadLabels.containsKey(labelName)) {
            throw new MalformedProgramException("Illegal jump to label " + labelName);
        }
    }
}
Also used : MalformedProgramException(com.dat3m.dartagnan.exception.MalformedProgramException) HashMap(java.util.HashMap) Label(com.dat3m.dartagnan.program.event.core.Label) Event(com.dat3m.dartagnan.program.event.core.Event) CondJump(com.dat3m.dartagnan.program.event.core.CondJump) HashSet(java.util.HashSet)

Aggregations

MalformedProgramException (com.dat3m.dartagnan.exception.MalformedProgramException)1 CondJump (com.dat3m.dartagnan.program.event.core.CondJump)1 Event (com.dat3m.dartagnan.program.event.core.Event)1 Label (com.dat3m.dartagnan.program.event.core.Label)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1