1*e4b17023SJohn Marino /* RTL specific diagnostic subroutines for GCC
2*e4b17023SJohn Marino Copyright (C) 2001, 2002, 2003, 2004, 2007, 2008, 2010
3*e4b17023SJohn Marino Free Software Foundation, Inc.
4*e4b17023SJohn Marino Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
5*e4b17023SJohn Marino
6*e4b17023SJohn Marino This file is part of GCC.
7*e4b17023SJohn Marino
8*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify
9*e4b17023SJohn Marino it under the terms of the GNU General Public License as published by
10*e4b17023SJohn Marino the Free Software Foundation; either version 3, or (at your option)
11*e4b17023SJohn Marino any later version.
12*e4b17023SJohn Marino
13*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful,
14*e4b17023SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
15*e4b17023SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16*e4b17023SJohn Marino GNU General Public License for more details.
17*e4b17023SJohn Marino
18*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
19*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see
20*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */
21*e4b17023SJohn Marino
22*e4b17023SJohn Marino #include "config.h"
23*e4b17023SJohn Marino #include "system.h"
24*e4b17023SJohn Marino #include "coretypes.h"
25*e4b17023SJohn Marino #include "tm.h"
26*e4b17023SJohn Marino #include "rtl-error.h"
27*e4b17023SJohn Marino #include "insn-attr.h"
28*e4b17023SJohn Marino #include "insn-config.h"
29*e4b17023SJohn Marino #include "input.h"
30*e4b17023SJohn Marino #include "intl.h"
31*e4b17023SJohn Marino #include "diagnostic.h"
32*e4b17023SJohn Marino
33*e4b17023SJohn Marino static location_t location_for_asm (const_rtx);
34*e4b17023SJohn Marino static void diagnostic_for_asm (const_rtx, const char *, va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
35*e4b17023SJohn Marino
36*e4b17023SJohn Marino /* Figure the location of the given INSN. */
37*e4b17023SJohn Marino static location_t
location_for_asm(const_rtx insn)38*e4b17023SJohn Marino location_for_asm (const_rtx insn)
39*e4b17023SJohn Marino {
40*e4b17023SJohn Marino rtx body = PATTERN (insn);
41*e4b17023SJohn Marino rtx asmop;
42*e4b17023SJohn Marino location_t loc;
43*e4b17023SJohn Marino
44*e4b17023SJohn Marino /* Find the (or one of the) ASM_OPERANDS in the insn. */
45*e4b17023SJohn Marino if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
46*e4b17023SJohn Marino asmop = SET_SRC (body);
47*e4b17023SJohn Marino else if (GET_CODE (body) == ASM_OPERANDS)
48*e4b17023SJohn Marino asmop = body;
49*e4b17023SJohn Marino else if (GET_CODE (body) == PARALLEL
50*e4b17023SJohn Marino && GET_CODE (XVECEXP (body, 0, 0)) == SET)
51*e4b17023SJohn Marino asmop = SET_SRC (XVECEXP (body, 0, 0));
52*e4b17023SJohn Marino else if (GET_CODE (body) == PARALLEL
53*e4b17023SJohn Marino && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
54*e4b17023SJohn Marino asmop = XVECEXP (body, 0, 0);
55*e4b17023SJohn Marino else
56*e4b17023SJohn Marino asmop = NULL;
57*e4b17023SJohn Marino
58*e4b17023SJohn Marino if (asmop)
59*e4b17023SJohn Marino loc = ASM_OPERANDS_SOURCE_LOCATION (asmop);
60*e4b17023SJohn Marino else
61*e4b17023SJohn Marino loc = input_location;
62*e4b17023SJohn Marino return loc;
63*e4b17023SJohn Marino }
64*e4b17023SJohn Marino
65*e4b17023SJohn Marino /* Report a diagnostic MESSAGE (an error or a WARNING) at the line number
66*e4b17023SJohn Marino of the insn INSN. This is used only when INSN is an `asm' with operands,
67*e4b17023SJohn Marino and each ASM_OPERANDS records its own source file and line. */
68*e4b17023SJohn Marino static void
diagnostic_for_asm(const_rtx insn,const char * msg,va_list * args_ptr,diagnostic_t kind)69*e4b17023SJohn Marino diagnostic_for_asm (const_rtx insn, const char *msg, va_list *args_ptr,
70*e4b17023SJohn Marino diagnostic_t kind)
71*e4b17023SJohn Marino {
72*e4b17023SJohn Marino diagnostic_info diagnostic;
73*e4b17023SJohn Marino
74*e4b17023SJohn Marino diagnostic_set_info (&diagnostic, msg, args_ptr,
75*e4b17023SJohn Marino location_for_asm (insn), kind);
76*e4b17023SJohn Marino report_diagnostic (&diagnostic);
77*e4b17023SJohn Marino }
78*e4b17023SJohn Marino
79*e4b17023SJohn Marino void
error_for_asm(const_rtx insn,const char * gmsgid,...)80*e4b17023SJohn Marino error_for_asm (const_rtx insn, const char *gmsgid, ...)
81*e4b17023SJohn Marino {
82*e4b17023SJohn Marino va_list ap;
83*e4b17023SJohn Marino
84*e4b17023SJohn Marino va_start (ap, gmsgid);
85*e4b17023SJohn Marino diagnostic_for_asm (insn, gmsgid, &ap, DK_ERROR);
86*e4b17023SJohn Marino va_end (ap);
87*e4b17023SJohn Marino }
88*e4b17023SJohn Marino
89*e4b17023SJohn Marino void
warning_for_asm(const_rtx insn,const char * gmsgid,...)90*e4b17023SJohn Marino warning_for_asm (const_rtx insn, const char *gmsgid, ...)
91*e4b17023SJohn Marino {
92*e4b17023SJohn Marino va_list ap;
93*e4b17023SJohn Marino
94*e4b17023SJohn Marino va_start (ap, gmsgid);
95*e4b17023SJohn Marino diagnostic_for_asm (insn, gmsgid, &ap, DK_WARNING);
96*e4b17023SJohn Marino va_end (ap);
97*e4b17023SJohn Marino }
98*e4b17023SJohn Marino
99*e4b17023SJohn Marino void
_fatal_insn(const char * msgid,const_rtx insn,const char * file,int line,const char * function)100*e4b17023SJohn Marino _fatal_insn (const char *msgid, const_rtx insn, const char *file, int line,
101*e4b17023SJohn Marino const char *function)
102*e4b17023SJohn Marino {
103*e4b17023SJohn Marino error ("%s", _(msgid));
104*e4b17023SJohn Marino
105*e4b17023SJohn Marino /* The above incremented error_count, but isn't an error that we want to
106*e4b17023SJohn Marino count, so reset it here. */
107*e4b17023SJohn Marino errorcount--;
108*e4b17023SJohn Marino
109*e4b17023SJohn Marino debug_rtx (insn);
110*e4b17023SJohn Marino fancy_abort (file, line, function);
111*e4b17023SJohn Marino }
112*e4b17023SJohn Marino
113*e4b17023SJohn Marino void
_fatal_insn_not_found(const_rtx insn,const char * file,int line,const char * function)114*e4b17023SJohn Marino _fatal_insn_not_found (const_rtx insn, const char *file, int line,
115*e4b17023SJohn Marino const char *function)
116*e4b17023SJohn Marino {
117*e4b17023SJohn Marino if (INSN_CODE (insn) < 0)
118*e4b17023SJohn Marino _fatal_insn ("unrecognizable insn:", insn, file, line, function);
119*e4b17023SJohn Marino else
120*e4b17023SJohn Marino _fatal_insn ("insn does not satisfy its constraints:",
121*e4b17023SJohn Marino insn, file, line, function);
122*e4b17023SJohn Marino }
123