Debian Codegraph @

gcc/testsuite/gm2/iso/run/pass/shift4.mod

raw
1 (* Copyright (C) 2009 Free Software Foundation, Inc. *)
2 (* This file is part of GNU Modula-2.
3
4 GNU Modula-2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with gm2; see the file COPYING. If not, write to the Free Software
16 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
17
18 MODULE shift4 ;
19
20 FROM libc IMPORT exit, printf ;
21 FROM SYSTEM IMPORT SHIFT, BITSPERLOC ;
22
23 TYPE
24 large = SET OF [0..1023] ;
25 VAR
26 r : INTEGER ;
27 i : INTEGER ;
28 b, c: large ;
29 BEGIN
30 r := 0 ;
31 b := large{1, 2, 3, 1022} ;
32 b := SHIFT(b, 1) ;
33 IF b#large{2, 3, 4, 1023}
34 THEN
35 exit(1)
36 END ;
37 b := large{1, 2, 3, 1023} ;
38 b := SHIFT(b, -1) ;
39 IF b#large{0, 1, 2, 1022}
40 THEN
41 exit(2)
42 END ;
43 b := large{1+SIZE(BITSET)*BITSPERLOC} ;
44 b := SHIFT(b, -1) ;
45 IF b#large{SIZE(BITSET)*BITSPERLOC}
46 THEN
47 exit(3)
48 END ;
49 b := SHIFT(b, -1) ;
50 IF b#large{SIZE(BITSET)*BITSPERLOC-1}
51 THEN
52 exit(4)
53 END ;
54 FOR i := 0 TO MAX(large) DO
55 b := large{0} ;
56 b := SHIFT(b, i) ;
57 c := large{i} ;
58 IF b#c
59 THEN
60 printf("failed shift left in loop on iteration %d\n", i) ;
61 r := 5
62 END
63 END ;
64 FOR i := 0 TO MAX(large) DO
65 b := large{i} ;
66 b := SHIFT(b, -i) ;
67 c := large{0} ;
68 IF b#c
69 THEN
70 printf("failed shift right in loop on iteration %d\n", i) ;
71 r := 6
72 END
73 END ;
74 printf("all done\n") ;
75 exit(r)
76 END shift4.