Allow llx tests as well
[oota-llvm.git] / test / LLC / 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(" 0x%lx", (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) = %llu\n\n", sizeof(struct test));
41
42   printdiff(&TestArray[3], TestArray);
43   printdiff(&Test1.A, &TestArray[3]);
44   printdiff(&Test1.S.Y, &Test1.A);
45   printdiff(&Test1.next, &Test1.S.Y);
46   printf("\n");
47
48   diff1 = (unsigned long) &TestArray[3] - (unsigned long) TestArray;
49   diff2 = (unsigned long) &Test1.A - (unsigned long) &TestArray[3];
50   diff3 = (unsigned long) &Test1.S.Y - (unsigned long) &Test1.A;
51   diff4 = (unsigned long) &Test1.next - (unsigned long) &Test1.S.Y;
52
53   printf("&TestArray[3] - TestArray = 0x%lx\n", diff1);
54   printf("Aptr - &TestArray[3] = 0x%lx\n", diff2);
55   printf("Xptr - Aptr          = 0x%lx\n", diff3);
56   printf("NextPtr - Xptr       = 0x%lx\n\n", diff4);
57
58   diff1 = (unsigned long) TestArrayPtr - (unsigned long) TestArray;
59   diff2 = (unsigned long) Aptr - (unsigned long) TestArrayPtr;
60   diff3 = (unsigned long) Yptr - (unsigned long) Aptr;
61   diff4 = (unsigned long) NextPtr - (unsigned long) Yptr;
62
63   printf("&TestArray[3] - TestArray = 0x%lx\n", diff1);
64   printf("Aptr - &TestArray[3] = 0x%lx\n", diff2);
65   printf("Xptr - Aptr          = 0x%lx\n", diff3);
66   printf("NextPtr - Xptr       = 0x%lx\n\n", diff4);
67
68   return 0;
69 }