added comment
[libfirm] / ir / be / test / fehler62.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <assert.h>
4
5 typedef union rtunion_def {
6         int rtint;
7         struct rtx_def *rtx;
8 } rtunion;
9
10 typedef struct rtx_def
11 {
12         unsigned short code;
13         int mode : 8;
14         unsigned int flag1 : 1;
15         unsigned int flag2 : 2;
16         rtunion fld[1];
17 } *rtx;
18
19 enum rtx_code {
20         CODE1,
21         CODE2,
22         CODE3,
23         AND,
24         THIS_IS_NOT_AND
25 };
26
27 enum machine_mode {
28         some_mode,
29         VOIDmode,
30 };
31
32 char rtx_class[] = {
33         'a', 'e', 'i', '1', '1'
34 };
35
36 #define GET_CODE(rtx)   ((enum rtx_code) (rtx)->code)
37 #define XEXP(RTX,N)    ((RTX)->fld[N].rtx)
38 #define GET_RTX_CLASS(CODE)     (rtx_class[(int)(CODE)])
39
40 static rtx* t(rtx *loc, rtx insn) {
41         register rtx x = *loc;
42         rtx *split;
43         enum rtx_code code = GET_CODE(x);
44
45         printf("start\n");
46
47         switch(GET_RTX_CLASS(code)) {
48         case 'b':
49         case '3':
50                 split = t(&XEXP(x, 2), insn);
51                 if(split)
52                         return split;
53                 /* fall through */
54
55         case '2':
56         case 'c':
57         case '<':
58                 split = t(&XEXP(x, 1), insn);
59                 if(split)
60                         return split;
61                 /* fall through */
62
63         case '1':
64                 if(GET_CODE(x) != AND && GET_CODE(XEXP(x, 0)) == AND) {
65                         return &XEXP(x, 0);
66                 }
67                 split = t(&XEXP(x, 0), insn);
68                 if(split) {
69                         /* in r15484 (and probably earlier) tail-recursion produces a jump
70                            to the beginning here */
71                         return split;
72                 }
73                 return loc;
74         }
75
76         printf("42\n");
77         return (rtx) 42;
78 }
79
80 struct rtx_def test_rtx_inner = {
81         /*AND */ CODE2,
82         VOIDmode,
83         0,
84         1,
85         {
86                 { .rtx = NULL }
87         }
88 };
89
90 struct rtx_def test_rtx = {
91         THIS_IS_NOT_AND,
92         VOIDmode,
93         0,
94         1,
95         {
96                 { .rtx = &test_rtx_inner }
97         }
98 };
99
100 int main()
101 {
102         rtx blo = &test_rtx;
103         //printf("%p %p %p\n", &test_rtx, &test_rtx_inner, &blo);
104         rtx *res = t(&blo, NULL);
105         //assert(res == &XEXP(blo, 0));
106         printf("Res: %p\n", res);
107         return 0;
108 }