1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002-2024 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 /* NB: Because warning and error can be interchanged, neither append a
37 error (const line_ref
*line
, const char *msg
, ...)
41 fprintf (stderr
, "%s:%d: ", line
->file_name
, line
->line_nr
);
43 vfprintf (stderr
, msg
, ap
);
49 warning (const line_ref
*line
, const char *msg
, ...)
53 fprintf (stderr
, "%s:%d: warning: ", line
->file_name
, line
->line_nr
);
55 vfprintf (stderr
, msg
, ap
);
60 notify (const line_ref
*line
, const char *msg
, ...)
64 fprintf (stdout
, "%s %d: info: ", line
->file_name
, line
->line_nr
);
66 vfprintf (stdout
, msg
, ap
);
73 void *memory
= malloc (size
);
75 ERROR ("zalloc failed");
76 memset (memory
, 0, size
);
86 unsigned long long num
= 0;
92 if (strcmp (a
, "true") == 0 || strcmp (a
, "TRUE") == 0)
95 if (strcmp (a
, "false") == 0 || strcmp (a
, "FALSE") == 0)
106 if (a
[1] == 'x' || a
[1] == 'X')
111 else if (a
[1] == 'b' || a
[1] == 'B')
132 if (ch
>= '0' && ch
<= '1')
134 num
= (num
* 2) + (ch
- '0');
143 if (ch
>= '0' && ch
<= '9')
145 num
= (num
* 10) + (ch
- '0');
154 if (ch
>= '0' && ch
<= '7')
156 num
= (num
* 8) + (ch
- '0');
165 if (ch
>= '0' && ch
<= '9')
167 num
= (num
* 16) + (ch
- '0');
169 else if (ch
>= 'a' && ch
<= 'f')
171 num
= (num
* 16) + (ch
- 'a' + 10);
173 else if (ch
>= 'A' && ch
<= 'F')
175 num
= (num
* 16) + (ch
- 'A' + 10);
192 target_a2i (int ms_bit_nr
, const char *a
)
195 return (ms_bit_nr
- a2i (a
));
201 i2target (int ms_bit_nr
, unsigned bit
)
204 return ms_bit_nr
- bit
;
211 name2i (const char *names
, const name_map
* map
)
213 const name_map
*curr
;
214 const char *name
= names
;
215 while (*name
!= '\0')
218 const char *end
= strchr (name
, ',');
223 end
= strchr (name
, '\0');
233 while (curr
->name
!= NULL
)
235 if (strncmp (curr
->name
, name
, len
) == 0
236 && strlen (curr
->name
) == len
)
242 /* nothing found, possibly return a default */
244 while (curr
->name
!= NULL
)
249 error (NULL
, "%s contains no valid names\n", names
);
254 i2name (const int i
, const name_map
* map
)
256 while (map
->name
!= NULL
)
262 error (NULL
, "map lookup failed for %d\n", i
);