rtl-error.c revision 117395
1/* RTL specific diagnostic subroutines for the GNU C compiler
2   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
3   Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GCC 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 GCC; see the file COPYING.  If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA.  */
21
22#include "config.h"
23#undef FLOAT /* This is for hpux. They should change hpux.  */
24#undef FFS  /* Some systems define this in param.h.  */
25#include "system.h"
26#include "rtl.h"
27#include "insn-attr.h"
28#include "insn-config.h"
29#include "input.h"
30#include "toplev.h"
31#include "intl.h"
32#include "diagnostic.h"
33
34static void file_and_line_for_asm PARAMS ((rtx, const char **, int *));
35static void diagnostic_for_asm PARAMS ((rtx, const char *, va_list *,
36                                        diagnostic_t));
37
38/* Figure file and line of the given INSN.  */
39static void
40file_and_line_for_asm (insn, pfile, pline)
41     rtx insn;
42     const char **pfile;
43     int *pline;
44{
45  rtx body = PATTERN (insn);
46  rtx asmop;
47
48  /* Find the (or one of the) ASM_OPERANDS in the insn.  */
49  if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
50    asmop = SET_SRC (body);
51  else if (GET_CODE (body) == ASM_OPERANDS)
52    asmop = body;
53  else if (GET_CODE (body) == PARALLEL
54	   && GET_CODE (XVECEXP (body, 0, 0)) == SET)
55    asmop = SET_SRC (XVECEXP (body, 0, 0));
56  else if (GET_CODE (body) == PARALLEL
57	   && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
58    asmop = XVECEXP (body, 0, 0);
59  else
60    asmop = NULL;
61
62  if (asmop)
63    {
64      *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
65      *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
66    }
67  else
68    {
69      *pfile = input_filename;
70      *pline = lineno;
71    }
72}
73
74/* Report a diagnostic MESSAGE (an errror or a WARNING) at the line number
75   of the insn INSN.  This is used only when INSN is an `asm' with operands,
76   and each ASM_OPERANDS records its own source file and line.  */
77static void
78diagnostic_for_asm (insn, msg, args_ptr, kind)
79     rtx insn;
80     const char *msg;
81     va_list *args_ptr;
82     diagnostic_t kind;
83{
84  diagnostic_info diagnostic;
85
86  diagnostic_set_info (&diagnostic, msg, args_ptr, NULL, 0, kind);
87  file_and_line_for_asm (insn, &diagnostic.location.file,
88                         &diagnostic.location.line);
89  report_diagnostic (&diagnostic);
90}
91
92void
93error_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
94{
95  VA_OPEN (ap, msgid);
96  VA_FIXEDARG (ap, rtx, insn);
97  VA_FIXEDARG (ap, const char *, msgid);
98
99  diagnostic_for_asm (insn, msgid, &ap, DK_ERROR);
100  VA_CLOSE (ap);
101}
102
103void
104warning_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
105{
106  VA_OPEN (ap, msgid);
107  VA_FIXEDARG (ap, rtx, insn);
108  VA_FIXEDARG (ap, const char *, msgid);
109
110  diagnostic_for_asm (insn, msgid, &ap, DK_WARNING);
111  VA_CLOSE (ap);
112}
113
114void
115_fatal_insn (msgid, insn, file, line, function)
116     const char *msgid;
117     rtx insn;
118     const char *file;
119     int line;
120     const char *function;
121{
122  error ("%s", _(msgid));
123
124  /* The above incremented error_count, but isn't an error that we want to
125     count, so reset it here.  */
126  errorcount--;
127
128  debug_rtx (insn);
129  fancy_abort (file, line, function);
130}
131
132void
133_fatal_insn_not_found (insn, file, line, function)
134     rtx insn;
135     const char *file;
136     int line;
137     const char *function;
138{
139  if (INSN_CODE (insn) < 0)
140    _fatal_insn ("unrecognizable insn:", insn, file, line, function);
141  else
142    _fatal_insn ("insn does not satisfy its constraints:",
143		insn, file, line, function);
144}
145
146