1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002 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 2 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, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
45 /* NB: Because warning and error can be interchanged, neither append a
49 error (const line_ref
*line
, char *msg
, ...)
53 fprintf (stderr
, "%s:%d: ", line
->file_name
, line
->line_nr
);
55 vfprintf (stderr
, msg
, ap
);
61 warning (const line_ref
*line
, char *msg
, ...)
65 fprintf (stderr
, "%s:%d: warning: ", line
->file_name
, line
->line_nr
);
67 vfprintf (stderr
, msg
, ap
);
72 notify (const line_ref
*line
, char *msg
, ...)
76 fprintf (stdout
, "%s %d: info: ", line
->file_name
, line
->line_nr
);
78 vfprintf (stdout
, msg
, ap
);
85 void *memory
= malloc (size
);
87 ERROR ("zalloc failed");
88 memset (memory
, 0, size
);
98 unsigned long long num
= 0;
104 if (strcmp (a
, "true") == 0 || strcmp (a
, "TRUE") == 0)
107 if (strcmp (a
, "false") == 0 || strcmp (a
, "false") == 0)
118 if (a
[1] == 'x' || a
[1] == 'X')
123 else if (a
[1] == 'b' || a
[1] == 'b')
144 if (ch
>= '0' && ch
<= '1')
146 num
= (num
* 2) + (ch
- '0');
155 if (ch
>= '0' && ch
<= '9')
157 num
= (num
* 10) + (ch
- '0');
166 if (ch
>= '0' && ch
<= '7')
168 num
= (num
* 8) + (ch
- '0');
177 if (ch
>= '0' && ch
<= '9')
179 num
= (num
* 16) + (ch
- '0');
181 else if (ch
>= 'a' && ch
<= 'f')
183 num
= (num
* 16) + (ch
- 'a' + 10);
185 else if (ch
>= 'A' && ch
<= 'F')
187 num
= (num
* 16) + (ch
- 'A' + 10);
204 target_a2i (int ms_bit_nr
, const char *a
)
207 return (ms_bit_nr
- a2i (a
));
213 i2target (int ms_bit_nr
, unsigned bit
)
216 return ms_bit_nr
- bit
;
223 name2i (const char *names
, const name_map
* map
)
225 const name_map
*curr
;
226 const char *name
= names
;
227 while (*name
!= '\0')
230 char *end
= strchr (name
, ',');
235 end
= strchr (name
, '\0');
245 while (curr
->name
!= NULL
)
247 if (strncmp (curr
->name
, name
, len
) == 0
248 && strlen (curr
->name
) == len
)
254 /* nothing found, possibly return a default */
256 while (curr
->name
!= NULL
)
261 error (NULL
, "%s contains no valid names", names
);
266 i2name (const int i
, const name_map
* map
)
268 while (map
->name
!= NULL
)
274 error (NULL
, "map lookup failed for %d\n", i
);