1 /* Miscellaneous simulator utilities.
2 Copyright (C) 1997 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 printf ("typedef struct _test_tuples {\n");
30 printf (" int line;\n");
31 printf (" int row;\n");
32 printf (" int col;\n");
33 printf (" long long val;\n");
34 printf (" long long check;\n");
35 printf ("} test_tuples;\n");
37 printf ("typedef struct _test_spec {\n");
38 printf (" const char *file;\n");
39 printf (" const char *macro;\n");
40 printf (" int nr_rows;\n");
41 printf (" int nr_cols;\n");
42 printf (" test_tuples *tuples;\n");
43 printf ("} test_spec;\n");
55 printf ("\n/* Test the %s macro */\n", macro
);
56 printf ("test_tuples %s_tuples[%d] = {\n", macro
, nr_bits
);
57 for (i
= 0; i
< nr_bits
; i
++)
59 /* compute what we think the value is */
60 unsigned long long bit
= 1;
62 bit
<<= nr_bits
- i
- 1;
66 bit
= (unsigned) bit
; /* truncate it! */
68 printf (" { __LINE__, ");
69 printf ("%d, %2d, ", -1, i
);
70 printf ("%s (%2d), ", macro
, i
);
71 printf ("UNSIGNED64 (0x%08lx%08lx), ",
72 (long) (bit
>> 32), (long) bit
);
77 printf ("test_spec %s_test = { __FILE__, \"%s\", 1, %d, %s_tuples, };\n",
78 macro
, macro
, nr_bits
, macro
);
84 gen_enum (const char *macro
,
89 printf ("\n/* Test the %s macro in an enum */\n", macro
);
90 printf ("enum enum_%s {\n", macro
);
91 for (i
= 0; i
< nr_bits
; i
++)
93 printf (" elem_%s_%d = %s (%d),\n", macro
, i
, macro
, i
);
101 gen_mask (int bitsize
,
108 printf ("\n/* Test the %s%s macro */\n", msb
, macro
);
109 printf ("test_tuples %s_tuples[%d][%d] = {\n", macro
, nr_bits
, nr_bits
);
110 for (l
= 0; l
< nr_bits
; l
++)
113 for (h
= 0; h
< nr_bits
; h
++)
115 printf (" { __LINE__, ");
116 if ((strcmp (msb
, "MS") == 0 && l
<= h
)
117 || (strcmp (msb
, "MS") != 0 && l
>= h
)
118 || (strcmp (macro
, "") == 0))
120 /* compute the mask */
121 unsigned long long mask
= 0;
123 for (b
= 0; b
< nr_bits
; b
++)
125 unsigned long long bit
= 1;
126 if (strcmp (msb
, "MS") == 0)
128 if ((l
<= b
&& b
<= h
)
129 || (h
< l
&& (b
<= h
|| b
>= l
)))
130 bit
<<= (nr_bits
- b
- 1);
136 if ((l
>= b
&& b
>= h
)
137 || (h
> l
&& (b
>= h
|| b
<= l
)))
145 mask
= (unsigned long) mask
;
146 printf ("%d, %d, ", l
, h
);
147 printf ("%s%s (%2d, %2d), ", msb
, macro
, l
, h
);
148 printf ("UNSIGNED64 (0x%08lx%08lx), ",
149 (long) (mask
>> 32), (long) mask
);
159 printf ("test_spec %s_test = { __FILE__, \"%s%s\", %d, %d, &%s_tuples[0][0], };\n",
160 macro
, msb
, macro
, nr_bits
, nr_bits
, macro
);
168 fprintf (stderr
, "Usage:\n");
169 fprintf (stderr
, " bits-gen <nr-bits> <msb> <byte-order>\n");
170 fprintf (stderr
, "Generate a test case for the simulator bit manipulation code\n");
171 fprintf (stderr
, " <nr-bits> = { 32 | 64 }\n");
172 fprintf (stderr
, " <msb> = { 0 | { 31 | 63 } }\n");
173 fprintf (stderr
, " <byte-order> = { big | little }\n");
177 case 1: fprintf (stderr
, "Wrong number of arguments\n");
180 fprintf (stderr
, "Invalid <nr-bits> argument\n");
183 fprintf (stderr
, "Invalid <msb> argument\n");
186 fprintf (stderr
, "Invalid <byte-order> argument\n");
209 if (strcmp (argv
[1], "32") == 0)
211 else if (strcmp (argv
[1], "64") == 0)
216 if (strcmp (argv
[2], "0") == 0)
218 else if (strcmp (argv
[2], "31") == 0 && bitsize
== 32)
220 else if (strcmp (argv
[2], "63") == 0 && bitsize
== 64)
229 if (strcmp (argv
[3], "big") == 0)
231 else if (strcmp (argv
[3], "little") == 0)
236 printf ("#define WITH_TARGET_WORD_BITSIZE %d\n", bitsize
);
237 printf ("#define WITH_TARGET_WORD_MSB %d\n", msb
);
238 printf ("#define WITH_HOST_WORD_BITSIZE %d\n", sizeof (int) * 8);
239 printf ("#define WITH_TARGET_BYTE_ORDER %s\n", big_endian
? "BIG_ENDIAN" : "LITTLE_ENDIAN");
241 printf ("#define SIM_BITS_INLINE (ALL_H_INLINE)\n");
243 printf ("#define ASSERT(X) do { if (!(X)) abort(); } while (0)\n");
245 printf ("#include \"sim-basics.h\"\n");
251 printf ("#define DO_BIT_TESTS\n");
252 gen_bit ( 4, msb
, "BIT4", 4);
253 gen_bit ( 5, msb
, "BIT5", 5);
254 gen_bit ( 8, msb
, "BIT8", 8);
255 gen_bit (10, msb
, "BIT10", 10);
256 gen_bit (16, msb
, "BIT16", 16);
257 gen_bit (32, msb
, "BIT32", 32);
258 gen_bit (64, msb
, "BIT64", 64);
259 gen_bit (bitsize
, msb
, "BIT", 64);
261 gen_bit ( 8, 8 - 1, "LSBIT8", 8);
262 gen_bit (16, 16 - 1, "LSBIT16", 16);
263 gen_bit (32, 32 - 1, "LSBIT32", 32);
264 gen_bit (64, 64 - 1, "LSBIT64", 64);
265 gen_bit (bitsize
, bitsize
- 1, "LSBIT", 64);
267 gen_bit ( 8, 0, "MSBIT8", 8);
268 gen_bit (16, 0, "MSBIT16", 16);
269 gen_bit (32, 0, "MSBIT32", 32);
270 gen_bit (64, 0, "MSBIT64", 64);
271 gen_bit (bitsize
, 0, "MSBIT", 64);
273 printf ("test_spec *(bit_tests[]) = {\n");
274 printf (" &BIT4_test,\n");
275 printf (" &BIT5_test,\n");
276 printf (" &BIT8_test,\n");
277 printf (" &BIT10_test,\n");
278 printf (" &BIT16_test,\n");
279 printf (" &BIT32_test,\n");
280 printf (" &BIT64_test,\n");
281 printf (" &BIT_test,\n");
282 printf (" &LSBIT8_test,\n");
283 printf (" &LSBIT16_test,\n");
284 printf (" &LSBIT32_test,\n");
285 printf (" &LSBIT64_test,\n");
286 printf (" &LSBIT_test,\n");
287 printf (" &MSBIT8_test,\n");
288 printf (" &MSBIT16_test,\n");
289 printf (" &MSBIT32_test,\n");
290 printf (" &MSBIT64_test,\n");
291 printf (" &MSBIT_test,\n");
295 gen_enum ("BIT", 64);
296 gen_enum ("LSBIT", 64);
297 gen_enum ("MSBIT", 64);
298 gen_enum ("BIT32", 32);
299 gen_enum ("LSBIT32", 32);
300 gen_enum ("MSBIT32", 32);
302 printf ("#define DO_MASK_TESTS\n");
303 gen_mask ( 8, ms
, "MASK8", 8);
304 gen_mask (16, ms
, "MASK16", 16);
305 gen_mask (32, ms
, "MASK32", 32);
306 gen_mask (64, ms
, "MASK64", 64);
307 gen_mask (bitsize
, ms
, "MASK", 64);
309 printf ("test_spec *(mask_tests[]) = {\n");
310 printf (" &MASK8_test,\n");
311 printf (" &MASK16_test,\n");
312 printf (" &MASK32_test,\n");
313 printf (" &MASK64_test,\n");
314 printf (" &MASK_test,\n");
This page took 0.038296 seconds and 5 git commands to generate.