From 05a81fe58ab528bf1fbb9d0d2deaab2285bdb518 Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Mon, 15 Jan 1996 22:25:24 +0000 Subject: [PATCH] c-lex.c (check_newline): Pass character after `#pragma' to HANDLE_PRAGMA. * c-lex.c (check_newline): Pass character after `#pragma' to HANDLE_PRAGMA. Don't call get_directive_line if at end of line. * c-common.c (get_directive_line): Watch for EOF. * h8300/h8300.h (HANDLE_PRAGMA): New argument `c'. Must issue `return' now. * i960/i960.h (HANDLE_PRAGMA): Likewise. * sh/sh.h (HANDLE_PRAGMA): Likewise. * nextstep.h (HANDLE_PRAGMA): Likewise. * h8300/h8300.c (handle_pragma): New argument `ch'. Simplify pragma processing. Delete support for `#pragma section'. * i960/i960.c (process_pragma): New argument `c'. Change result to terminating character. * nextstep.c (handle_pragma): Likewise. * sh/sh.c (handle_pragma): Likewise. Also simplified. From-SVN: r10999 --- gcc/c-common.c | 8 +++++-- gcc/c-lex.c | 15 +++++++------ gcc/config/h8300/h8300.c | 48 +++++++++++----------------------------- gcc/config/h8300/h8300.h | 8 ++++++- gcc/config/i960/i960.c | 11 ++++----- gcc/config/i960/i960.h | 2 +- gcc/config/nextstep.c | 21 +++++++++++++----- gcc/config/nextstep.h | 5 +++-- gcc/config/sh/sh.c | 44 ++++++++++++++++++------------------ gcc/config/sh/sh.h | 10 +++++++-- 10 files changed, 89 insertions(+), 83 deletions(-) diff --git a/gcc/c-common.c b/gcc/c-common.c index ad613196b19..58e9df02cd9 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -2163,7 +2163,10 @@ truthvalue_conversion (expr) a part of the directive. The value is a string in a reusable buffer. It remains valid - only until the next time this function is called. */ + only until the next time this function is called. + + The terminating character ('\n' or EOF) is left in FINPUT for the + caller to re-read. */ char * get_directive_line (finput) @@ -2207,7 +2210,8 @@ get_directive_line (finput) continue; /* Detect the end of the directive. */ - if (c == '\n' && looking_for == 0) + if (looking_for == 0 + && (c == '\n' || c == EOF)) { ungetc (c, finput); c = '\0'; diff --git a/gcc/c-lex.c b/gcc/c-lex.c index 210c365dda8..51479beb53f 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -1,5 +1,5 @@ /* Lexical analyzer for C and Objective C. - Copyright (C) 1987, 88, 89, 92, 94, 1995 Free Software Foundation, Inc. + Copyright (C) 1987, 88, 89, 92, 94, 95, 1996 Free Software Foundation, Inc. This file is part of GNU CC. @@ -402,7 +402,7 @@ check_newline () return handle_sysv_pragma (finput, c); #else /* !HANDLE_SYSV_PRAGMA */ #ifdef HANDLE_PRAGMA - HANDLE_PRAGMA (finput); + HANDLE_PRAGMA (finput, c); #endif /* HANDLE_PRAGMA */ goto skipline; #endif /* !HANDLE_SYSV_PRAGMA */ @@ -419,7 +419,8 @@ check_newline () && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n')) { #ifdef DWARF_DEBUGGING_INFO - if ((debug_info_level == DINFO_LEVEL_VERBOSE) + if (c != '\n' + && (debug_info_level == DINFO_LEVEL_VERBOSE) && (write_symbols == DWARF_DEBUG)) dwarfout_define (lineno, get_directive_line (finput)); #endif /* DWARF_DEBUGGING_INFO */ @@ -435,7 +436,8 @@ check_newline () && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n')) { #ifdef DWARF_DEBUGGING_INFO - if ((debug_info_level == DINFO_LEVEL_VERBOSE) + if (c != '\n' + && (debug_info_level == DINFO_LEVEL_VERBOSE) && (write_symbols == DWARF_DEBUG)) dwarfout_undef (lineno, get_directive_line (finput)); #endif /* DWARF_DEBUGGING_INFO */ @@ -674,9 +676,8 @@ linenum: /* skip the rest of this line. */ skipline: - if (c == '\n') - return c; - while ((c = getc (finput)) != EOF && c != '\n'); + while (c != '\n' && c != EOF) + c = getc (finput); return c; } diff --git a/gcc/config/h8300/h8300.c b/gcc/config/h8300/h8300.c index 8db3c3646e9..f6a42ebdc2b 100644 --- a/gcc/config/h8300/h8300.c +++ b/gcc/config/h8300/h8300.c @@ -548,57 +548,35 @@ eq_operator (x, mode) with this attribute may be safely used in an interrupt vector. */ int -handle_pragma (file) +handle_pragma (file, c) FILE *file; + int c; { - int c; char pbuf[20]; int psize = 0; - c = getc (file); while (c == ' ' || c == '\t') c = getc (file); - if (c == '\n' || c == EOF) - return c; - - /* The only pragmas we understand are interrupt and saveall. */ - while (psize < sizeof (pbuf) - 1 - && isalpha (c)) + if (c != '\n' & c != EOF) { - pbuf[psize++] = c; - c = getc (file); - } - pbuf[psize] = 0; - - if (strcmp (pbuf, "interrupt") == 0) - pragma_interrupt = 1; - - if (strcmp (pbuf, "saveall") == 0) - pragma_saveall = 1; - - /* ??? This is deprecated. Delete for gcc 2.8. */ - if (strcmp (pbuf, "section") == 0) - { - static int printed_p = 0; - if (!printed_p) - { - warning ("#pragma section is deprecated, use section attributes"); - printed_p = 1; - } - while (c && !isalpha (c)) - c = getc (file); - psize = 0; while (psize < sizeof (pbuf) - 1 - && isalpha (c) || isdigit (c) || c == '_') + && isalpha (c)) { pbuf[psize++] = c; c = getc (file); } pbuf[psize] = 0; - named_section (NULL_TREE, pbuf); + + if (strcmp (pbuf, "interrupt") == 0) + pragma_interrupt = 1; + else if (strcmp (pbuf, "saveall") == 0) + pragma_saveall = 1; + + while (c != '\n' && c != EOF) + c = getc (file); } - ungetc (c, file); + return c; } diff --git a/gcc/config/h8300/h8300.h b/gcc/config/h8300/h8300.h index 3996bf4b35f..b146ed907fc 100644 --- a/gcc/config/h8300/h8300.h +++ b/gcc/config/h8300/h8300.h @@ -1272,7 +1272,13 @@ do { char dstr[30]; \ #define PRINT_OPERAND_ADDRESS(FILE, ADDR) print_operand_address (FILE, ADDR) -#define HANDLE_PRAGMA(FILE) handle_pragma (FILE) +/* Define this macro if you want to implement any pragmas. If defined, it + should be a C statement to be executed when #pragma is seen. The + argument STREAM is the stdio input stream from which the source + text can be read. CH is the first character after the #pragma. The + statement should execute a `return' with the terminating character found + (newline or EOF). */ +#define HANDLE_PRAGMA(FILE, CH) return handle_pragma (FILE, CH) #define FINAL_PRESCAN_INSN(insn, operand, nop) final_prescan_insn (insn, operand,nop) diff --git a/gcc/config/i960/i960.c b/gcc/config/i960/i960.c index cdd591396c4..72dabd2d7db 100644 --- a/gcc/config/i960/i960.c +++ b/gcc/config/i960/i960.c @@ -89,14 +89,13 @@ static int ret_label = 0; /* ??? This is incomplete, since it does not handle all pragmas that the intel compilers understand. */ -void -process_pragma (finput) +int +process_pragma (finput, c) FILE *finput; + int c; { - int c; int i; - c = getc (finput); while (c == ' ' || c == '\t') c = getc (finput); @@ -162,7 +161,9 @@ process_pragma (finput) /* Should be pragma 'far' or equivalent for callx/balx here. */ - ungetc (c, finput); + while (c != '\n' && c != EOF) + c = getc (finput); + return c; } /* Initialize variables before compiling any files. */ diff --git a/gcc/config/i960/i960.h b/gcc/config/i960/i960.h index c66f4a801f4..331e212afda 100644 --- a/gcc/config/i960/i960.h +++ b/gcc/config/i960/i960.h @@ -119,7 +119,7 @@ Boston, MA 02111-1307, USA. */ fprintf (asm_out_file, "\t.type\t0x%x;", (A & 0xf) + 2 * (A & ~0xf)) /* Handle pragmas for compatibility with Intel's compilers. */ -#define HANDLE_PRAGMA(FILE) process_pragma (FILE) +#define HANDLE_PRAGMA(FILE, CH) return process_pragma (FILE, CH) /* Run-time compilation parameters selecting different hardware subsets. */ diff --git a/gcc/config/nextstep.c b/gcc/config/nextstep.c index 823bceeffe3..65bf16e387e 100644 --- a/gcc/config/nextstep.c +++ b/gcc/config/nextstep.c @@ -1,5 +1,5 @@ /* Functions for generic NeXT as target machine for GNU C compiler. - Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. + Copyright (C) 1989, 90-93, 1996 Free Software Foundation, Inc. This file is part of GNU CC. @@ -35,14 +35,17 @@ static int initial_optimize_flag; extern char *get_directive_line (); /* Called from check_newline via the macro HANDLE_PRAGMA. - FINPUT is the source file input stream. */ + FINPUT is the source file input stream. + CH is the first character after `#pragma'. + The result is the terminating character ('\n' or EOF). */ -void -handle_pragma (finput, get_line_function) +int +handle_pragma (finput, ch, get_line_function) FILE *finput; + int ch; char *(*get_line_function) (); { - register char *p = (*get_line_function) (finput); + register char *p; /* Record initial setting of optimize flag, so we can restore it. */ if (!pragma_initialized) @@ -51,6 +54,11 @@ handle_pragma (finput, get_line_function) initial_optimize_flag = optimize; } + /* Nothing to do if #pragma is by itself. */ + if (ch == '\n' || ch == EOF) + return ch; + + p = (*get_line_function) (finput); if (OPT_STRCMP ("CC_OPT_ON")) { optimize = 1, obey_regdecls = 0; @@ -81,4 +89,7 @@ handle_pragma (finput, get_line_function) flag_writable_strings = 0; else if (OPT_STRCMP ("CC_NO_MACH_TEXT_SECTIONS")) flag_no_mach_text_sections = 1; + + /* get_line_function must leave the last character read in FINPUT. */ + return getc (finput); } diff --git a/gcc/config/nextstep.h b/gcc/config/nextstep.h index 6e2e986713e..bfd039c2241 100644 --- a/gcc/config/nextstep.h +++ b/gcc/config/nextstep.h @@ -1,6 +1,6 @@ /* nextstep.h -- operating system specific defines to be used when targeting GCC for NeXTSTEP. - Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. + Copyright (C) 1989, 90-93, 1996 Free Software Foundation, Inc. This file is part of GNU CC. @@ -240,7 +240,8 @@ Boston, MA 02111-1307, USA. */ /* How to parse #pragma's */ #undef HANDLE_PRAGMA -#define HANDLE_PRAGMA(finput) handle_pragma (finput, &get_directive_line) +#define HANDLE_PRAGMA(finput, ch) \ + return handle_pragma (finput, ch, &get_directive_line) /* Give methods pretty symbol names on NeXT. */ diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c index 4d93874bb3e..81125b3e41c 100644 --- a/gcc/config/sh/sh.c +++ b/gcc/config/sh/sh.c @@ -1,5 +1,5 @@ /* Output routines for GCC for Hitachi Super-H. - Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. + Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc. This file is part of GNU CC. @@ -23,6 +23,7 @@ Boston, MA 02111-1307, USA. */ #include "config.h" +#include #include #include "rtl.h" @@ -2019,40 +2020,37 @@ initial_elimination_offset (from, to) compiler. */ int -handle_pragma (file) +handle_pragma (file, c) FILE *file; + int c; { - int c; char pbuf[200]; int psize = 0; - c = getc (file); while (c == ' ' || c == '\t') c = getc (file); - if (c == '\n' || c == EOF) - return c; - - while (psize < sizeof (pbuf) - 1 && c != '\n') + if (c != '\n' & c != EOF) { - pbuf[psize++] = c; - if (psize == 9 && strncmp (pbuf, "interrupt", 9) == 0) - { - pragma_interrupt = 1; - return ' '; - } - if (psize == 5 && strncmp (pbuf, "trapa", 5) == 0) - { - pragma_interrupt = pragma_trapa = 1; - return ' '; - } - if (psize == 15 && strncmp (pbuf, "nosave_low_regs", 15) == 0) + while (psize < sizeof (pbuf) - 1 + && (isalpha (c) || c == '_')) { - pragma_nosave_low_regs = 1; - return ' '; + pbuf[psize++] = c; + c = getc (file); } - c = getc (file); + pbuf[psize] = 0; + + if (strcmp (pbuf, "interrupt") == 0) + pragma_interrupt = 1; + else if (strcmp (pbuf, "trapa") == 0) + pragma_interrupt = pragma_trapa = 1; + else if (strcmp (pbuf, "nosave_low_regs") == 0) + pragma_nosave_low_regs = 1; + + while (c != '\n' && c != EOF) + c = getc (file); } + return c; } diff --git a/gcc/config/sh/sh.h b/gcc/config/sh/sh.h index 4d05a893cc0..2c6f947c64b 100644 --- a/gcc/config/sh/sh.h +++ b/gcc/config/sh/sh.h @@ -1,5 +1,5 @@ /* Definitions of target machine for GNU compiler for Hitachi Super-H. - Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. + Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc. Contributed by Steve Chamberlain (sac@cygnus.com). Improved by Jim Wilson (wilson@cygnus.com). @@ -1388,7 +1388,13 @@ extern char *output_far_jump(); #define TARGET_MEM_FUNCTIONS -#define HANDLE_PRAGMA(finput) return handle_pragma (finput) +/* Define this macro if you want to implement any pragmas. If defined, it + should be a C statement to be executed when #pragma is seen. The + argument STREAM is the stdio input stream from which the source + text can be read. CH is the first character after the #pragma. The + statement should execute a `return' with the terminating character found + (newline or EOF). */ +#define HANDLE_PRAGMA(FILE, CH) return handle_pragma (FILE, CH) /* Set when processing a function with pragma interrupt turned on. */ -- 2.30.2