From 61b96bb4281e65ed15d15ed7e9ae5102d64bc8c9 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Sat, 31 Mar 2001 06:47:54 +0000 Subject: [PATCH] Fix conditional assembly listings when more than one .else/.elsif --- gas/ChangeLog | 5 ++ gas/cond.c | 100 +++++++++++++++++------------------ gas/listing.c | 10 ++-- gas/testsuite/ChangeLog | 5 ++ gas/testsuite/gas/all/cond.d | 20 +++++-- gas/testsuite/gas/all/cond.s | 14 +++++ 6 files changed, 95 insertions(+), 59 deletions(-) diff --git a/gas/ChangeLog b/gas/ChangeLog index d73ab69d56..4d20134f0d 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,5 +1,10 @@ 2001-03-31 Alan Modra + * listing.c (listing_listing): Enable listing on EDICT_NOLIST_NEXT + for one line if not already enabled. + * cond.c (s_elseif): Correct conditional assembly listing. + (s_else): Likewise. + * cond.c (s_endif): Correct handling of "if .. elseif .." trees. Don't abort on NULL current_cframe. diff --git a/gas/cond.c b/gas/cond.c index 034796b2e3..6c6e8adfa3 100644 --- a/gas/cond.c +++ b/gas/cond.c @@ -255,9 +255,6 @@ void s_elseif (arg) int arg; { - expressionS operand; - int t; - if (current_cframe == NULL) { as_bad (_("\".elseif\" without matching \".if\" - ignored")); @@ -277,54 +274,55 @@ s_elseif (arg) as_where (¤t_cframe->else_file_line.file, ¤t_cframe->else_file_line.line); - if (!current_cframe->dead_tree) - { - current_cframe->dead_tree = !current_cframe->ignoring; - current_cframe->ignoring = !current_cframe->ignoring; - if (LISTING_SKIP_COND ()) - { - if (! current_cframe->ignoring) - listing_list (1); - else - listing_list (2); - } - } /* if not a dead tree */ - } /* if error else do it */ + current_cframe->dead_tree |= !current_cframe->ignoring; + current_cframe->ignoring = current_cframe->dead_tree; + } if (current_cframe == NULL || current_cframe->ignoring) { while (! is_end_of_line[(unsigned char) *input_line_pointer]) ++input_line_pointer; - return; + + if (current_cframe == NULL) + return; } - - /* Leading whitespace is part of operand. */ - SKIP_WHITESPACE (); - - expression (&operand); - if (operand.X_op != O_constant) - as_bad (_("non-constant expression in \".elseif\" statement")); - - switch ((operatorT) arg) + else { - case O_eq: t = operand.X_add_number == 0; break; - case O_ne: t = operand.X_add_number != 0; break; - case O_lt: t = operand.X_add_number < 0; break; - case O_le: t = operand.X_add_number <= 0; break; - case O_ge: t = operand.X_add_number >= 0; break; - case O_gt: t = operand.X_add_number > 0; break; - default: - abort (); - return; - } + expressionS operand; + int t; - current_cframe->ignoring = current_cframe->dead_tree || ! t; + /* Leading whitespace is part of operand. */ + SKIP_WHITESPACE (); + + expression (&operand); + if (operand.X_op != O_constant) + as_bad (_("non-constant expression in \".elseif\" statement")); + + switch ((operatorT) arg) + { + case O_eq: t = operand.X_add_number == 0; break; + case O_ne: t = operand.X_add_number != 0; break; + case O_lt: t = operand.X_add_number < 0; break; + case O_le: t = operand.X_add_number <= 0; break; + case O_ge: t = operand.X_add_number >= 0; break; + case O_gt: t = operand.X_add_number > 0; break; + default: + abort (); + return; + } + + current_cframe->ignoring = current_cframe->dead_tree || ! t; + } if (LISTING_SKIP_COND () - && current_cframe->ignoring && (current_cframe->previous_cframe == NULL || ! current_cframe->previous_cframe->ignoring)) - listing_list (2); + { + if (! current_cframe->ignoring) + listing_list (1); + else + listing_list (2); + } demand_empty_rest_of_line (); } @@ -368,7 +366,6 @@ s_else (arg) if (current_cframe == NULL) { as_bad (_(".else without matching .if - ignored")); - } else if (current_cframe->else_seen) { @@ -385,20 +382,21 @@ s_else (arg) as_where (¤t_cframe->else_file_line.file, ¤t_cframe->else_file_line.line); - if (!current_cframe->dead_tree) + current_cframe->ignoring = + current_cframe->dead_tree | !current_cframe->ignoring; + + if (LISTING_SKIP_COND () + && (current_cframe->previous_cframe == NULL + || ! current_cframe->previous_cframe->ignoring)) { - current_cframe->ignoring = !current_cframe->ignoring; - if (LISTING_SKIP_COND ()) - { - if (! current_cframe->ignoring) - listing_list (1); - else - listing_list (2); - } - } /* if not a dead tree */ + if (! current_cframe->ignoring) + listing_list (1); + else + listing_list (2); + } current_cframe->else_seen = 1; - } /* if error else do it */ + } if (flag_mri) { diff --git a/gas/listing.c b/gas/listing.c index 96c723906e..8168ebe6b9 100644 --- a/gas/listing.c +++ b/gas/listing.c @@ -1,5 +1,6 @@ /* listing.c - mainting assembly listings - Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 + Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, + 2001 Free Software Foundation, Inc. This file is part of GAS, the GNU Assembler. @@ -1007,6 +1008,8 @@ listing_listing (name) show_listing--; break; case EDICT_NOLIST_NEXT: + if (show_listing == 0) + list_line--; break; case EDICT_EJECT: break; @@ -1029,7 +1032,8 @@ listing_listing (name) p = buffer_line (list->file, buffer, width); } - if (list->edict == EDICT_LIST) + if (list->edict == EDICT_LIST + || (list->edict == EDICT_NOLIST_NEXT && show_listing == 0)) { /* Enable listing for the single line that caused the enable. */ list_line++; @@ -1090,7 +1094,7 @@ listing_listing (name) } } - if (list->edict == EDICT_NOLIST_NEXT) + if (list->edict == EDICT_NOLIST_NEXT && show_listing == 1) --show_listing; list = list->next; diff --git a/gas/testsuite/ChangeLog b/gas/testsuite/ChangeLog index f1abc4b772..3c218e4fe4 100644 --- a/gas/testsuite/ChangeLog +++ b/gas/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2001-03-31 Alan Modra + + * gas/all/cond.s: Add .if .elseif tree. + * gas/all/cond.d: Match above. + 2001-03-30 H.J. Lu * gas/i386/relax.d: Dump with -s instead of -drw. diff --git a/gas/testsuite/gas/all/cond.d b/gas/testsuite/gas/all/cond.d index a496287916..4d0da366f7 100644 --- a/gas/testsuite/gas/all/cond.d +++ b/gas/testsuite/gas/all/cond.d @@ -13,8 +13,18 @@ 15 0004 0[04] ?00 ?00 ?0[04][ ]+.long[ ]+4 16[ ]+.endc 17[ ]+.endc - 18 0008 00 ?00 ?00 ?00[ ]+.p2align 5,0 - 18[ ]+00 ?00 ?00 ?00 - 18[ ]+00 ?00 ?00 ?00 - 18[ ]+00 ?00 ?00 ?00 - 18[ ]+00 ?00 ?00 ?00 + 18[ ]+ + 19[ ]+.if 0 + 21[ ]+.elseif 1 + 22[ ]+.if 0 + 24[ ]+.elseif 1 + 25 0008 0[07] ?00 ?00 ?0[07][ ]+.long[ ]+7 + 26[ ]+.endif + 27[ ]+.elseif 1 + 29[ ]+.else + 31[ ]+.endif + 32 000c 00 ?00 ?00 ?00[ ]+.p2align 5,0 + 32[ ]+00 ?00 ?00 ?00 + 32[ ]+00 ?00 ?00 ?00 + 32[ ]+00 ?00 ?00 ?00 + 32[ ]+00 ?00 ?00 ?00 diff --git a/gas/testsuite/gas/all/cond.s b/gas/testsuite/gas/all/cond.s index 39583211e6..ba4bd6ca61 100644 --- a/gas/testsuite/gas/all/cond.s +++ b/gas/testsuite/gas/all/cond.s @@ -15,4 +15,18 @@ .long 4 .endc .endc + + .if 0 + .long 5 + .elseif 1 + .if 0 + .long 6 + .elseif 1 + .long 7 + .endif + .elseif 1 + .long 8 + .else + .long 9 + .endif .p2align 5,0