rtl-error.c revision 90075
190075Sobrien/* RTL specific diagnostic subroutines for the GNU C compiler
290075Sobrien   Copyright (C) 2001 Free Software Foundation, Inc.
390075Sobrien   Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
490075Sobrien
590075SobrienThis file is part of GCC.
690075Sobrien
790075SobrienGCC is free software; you can redistribute it and/or modify
890075Sobrienit under the terms of the GNU General Public License as published by
990075Sobrienthe Free Software Foundation; either version 2, or (at your option)
1090075Sobrienany later version.
1190075Sobrien
1290075SobrienGCC is distributed in the hope that it will be useful,
1390075Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of
1490075SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1590075SobrienGNU General Public License for more details.
1690075Sobrien
1790075SobrienYou should have received a copy of the GNU General Public License
1890075Sobrienalong with GCC; see the file COPYING.  If not, write to
1990075Sobrienthe Free Software Foundation, 59 Temple Place - Suite 330,
2090075SobrienBoston, MA 02111-1307, USA.  */
2190075Sobrien
2290075Sobrien#include "config.h"
2390075Sobrien#undef FLOAT /* This is for hpux. They should change hpux.  */
2490075Sobrien#undef FFS  /* Some systems define this in param.h.  */
2590075Sobrien#include "system.h"
2690075Sobrien#include "rtl.h"
2790075Sobrien#include "insn-attr.h"
2890075Sobrien#include "insn-config.h"
2990075Sobrien#include "input.h"
3090075Sobrien#include "toplev.h"
3190075Sobrien#include "intl.h"
3290075Sobrien#include "diagnostic.h"
3390075Sobrien
3490075Sobrienstatic void file_and_line_for_asm PARAMS ((rtx, const char **, int *));
3590075Sobrienstatic void diagnostic_for_asm PARAMS ((rtx, const char *, va_list *, int));
3690075Sobrien
3790075Sobrien/* Figure file and line of the given INSN.  */
3890075Sobrienstatic void
3990075Sobrienfile_and_line_for_asm (insn, pfile, pline)
4090075Sobrien     rtx insn;
4190075Sobrien     const char **pfile;
4290075Sobrien     int *pline;
4390075Sobrien{
4490075Sobrien  rtx body = PATTERN (insn);
4590075Sobrien  rtx asmop;
4690075Sobrien
4790075Sobrien  /* Find the (or one of the) ASM_OPERANDS in the insn.  */
4890075Sobrien  if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
4990075Sobrien    asmop = SET_SRC (body);
5090075Sobrien  else if (GET_CODE (body) == ASM_OPERANDS)
5190075Sobrien    asmop = body;
5290075Sobrien  else if (GET_CODE (body) == PARALLEL
5390075Sobrien	   && GET_CODE (XVECEXP (body, 0, 0)) == SET)
5490075Sobrien    asmop = SET_SRC (XVECEXP (body, 0, 0));
5590075Sobrien  else if (GET_CODE (body) == PARALLEL
5690075Sobrien	   && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
5790075Sobrien    asmop = XVECEXP (body, 0, 0);
5890075Sobrien  else
5990075Sobrien    asmop = NULL;
6090075Sobrien
6190075Sobrien  if (asmop)
6290075Sobrien    {
6390075Sobrien      *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
6490075Sobrien      *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
6590075Sobrien    }
6690075Sobrien  else
6790075Sobrien    {
6890075Sobrien      *pfile = input_filename;
6990075Sobrien      *pline = lineno;
7090075Sobrien    }
7190075Sobrien}
7290075Sobrien
7390075Sobrien/* Report a diagnostic MESSAGE (an errror or a WARNING) at the line number
7490075Sobrien   of the insn INSN.  This is used only when INSN is an `asm' with operands,
7590075Sobrien   and each ASM_OPERANDS records its own source file and line.  */
7690075Sobrienstatic void
7790075Sobriendiagnostic_for_asm (insn, msg, args_ptr, warn)
7890075Sobrien     rtx insn;
7990075Sobrien     const char *msg;
8090075Sobrien     va_list *args_ptr;
8190075Sobrien     int warn;
8290075Sobrien{
8390075Sobrien  diagnostic_context dc;
8490075Sobrien
8590075Sobrien  set_diagnostic_context (&dc, msg, args_ptr, NULL, 0, warn);
8690075Sobrien  file_and_line_for_asm (insn, &diagnostic_file_location (&dc),
8790075Sobrien                         &diagnostic_line_location (&dc));
8890075Sobrien  report_diagnostic (&dc);
8990075Sobrien}
9090075Sobrien
9190075Sobrienvoid
9290075Sobrienerror_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
9390075Sobrien{
9490075Sobrien  VA_OPEN (ap, msgid);
9590075Sobrien  VA_FIXEDARG (ap, rtx, insn);
9690075Sobrien  VA_FIXEDARG (ap, const char *, msgid);
9790075Sobrien
9890075Sobrien  diagnostic_for_asm (insn, msgid, &ap, /* warn = */ 0);
9990075Sobrien  VA_CLOSE (ap);
10090075Sobrien}
10190075Sobrien
10290075Sobrienvoid
10390075Sobrienwarning_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
10490075Sobrien{
10590075Sobrien  VA_OPEN (ap, msgid);
10690075Sobrien  VA_FIXEDARG (ap, rtx, insn);
10790075Sobrien  VA_FIXEDARG (ap, const char *, msgid);
10890075Sobrien
10990075Sobrien  diagnostic_for_asm (insn, msgid, &ap, /* warn = */ 1);
11090075Sobrien  VA_CLOSE (ap);
11190075Sobrien}
11290075Sobrien
11390075Sobrienvoid
11490075Sobrien_fatal_insn (msgid, insn, file, line, function)
11590075Sobrien     const char *msgid;
11690075Sobrien     rtx insn;
11790075Sobrien     const char *file;
11890075Sobrien     int line;
11990075Sobrien     const char *function;
12090075Sobrien{
12190075Sobrien  error ("%s", _(msgid));
12290075Sobrien
12390075Sobrien  /* The above incremented error_count, but isn't an error that we want to
12490075Sobrien     count, so reset it here.  */
12590075Sobrien  errorcount--;
12690075Sobrien
12790075Sobrien  debug_rtx (insn);
12890075Sobrien  fancy_abort (file, line, function);
12990075Sobrien}
13090075Sobrien
13190075Sobrienvoid
13290075Sobrien_fatal_insn_not_found (insn, file, line, function)
13390075Sobrien     rtx insn;
13490075Sobrien     const char *file;
13590075Sobrien     int line;
13690075Sobrien     const char *function;
13790075Sobrien{
13890075Sobrien  if (INSN_CODE (insn) < 0)
13990075Sobrien    _fatal_insn ("unrecognizable insn:", insn, file, line, function);
14090075Sobrien  else
14190075Sobrien    _fatal_insn ("insn does not satisfy its constraints:",
14290075Sobrien		insn, file, line, function);
14390075Sobrien}
14490075Sobrien
145