Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Fortran language support routines for GDB, the GNU debugger. |
d9fcf2fb | 2 | Copyright 1993, 1994, 1996, 2000 Free Software Foundation, Inc. |
c906108c SS |
3 | Contributed by Motorola. Adapted from the C parser by Farooq Butt |
4 | (fmbutt@engage.sps.mot.com). | |
5 | ||
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b JM |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
22 | |
23 | #include "defs.h" | |
24 | #include "gdb_string.h" | |
25 | #include "symtab.h" | |
26 | #include "gdbtypes.h" | |
27 | #include "expression.h" | |
28 | #include "parser-defs.h" | |
29 | #include "language.h" | |
30 | #include "f-lang.h" | |
745b8ca0 | 31 | #include "valprint.h" |
c906108c SS |
32 | |
33 | /* The built-in types of F77. FIXME: integer*4 is missing, plain | |
34 | logical is missing (builtin_type_logical is logical*4). */ | |
35 | ||
36 | struct type *builtin_type_f_character; | |
37 | struct type *builtin_type_f_logical; | |
38 | struct type *builtin_type_f_logical_s1; | |
39 | struct type *builtin_type_f_logical_s2; | |
c5aa993b | 40 | struct type *builtin_type_f_integer; |
c906108c SS |
41 | struct type *builtin_type_f_integer_s2; |
42 | struct type *builtin_type_f_real; | |
43 | struct type *builtin_type_f_real_s8; | |
44 | struct type *builtin_type_f_real_s16; | |
45 | struct type *builtin_type_f_complex_s8; | |
46 | struct type *builtin_type_f_complex_s16; | |
47 | struct type *builtin_type_f_complex_s32; | |
48 | struct type *builtin_type_f_void; | |
49 | ||
50 | /* Following is dubious stuff that had been in the xcoff reader. */ | |
51 | ||
52 | struct saved_fcn | |
c5aa993b JM |
53 | { |
54 | long line_offset; /* Line offset for function */ | |
55 | struct saved_fcn *next; | |
56 | }; | |
c906108c SS |
57 | |
58 | ||
c5aa993b JM |
59 | struct saved_bf_symnum |
60 | { | |
61 | long symnum_fcn; /* Symnum of function (i.e. .function directive) */ | |
62 | long symnum_bf; /* Symnum of .bf for this function */ | |
63 | struct saved_bf_symnum *next; | |
64 | }; | |
c906108c | 65 | |
c5aa993b JM |
66 | typedef struct saved_fcn SAVED_FUNCTION, *SAVED_FUNCTION_PTR; |
67 | typedef struct saved_bf_symnum SAVED_BF, *SAVED_BF_PTR; | |
c906108c SS |
68 | |
69 | /* Local functions */ | |
70 | ||
392a587b | 71 | extern void _initialize_f_language PARAMS ((void)); |
c906108c SS |
72 | #if 0 |
73 | static void clear_function_list PARAMS ((void)); | |
74 | static long get_bf_for_fcn PARAMS ((long)); | |
75 | static void clear_bf_list PARAMS ((void)); | |
76 | static void patch_all_commons_by_name PARAMS ((char *, CORE_ADDR, int)); | |
77 | static SAVED_F77_COMMON_PTR find_first_common_named PARAMS ((char *)); | |
78 | static void add_common_entry PARAMS ((struct symbol *)); | |
79 | static void add_common_block PARAMS ((char *, CORE_ADDR, int, char *)); | |
80 | static SAVED_FUNCTION *allocate_saved_function_node PARAMS ((void)); | |
81 | static SAVED_BF_PTR allocate_saved_bf_node PARAMS ((void)); | |
82 | static COMMON_ENTRY_PTR allocate_common_entry_node PARAMS ((void)); | |
83 | static SAVED_F77_COMMON_PTR allocate_saved_f77_common_node PARAMS ((void)); | |
84 | static void patch_common_entries PARAMS ((SAVED_F77_COMMON_PTR, CORE_ADDR, int)); | |
85 | #endif | |
86 | ||
87 | static struct type *f_create_fundamental_type PARAMS ((struct objfile *, int)); | |
d9fcf2fb JM |
88 | static void f_printstr (struct ui_file * stream, char *string, |
89 | unsigned int length, int width, | |
90 | int force_ellipses); | |
91 | static void f_printchar (int c, struct ui_file * stream); | |
92 | static void f_emit_char (int c, struct ui_file * stream, int quoter); | |
c906108c SS |
93 | |
94 | /* Print the character C on STREAM as part of the contents of a literal | |
95 | string whose delimiter is QUOTER. Note that that format for printing | |
96 | characters and strings is language specific. | |
97 | FIXME: This is a copy of the same function from c-exp.y. It should | |
98 | be replaced with a true F77 version. */ | |
99 | ||
100 | static void | |
101 | f_emit_char (c, stream, quoter) | |
102 | register int c; | |
d9fcf2fb | 103 | struct ui_file *stream; |
c906108c SS |
104 | int quoter; |
105 | { | |
106 | c &= 0xFF; /* Avoid sign bit follies */ | |
c5aa993b | 107 | |
c906108c SS |
108 | if (PRINT_LITERAL_FORM (c)) |
109 | { | |
110 | if (c == '\\' || c == quoter) | |
111 | fputs_filtered ("\\", stream); | |
112 | fprintf_filtered (stream, "%c", c); | |
113 | } | |
114 | else | |
115 | { | |
116 | switch (c) | |
117 | { | |
118 | case '\n': | |
119 | fputs_filtered ("\\n", stream); | |
120 | break; | |
121 | case '\b': | |
122 | fputs_filtered ("\\b", stream); | |
123 | break; | |
124 | case '\t': | |
125 | fputs_filtered ("\\t", stream); | |
126 | break; | |
127 | case '\f': | |
128 | fputs_filtered ("\\f", stream); | |
129 | break; | |
130 | case '\r': | |
131 | fputs_filtered ("\\r", stream); | |
132 | break; | |
133 | case '\033': | |
134 | fputs_filtered ("\\e", stream); | |
135 | break; | |
136 | case '\007': | |
137 | fputs_filtered ("\\a", stream); | |
138 | break; | |
139 | default: | |
140 | fprintf_filtered (stream, "\\%.3o", (unsigned int) c); | |
141 | break; | |
142 | } | |
143 | } | |
144 | } | |
145 | ||
146 | /* FIXME: This is a copy of the same function from c-exp.y. It should | |
147 | be replaced with a true F77version. */ | |
148 | ||
149 | static void | |
150 | f_printchar (c, stream) | |
151 | int c; | |
d9fcf2fb | 152 | struct ui_file *stream; |
c906108c SS |
153 | { |
154 | fputs_filtered ("'", stream); | |
155 | LA_EMIT_CHAR (c, stream, '\''); | |
156 | fputs_filtered ("'", stream); | |
157 | } | |
158 | ||
159 | /* Print the character string STRING, printing at most LENGTH characters. | |
160 | Printing stops early if the number hits print_max; repeat counts | |
161 | are printed as appropriate. Print ellipses at the end if we | |
162 | had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. | |
163 | FIXME: This is a copy of the same function from c-exp.y. It should | |
164 | be replaced with a true F77 version. */ | |
165 | ||
166 | static void | |
167 | f_printstr (stream, string, length, width, force_ellipses) | |
d9fcf2fb | 168 | struct ui_file *stream; |
c906108c SS |
169 | char *string; |
170 | unsigned int length; | |
171 | int width; | |
172 | int force_ellipses; | |
173 | { | |
174 | register unsigned int i; | |
175 | unsigned int things_printed = 0; | |
176 | int in_quotes = 0; | |
177 | int need_comma = 0; | |
178 | extern int inspect_it; | |
c5aa993b | 179 | |
c906108c SS |
180 | if (length == 0) |
181 | { | |
182 | fputs_filtered ("''", gdb_stdout); | |
183 | return; | |
184 | } | |
c5aa993b | 185 | |
c906108c SS |
186 | for (i = 0; i < length && things_printed < print_max; ++i) |
187 | { | |
188 | /* Position of the character we are examining | |
c5aa993b | 189 | to see whether it is repeated. */ |
c906108c SS |
190 | unsigned int rep1; |
191 | /* Number of repetitions we have detected so far. */ | |
192 | unsigned int reps; | |
c5aa993b | 193 | |
c906108c | 194 | QUIT; |
c5aa993b | 195 | |
c906108c SS |
196 | if (need_comma) |
197 | { | |
198 | fputs_filtered (", ", stream); | |
199 | need_comma = 0; | |
200 | } | |
c5aa993b | 201 | |
c906108c SS |
202 | rep1 = i + 1; |
203 | reps = 1; | |
204 | while (rep1 < length && string[rep1] == string[i]) | |
205 | { | |
206 | ++rep1; | |
207 | ++reps; | |
208 | } | |
c5aa993b | 209 | |
c906108c SS |
210 | if (reps > repeat_count_threshold) |
211 | { | |
212 | if (in_quotes) | |
213 | { | |
214 | if (inspect_it) | |
215 | fputs_filtered ("\\', ", stream); | |
216 | else | |
217 | fputs_filtered ("', ", stream); | |
218 | in_quotes = 0; | |
219 | } | |
220 | f_printchar (string[i], stream); | |
221 | fprintf_filtered (stream, " <repeats %u times>", reps); | |
222 | i = rep1 - 1; | |
223 | things_printed += repeat_count_threshold; | |
224 | need_comma = 1; | |
225 | } | |
226 | else | |
227 | { | |
228 | if (!in_quotes) | |
229 | { | |
230 | if (inspect_it) | |
231 | fputs_filtered ("\\'", stream); | |
232 | else | |
233 | fputs_filtered ("'", stream); | |
234 | in_quotes = 1; | |
235 | } | |
236 | LA_EMIT_CHAR (string[i], stream, '"'); | |
237 | ++things_printed; | |
238 | } | |
239 | } | |
c5aa993b | 240 | |
c906108c SS |
241 | /* Terminate the quotes if necessary. */ |
242 | if (in_quotes) | |
243 | { | |
244 | if (inspect_it) | |
245 | fputs_filtered ("\\'", stream); | |
246 | else | |
247 | fputs_filtered ("'", stream); | |
248 | } | |
c5aa993b | 249 | |
c906108c SS |
250 | if (force_ellipses || i < length) |
251 | fputs_filtered ("...", stream); | |
252 | } | |
253 | ||
254 | /* FIXME: This is a copy of c_create_fundamental_type(), before | |
255 | all the non-C types were stripped from it. Needs to be fixed | |
256 | by an experienced F77 programmer. */ | |
257 | ||
258 | static struct type * | |
259 | f_create_fundamental_type (objfile, typeid) | |
260 | struct objfile *objfile; | |
261 | int typeid; | |
262 | { | |
263 | register struct type *type = NULL; | |
c5aa993b | 264 | |
c906108c SS |
265 | switch (typeid) |
266 | { | |
267 | case FT_VOID: | |
268 | type = init_type (TYPE_CODE_VOID, | |
269 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
270 | 0, "VOID", objfile); | |
271 | break; | |
272 | case FT_BOOLEAN: | |
273 | type = init_type (TYPE_CODE_BOOL, | |
274 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
275 | TYPE_FLAG_UNSIGNED, "boolean", objfile); | |
276 | break; | |
277 | case FT_STRING: | |
278 | type = init_type (TYPE_CODE_STRING, | |
279 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
280 | 0, "string", objfile); | |
281 | break; | |
282 | case FT_CHAR: | |
283 | type = init_type (TYPE_CODE_INT, | |
284 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
285 | 0, "character", objfile); | |
286 | break; | |
287 | case FT_SIGNED_CHAR: | |
288 | type = init_type (TYPE_CODE_INT, | |
289 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
290 | 0, "integer*1", objfile); | |
291 | break; | |
292 | case FT_UNSIGNED_CHAR: | |
293 | type = init_type (TYPE_CODE_BOOL, | |
294 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
295 | TYPE_FLAG_UNSIGNED, "logical*1", objfile); | |
296 | break; | |
297 | case FT_SHORT: | |
298 | type = init_type (TYPE_CODE_INT, | |
299 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
300 | 0, "integer*2", objfile); | |
301 | break; | |
302 | case FT_SIGNED_SHORT: | |
303 | type = init_type (TYPE_CODE_INT, | |
304 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
305 | 0, "short", objfile); /* FIXME-fnf */ | |
306 | break; | |
307 | case FT_UNSIGNED_SHORT: | |
308 | type = init_type (TYPE_CODE_BOOL, | |
309 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
310 | TYPE_FLAG_UNSIGNED, "logical*2", objfile); | |
311 | break; | |
312 | case FT_INTEGER: | |
313 | type = init_type (TYPE_CODE_INT, | |
314 | TARGET_INT_BIT / TARGET_CHAR_BIT, | |
315 | 0, "integer*4", objfile); | |
316 | break; | |
317 | case FT_SIGNED_INTEGER: | |
318 | type = init_type (TYPE_CODE_INT, | |
319 | TARGET_INT_BIT / TARGET_CHAR_BIT, | |
c5aa993b | 320 | 0, "integer", objfile); /* FIXME -fnf */ |
c906108c SS |
321 | break; |
322 | case FT_UNSIGNED_INTEGER: | |
c5aa993b | 323 | type = init_type (TYPE_CODE_BOOL, |
c906108c SS |
324 | TARGET_INT_BIT / TARGET_CHAR_BIT, |
325 | TYPE_FLAG_UNSIGNED, "logical*4", objfile); | |
326 | break; | |
327 | case FT_FIXED_DECIMAL: | |
328 | type = init_type (TYPE_CODE_INT, | |
329 | TARGET_INT_BIT / TARGET_CHAR_BIT, | |
330 | 0, "fixed decimal", objfile); | |
331 | break; | |
332 | case FT_LONG: | |
333 | type = init_type (TYPE_CODE_INT, | |
334 | TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
335 | 0, "long", objfile); | |
336 | break; | |
337 | case FT_SIGNED_LONG: | |
338 | type = init_type (TYPE_CODE_INT, | |
339 | TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
c5aa993b | 340 | 0, "long", objfile); /* FIXME -fnf */ |
c906108c SS |
341 | break; |
342 | case FT_UNSIGNED_LONG: | |
343 | type = init_type (TYPE_CODE_INT, | |
344 | TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
345 | TYPE_FLAG_UNSIGNED, "unsigned long", objfile); | |
346 | break; | |
347 | case FT_LONG_LONG: | |
348 | type = init_type (TYPE_CODE_INT, | |
349 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
350 | 0, "long long", objfile); | |
351 | break; | |
352 | case FT_SIGNED_LONG_LONG: | |
353 | type = init_type (TYPE_CODE_INT, | |
354 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
355 | 0, "signed long long", objfile); | |
356 | break; | |
357 | case FT_UNSIGNED_LONG_LONG: | |
358 | type = init_type (TYPE_CODE_INT, | |
359 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
360 | TYPE_FLAG_UNSIGNED, "unsigned long long", objfile); | |
361 | break; | |
362 | case FT_FLOAT: | |
363 | type = init_type (TYPE_CODE_FLT, | |
364 | TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
365 | 0, "real", objfile); | |
366 | break; | |
367 | case FT_DBL_PREC_FLOAT: | |
368 | type = init_type (TYPE_CODE_FLT, | |
369 | TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
370 | 0, "real*8", objfile); | |
371 | break; | |
372 | case FT_FLOAT_DECIMAL: | |
373 | type = init_type (TYPE_CODE_FLT, | |
374 | TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
375 | 0, "floating decimal", objfile); | |
376 | break; | |
377 | case FT_EXT_PREC_FLOAT: | |
378 | type = init_type (TYPE_CODE_FLT, | |
379 | TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, | |
380 | 0, "real*16", objfile); | |
381 | break; | |
382 | case FT_COMPLEX: | |
383 | type = init_type (TYPE_CODE_COMPLEX, | |
384 | 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
385 | 0, "complex*8", objfile); | |
386 | TYPE_TARGET_TYPE (type) = builtin_type_f_real; | |
387 | break; | |
388 | case FT_DBL_PREC_COMPLEX: | |
389 | type = init_type (TYPE_CODE_COMPLEX, | |
390 | 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
391 | 0, "complex*16", objfile); | |
392 | TYPE_TARGET_TYPE (type) = builtin_type_f_real_s8; | |
393 | break; | |
394 | case FT_EXT_PREC_COMPLEX: | |
395 | type = init_type (TYPE_CODE_COMPLEX, | |
396 | 2 * TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, | |
397 | 0, "complex*32", objfile); | |
398 | TYPE_TARGET_TYPE (type) = builtin_type_f_real_s16; | |
399 | break; | |
400 | default: | |
401 | /* FIXME: For now, if we are asked to produce a type not in this | |
c5aa993b JM |
402 | language, create the equivalent of a C integer type with the |
403 | name "<?type?>". When all the dust settles from the type | |
404 | reconstruction work, this should probably become an error. */ | |
c906108c SS |
405 | type = init_type (TYPE_CODE_INT, |
406 | TARGET_INT_BIT / TARGET_CHAR_BIT, | |
407 | 0, "<?type?>", objfile); | |
408 | warning ("internal error: no F77 fundamental type %d", typeid); | |
409 | break; | |
410 | } | |
411 | return (type); | |
412 | } | |
c906108c | 413 | \f |
c5aa993b | 414 | |
c906108c SS |
415 | /* Table of operators and their precedences for printing expressions. */ |
416 | ||
c5aa993b JM |
417 | static const struct op_print f_op_print_tab[] = |
418 | { | |
419 | {"+", BINOP_ADD, PREC_ADD, 0}, | |
420 | {"+", UNOP_PLUS, PREC_PREFIX, 0}, | |
421 | {"-", BINOP_SUB, PREC_ADD, 0}, | |
422 | {"-", UNOP_NEG, PREC_PREFIX, 0}, | |
423 | {"*", BINOP_MUL, PREC_MUL, 0}, | |
424 | {"/", BINOP_DIV, PREC_MUL, 0}, | |
425 | {"DIV", BINOP_INTDIV, PREC_MUL, 0}, | |
426 | {"MOD", BINOP_REM, PREC_MUL, 0}, | |
427 | {"=", BINOP_ASSIGN, PREC_ASSIGN, 1}, | |
428 | {".OR.", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0}, | |
429 | {".AND.", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0}, | |
430 | {".NOT.", UNOP_LOGICAL_NOT, PREC_PREFIX, 0}, | |
431 | {".EQ.", BINOP_EQUAL, PREC_EQUAL, 0}, | |
432 | {".NE.", BINOP_NOTEQUAL, PREC_EQUAL, 0}, | |
433 | {".LE.", BINOP_LEQ, PREC_ORDER, 0}, | |
434 | {".GE.", BINOP_GEQ, PREC_ORDER, 0}, | |
435 | {".GT.", BINOP_GTR, PREC_ORDER, 0}, | |
436 | {".LT.", BINOP_LESS, PREC_ORDER, 0}, | |
437 | {"**", UNOP_IND, PREC_PREFIX, 0}, | |
438 | {"@", BINOP_REPEAT, PREC_REPEAT, 0}, | |
439 | {NULL, 0, 0, 0} | |
c906108c SS |
440 | }; |
441 | \f | |
c5aa993b | 442 | struct type **CONST_PTR (f_builtin_types[]) = |
c906108c SS |
443 | { |
444 | &builtin_type_f_character, | |
c5aa993b JM |
445 | &builtin_type_f_logical, |
446 | &builtin_type_f_logical_s1, | |
447 | &builtin_type_f_logical_s2, | |
448 | &builtin_type_f_integer, | |
449 | &builtin_type_f_integer_s2, | |
450 | &builtin_type_f_real, | |
451 | &builtin_type_f_real_s8, | |
452 | &builtin_type_f_real_s16, | |
453 | &builtin_type_f_complex_s8, | |
454 | &builtin_type_f_complex_s16, | |
c906108c | 455 | #if 0 |
c5aa993b | 456 | &builtin_type_f_complex_s32, |
c906108c | 457 | #endif |
c5aa993b JM |
458 | &builtin_type_f_void, |
459 | 0 | |
c906108c SS |
460 | }; |
461 | ||
462 | /* This is declared in c-lang.h but it is silly to import that file for what | |
463 | is already just a hack. */ | |
d9fcf2fb JM |
464 | extern int c_value_print (struct value *, struct ui_file *, int, |
465 | enum val_prettyprint); | |
c906108c | 466 | |
c5aa993b JM |
467 | const struct language_defn f_language_defn = |
468 | { | |
c906108c SS |
469 | "fortran", |
470 | language_fortran, | |
471 | f_builtin_types, | |
472 | range_check_on, | |
473 | type_check_on, | |
474 | f_parse, /* parser */ | |
475 | f_error, /* parser error function */ | |
476 | evaluate_subexp_standard, | |
477 | f_printchar, /* Print character constant */ | |
478 | f_printstr, /* function to print string constant */ | |
479 | f_emit_char, /* Function to print a single character */ | |
480 | f_create_fundamental_type, /* Create fundamental type in this language */ | |
c5aa993b | 481 | f_print_type, /* Print a type using appropriate syntax */ |
c906108c | 482 | f_val_print, /* Print a value using appropriate syntax */ |
c5aa993b JM |
483 | c_value_print, /* FIXME */ |
484 | {"", "", "", ""}, /* Binary format info */ | |
485 | {"0%o", "0", "o", ""}, /* Octal format info */ | |
486 | {"%d", "", "d", ""}, /* Decimal format info */ | |
487 | {"0x%x", "0x", "x", ""}, /* Hex format info */ | |
c906108c SS |
488 | f_op_print_tab, /* expression operators for printing */ |
489 | 0, /* arrays are first-class (not c-style) */ | |
490 | 1, /* String lower bound */ | |
c5aa993b | 491 | &builtin_type_f_character, /* Type of string elements */ |
c906108c | 492 | LANG_MAGIC |
c5aa993b | 493 | }; |
c906108c SS |
494 | |
495 | void | |
496 | _initialize_f_language () | |
497 | { | |
498 | builtin_type_f_void = | |
499 | init_type (TYPE_CODE_VOID, 1, | |
500 | 0, | |
501 | "VOID", (struct objfile *) NULL); | |
c5aa993b | 502 | |
c906108c SS |
503 | builtin_type_f_character = |
504 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
505 | 0, | |
506 | "character", (struct objfile *) NULL); | |
c5aa993b | 507 | |
c906108c SS |
508 | builtin_type_f_logical_s1 = |
509 | init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
510 | TYPE_FLAG_UNSIGNED, | |
511 | "logical*1", (struct objfile *) NULL); | |
c5aa993b | 512 | |
c906108c SS |
513 | builtin_type_f_integer_s2 = |
514 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
515 | 0, | |
516 | "integer*2", (struct objfile *) NULL); | |
c5aa993b | 517 | |
c906108c SS |
518 | builtin_type_f_logical_s2 = |
519 | init_type (TYPE_CODE_BOOL, TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
520 | TYPE_FLAG_UNSIGNED, | |
521 | "logical*2", (struct objfile *) NULL); | |
c5aa993b | 522 | |
c906108c SS |
523 | builtin_type_f_integer = |
524 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
525 | 0, | |
526 | "integer", (struct objfile *) NULL); | |
c5aa993b | 527 | |
c906108c SS |
528 | builtin_type_f_logical = |
529 | init_type (TYPE_CODE_BOOL, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
530 | TYPE_FLAG_UNSIGNED, | |
531 | "logical*4", (struct objfile *) NULL); | |
c5aa993b | 532 | |
c906108c SS |
533 | builtin_type_f_real = |
534 | init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
535 | 0, | |
536 | "real", (struct objfile *) NULL); | |
c5aa993b | 537 | |
c906108c SS |
538 | builtin_type_f_real_s8 = |
539 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
540 | 0, | |
541 | "real*8", (struct objfile *) NULL); | |
c5aa993b | 542 | |
c906108c SS |
543 | builtin_type_f_real_s16 = |
544 | init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, | |
545 | 0, | |
546 | "real*16", (struct objfile *) NULL); | |
c5aa993b | 547 | |
c906108c SS |
548 | builtin_type_f_complex_s8 = |
549 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
550 | 0, | |
551 | "complex*8", (struct objfile *) NULL); | |
552 | TYPE_TARGET_TYPE (builtin_type_f_complex_s8) = builtin_type_f_real; | |
c5aa993b | 553 | |
c906108c SS |
554 | builtin_type_f_complex_s16 = |
555 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
556 | 0, | |
557 | "complex*16", (struct objfile *) NULL); | |
558 | TYPE_TARGET_TYPE (builtin_type_f_complex_s16) = builtin_type_f_real_s8; | |
c5aa993b | 559 | |
c906108c SS |
560 | /* We have a new size == 4 double floats for the |
561 | complex*32 data type */ | |
c5aa993b JM |
562 | |
563 | builtin_type_f_complex_s32 = | |
c906108c SS |
564 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, |
565 | 0, | |
566 | "complex*32", (struct objfile *) NULL); | |
567 | TYPE_TARGET_TYPE (builtin_type_f_complex_s32) = builtin_type_f_real_s16; | |
568 | ||
569 | builtin_type_string = | |
570 | init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
571 | 0, | |
c5aa993b JM |
572 | "character string", (struct objfile *) NULL); |
573 | ||
c906108c SS |
574 | add_language (&f_language_defn); |
575 | } | |
576 | ||
577 | #if 0 | |
578 | static SAVED_BF_PTR | |
c5aa993b | 579 | allocate_saved_bf_node () |
c906108c SS |
580 | { |
581 | SAVED_BF_PTR new; | |
c5aa993b | 582 | |
c906108c | 583 | new = (SAVED_BF_PTR) xmalloc (sizeof (SAVED_BF)); |
c5aa993b | 584 | return (new); |
c906108c SS |
585 | } |
586 | ||
587 | static SAVED_FUNCTION * | |
c5aa993b | 588 | allocate_saved_function_node () |
c906108c SS |
589 | { |
590 | SAVED_FUNCTION *new; | |
c5aa993b | 591 | |
c906108c | 592 | new = (SAVED_FUNCTION *) xmalloc (sizeof (SAVED_FUNCTION)); |
c5aa993b | 593 | return (new); |
c906108c SS |
594 | } |
595 | ||
c5aa993b JM |
596 | static SAVED_F77_COMMON_PTR |
597 | allocate_saved_f77_common_node () | |
c906108c SS |
598 | { |
599 | SAVED_F77_COMMON_PTR new; | |
c5aa993b | 600 | |
c906108c | 601 | new = (SAVED_F77_COMMON_PTR) xmalloc (sizeof (SAVED_F77_COMMON)); |
c5aa993b | 602 | return (new); |
c906108c SS |
603 | } |
604 | ||
c5aa993b JM |
605 | static COMMON_ENTRY_PTR |
606 | allocate_common_entry_node () | |
c906108c SS |
607 | { |
608 | COMMON_ENTRY_PTR new; | |
c5aa993b | 609 | |
c906108c | 610 | new = (COMMON_ENTRY_PTR) xmalloc (sizeof (COMMON_ENTRY)); |
c5aa993b | 611 | return (new); |
c906108c SS |
612 | } |
613 | #endif | |
614 | ||
c5aa993b JM |
615 | SAVED_F77_COMMON_PTR head_common_list = NULL; /* Ptr to 1st saved COMMON */ |
616 | SAVED_F77_COMMON_PTR tail_common_list = NULL; /* Ptr to last saved COMMON */ | |
617 | SAVED_F77_COMMON_PTR current_common = NULL; /* Ptr to current COMMON */ | |
c906108c SS |
618 | |
619 | #if 0 | |
c5aa993b JM |
620 | static SAVED_BF_PTR saved_bf_list = NULL; /* Ptr to (.bf,function) |
621 | list */ | |
622 | static SAVED_BF_PTR saved_bf_list_end = NULL; /* Ptr to above list's end */ | |
623 | static SAVED_BF_PTR current_head_bf_list = NULL; /* Current head of above list | |
624 | */ | |
c906108c | 625 | |
c5aa993b JM |
626 | static SAVED_BF_PTR tmp_bf_ptr; /* Generic temporary for use |
627 | in macros */ | |
c906108c SS |
628 | |
629 | /* The following function simply enters a given common block onto | |
630 | the global common block chain */ | |
631 | ||
632 | static void | |
c5aa993b | 633 | add_common_block (name, offset, secnum, func_stab) |
c906108c SS |
634 | char *name; |
635 | CORE_ADDR offset; | |
636 | int secnum; | |
637 | char *func_stab; | |
638 | { | |
639 | SAVED_F77_COMMON_PTR tmp; | |
c5aa993b JM |
640 | char *c, *local_copy_func_stab; |
641 | ||
c906108c SS |
642 | /* If the COMMON block we are trying to add has a blank |
643 | name (i.e. "#BLNK_COM") then we set it to __BLANK | |
644 | because the darn "#" character makes GDB's input | |
c5aa993b JM |
645 | parser have fits. */ |
646 | ||
647 | ||
648 | if (STREQ (name, BLANK_COMMON_NAME_ORIGINAL) || | |
649 | STREQ (name, BLANK_COMMON_NAME_MF77)) | |
c906108c | 650 | { |
c5aa993b JM |
651 | |
652 | free (name); | |
653 | name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1); | |
654 | strcpy (name, BLANK_COMMON_NAME_LOCAL); | |
c906108c | 655 | } |
c5aa993b JM |
656 | |
657 | tmp = allocate_saved_f77_common_node (); | |
658 | ||
659 | local_copy_func_stab = xmalloc (strlen (func_stab) + 1); | |
660 | strcpy (local_copy_func_stab, func_stab); | |
661 | ||
662 | tmp->name = xmalloc (strlen (name) + 1); | |
663 | ||
c906108c | 664 | /* local_copy_func_stab is a stabstring, let us first extract the |
c5aa993b JM |
665 | function name from the stab by NULLing out the ':' character. */ |
666 | ||
667 | ||
668 | c = NULL; | |
669 | c = strchr (local_copy_func_stab, ':'); | |
670 | ||
c906108c SS |
671 | if (c) |
672 | *c = '\0'; | |
673 | else | |
c5aa993b JM |
674 | error ("Malformed function STAB found in add_common_block()"); |
675 | ||
676 | ||
677 | tmp->owning_function = xmalloc (strlen (local_copy_func_stab) + 1); | |
678 | ||
679 | strcpy (tmp->owning_function, local_copy_func_stab); | |
680 | ||
681 | strcpy (tmp->name, name); | |
682 | tmp->offset = offset; | |
c906108c SS |
683 | tmp->next = NULL; |
684 | tmp->entries = NULL; | |
c5aa993b JM |
685 | tmp->secnum = secnum; |
686 | ||
c906108c | 687 | current_common = tmp; |
c5aa993b | 688 | |
c906108c SS |
689 | if (head_common_list == NULL) |
690 | { | |
691 | head_common_list = tail_common_list = tmp; | |
692 | } | |
693 | else | |
694 | { | |
c5aa993b | 695 | tail_common_list->next = tmp; |
c906108c SS |
696 | tail_common_list = tmp; |
697 | } | |
698 | } | |
699 | #endif | |
700 | ||
701 | /* The following function simply enters a given common entry onto | |
c5aa993b | 702 | the "current_common" block that has been saved away. */ |
c906108c SS |
703 | |
704 | #if 0 | |
705 | static void | |
c5aa993b JM |
706 | add_common_entry (entry_sym_ptr) |
707 | struct symbol *entry_sym_ptr; | |
c906108c SS |
708 | { |
709 | COMMON_ENTRY_PTR tmp; | |
c5aa993b JM |
710 | |
711 | ||
712 | ||
c906108c SS |
713 | /* The order of this list is important, since |
714 | we expect the entries to appear in decl. | |
c5aa993b JM |
715 | order when we later issue "info common" calls */ |
716 | ||
717 | tmp = allocate_common_entry_node (); | |
718 | ||
c906108c SS |
719 | tmp->next = NULL; |
720 | tmp->symbol = entry_sym_ptr; | |
c5aa993b | 721 | |
c906108c | 722 | if (current_common == NULL) |
c5aa993b JM |
723 | error ("Attempt to add COMMON entry with no block open!"); |
724 | else | |
c906108c SS |
725 | { |
726 | if (current_common->entries == NULL) | |
727 | { | |
728 | current_common->entries = tmp; | |
c5aa993b | 729 | current_common->end_of_entries = tmp; |
c906108c SS |
730 | } |
731 | else | |
732 | { | |
c5aa993b JM |
733 | current_common->end_of_entries->next = tmp; |
734 | current_common->end_of_entries = tmp; | |
c906108c SS |
735 | } |
736 | } | |
737 | } | |
738 | #endif | |
739 | ||
c5aa993b | 740 | /* This routine finds the first encountred COMMON block named "name" */ |
c906108c SS |
741 | |
742 | #if 0 | |
743 | static SAVED_F77_COMMON_PTR | |
c5aa993b JM |
744 | find_first_common_named (name) |
745 | char *name; | |
c906108c | 746 | { |
c5aa993b | 747 | |
c906108c | 748 | SAVED_F77_COMMON_PTR tmp; |
c5aa993b | 749 | |
c906108c | 750 | tmp = head_common_list; |
c5aa993b | 751 | |
c906108c SS |
752 | while (tmp != NULL) |
753 | { | |
c5aa993b JM |
754 | if (STREQ (tmp->name, name)) |
755 | return (tmp); | |
c906108c SS |
756 | else |
757 | tmp = tmp->next; | |
758 | } | |
c5aa993b | 759 | return (NULL); |
c906108c SS |
760 | } |
761 | #endif | |
762 | ||
763 | /* This routine finds the first encountred COMMON block named "name" | |
c5aa993b | 764 | that belongs to function funcname */ |
c906108c | 765 | |
c5aa993b JM |
766 | SAVED_F77_COMMON_PTR |
767 | find_common_for_function (name, funcname) | |
c906108c | 768 | char *name; |
c5aa993b | 769 | char *funcname; |
c906108c | 770 | { |
c5aa993b | 771 | |
c906108c | 772 | SAVED_F77_COMMON_PTR tmp; |
c5aa993b | 773 | |
c906108c | 774 | tmp = head_common_list; |
c5aa993b | 775 | |
c906108c SS |
776 | while (tmp != NULL) |
777 | { | |
c5aa993b JM |
778 | if (STREQ (tmp->name, name) && STREQ (tmp->owning_function, funcname)) |
779 | return (tmp); | |
c906108c SS |
780 | else |
781 | tmp = tmp->next; | |
782 | } | |
c5aa993b | 783 | return (NULL); |
c906108c SS |
784 | } |
785 | ||
786 | ||
787 | #if 0 | |
788 | ||
789 | /* The following function is called to patch up the offsets | |
790 | for the statics contained in the COMMON block named | |
c5aa993b | 791 | "name." */ |
c906108c SS |
792 | |
793 | static void | |
794 | patch_common_entries (blk, offset, secnum) | |
795 | SAVED_F77_COMMON_PTR blk; | |
796 | CORE_ADDR offset; | |
797 | int secnum; | |
798 | { | |
799 | COMMON_ENTRY_PTR entry; | |
c5aa993b JM |
800 | |
801 | blk->offset = offset; /* Keep this around for future use. */ | |
802 | ||
c906108c | 803 | entry = blk->entries; |
c5aa993b | 804 | |
c906108c SS |
805 | while (entry != NULL) |
806 | { | |
c5aa993b | 807 | SYMBOL_VALUE (entry->symbol) += offset; |
c906108c | 808 | SYMBOL_SECTION (entry->symbol) = secnum; |
c5aa993b | 809 | |
c906108c SS |
810 | entry = entry->next; |
811 | } | |
c5aa993b | 812 | blk->secnum = secnum; |
c906108c SS |
813 | } |
814 | ||
815 | /* Patch all commons named "name" that need patching.Since COMMON | |
816 | blocks occur with relative infrequency, we simply do a linear scan on | |
817 | the name. Eventually, the best way to do this will be a | |
818 | hashed-lookup. Secnum is the section number for the .bss section | |
819 | (which is where common data lives). */ | |
820 | ||
821 | static void | |
822 | patch_all_commons_by_name (name, offset, secnum) | |
823 | char *name; | |
824 | CORE_ADDR offset; | |
825 | int secnum; | |
826 | { | |
c5aa993b | 827 | |
c906108c | 828 | SAVED_F77_COMMON_PTR tmp; |
c5aa993b | 829 | |
c906108c SS |
830 | /* For blank common blocks, change the canonical reprsentation |
831 | of a blank name */ | |
c5aa993b JM |
832 | |
833 | if ((STREQ (name, BLANK_COMMON_NAME_ORIGINAL)) || | |
834 | (STREQ (name, BLANK_COMMON_NAME_MF77))) | |
c906108c | 835 | { |
c5aa993b JM |
836 | free (name); |
837 | name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1); | |
838 | strcpy (name, BLANK_COMMON_NAME_LOCAL); | |
c906108c | 839 | } |
c5aa993b | 840 | |
c906108c | 841 | tmp = head_common_list; |
c5aa993b | 842 | |
c906108c SS |
843 | while (tmp != NULL) |
844 | { | |
c5aa993b JM |
845 | if (COMMON_NEEDS_PATCHING (tmp)) |
846 | if (STREQ (tmp->name, name)) | |
847 | patch_common_entries (tmp, offset, secnum); | |
848 | ||
c906108c | 849 | tmp = tmp->next; |
c5aa993b | 850 | } |
c906108c SS |
851 | } |
852 | #endif | |
853 | ||
854 | /* This macro adds the symbol-number for the start of the function | |
855 | (the symbol number of the .bf) referenced by symnum_fcn to a | |
856 | list. This list, in reality should be a FIFO queue but since | |
857 | #line pragmas sometimes cause line ranges to get messed up | |
858 | we simply create a linear list. This list can then be searched | |
859 | first by a queueing algorithm and upon failure fall back to | |
c5aa993b | 860 | a linear scan. */ |
c906108c SS |
861 | |
862 | #if 0 | |
863 | #define ADD_BF_SYMNUM(bf_sym,fcn_sym) \ | |
864 | \ | |
865 | if (saved_bf_list == NULL) \ | |
866 | { \ | |
867 | tmp_bf_ptr = allocate_saved_bf_node(); \ | |
868 | \ | |
869 | tmp_bf_ptr->symnum_bf = (bf_sym); \ | |
870 | tmp_bf_ptr->symnum_fcn = (fcn_sym); \ | |
871 | tmp_bf_ptr->next = NULL; \ | |
872 | \ | |
873 | current_head_bf_list = saved_bf_list = tmp_bf_ptr; \ | |
874 | saved_bf_list_end = tmp_bf_ptr; \ | |
875 | } \ | |
876 | else \ | |
877 | { \ | |
878 | tmp_bf_ptr = allocate_saved_bf_node(); \ | |
879 | \ | |
880 | tmp_bf_ptr->symnum_bf = (bf_sym); \ | |
881 | tmp_bf_ptr->symnum_fcn = (fcn_sym); \ | |
882 | tmp_bf_ptr->next = NULL; \ | |
883 | \ | |
884 | saved_bf_list_end->next = tmp_bf_ptr; \ | |
885 | saved_bf_list_end = tmp_bf_ptr; \ | |
c5aa993b | 886 | } |
c906108c SS |
887 | #endif |
888 | ||
c5aa993b | 889 | /* This function frees the entire (.bf,function) list */ |
c906108c SS |
890 | |
891 | #if 0 | |
c5aa993b JM |
892 | static void |
893 | clear_bf_list () | |
c906108c | 894 | { |
c5aa993b | 895 | |
c906108c | 896 | SAVED_BF_PTR tmp = saved_bf_list; |
c5aa993b JM |
897 | SAVED_BF_PTR next = NULL; |
898 | ||
c906108c SS |
899 | while (tmp != NULL) |
900 | { | |
901 | next = tmp->next; | |
c5aa993b JM |
902 | free (tmp); |
903 | tmp = next; | |
c906108c SS |
904 | } |
905 | saved_bf_list = NULL; | |
906 | } | |
907 | #endif | |
908 | ||
909 | int global_remote_debug; | |
910 | ||
911 | #if 0 | |
912 | ||
913 | static long | |
914 | get_bf_for_fcn (the_function) | |
915 | long the_function; | |
916 | { | |
917 | SAVED_BF_PTR tmp; | |
918 | int nprobes = 0; | |
c5aa993b | 919 | |
c906108c SS |
920 | /* First use a simple queuing algorithm (i.e. look and see if the |
921 | item at the head of the queue is the one you want) */ | |
c5aa993b | 922 | |
c906108c | 923 | if (saved_bf_list == NULL) |
96baa820 | 924 | internal_error ("cannot get .bf node off empty list"); |
c5aa993b JM |
925 | |
926 | if (current_head_bf_list != NULL) | |
c906108c SS |
927 | if (current_head_bf_list->symnum_fcn == the_function) |
928 | { | |
c5aa993b JM |
929 | if (global_remote_debug) |
930 | fprintf (stderr, "*"); | |
c906108c | 931 | |
c5aa993b | 932 | tmp = current_head_bf_list; |
c906108c | 933 | current_head_bf_list = current_head_bf_list->next; |
c5aa993b | 934 | return (tmp->symnum_bf); |
c906108c | 935 | } |
c5aa993b | 936 | |
c906108c SS |
937 | /* If the above did not work (probably because #line directives were |
938 | used in the sourcefile and they messed up our internal tables) we now do | |
939 | the ugly linear scan */ | |
c5aa993b JM |
940 | |
941 | if (global_remote_debug) | |
942 | fprintf (stderr, "\ndefaulting to linear scan\n"); | |
943 | ||
944 | nprobes = 0; | |
c906108c SS |
945 | tmp = saved_bf_list; |
946 | while (tmp != NULL) | |
947 | { | |
c5aa993b | 948 | nprobes++; |
c906108c | 949 | if (tmp->symnum_fcn == the_function) |
c5aa993b | 950 | { |
c906108c | 951 | if (global_remote_debug) |
c5aa993b | 952 | fprintf (stderr, "Found in %d probes\n", nprobes); |
c906108c | 953 | current_head_bf_list = tmp->next; |
c5aa993b JM |
954 | return (tmp->symnum_bf); |
955 | } | |
956 | tmp = tmp->next; | |
c906108c | 957 | } |
c5aa993b JM |
958 | |
959 | return (-1); | |
c906108c SS |
960 | } |
961 | ||
c5aa993b JM |
962 | static SAVED_FUNCTION_PTR saved_function_list = NULL; |
963 | static SAVED_FUNCTION_PTR saved_function_list_end = NULL; | |
c906108c SS |
964 | |
965 | static void | |
c5aa993b | 966 | clear_function_list () |
c906108c SS |
967 | { |
968 | SAVED_FUNCTION_PTR tmp = saved_function_list; | |
c5aa993b JM |
969 | SAVED_FUNCTION_PTR next = NULL; |
970 | ||
c906108c SS |
971 | while (tmp != NULL) |
972 | { | |
973 | next = tmp->next; | |
c5aa993b | 974 | free (tmp); |
c906108c SS |
975 | tmp = next; |
976 | } | |
c5aa993b | 977 | |
c906108c SS |
978 | saved_function_list = NULL; |
979 | } | |
980 | #endif |