OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [testsuite/] [gdb.base/] [restore.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 markom
/* Test GDB's ability to restore saved registers from stack frames
2
   when using the `return' command.
3
   Jim Blandy <jimb@cygnus.com> --- December 1998 */
4
 
5
#include <stdio.h>
6
 
7
/* This is the Emacs Lisp expression I used to generate the functions
8
   in this file.  If people modify the functions manually, instead of
9
   changing this expression and re-running it, then evaluating this
10
   expression could wipe out their work, so you probably shouldn't
11
   re-run it.  But I leave it here for reference.
12
 
13
   (defun callee (n) (format "callee%d" n))
14
   (defun caller (n) (format "caller%d" n))
15
   (defun local  (n) (format "l%d"  n))
16
   (defun local-sum (n)
17
     (let ((j 1))
18
       (while (<= j n)
19
         (insert (local j))
20
         (if (< j n) (insert "+"))
21
         (setq j (1+ j)))))
22
   (defun local-chain (n previous first-end)
23
     (let ((j 1))
24
       (while (<= j n)
25
         (insert "  register int " (local j)
26
                 " = increment (" previous  ");")
27
         (if first-end
28
           (progn
29
             (insert "  /" "* " first-end " *" "/")
30
             (setq first-end nil)))
31
         (insert "\n")
32
         (setq previous (local j))
33
         (setq j (1+ j))))
34
     previous)
35
 
36
   (save-excursion
37
     (let ((limit 5))
38
       (goto-char (point-max))
39
       (search-backward "generated code starts here")
40
       (forward-line 1)
41
       (let ((start (point)))
42
         (search-forward "generated code ends here")
43
         (forward-line 0)
44
         (delete-region start (point)))
45
 
46
       ;; Generate callee functions.
47
       (let ((i 0))
48
         (while (<= i limit)
49
           (insert (format "/%s Returns n * %d + %d %s/\n"
50
                           "*" i (/ (+ i (* i i)) 2) "*"))
51
           (insert "int\n")
52
           (insert (callee i) " (int n)\n")
53
           (insert "{\n")
54
           (local-chain i "n" (callee i))
55
           (insert "  return ")
56
           (if (<= i 0) (insert "n")
57
             (local-sum i))
58
           (insert ";\n")
59
           (insert "}\n\n")
60
           (setq i (1+ i))))
61
 
62
       ;; Generate caller functions.
63
       (let ((i 1))
64
         (while (<= i limit)
65
           (insert "int\n")
66
           (insert (caller i) " (void)\n")
67
           (insert "{\n")
68
           (let ((last (local-chain i "0x7eeb" (caller i))))
69
             (insert "  register int n;\n")
70
             (let ((j 0))
71
               (while (<= j limit)
72
                 (insert "  n = " (callee j) " ("
73
                         (if (> j 0) "n + " "")
74
                         last ");\n")
75
                 (setq j (1+ j)))))
76
           (insert "  return n+")
77
           (local-sum i)
78
           (insert ";\n")
79
           (insert "}\n\n")
80
           (setq i (1+ i))))
81
 
82
       ;; Generate driver function.
83
       (insert "void\n")
84
       (insert "driver (void)\n")
85
       (insert "{\n")
86
       (let ((i 1))
87
         (while (<= i limit)
88
           (insert "  printf (\"" (caller i) " () => %d\\n\", "
89
                   (caller i) " ());\n")
90
           (setq i (1+ i))))
91
       (insert "}\n\n")))
92
 
93
         */
94
 
95
int
96
increment (int n)
97
{
98
  return n + 1;
99
}
100
 
101
/* generated code starts here */
102
/* Returns n * 0 + 0 */
103
int
104
callee0 (int n)
105
{
106
  return n;
107
}
108
 
109
/* Returns n * 1 + 1 */
110
int
111
callee1 (int n)
112
{
113
  register int l1 = increment (n);  /* callee1 */
114
  return l1;
115
}
116
 
117
/* Returns n * 2 + 3 */
118
int
119
callee2 (int n)
120
{
121
  register int l1 = increment (n);  /* callee2 */
122
  register int l2 = increment (l1);
123
  return l1+l2;
124
}
125
 
126
/* Returns n * 3 + 6 */
127
int
128
callee3 (int n)
129
{
130
  register int l1 = increment (n);  /* callee3 */
131
  register int l2 = increment (l1);
132
  register int l3 = increment (l2);
133
  return l1+l2+l3;
134
}
135
 
136
/* Returns n * 4 + 10 */
137
int
138
callee4 (int n)
139
{
140
  register int l1 = increment (n);  /* callee4 */
141
  register int l2 = increment (l1);
142
  register int l3 = increment (l2);
143
  register int l4 = increment (l3);
144
  return l1+l2+l3+l4;
145
}
146
 
147
/* Returns n * 5 + 15 */
148
int
149
callee5 (int n)
150
{
151
  register int l1 = increment (n);  /* callee5 */
152
  register int l2 = increment (l1);
153
  register int l3 = increment (l2);
154
  register int l4 = increment (l3);
155
  register int l5 = increment (l4);
156
  return l1+l2+l3+l4+l5;
157
}
158
 
159
int
160
caller1 (void)
161
{
162
  register int l1 = increment (0x7eeb);  /* caller1 */
163
  register int n;
164
  n = callee0 (l1);
165
  n = callee1 (n + l1);
166
  n = callee2 (n + l1);
167
  n = callee3 (n + l1);
168
  n = callee4 (n + l1);
169
  n = callee5 (n + l1);
170
  return n+l1;
171
}
172
 
173
int
174
caller2 (void)
175
{
176
  register int l1 = increment (0x7eeb);  /* caller2 */
177
  register int l2 = increment (l1);
178
  register int n;
179
  n = callee0 (l2);
180
  n = callee1 (n + l2);
181
  n = callee2 (n + l2);
182
  n = callee3 (n + l2);
183
  n = callee4 (n + l2);
184
  n = callee5 (n + l2);
185
  return n+l1+l2;
186
}
187
 
188
int
189
caller3 (void)
190
{
191
  register int l1 = increment (0x7eeb);  /* caller3 */
192
  register int l2 = increment (l1);
193
  register int l3 = increment (l2);
194
  register int n;
195
  n = callee0 (l3);
196
  n = callee1 (n + l3);
197
  n = callee2 (n + l3);
198
  n = callee3 (n + l3);
199
  n = callee4 (n + l3);
200
  n = callee5 (n + l3);
201
  return n+l1+l2+l3;
202
}
203
 
204
int
205
caller4 (void)
206
{
207
  register int l1 = increment (0x7eeb);  /* caller4 */
208
  register int l2 = increment (l1);
209
  register int l3 = increment (l2);
210
  register int l4 = increment (l3);
211
  register int n;
212
  n = callee0 (l4);
213
  n = callee1 (n + l4);
214
  n = callee2 (n + l4);
215
  n = callee3 (n + l4);
216
  n = callee4 (n + l4);
217
  n = callee5 (n + l4);
218
  return n+l1+l2+l3+l4;
219
}
220
 
221
int
222
caller5 (void)
223
{
224
  register int l1 = increment (0x7eeb);  /* caller5 */
225
  register int l2 = increment (l1);
226
  register int l3 = increment (l2);
227
  register int l4 = increment (l3);
228
  register int l5 = increment (l4);
229
  register int n;
230
  n = callee0 (l5);
231
  n = callee1 (n + l5);
232
  n = callee2 (n + l5);
233
  n = callee3 (n + l5);
234
  n = callee4 (n + l5);
235
  n = callee5 (n + l5);
236
  return n+l1+l2+l3+l4+l5;
237
}
238
 
239
void
240
driver (void)
241
{
242
  printf ("caller1 () => %d\n", caller1 ());
243
  printf ("caller2 () => %d\n", caller2 ());
244
  printf ("caller3 () => %d\n", caller3 ());
245
  printf ("caller4 () => %d\n", caller4 ());
246
  printf ("caller5 () => %d\n", caller5 ());
247
}
248
 
249
/* generated code ends here */
250
 
251
int main ()
252
{
253
  register int local;
254
#ifdef usestubs
255
  set_debug_traps();
256
  breakpoint();
257
#endif
258
  driver ();
259
  printf("exiting\n");
260
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.