rest of utah changes
[deliverable/binutils-gdb.git] / ld / ldexp.c
CommitLineData
c611e285
SC
1/* This module handles expression trees.
2Copyright (C) 1991 Free Software Foundation, Inc.
3Written by Steve Chamberlain of Cygnus Support (sac@cygnus.com).
2fa0b342
DHW
4
5This file is part of GLD, the Gnu Linker.
6
7GLD is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
c611e285 9the Free Software Foundation; either version 2, or (at your option)
2fa0b342
DHW
10any later version.
11
12GLD is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GLD; see the file COPYING. If not, write to
19the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21/*
c611e285 22This module is in charge of working out the contents of expressions.
2fa0b342 23
c611e285
SC
24It has to keep track of the relative/absness of a symbol etc. This is
25done by keeping all values in a struct (an etree_value_type) which
26contains a value, a section to which it is relative and a valid bit.
27
28*/
2fa0b342
DHW
29
30
2fa0b342 31#include "bfd.h"
c611e285 32#include "sysdep.h"
2fa0b342
DHW
33
34#include "ld.h"
35#include "ldmain.h"
36#include "ldmisc.h"
37#include "ldexp.h"
c611e285 38#include "ldgram.h"
2fa0b342
DHW
39#include "ldsym.h"
40#include "ldlang.h"
41
42extern char *output_filename;
43extern unsigned int undefined_global_sym_count;
44extern unsigned int defined_global_sym_count;
45extern bfd *output_bfd;
c611e285 46extern bfd_size_type largest_section;
2fa0b342
DHW
47extern lang_statement_list_type file_chain;
48extern args_type command_line;
49extern ld_config_type config;
50
51extern lang_input_statement_type *script_file;
52extern unsigned int defined_global_sym_count;
76971f0d 53 extern lang_output_section_statement_type *abs_output_section;
2fa0b342
DHW
54extern bfd_vma print_dot;
55
56
57static void
2e2bf962 58DEFUN(exp_print_token,( code),
c611e285 59 token_code_type code)
2fa0b342
DHW
60{
61 static struct {
62 token_code_type code;
63 char *name;
64 } table[] =
c611e285
SC
65 {
66 INT, "int",
67 NAME,"NAME",
68 PLUSEQ,"+=",
69 MINUSEQ,"-=",
70 MULTEQ,"*=",
71 DIVEQ,"/=",
72 LSHIFTEQ,"<<=",
73 RSHIFTEQ,">>=",
74 ANDEQ,"&=",
75 OREQ,"|=",
76 OROR,"||",
77 ANDAND,"&&",
78 EQ,"==",
79 NE,"!=",
80 LE,"<=",
81 GE,">=",
82 LSHIFT,"<<",
83 RSHIFT,">>=",
84 ALIGN_K,"ALIGN",
85 BLOCK,"BLOCK",
86 SECTIONS,"SECTIONS",
87 SIZEOF_HEADERS,"SIZEOF_HEADERS",
88 NEXT,"NEXT",
89 SIZEOF,"SIZEOF",
90 ADDR,"ADDR",
91 MEMORY,"MEMORY",
92
93
94
95
96
97 DEFINED,"DEFINED",
98 TARGET_K,"TARGET",
99 SEARCH_DIR,"SEARCH_DIR",
100 MAP,"MAP",
101 LONG,"LONG",
102 SHORT,"SHORT",
103 BYTE,"BYTE",
104 ENTRY,"ENTRY",
105 0,(char *)NULL} ;
2fa0b342
DHW
106
107
108
109 unsigned int idx;
110 for (idx = 0; table[idx].name != (char*)NULL; idx++) {
111 if (table[idx].code == code) {
2e2bf962 112 fprintf(config.map_file, "%s", table[idx].name);
2fa0b342
DHW
113 return;
114 }
115 }
116 /* Not in table, just print it alone */
2e2bf962 117 fprintf(config.map_file, "%c",code);
2fa0b342
DHW
118}
119
120static void
c611e285
SC
121DEFUN(make_abs,(ptr),
122 etree_value_type *ptr)
2fa0b342 123{
2fa0b342
DHW
124 asection *s = ptr->section->bfd_section;
125 ptr->value += s->vma;
76971f0d 126 ptr->section = abs_output_section;
2fa0b342 127}
c611e285 128
2fa0b342 129static
c611e285
SC
130DEFUN(etree_value_type new_abs,(value),
131 bfd_vma value)
2fa0b342 132{
76971f0d
SC
133
134
2fa0b342
DHW
135 etree_value_type new;
136 new.valid = true;
76971f0d 137 new.section = abs_output_section;
2fa0b342
DHW
138 new.value = value;
139 return new;
140}
141
3a399523
SC
142static void
143DEFUN(check, (os, name, op),
144 lang_output_section_statement_type *os AND
145 CONST char *name AND
146 CONST char *op)
2fa0b342
DHW
147{
148 if (os == (lang_output_section_statement_type *)NULL) {
c611e285 149 einfo("%F%P %s uses undefined section %s\n", op, name);
2fa0b342
DHW
150 }
151 if (os->processed == false) {
c611e285 152 einfo("%F%P %s forward reference of section %s\n",op, name);
2fa0b342
DHW
153 }
154}
155
c611e285
SC
156etree_type *
157DEFUN(exp_intop,(value),
158 bfd_vma value)
2fa0b342 159{
bfbdc80f 160 etree_type *new = (etree_type *)stat_alloc((bfd_size_type)(sizeof(new->value)));
2fa0b342
DHW
161 new->type.node_code = INT;
162 new->value.value = value;
163 new->type.node_class = etree_value;
164 return new;
165
166}
167
168
169static
c611e285
SC
170DEFUN(etree_value_type new_rel,(value, section),
171 bfd_vma value AND
172 lang_output_section_statement_type *section)
2fa0b342
DHW
173{
174 etree_value_type new;
175 new.valid = true;
176 new.value = value;
177 new.section = section;
178 return new;
179}
180
181static
c611e285
SC
182DEFUN(etree_value_type
183 new_rel_from_section, (value, section),
184 bfd_vma value AND
185 lang_output_section_statement_type *section)
2fa0b342
DHW
186{
187 etree_value_type new;
188 new.valid = true;
189 new.value = value;
190 new.section = section;
76971f0d 191
2fa0b342 192 new.value -= section->bfd_section->vma;
76971f0d 193
2fa0b342
DHW
194 return new;
195}
196
197static etree_value_type
c611e285
SC
198DEFUN(fold_binary,(tree, current_section, allocation_done, dot, dotp),
199 etree_type *tree AND
200 lang_output_section_statement_type *current_section AND
201 lang_phase_type allocation_done AND
202 bfd_vma dot AND
203 bfd_vma *dotp)
2fa0b342
DHW
204{
205 etree_value_type result;
206
207 result = exp_fold_tree(tree->binary.lhs, current_section,
208 allocation_done, dot, dotp);
209 if (result.valid) {
210 etree_value_type other;
211 other = exp_fold_tree(tree->binary.rhs,
212 current_section,
213 allocation_done, dot,dotp) ;
214 if (other.valid) {
215 /* If values are from different sections, or this is an */
216 /* absolute expression, make both source args absolute */
217 if (result.section != other.section ||
76971f0d
SC
218 current_section == abs_output_section)
219 {
2fa0b342
DHW
220 make_abs(&result);
221 make_abs(&other);
222 }
223
224 switch (tree->type.node_code)
225 {
226 case '%':
227 /* Mod, both absolule*/
228
229 if (other.value == 0) {
c611e285 230 einfo("%F%S % by zero\n");
2fa0b342 231 }
76971f0d 232 result.value = (int)result.value % (int)other.value;
2fa0b342
DHW
233 break;
234 case '/':
235 if (other.value == 0) {
c611e285 236 einfo("%F%S / by zero\n");
2fa0b342 237 }
76971f0d 238 result.value = (int)result.value / (int) other.value;
2fa0b342
DHW
239 break;
240#define BOP(x,y) case x : result.value = result.value y other.value;break;
241 BOP('+',+);
242 BOP('*',*);
243 BOP('-',-);
244 BOP(LSHIFT,<<);
245 BOP(RSHIFT,>>);
246 BOP(EQ,==);
247 BOP(NE,!=);
248 BOP('<',<);
249 BOP('>',>);
250 BOP(LE,<=);
251 BOP(GE,>=);
252 BOP('&',&);
253 BOP('^',^);
254 BOP('|',|);
255 BOP(ANDAND,&&);
256 BOP(OROR,||);
257 default:
258 FAIL();
259 }
260 }
070aa819
SC
261 else {
262 result.valid = false;
263 }
2fa0b342
DHW
264 }
265 return result;
266}
c611e285
SC
267etree_value_type
268DEFUN_VOID(invalid)
2fa0b342
DHW
269{
270 etree_value_type new;
271 new.valid = false;
272 return new;
273}
274
c611e285
SC
275etree_value_type
276DEFUN(fold_name, (tree, current_section, allocation_done, dot),
277 etree_type *tree AND
278 lang_output_section_statement_type *current_section AND
279 lang_phase_type allocation_done AND
280 bfd_vma dot)
2fa0b342
DHW
281{
282 etree_value_type result;
283 switch (tree->type.node_code)
ac004870 284 {
65c552e3
SC
285 case SIZEOF_HEADERS:
286 if (allocation_done != lang_first_phase_enum)
287 {
288 result = new_abs(bfd_sizeof_headers(output_bfd,
289 config.relocateable_output));
290
291 }
292 else {
293 result.valid = false;
294 }
295 break;
ac004870
SC
296 case DEFINED:
297 result.value =
298 ldsym_get_soft(tree->name.name) != (ldsym_type *)NULL;
299 result.section = 0;
300 result.valid = true;
301 break;
302 case NAME:
303 result.valid = false;
304 if (tree->name.name[0] == '.' && tree->name.name[1] == 0) {
305
306 if (allocation_done != lang_first_phase_enum) {
307 result = new_rel_from_section(dot, current_section);
308 }
309 else {
310 result = invalid();
311 }
2fa0b342
DHW
312 }
313 else {
ac004870
SC
314 if (allocation_done == lang_final_phase_enum) {
315 ldsym_type *sy = ldsym_get_soft(tree->name.name);
2fa0b342 316
ac004870
SC
317 if (sy) {
318 asymbol **sdefp = sy->sdefs_chain;
319
320 if (sdefp) {
321 asymbol *sdef = *sdefp;
76971f0d 322#if 0
ac004870
SC
323 if (sdef->section == (asection *)NULL) {
324 /* This is an absolute symbol */
325 result = new_abs(sdef->value);
326 }
76971f0d
SC
327 else
328#endif
329 {
ac004870
SC
330 lang_output_section_statement_type *os =
331 lang_output_section_statement_lookup(
332 sdef->section->output_section->name);
333 /* If the symbol is from a file which we are not
334 relocating (-R) then return an absolute for its
335 value */
336 if (sdef->the_bfd->usrdata &&
337 ((lang_input_statement_type*)(sdef->the_bfd->usrdata))->just_syms_flag == true)
338 {
76971f0d
SC
339 result = new_abs(sdef->value +sdef->section->vma);
340
ac004870
SC
341 }
342 else {
a37cc0c0 343 result = new_rel(sdef->value + sdef->section->output_offset, os);
ac004870
SC
344 }
345 }
2fa0b342
DHW
346 }
347 }
ac004870 348 if (result.valid == false) {
c611e285 349 einfo("%F%S: undefined symbol `%s' referenced in expression.\n",
2fa0b342 350 tree->name.name);
ac004870 351 }
2fa0b342 352
ac004870 353 }
2fa0b342 354 }
2fa0b342 355
ac004870 356 break;
2fa0b342 357
ac004870 358 case ADDR:
2fa0b342 359
ac004870
SC
360 if (allocation_done != lang_first_phase_enum) {
361 lang_output_section_statement_type *os =
362 lang_output_section_find(tree->name.name);
363 check(os,tree->name.name,"ADDR");
364 result = new_rel((bfd_vma)0, os);
365 }
366 else {
367 result = invalid();
368 }
369 break;
370 case SIZEOF:
371 if(allocation_done != lang_first_phase_enum) {
372 lang_output_section_statement_type *os =
373 lang_output_section_find(tree->name.name);
374 check(os,tree->name.name,"SIZEOF");
c611e285 375 result = new_abs((bfd_vma)(os->bfd_section->_raw_size));
ac004870
SC
376 }
377 else {
378 result = invalid();
379 }
380 break;
2fa0b342 381
ac004870
SC
382 default:
383 FAIL();
384 break;
385 }
2fa0b342
DHW
386
387 return result;
388}
c611e285
SC
389etree_value_type
390DEFUN(exp_fold_tree,(tree, current_section, allocation_done,
391 dot, dotp),
392 etree_type *tree AND
393 lang_output_section_statement_type *current_section AND
394 lang_phase_type allocation_done AND
395 bfd_vma dot AND
396 bfd_vma *dotp)
2fa0b342
DHW
397{
398 etree_value_type result;
399
400 if (tree == (etree_type *)NULL) {
c611e285
SC
401 result.valid = false;
402 }
2fa0b342 403 else {
c611e285
SC
404 switch (tree->type.node_class)
405 {
406 case etree_value:
407 result = new_rel(tree->value.value, current_section);
408 break;
409 case etree_unary:
410 result = exp_fold_tree(tree->unary.child,
411 current_section,
412 allocation_done, dot, dotp);
413 if (result.valid == true)
d4c02e29 414 {
c611e285
SC
415 switch(tree->type.node_code)
416 {
417 case ALIGN_K:
418 if (allocation_done != lang_first_phase_enum) {
419 result = new_rel_from_section(ALIGN(dot,
420 result.value) ,
421 current_section);
d4c02e29 422
2fa0b342 423 }
c611e285
SC
424 else {
425 result.valid = false;
426 }
427 break;
428 case '~':
429 make_abs(&result);
430 result.value = ~result.value;
431 break;
432 case '!':
433 make_abs(&result);
434 result.value = !result.value;
435 break;
436 case '-':
437 make_abs(&result);
438 result.value = -result.value;
439 break;
440 case NEXT:
441 if (allocation_done ==lang_allocating_phase_enum) {
442 make_abs(&result);
443 result.value = ALIGN(dot, result.value);
444 }
445 else {
446 /* Return next place aligned to value */
447 result.valid = false;
448 }
449 break;
450 default:
451 FAIL();
452 }
453 }
2fa0b342 454
c611e285
SC
455 break;
456 case etree_trinary:
2fa0b342 457
c611e285
SC
458 result = exp_fold_tree(tree->trinary.cond,
459 current_section,
460 allocation_done, dot, dotp);
461 if (result.valid) {
d4c02e29
SC
462 result = exp_fold_tree(result.value ?
463 tree->trinary.lhs:tree->trinary.rhs,
2fa0b342 464 current_section,
d4c02e29
SC
465 allocation_done, dot, dotp);
466 }
467
c611e285
SC
468 break;
469 case etree_binary:
470 result = fold_binary(tree, current_section, allocation_done,
471 dot, dotp);
472 break;
473 case etree_assign:
474 if (tree->assign.dst[0] == '.' && tree->assign.dst[1] == 0) {
d4c02e29
SC
475 /* Assignment to dot can only be done during allocation */
476 if (allocation_done == lang_allocating_phase_enum) {
c611e285
SC
477 result = exp_fold_tree(tree->assign.src,
478 current_section,
479 lang_allocating_phase_enum, dot, dotp);
480 if (result.valid == false) {
481 einfo("%F%S invalid assignment to location counter\n");
d4c02e29 482 }
c611e285
SC
483 else {
484 if (current_section ==
485 (lang_output_section_statement_type *)NULL) {
486 einfo("%F%S assignment to location counter invalid outside of SECTION\n");
487 }
488 else {
489 unsigned long nextdot =result.value +
490 current_section->bfd_section->vma;
491 if (nextdot < dot) {
492 einfo("%F%S cannot move location counter backwards");
493 }
494 else {
495 *dotp = nextdot;
496 }
497 }
d4c02e29 498 }
2fa0b342 499 }
2fa0b342 500 }
c611e285 501 else {
d4c02e29
SC
502 ldsym_type *sy = ldsym_get(tree->assign.dst);
503
504 /* If this symbol has just been created then we'll place it into
505 * a section of our choice
506 */
507 result = exp_fold_tree(tree->assign.src,
508 current_section, allocation_done,
509 dot, dotp);
510 if (result.valid)
c611e285
SC
511 {
512 asymbol *def;
513 asymbol **def_ptr ;
514 /* Add this definition to script file */
515 if (sy->sdefs_chain)
516 {
517 def_ptr = sy->sdefs_chain;
518 def = *def_ptr;
519
520 }
521 else
522 {
bfbdc80f 523 def_ptr = (asymbol **)stat_alloc((bfd_size_type)(sizeof(asymbol **)));
76971f0d 524 def = (asymbol *)bfd_make_empty_symbol(script_file->the_bfd);
c611e285
SC
525
526
76971f0d
SC
527 def->flags = 0;
528
529 sy->sdefs_chain = def_ptr;
c611e285
SC
530 *def_ptr = def;
531 }
532
533 def->value = result.value;
76971f0d 534
d4c02e29
SC
535 def->section = result.section->bfd_section;
536 def->flags = BSF_GLOBAL | BSF_EXPORT;
d4c02e29
SC
537
538
c611e285
SC
539 def->udata = (PTR)NULL;
540 def->name = sy->name;
541
542 if (sy->sdefs_chain == 0) Q_enter_global_ref(def_ptr);
543 }
2fa0b342 544
d4c02e29 545 }
2fa0b342
DHW
546
547
c611e285
SC
548 break;
549 case etree_name:
550 result = fold_name(tree, current_section, allocation_done, dot);
551 break;
552 default:
553 einfo("%F%S Need more of these %d",tree->type.node_class );
2fa0b342 554
c611e285
SC
555 }
556 }
2fa0b342
DHW
557
558 return result;
559}
560
561
c611e285
SC
562etree_value_type
563DEFUN(exp_fold_tree_no_dot,(tree, current_section, allocation_done),
564 etree_type *tree AND
565 lang_output_section_statement_type *current_section AND
566 lang_phase_type allocation_done)
2fa0b342
DHW
567{
568return exp_fold_tree(tree, current_section, allocation_done, (bfd_vma)
569 0, (bfd_vma *)NULL);
570}
571
572etree_type *
c611e285
SC
573DEFUN(exp_binop,(code, lhs, rhs),
574 int code AND
575 etree_type *lhs AND
576 etree_type *rhs)
2fa0b342
DHW
577{
578 etree_type value, *new;
579 etree_value_type r;
580
581 value.type.node_code = code;
582 value.binary.lhs = lhs;
583 value.binary.rhs = rhs;
584 value.type.node_class = etree_binary;
76971f0d
SC
585 r = exp_fold_tree_no_dot(&value,
586 abs_output_section,
2fa0b342
DHW
587 lang_first_phase_enum );
588 if (r.valid)
589 {
590 return exp_intop(r.value);
591 }
bfbdc80f 592 new = (etree_type *)stat_alloc((bfd_size_type)(sizeof(new->binary)));
2fa0b342
DHW
593 memcpy((char *)new, (char *)&value, sizeof(new->binary));
594 return new;
595}
596
597etree_type *
c611e285
SC
598DEFUN(exp_trinop,(code, cond, lhs, rhs),
599 int code AND
600 etree_type *cond AND
601 etree_type *lhs AND
602 etree_type *rhs)
2fa0b342
DHW
603{
604 etree_type value, *new;
605 etree_value_type r;
606 value.type.node_code = code;
607 value.trinary.lhs = lhs;
608 value.trinary.cond = cond;
609 value.trinary.rhs = rhs;
610 value.type.node_class = etree_trinary;
611 r= exp_fold_tree_no_dot(&value, (lang_output_section_statement_type
612 *)NULL,lang_first_phase_enum);
613 if (r.valid) {
614 return exp_intop(r.value);
615 }
bfbdc80f 616 new = (etree_type *)stat_alloc((bfd_size_type)(sizeof(new->trinary)));
2fa0b342
DHW
617 memcpy((char *)new,(char *) &value, sizeof(new->trinary));
618 return new;
619}
620
621
622etree_type *
c611e285
SC
623DEFUN(exp_unop,(code, child),
624 int code AND
625 etree_type *child)
2fa0b342
DHW
626{
627 etree_type value, *new;
628
629 etree_value_type r;
630 value.unary.type.node_code = code;
631 value.unary.child = child;
632 value.unary.type.node_class = etree_unary;
c611e285
SC
633 r = exp_fold_tree_no_dot(&value,(lang_output_section_statement_type *)NULL,
634 lang_first_phase_enum);
635 if (r.valid) {
2fa0b342
DHW
636 return exp_intop(r.value);
637 }
bfbdc80f 638 new = (etree_type *)stat_alloc((bfd_size_type)(sizeof(new->unary)));
2fa0b342
DHW
639 memcpy((char *)new, (char *)&value, sizeof(new->unary));
640 return new;
641}
642
643
644etree_type *
c611e285
SC
645DEFUN(exp_nameop,(code, name),
646 int code AND
647 CONST char *name)
2fa0b342
DHW
648{
649
650 etree_type value, *new;
2fa0b342
DHW
651 etree_value_type r;
652 value.name.type.node_code = code;
653 value.name.name = name;
654 value.name.type.node_class = etree_name;
655
656
76971f0d
SC
657 r = exp_fold_tree_no_dot(&value,
658 (lang_output_section_statement_type *)NULL,
659 lang_first_phase_enum);
2fa0b342
DHW
660 if (r.valid) {
661 return exp_intop(r.value);
662 }
bfbdc80f 663 new = (etree_type *)stat_alloc((bfd_size_type)(sizeof(new->name)));
2fa0b342
DHW
664 memcpy((char *)new, (char *)&value, sizeof(new->name));
665 return new;
666
667}
668
669
670
671
672etree_type *
c611e285
SC
673DEFUN(exp_assop,(code, dst, src),
674 int code AND
675 CONST char *dst AND
676 etree_type *src)
2fa0b342
DHW
677{
678 etree_type value, *new;
679
680 value.assign.type.node_code = code;
681
682
683 value.assign.src = src;
684 value.assign.dst = dst;
685 value.assign.type.node_class = etree_assign;
686
687#if 0
688 if (exp_fold_tree_no_dot(&value, &result)) {
689 return exp_intop(result);
690 }
691#endif
bfbdc80f 692 new = (etree_type*)stat_alloc((bfd_size_type)(sizeof(new->assign)));
2fa0b342
DHW
693 memcpy((char *)new, (char *)&value, sizeof(new->assign));
694 return new;
695}
696
697void
2e2bf962 698DEFUN(exp_print_tree,(tree),
c611e285 699 etree_type *tree)
2fa0b342
DHW
700{
701 switch (tree->type.node_class) {
702 case etree_value:
c611e285 703 print_address(tree->value.value);
2fa0b342 704 return;
c611e285 705
2fa0b342
DHW
706 case etree_assign:
707#if 0
708 if (tree->assign.dst->sdefs != (asymbol *)NULL){
2e2bf962 709 fprintf(config.map_file,"%s (%x) ",tree->assign.dst->name,
2fa0b342
DHW
710 tree->assign.dst->sdefs->value);
711 }
712 else {
2e2bf962 713 fprintf(config.map_file,"%s (UNDEFINED)",tree->assign.dst->name);
2fa0b342
DHW
714 }
715#endif
2e2bf962
SC
716 fprintf(config.map_file,"%s ",tree->assign.dst);
717 exp_print_token(tree->type.node_code);
718 exp_print_tree(tree->assign.src);
2fa0b342
DHW
719 break;
720 case etree_binary:
bfbdc80f 721 fprintf(config.map_file,"(");
2e2bf962
SC
722 exp_print_tree(tree->binary.lhs);
723 exp_print_token(tree->type.node_code);
724 exp_print_tree(tree->binary.rhs);
bfbdc80f 725 fprintf(config.map_file,")");
2fa0b342
DHW
726 break;
727 case etree_trinary:
2e2bf962
SC
728 exp_print_tree(tree->trinary.cond);
729 fprintf(config.map_file,"?");
730 exp_print_tree(tree->trinary.lhs);
731 fprintf(config.map_file,":");
732 exp_print_tree(tree->trinary.rhs);
2fa0b342
DHW
733 break;
734 case etree_unary:
2e2bf962 735 exp_print_token(tree->unary.type.node_code);
bfbdc80f
SC
736 if (tree->unary.child)
737 {
738
2e2bf962
SC
739 fprintf(config.map_file,"(");
740 exp_print_tree(tree->unary.child);
741 fprintf(config.map_file,")");
bfbdc80f
SC
742 }
743
2fa0b342
DHW
744 break;
745 case etree_undef:
2e2bf962 746 fprintf(config.map_file,"????????");
2fa0b342
DHW
747 break;
748 case etree_name:
749 if (tree->type.node_code == NAME) {
2e2bf962 750 fprintf(config.map_file,"%s", tree->name.name);
2fa0b342
DHW
751 }
752 else {
2e2bf962 753 exp_print_token(tree->type.node_code);
bfbdc80f 754 if (tree->name.name)
2e2bf962 755 fprintf(config.map_file,"(%s)", tree->name.name);
2fa0b342
DHW
756 }
757 break;
758 default:
759 FAIL();
760 break;
761 }
762}
763
764
765
766
767bfd_vma
c611e285
SC
768DEFUN(exp_get_vma,(tree, def, name, allocation_done),
769 etree_type *tree AND
770 bfd_vma def AND
771 char *name AND
772 lang_phase_type allocation_done)
2fa0b342
DHW
773{
774 etree_value_type r;
775
776 if (tree != (etree_type *)NULL) {
777 r = exp_fold_tree_no_dot(tree,
bfbdc80f 778 abs_output_section,
2fa0b342
DHW
779 allocation_done);
780 if (r.valid == false && name) {
c611e285 781 einfo("%F%S Nonconstant expression for %s\n",name);
2fa0b342
DHW
782 }
783 return r.value;
784 }
785 else {
786 return def;
787 }
788}
789
790int
c611e285
SC
791DEFUN(exp_get_value_int,(tree,def,name, allocation_done),
792 etree_type *tree AND
793 int def AND
794 char *name AND
795 lang_phase_type allocation_done)
2fa0b342
DHW
796{
797 return (int)exp_get_vma(tree,(bfd_vma)def,name, allocation_done);
798}
65c552e3 799
This page took 0.112446 seconds and 4 git commands to generate.