4 * Copyright (C) 2003 Transmeta Corp.
5 * 2003-2004 Linus Torvalds
7 * Licensed under the Open Software License version 1.1
9 * Print out results of parsing for debugging and testing.
25 #include "expression.h"
28 static int show_symbol_expr(struct symbol
*sym
);
29 static int show_string_expr(struct expression
*expr
);
31 static void do_debug_symbol(struct symbol
*sym
, int indent
)
33 static const char indent_string
[] = " ";
34 static const char *typestr
[] = {
35 [SYM_UNINITIALIZED
] = "none",
36 [SYM_PREPROCESSOR
] = "cpp.",
37 [SYM_BASETYPE
] = "base",
42 [SYM_STRUCT
] = "strt",
45 [SYM_TYPEDEF
] = "tdef",
46 [SYM_TYPEOF
] = "tpof",
47 [SYM_MEMBER
] = "memb",
48 [SYM_BITFIELD
] = "bitf",
50 [SYM_RESTRICT
] = "rstr",
51 [SYM_FOULED
] = "foul",
54 struct context
*context
;
59 fprintf(stderr
, "%.*s%s%3d:%lu %s %s (as: %d) %p (%s:%d:%d) %s\n",
60 indent
, indent_string
, typestr
[sym
->type
],
61 sym
->bit_size
, sym
->ctype
.alignment
,
62 modifier_string(sym
->ctype
.modifiers
), show_ident(sym
->ident
), sym
->ctype
.as
,
63 sym
, stream_name(sym
->pos
.stream
), sym
->pos
.line
, sym
->pos
.pos
,
64 builtin_typename(sym
) ?: "");
66 FOR_EACH_PTR(sym
->ctype
.contexts
, context
) {
67 /* FIXME: should print context expression */
68 fprintf(stderr
, "< context%d: in=%d, out=%d\n",
69 i
, context
->in
, context
->out
);
70 fprintf(stderr
, " end context%d >\n", i
);
72 } END_FOR_EACH_PTR(context
);
73 if (sym
->type
== SYM_FN
) {
76 FOR_EACH_PTR(sym
->arguments
, arg
) {
77 fprintf(stderr
, "< arg%d:\n", i
);
78 do_debug_symbol(arg
, 0);
79 fprintf(stderr
, " end arg%d >\n", i
);
81 } END_FOR_EACH_PTR(arg
);
83 do_debug_symbol(sym
->ctype
.base_type
, indent
+2);
86 void debug_symbol(struct symbol
*sym
)
88 do_debug_symbol(sym
, 0);
92 * Symbol type printout. The type system is by far the most
93 * complicated part of C - everything else is trivial.
95 const char *modifier_string(unsigned long mod
)
97 static char buffer
[100];
99 const char *res
,**ptr
, *names
[] = {
100 "auto", "register", "static", "extern",
101 "const", "volatile", "[signed]", "[unsigned]",
102 "[char]", "[short]", "[long]", "[long long]",
103 "[typdef]", "[structof]", "[unionof]", "[enum]",
104 "[typeof]", "[attribute]", "inline", "[addressable]",
105 "[nocast]", "[noderef]", "[accessed]", "[toplevel]",
106 "[label]", "[assigned]", "[type]", "[safe]",
107 "[usertype]", "[force]", "[explicitly-signed]",
111 while ((res
= *ptr
++) != NULL
) {
114 while ((c
= *res
++) != '\0')
124 static void show_struct_member(struct symbol
*sym
)
126 printf("\t%s:%d:%ld at offset %ld.%d", show_ident(sym
->ident
), sym
->bit_size
, sym
->ctype
.alignment
, sym
->offset
, sym
->bit_offset
);
130 void show_symbol_list(struct symbol_list
*list
, const char *sep
)
133 const char *prepend
= "";
135 FOR_EACH_PTR(list
, sym
) {
139 } END_FOR_EACH_PTR(sym
);
147 static void FORMAT_ATTR(2) prepend(struct type_name
*name
, const char *fmt
, ...)
149 static char buffer
[512];
154 n
= vsprintf(buffer
, fmt
, args
);
158 memcpy(name
->start
, buffer
, n
);
161 static void FORMAT_ATTR(2) append(struct type_name
*name
, const char *fmt
, ...)
163 static char buffer
[512];
168 n
= vsprintf(buffer
, fmt
, args
);
171 memcpy(name
->end
, buffer
, n
);
175 static struct ctype_name
{
179 { & char_ctype
, "char" },
180 { &schar_ctype
, "signed char" },
181 { &uchar_ctype
, "unsigned char" },
182 { & short_ctype
, "short" },
183 { &sshort_ctype
, "signed short" },
184 { &ushort_ctype
, "unsigned short" },
185 { & int_ctype
, "int" },
186 { &sint_ctype
, "signed int" },
187 { &uint_ctype
, "unsigned int" },
188 { &slong_ctype
, "signed long" },
189 { & long_ctype
, "long" },
190 { &ulong_ctype
, "unsigned long" },
191 { & llong_ctype
, "long long" },
192 { &sllong_ctype
, "signed long long" },
193 { &ullong_ctype
, "unsigned long long" },
195 { &void_ctype
, "void" },
196 { &bool_ctype
, "bool" },
197 { &string_ctype
, "string" },
199 { &float_ctype
, "float" },
200 { &double_ctype
, "double" },
201 { &ldouble_ctype
,"long double" },
202 { &incomplete_ctype
, "incomplete type" },
203 { &int_type
, "abstract int" },
204 { &fp_type
, "abstract fp" },
205 { &label_ctype
, "label type" },
206 { &bad_ctype
, "bad type" },
209 const char *builtin_typename(struct symbol
*sym
)
213 for (i
= 0; i
< sizeof(typenames
)/sizeof(typenames
[0]); i
++)
214 if (typenames
[i
].sym
== sym
)
215 return typenames
[i
].name
;
219 const char *builtin_ctypename(struct ctype
*ctype
)
223 for (i
= 0; i
< sizeof(typenames
)/sizeof(typenames
[0]); i
++)
224 if (&typenames
[i
].sym
->ctype
== ctype
)
225 return typenames
[i
].name
;
229 static void do_show_type(struct symbol
*sym
, struct type_name
*name
)
233 const char *typename
;
237 if ((typename
= builtin_typename(sym
))) {
238 int len
= strlen(typename
);
239 *--name
->start
= ' ';
241 memcpy(name
->start
, typename
, len
);
254 prepend(name
, "struct %s ", show_ident(sym
->ident
));
258 prepend(name
, "union %s ", show_ident(sym
->ident
));
262 prepend(name
, "enum %s ", show_ident(sym
->ident
));
266 append(name
, "%s", show_ident(sym
->ident
));
270 append(name
, ":%d", sym
->bit_size
);
274 append(name
, "label(%s:%p)", show_ident(sym
->ident
), sym
);
287 prepend(name
, "unknown type %d", sym
->type
);
291 mod
= modifier_string(sym
->ctype
.modifiers
);
292 modlen
= strlen(mod
);
293 name
->start
-= modlen
;
294 memcpy(name
->start
, mod
, modlen
);
296 do_show_type(sym
->ctype
.base_type
, name
);
300 append(name
, "<asn:%d>", sym
->ctype
.as
);
307 append(name
, " )( ... )");
311 append(name
, "[%lld]", get_expression_value(sym
->array_size
));
315 prepend(name
, "restricted ");
319 prepend(name
, "fouled ");
327 void show_type(struct symbol
*sym
)
330 struct type_name name
;
332 name
.start
= name
.end
= array
+100;
333 do_show_type(sym
, &name
);
335 printf("%s", name
.start
);
338 const char *show_typename(struct symbol
*sym
)
340 static char array
[200];
341 struct type_name name
;
343 name
.start
= name
.end
= array
+100;
344 do_show_type(sym
, &name
);
349 void show_symbol(struct symbol
*sym
)
356 if (sym
->ctype
.alignment
)
357 printf(".align %ld\n", sym
->ctype
.alignment
);
360 type
= sym
->ctype
.base_type
;
365 * Show actual implementation information
367 switch (type
->type
) {
368 struct symbol
*member
;
373 FOR_EACH_PTR(type
->symbol_list
, member
) {
374 show_struct_member(member
);
375 } END_FOR_EACH_PTR(member
);
380 struct statement
*stmt
= type
->stmt
;
384 val
= show_statement(stmt
);
386 printf("\tmov.%d\t\tretval,%d\n", stmt
->ret
->bit_size
, val
);
396 if (sym
->initializer
) {
398 show_expression(sym
->initializer
);
402 static int show_symbol_init(struct symbol
*sym
);
404 static int new_pseudo(void)
410 static int new_label(void)
412 static int label
= 0;
416 static void show_switch_statement(struct statement
*stmt
)
418 int val
= show_expression(stmt
->switch_expression
);
420 printf("\tswitch v%d\n", val
);
423 * Debugging only: Check that the case list is correct
424 * by printing it out.
426 * This is where a _real_ back-end would go through the
427 * cases to decide whether to use a lookup table or a
428 * series of comparisons etc
430 printf("# case table:\n");
431 FOR_EACH_PTR(stmt
->switch_case
->symbol_list
, sym
) {
432 struct statement
*case_stmt
= sym
->stmt
;
433 struct expression
*expr
= case_stmt
->case_expression
;
434 struct expression
*to
= case_stmt
->case_to
;
439 if (expr
->type
== EXPR_VALUE
) {
440 printf(" case %lld", expr
->value
);
442 if (to
->type
== EXPR_VALUE
) {
443 printf(" .. %lld", to
->value
);
451 printf(": .L%p\n", sym
->bb_target
);
452 } END_FOR_EACH_PTR(sym
);
453 printf("# end case table\n");
455 show_statement(stmt
->switch_statement
);
457 if (stmt
->switch_break
->used
)
458 printf(".L%p:\n", stmt
->switch_break
->bb_target
);
461 static void show_symbol_decl(struct symbol_list
*syms
)
464 FOR_EACH_PTR(syms
, sym
) {
465 show_symbol_init(sym
);
466 } END_FOR_EACH_PTR(sym
);
469 static int show_return_stmt(struct statement
*stmt
);
472 * Print out a statement
474 int show_statement(struct statement
*stmt
)
478 switch (stmt
->type
) {
479 case STMT_DECLARATION
:
480 show_symbol_decl(stmt
->declaration
);
483 return show_return_stmt(stmt
);
484 case STMT_COMPOUND
: {
488 if (stmt
->inline_fn
) {
489 show_statement(stmt
->args
);
490 printf("\tbegin_inline \t%s\n", show_ident(stmt
->inline_fn
->ident
));
492 FOR_EACH_PTR(stmt
->stmts
, s
) {
493 last
= show_statement(s
);
494 } END_FOR_EACH_PTR(s
);
497 printf(".L%p:\n", stmt
->ret
);
498 addr
= show_symbol_expr(stmt
->ret
);
499 bits
= stmt
->ret
->bit_size
;
501 printf("\tld.%d\t\tv%d,[v%d]\n", bits
, last
, addr
);
504 printf("\tend_inlined\t%s\n", show_ident(stmt
->inline_fn
->ident
));
508 case STMT_EXPRESSION
:
509 return show_expression(stmt
->expression
);
512 struct expression
*cond
= stmt
->if_conditional
;
514 /* This is only valid if nobody can jump into the "dead" statement */
516 if (cond
->type
== EXPR_VALUE
) {
517 struct statement
*s
= stmt
->if_true
;
524 val
= show_expression(cond
);
525 target
= new_label();
526 printf("\tje\t\tv%d,.L%d\n", val
, target
);
527 show_statement(stmt
->if_true
);
528 if (stmt
->if_false
) {
529 int last
= new_label();
530 printf("\tjmp\t\t.L%d\n", last
);
531 printf(".L%d:\n", target
);
533 show_statement(stmt
->if_false
);
535 printf(".L%d:\n", target
);
539 show_switch_statement(stmt
);
543 printf(".L%p:\n", stmt
->case_label
);
544 show_statement(stmt
->case_statement
);
547 case STMT_ITERATOR
: {
548 struct statement
*pre_statement
= stmt
->iterator_pre_statement
;
549 struct expression
*pre_condition
= stmt
->iterator_pre_condition
;
550 struct statement
*statement
= stmt
->iterator_statement
;
551 struct statement
*post_statement
= stmt
->iterator_post_statement
;
552 struct expression
*post_condition
= stmt
->iterator_post_condition
;
553 int val
, loop_top
= 0, loop_bottom
= 0;
555 show_symbol_decl(stmt
->iterator_syms
);
556 show_statement(pre_statement
);
558 if (pre_condition
->type
== EXPR_VALUE
) {
559 if (!pre_condition
->value
) {
560 loop_bottom
= new_label();
561 printf("\tjmp\t\t.L%d\n", loop_bottom
);
564 loop_bottom
= new_label();
565 val
= show_expression(pre_condition
);
566 printf("\tje\t\tv%d, .L%d\n", val
, loop_bottom
);
569 if (!post_condition
|| post_condition
->type
!= EXPR_VALUE
|| post_condition
->value
) {
570 loop_top
= new_label();
571 printf(".L%d:\n", loop_top
);
573 show_statement(statement
);
574 if (stmt
->iterator_continue
->used
)
575 printf(".L%p:\n", stmt
->iterator_continue
);
576 show_statement(post_statement
);
577 if (!post_condition
) {
578 printf("\tjmp\t\t.L%d\n", loop_top
);
579 } else if (post_condition
->type
== EXPR_VALUE
) {
580 if (post_condition
->value
)
581 printf("\tjmp\t\t.L%d\n", loop_top
);
583 val
= show_expression(post_condition
);
584 printf("\tjne\t\tv%d, .L%d\n", val
, loop_top
);
586 if (stmt
->iterator_break
->used
)
587 printf(".L%p:\n", stmt
->iterator_break
);
589 printf(".L%d:\n", loop_bottom
);
596 printf(".L%p:\n", stmt
->label_identifier
);
597 show_statement(stmt
->label_statement
);
601 if (stmt
->goto_expression
) {
602 int val
= show_expression(stmt
->goto_expression
);
603 printf("\tgoto\t\t*v%d\n", val
);
605 printf("\tgoto\t\t.L%p\n", stmt
->goto_label
->bb_target
);
609 printf("\tasm( .... )\n");
612 int val
= show_expression(stmt
->expression
);
613 printf("\tcontext( %d )\n", val
);
617 int val
= show_expression(stmt
->range_expression
);
618 int low
= show_expression(stmt
->range_low
);
619 int high
= show_expression(stmt
->range_high
);
620 printf("\trange( %d %d-%d)\n", val
, low
, high
);
627 static int show_call_expression(struct expression
*expr
)
629 struct symbol
*direct
;
630 struct expression
*arg
, *fn
;
635 warning(expr
->pos
, "\tcall with no type!");
640 FOR_EACH_PTR_REVERSE(expr
->args
, arg
) {
641 int new = show_expression(arg
);
642 int size
= arg
->ctype
->bit_size
;
643 printf("\tpush.%d\t\tv%d\n", size
, new);
644 framesize
+= size
>> 3;
645 } END_FOR_EACH_PTR_REVERSE(arg
);
649 /* Remove dereference, if any */
651 if (fn
->type
== EXPR_PREOP
) {
652 if (fn
->unop
->type
== EXPR_SYMBOL
) {
653 struct symbol
*sym
= fn
->unop
->symbol
;
654 if (sym
->ctype
.base_type
->type
== SYM_FN
)
659 printf("\tcall\t\t%s\n", show_ident(direct
->ident
));
661 fncall
= show_expression(fn
);
662 printf("\tcall\t\t*v%d\n", fncall
);
665 printf("\tadd.%d\t\tvSP,vSP,$%d\n", bits_in_pointer
, framesize
);
667 retval
= new_pseudo();
668 printf("\tmov.%d\t\tv%d,retval\n", expr
->ctype
->bit_size
, retval
);
672 static int show_comma(struct expression
*expr
)
674 show_expression(expr
->left
);
675 return show_expression(expr
->right
);
678 static int show_binop(struct expression
*expr
)
680 int left
= show_expression(expr
->left
);
681 int right
= show_expression(expr
->right
);
682 int new = new_pseudo();
684 static const char *name
[] = {
685 ['+'] = "add", ['-'] = "sub",
686 ['*'] = "mul", ['/'] = "div",
687 ['%'] = "mod", ['&'] = "and",
688 ['|'] = "lor", ['^'] = "xor"
690 unsigned int op
= expr
->op
;
692 opname
= show_special(op
);
693 if (op
< sizeof(name
)/sizeof(*name
))
695 printf("\t%s.%d\t\tv%d,v%d,v%d\n", opname
,
696 expr
->ctype
->bit_size
,
701 static int show_slice(struct expression
*expr
)
703 int target
= show_expression(expr
->base
);
704 int new = new_pseudo();
705 printf("\tslice.%d\t\tv%d,v%d,%d\n", expr
->r_nrbits
, target
, new, expr
->r_bitpos
);
709 static int show_regular_preop(struct expression
*expr
)
711 int target
= show_expression(expr
->unop
);
712 int new = new_pseudo();
713 static const char *name
[] = {
714 ['!'] = "nonzero", ['-'] = "neg",
717 unsigned int op
= expr
->op
;
720 opname
= show_special(op
);
721 if (op
< sizeof(name
)/sizeof(*name
))
723 printf("\t%s.%d\t\tv%d,v%d\n", opname
, expr
->ctype
->bit_size
, new, target
);
728 * FIXME! Not all accesses are memory loads. We should
729 * check what kind of symbol is behind the dereference.
731 static int show_address_gen(struct expression
*expr
)
733 return show_expression(expr
->unop
);
736 static int show_load_gen(int bits
, struct expression
*expr
, int addr
)
738 int new = new_pseudo();
740 printf("\tld.%d\t\tv%d,[v%d]\n", bits
, new, addr
);
744 static void show_store_gen(int bits
, int value
, struct expression
*expr
, int addr
)
746 /* FIXME!!! Bitfield store! */
747 printf("\tst.%d\t\tv%d,[v%d]\n", bits
, value
, addr
);
750 static int show_assignment(struct expression
*expr
)
752 struct expression
*target
= expr
->left
;
758 bits
= expr
->ctype
->bit_size
;
759 val
= show_expression(expr
->right
);
760 addr
= show_address_gen(target
);
761 show_store_gen(bits
, val
, target
, addr
);
765 static int show_return_stmt(struct statement
*stmt
)
767 struct expression
*expr
= stmt
->ret_value
;
768 struct symbol
*target
= stmt
->ret_target
;
770 if (expr
&& expr
->ctype
) {
771 int val
= show_expression(expr
);
772 int bits
= expr
->ctype
->bit_size
;
773 int addr
= show_symbol_expr(target
);
774 show_store_gen(bits
, val
, NULL
, addr
);
776 printf("\tret\t\t(%p)\n", target
);
780 static int show_initialization(struct symbol
*sym
, struct expression
*expr
)
787 bits
= expr
->ctype
->bit_size
;
788 val
= show_expression(expr
);
789 addr
= show_symbol_expr(sym
);
790 // FIXME! The "target" expression is for bitfield store information.
791 // Leave it NULL, which works fine.
792 show_store_gen(bits
, val
, NULL
, addr
);
796 static int show_access(struct expression
*expr
)
798 int addr
= show_address_gen(expr
);
799 return show_load_gen(expr
->ctype
->bit_size
, expr
, addr
);
802 static int show_inc_dec(struct expression
*expr
, int postop
)
804 int addr
= show_address_gen(expr
->unop
);
806 const char *opname
= expr
->op
== SPECIAL_INCREMENT
? "add" : "sub";
807 int bits
= expr
->ctype
->bit_size
;
809 retval
= show_load_gen(bits
, expr
->unop
, addr
);
813 printf("\t%s.%d\t\tv%d,v%d,$1\n", opname
, bits
, new, retval
);
814 show_store_gen(bits
, new, expr
->unop
, addr
);
818 static int show_preop(struct expression
*expr
)
821 * '*' is an lvalue access, and is fundamentally different
822 * from an arithmetic operation. Maybe it should have an
823 * expression type of its own..
826 return show_access(expr
);
827 if (expr
->op
== SPECIAL_INCREMENT
|| expr
->op
== SPECIAL_DECREMENT
)
828 return show_inc_dec(expr
, 0);
829 return show_regular_preop(expr
);
832 static int show_postop(struct expression
*expr
)
834 return show_inc_dec(expr
, 1);
837 static int show_symbol_expr(struct symbol
*sym
)
839 int new = new_pseudo();
841 if (sym
->initializer
&& sym
->initializer
->type
== EXPR_STRING
)
842 return show_string_expr(sym
->initializer
);
844 if (sym
->ctype
.modifiers
& (MOD_TOPLEVEL
| MOD_EXTERN
| MOD_STATIC
)) {
845 printf("\tmovi.%d\t\tv%d,$%s\n", bits_in_pointer
, new, show_ident(sym
->ident
));
848 if (sym
->ctype
.modifiers
& MOD_ADDRESSABLE
) {
849 printf("\taddi.%d\t\tv%d,vFP,$%lld\n", bits_in_pointer
, new, sym
->value
);
852 printf("\taddi.%d\t\tv%d,vFP,$offsetof(%s:%p)\n", bits_in_pointer
, new, show_ident(sym
->ident
), sym
);
856 static int show_symbol_init(struct symbol
*sym
)
858 struct expression
*expr
= sym
->initializer
;
863 bits
= expr
->ctype
->bit_size
;
864 val
= show_expression(expr
);
865 addr
= show_symbol_expr(sym
);
866 show_store_gen(bits
, val
, NULL
, addr
);
871 static int type_is_signed(struct symbol
*sym
)
873 if (sym
->type
== SYM_NODE
)
874 sym
= sym
->ctype
.base_type
;
875 if (sym
->type
== SYM_PTR
)
877 return !(sym
->ctype
.modifiers
& MOD_UNSIGNED
);
880 static int show_cast_expr(struct expression
*expr
)
882 struct symbol
*old_type
, *new_type
;
883 int op
= show_expression(expr
->cast_expression
);
884 int oldbits
, newbits
;
887 old_type
= expr
->cast_expression
->ctype
;
888 new_type
= expr
->cast_type
;
890 oldbits
= old_type
->bit_size
;
891 newbits
= new_type
->bit_size
;
892 if (oldbits
>= newbits
)
895 is_signed
= type_is_signed(old_type
);
897 printf("\tsext%d.%d\tv%d,v%d\n", oldbits
, newbits
, new, op
);
899 printf("\tandl.%d\t\tv%d,v%d,$%lu\n", newbits
, new, op
, (1UL << oldbits
)-1);
904 static int show_value(struct expression
*expr
)
906 int new = new_pseudo();
907 unsigned long long value
= expr
->value
;
909 printf("\tmovi.%d\t\tv%d,$%llu\n", expr
->ctype
->bit_size
, new, value
);
913 static int show_fvalue(struct expression
*expr
)
915 int new = new_pseudo();
916 long double value
= expr
->fvalue
;
918 printf("\tmovf.%d\t\tv%d,$%Lf\n", expr
->ctype
->bit_size
, new, value
);
922 static int show_string_expr(struct expression
*expr
)
924 int new = new_pseudo();
926 printf("\tmovi.%d\t\tv%d,&%s\n", bits_in_pointer
, new, show_string(expr
->string
));
930 static int show_label_expr(struct expression
*expr
)
932 int new = new_pseudo();
933 printf("\tmovi.%d\t\tv%d,.L%p\n",bits_in_pointer
, new, expr
->label_symbol
);
937 static int show_conditional_expr(struct expression
*expr
)
939 int cond
= show_expression(expr
->conditional
);
940 int true = show_expression(expr
->cond_true
);
941 int false = show_expression(expr
->cond_false
);
942 int new = new_pseudo();
944 printf("[v%d]\tcmov.%d\t\tv%d,v%d,v%d\n", cond
, expr
->ctype
->bit_size
, new, true, false);
948 static int show_statement_expr(struct expression
*expr
)
950 return show_statement(expr
->statement
);
953 static int show_position_expr(struct expression
*expr
, struct symbol
*base
)
955 int new = show_expression(expr
->init_expr
);
956 struct symbol
*ctype
= expr
->init_expr
->ctype
;
959 bit_offset
= ctype
? ctype
->bit_offset
: -1;
961 printf("\tinsert v%d at [%d:%d] of %s\n", new,
962 expr
->init_offset
, bit_offset
,
963 show_ident(base
->ident
));
967 static int show_initializer_expr(struct expression
*expr
, struct symbol
*ctype
)
969 struct expression
*entry
;
971 FOR_EACH_PTR(expr
->expr_list
, entry
) {
974 // Nested initializers have their positions already
975 // recursively calculated - just output them too
976 if (entry
->type
== EXPR_INITIALIZER
) {
977 show_initializer_expr(entry
, ctype
);
981 // Initializer indexes and identifiers should
982 // have been evaluated to EXPR_POS
983 if (entry
->type
== EXPR_IDENTIFIER
) {
984 printf(" AT '%s':\n", show_ident(entry
->expr_ident
));
985 entry
= entry
->ident_expression
;
989 if (entry
->type
== EXPR_INDEX
) {
990 printf(" AT '%d..%d:\n", entry
->idx_from
, entry
->idx_to
);
991 entry
= entry
->idx_expression
;
994 if (entry
->type
== EXPR_POS
) {
995 show_position_expr(entry
, ctype
);
998 show_initialization(ctype
, entry
);
999 } END_FOR_EACH_PTR(entry
);
1003 int show_symbol_expr_init(struct symbol
*sym
)
1005 struct expression
*expr
= sym
->initializer
;
1008 show_expression(expr
);
1009 return show_symbol_expr(sym
);
1013 * Print out an expression. Return the pseudo that contains the
1016 int show_expression(struct expression
*expr
)
1022 struct position
*pos
= &expr
->pos
;
1023 printf("\tno type at %s:%d:%d\n",
1024 stream_name(pos
->stream
),
1025 pos
->line
, pos
->pos
);
1029 switch (expr
->type
) {
1031 return show_call_expression(expr
);
1033 case EXPR_ASSIGNMENT
:
1034 return show_assignment(expr
);
1037 return show_comma(expr
);
1041 return show_binop(expr
);
1043 return show_preop(expr
);
1045 return show_postop(expr
);
1047 return show_symbol_expr(expr
->symbol
);
1050 case EXPR_PTRSIZEOF
:
1052 warning(expr
->pos
, "invalid expression after evaluation");
1055 case EXPR_IMPLIED_CAST
:
1056 return show_cast_expr(expr
);
1058 return show_value(expr
);
1060 return show_fvalue(expr
);
1062 return show_string_expr(expr
);
1063 case EXPR_INITIALIZER
:
1064 return show_initializer_expr(expr
, expr
->ctype
);
1066 case EXPR_CONDITIONAL
:
1067 return show_conditional_expr(expr
);
1068 case EXPR_STATEMENT
:
1069 return show_statement_expr(expr
);
1071 return show_label_expr(expr
);
1073 return show_slice(expr
);
1075 // None of these should exist as direct expressions: they are only
1076 // valid as sub-expressions of initializers.
1078 warning(expr
->pos
, "unable to show plain initializer position expression");
1080 case EXPR_IDENTIFIER
:
1081 warning(expr
->pos
, "unable to show identifier expression");
1084 warning(expr
->pos
, "unable to show index expression");
1087 warning(expr
->pos
, "unable to show type expression");