-
Notifications
You must be signed in to change notification settings - Fork 13
/
Adder.txs
111 lines (80 loc) · 4.08 KB
/
Adder.txs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{-
TorXakis - Model Based Testing
Copyright (c) 2015-2017 TNO and Radboud University
See LICENSE at root directory of this repository.
-}
-- ----------------------------------------------------------------------------------------- --
-- Model of (parallel) Adders, for one adder - Adder1 -, and for three adders - Adder3 -,
-- with inputs "Plus(i) x y" and "Minus(i) x y", and output "Result(i) z".
-- ----------------------------------------------------------------------------------------- --
TYPEDEF Operation ::=
Plus { p1, p2 :: Int }
| Minus { m1, m2 :: Int }
ENDDEF
FUNCDEF overflow (x :: Int) :: Bool ::=
(x < -2147483648) \/ ( x > +2147483647)
ENDDEF
-- ----------------------------------------------------------------------------------------- --
PROCDEF adder [ Act :: Operation; Res :: Int ] ( ) ::=
Act ?opn [[ IF isPlus(opn) THEN not (overflow (p1(opn)))
/\ not (overflow (p2(opn)))
/\ not (overflow (p1(opn)+p2(opn)))
ELSE False FI ]] >-> Res !p1(opn)+p2(opn) >-> adder [ Act, Res ] ( )
##
Act ?opn [[ IF isMinus(opn) THEN not (overflow (m1(opn)))
/\ not (overflow (m2(opn)))
/\ not (overflow (m1(opn)-m2(opn)))
ELSE False FI ]] >-> Res !m1(opn)-m2(opn) >-> adder [ Act, Res ] ( )
ENDDEF
-- ----------------------------------------------------------------------------------------- --
CHANDEF Chans ::= Action, Action1, Action2, Action3 :: Operation
; Result, Result1, Result2, Result3 :: Int
ENDDEF
-- ----------------------------------------------------------------------------------------- --
MODELDEF Adder ::=
CHAN IN Action
CHAN OUT Result
BEHAVIOUR adder [ Action, Result ] ( )
ENDDEF
-- ----------------------------------------------------------------------------------------- --
CNECTDEF SutConnection ::=
CLIENTSOCK
CHAN OUT Action HOST "localhost" PORT 7890
ENCODE Action ? opn -> ! toString(opn)
CHAN IN Result HOST "localhost" PORT 7890
DECODE Result ! fromString(s) <- ? s
ENDDEF
CNECTDEF Sim ::=
SERVERSOCK
CHAN IN Action HOST "localhost" PORT 7890
DECODE Action ! fromString(s) <- ? s
CHAN OUT Result HOST "localhost" PORT 7890
ENCODE Result ? result -> ! toString(result)
ENDDEF
-- ----------------------------------------------------------------------------------------- --
MODELDEF Adder3 ::=
CHAN IN Action1, Action2, Action3
CHAN OUT Result1, Result2, Result3
BEHAVIOUR adder [ Action1, Result1 ] ( )
|||
adder [ Action2, Result2 ] ( )
|||
adder [ Action3, Result3 ] ( )
ENDDEF
CNECTDEF Sut3 ::=
CLIENTSOCK
CHAN OUT Action1 HOST "localhost" PORT 7891
ENCODE Action1 ? opn -> ! toString(opn)
CHAN IN Result1 HOST "localhost" PORT 7891
DECODE Result1 ! fromString(s) <- ? s
CHAN OUT Action2 HOST "localhost" PORT 7892
ENCODE Action2 ? opn -> ! toString(opn)
CHAN IN Result2 HOST "localhost" PORT 7892
DECODE Result2 ! fromString(s) <- ? s
CHAN OUT Action3 HOST "localhost" PORT 7893
ENCODE Action3 ? opn -> ! toString(opn)
CHAN IN Result3 HOST "localhost" PORT 7893
DECODE Result3 ! fromString(s) <- ? s
ENDDEF
-- ----------------------------------------------------------------------------------------- --
-- ----------------------------------------------------------------------------------------- --