e05d68c21451c69ada27fdbe3cf71ff1d6b4e55e
1 /* 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 */
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.
13 (defun callee (n) (format "callee%d" n))
14 (defun caller (n) (format "caller%d" n))
15 (defun local (n) (format "l%d" n))
17 (if (zerop n) (insert "0")
21 (if (< j n) (insert "+"))
23 (defun local-chain (n previous first-end)
26 (insert " register int " (local j)
27 " = increment (" previous ");")
30 (insert " /" "* " first-end " *" "/")
31 (setq first-end nil)))
33 (setq previous (local j))
39 (goto-char (point-max))
40 (search-backward "generated code starts here")
42 (let ((start (point)))
43 (search-forward "generated code ends here")
45 (delete-region start (point)))
47 ;; Generate callee functions.
50 (insert (format "/%s Returns n * %d + %d %s/\n"
51 "*" i (/ (+ i (* i i)) 2) "*"))
53 (insert (callee i) " (int n)\n")
55 (local-chain i "n" (callee i))
62 ;; Generate caller functions.
66 (insert (caller i) " (void)\n")
68 (let ((last (local-chain i "0x7eeb" (caller i))))
69 (insert " register int n;\n")
72 (insert " n = " (callee j) " ("
73 (if (> j 0) "n + " "")
82 ;; Generate driver function.
84 (insert "driver (void)\n")
88 (insert " printf (\"" (caller i) " () => %d\\n\", "
101 /* generated code starts here */
102 /* Returns n * 0 + 0 */
109 /* Returns n * 1 + 1 */
113 register int l1
= increment (n
); /* callee1 */
117 /* Returns n * 2 + 3 */
121 register int l1
= increment (n
); /* callee2 */
122 register int l2
= increment (l1
);
126 /* Returns n * 3 + 6 */
130 register int l1
= increment (n
); /* callee3 */
131 register int l2
= increment (l1
);
132 register int l3
= increment (l2
);
136 /* Returns n * 4 + 10 */
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
);
147 /* Returns n * 5 + 15 */
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
;
162 register int l1
= increment (0x7eeb); /* caller1 */
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
);
176 register int l1
= increment (0x7eeb); /* caller2 */
177 register int l2
= increment (l1
);
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
);
191 register int l1
= increment (0x7eeb); /* caller3 */
192 register int l2
= increment (l1
);
193 register int l3
= increment (l2
);
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
);
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
);
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
;
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
);
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
;
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 ());
249 /* generated code ends here */
This page took 0.033872 seconds and 4 git commands to generate.