Debian Codegraph @

gcc/testsuite/gm2/sets/run/pass/simplepacked.mod

raw
1 MODULE simplepacked ;
2
3 FROM libc IMPORT printf, exit ;
4 FROM SYSTEM IMPORT TBITSIZE, ROTATE ;
5
6 TYPE
7 settype = SET OF [0..8] ;
8 psettype = PACKEDSET OF [0..8] ;
9
10
11 PROCEDURE assert (cond: BOOLEAN; line: CARDINAL; message: ARRAY OF CHAR) ;
12 BEGIN
13 IF NOT cond
14 THEN
15 printf ("assert failed %s at line %d\n", message, line) ;
16 exit (1)
17 END
18 END assert ;
19
20
21 PROCEDURE testset ;
22 VAR
23 a, b: settype ;
24 BEGIN
25 a := settype {1} ;
26 b := a ;
27 (* Assumes that the bitset will be contained in <= 64 bits, most likely
28 32. But probably safe to assume <= 64 bits for some time. *)
29 printf ("TBITSIZE (a) = %d\n", TBITSIZE (a));
30 assert (TBITSIZE (a) <= 64, __LINE__, "TBITSIZE <= 64") ;
31 assert (a = b, __LINE__, "comparision between variable sets") ;
32 assert (a = settype {1}, __LINE__, "comparision between variable and constant sets") ;
33 assert (b = settype {1}, __LINE__, "comparision between variable and constant sets") ;
34 assert (settype {1} = settype {1}, __LINE__, "comparision between constant sets") ;
35 assert (settype {1} # settype {2}, __LINE__, "comparision between constant sets") ;
36 assert (ROTATE (settype {1}, 1) = ROTATE (settype {1}, 1), __LINE__, "comparision between constant rotated sets") ;
37 assert (ROTATE (settype {1}, 1) # ROTATE (settype {2}, 1), __LINE__, "comparision between constant rotated sets") ;
38 assert (ROTATE (a, 1) = settype {2}, __LINE__, "comparision between rotated variable and constant sets") ;
39 assert (ROTATE (a, -1) = settype {0}, __LINE__, "comparision between rotated variable and constant sets") ;
40 END testset ;
41
42
43 PROCEDURE testpset ;
44 VAR
45 a, b: psettype ;
46 BEGIN
47 a := psettype {1} ;
48 b := a ;
49 (* Packed set should be stored in a BYTE. *)
50 printf ("TBITSIZE (a) = %d\n", TBITSIZE (a));
51 assert (TBITSIZE (a) <= 32, __LINE__, "TBITSIZE <= 32 ( packed set )") ;
52 assert (a = b, __LINE__, "comparision between variable packed sets") ;
53 assert (a = psettype {1}, __LINE__, "comparision between variable and constant packed sets") ;
54 assert (b = psettype {1}, __LINE__, "comparision between variable and constant packed sets") ;
55 assert (psettype {1} = psettype {1}, __LINE__, "comparision between constant packed sets") ;
56 assert (psettype {1} # psettype {2}, __LINE__, "comparision between constant packed sets") ;
57 assert (ROTATE (psettype {1}, 1) = ROTATE (psettype {1}, 1), __LINE__, "comparision between constant rotated packed sets") ;
58 assert (ROTATE (psettype {1}, 1) # ROTATE (psettype {2}, 1), __LINE__, "comparision between constant rotated packed sets") ;
59 assert (ROTATE (a, 1) = psettype {2}, __LINE__, "comparision between rotated variable and constant packed sets") ;
60 assert (ROTATE (a, -1) = settype {0}, __LINE__, "comparision between rotated variable and constant packed sets") ;
61 END testpset ;
62
63
64 BEGIN
65 testset ;
66 testpset
67 END simplepacked.