ex2.b.smv 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. MODULE main
  2. VAR
  3. pc: { L0, L1, L2, L3, L4, L5, L6, L7, L8 };
  4. year: unsigned word [11];
  5. days: unsigned word [14];
  6. DEFINE
  7. is_leap_year := (toint(year) mod 4 = 0 & toint(year) mod 100 != 0) |
  8. (toint(year) mod 400 = 0);
  9. ASSIGN
  10. init(pc) := L0;
  11. next(pc) :=
  12. case
  13. pc = L0 : L1;
  14. pc = L1 & days > 0ud14_365 : L2;
  15. pc = L1 : L8;
  16. pc = L2 & is_leap_year : L3;
  17. pc = L2 : L6;
  18. pc = L3 & days > 0ud14_366 : L4;
  19. pc = L3 : L1;
  20. pc = L4 : L5;
  21. pc = L5 : L1;
  22. pc = L6 : L7;
  23. pc = L7 : L1;
  24. -- self-loop at final location L8, to obtain infinite paths
  25. pc = L8 : L8;
  26. esac;
  27. next(year) :=
  28. case
  29. pc = L0 : 0ud11_1980;
  30. pc = L5 : year + 0ud11_1;
  31. pc = L7 : year + 0ud11_1;
  32. TRUE: year;
  33. esac;
  34. next(days) :=
  35. case
  36. -- in case we are at line 4, we subtract 366 days (with a unsigned 14-bit constant)
  37. pc = L4 : days - 0ud14_366;
  38. -- in case we are at line 4, we subtract 365 days (with a unsigned 14-bit constant)
  39. pc = L6 : days - 0ud14_365;
  40. TRUE : days;
  41. esac;
  42. -- we enter the loop with PC being L1 (which is a consequence of PC being L0)
  43. -- all executions will start at L0 and end up in L1, so we could optimize away the premise of the implication, but we still want to implement the expressed property
  44. -- if the premise is fulfilled, then for all execution paths sometime in the future the PC must reach L8, which is the line where the loop has been exited
  45. SPEC AG (pc = L1 -> AF (pc = L8))
  46. -- out of curiosity we also verify include the optimized property
  47. --SPEC AF (pc = L8)
  48. -- it gives the same output!