- fixed comment: bs cannot be NULL anymore (and was never NULL previously)
[libfirm] / ir / be / test / globalrefs.c
1 /* globalrefs.c - Test symbolic constant expressions constructed from
2  * global addresses and index expressions into global addresses.
3  * Do this both with global constants and with inline constant.
4  * Instead of printing absolute addresses, print out the differences in
5  * memory addresses to get output that matches that of the native compiler.
6  */
7
8 #include <stdio.h>
9
10 #define __STDC_LIMIT_MACROS 1
11 #include <inttypes.h>
12
13 struct test {
14   long A;
15   struct { unsigned X; unsigned Y; } S;
16   struct test* next;
17 };
18
19 struct test  TestArray[10];
20 struct test  Test1;
21
22 /* Create global symbolic constants from the addresses of the above globals */
23
24 struct test* TestArrayPtr = &TestArray[3];
25 long*        Aptr         = &Test1.A;
26 unsigned*    Yptr         = &Test1.S.Y;
27 struct test** NextPtr     = &Test1.next;
28
29 void
30 printdiff(void* p1, void* p2)
31 {
32   printf(" %d", (int)((unsigned long) p1 - (unsigned long) p2));
33 }
34
35 int
36 main(int argc, char** argv)
37 {
38   unsigned long diff1, diff2, diff3, diff4;
39
40   printf("sizeof(struct Test) = %d\n\n", (int)sizeof(struct test));
41
42   printdiff(&TestArray[3], TestArray);
43   printdiff(&Test1.S.Y, &Test1.A);
44   printdiff(&Test1.next, &Test1.S.Y);
45   printf("\n");
46
47   diff1 = (unsigned long) &TestArray[3] - (unsigned long) TestArray;
48   diff3 = (unsigned long) &Test1.S.Y - (unsigned long) &Test1.A;
49   diff4 = (unsigned long) &Test1.next - (unsigned long) &Test1.S.Y;
50
51   printf("&TestArray[3] - TestArray = 0x%lx\n", diff1);
52   printf("Xptr - Aptr          = 0x%lx\n", diff3);
53   printf("NextPtr - Xptr       = 0x%lx\n\n", diff4);
54
55   diff1 = (unsigned long) TestArrayPtr - (unsigned long) TestArray;
56   diff3 = (unsigned long) Yptr - (unsigned long) Aptr;
57   diff4 = (unsigned long) NextPtr - (unsigned long) Yptr;
58
59   printf("&TestArray[3] - TestArray = 0x%lx\n", diff1);
60   printf("Xptr - Aptr          = 0x%lx\n", diff3);
61   printf("NextPtr - Xptr       = 0x%lx\n\n", diff4);
62
63   return 0;
64 }