ex2.c.smv 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. MODULE main
  2. VAR
  3. pc: { L0, L1, L2, L3, L4 };
  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. days_in_year := is_leap_year ? 0ud14_366 : 0ud14_365;
  10. ASSIGN
  11. init(pc) := L0;
  12. next(pc) :=
  13. case
  14. pc = L0 : L1;
  15. pc = L1 & days > days_in_year : L2;
  16. pc = L1 : L4;
  17. pc = L2 : L3;
  18. pc = L3 : L1;
  19. -- self-loop at final location L4, to obtain infinite paths
  20. pc = L4 : L4;
  21. esac;
  22. next(year) :=
  23. case
  24. pc = L0 : 0ud11_1980;
  25. -- we compacted the program to just one addition branch on year
  26. pc = L3 : year + 0ud11_1;
  27. TRUE: year;
  28. esac;
  29. next(days) :=
  30. case
  31. -- we compacted the program to just one subtraction branch on days
  32. pc = L2 : days - days_in_year;
  33. TRUE : days;
  34. esac;
  35. -- for completeness, here is the program we are modeling in this version
  36. -- it is the legendary readable and compact solution provided by Stefan Ciobaca
  37. -- in our case we don't need any inlined functions :)
  38. -- L0: year = ORIGIN_YEAR;
  39. -- L1: while (days > DaysInYear(year)) {
  40. -- L2: days -= DaysInYear(year);
  41. -- L3: year++;
  42. -- }
  43. -- L4: exit;
  44. -- our specification remains the same as in subtask (b), only this time our exit PC is L4
  45. SPEC AG (pc = L1 -> AF (pc = L4))
  46. -- out of curiosity we also verify include the optimized property
  47. --SPEC AF (pc = L4)
  48. -- it gives the same output!