1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002-2016 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/>. */
43 /* NB: Because warning and error can be interchanged, neither append a
47 error (const line_ref *line, char *msg, ...)
51 fprintf (stderr, "%s:%d: ", line->file_name, line->line_nr);
53 vfprintf (stderr, msg, ap);
59 warning (const line_ref *line, char *msg, ...)
63 fprintf (stderr, "%s:%d: warning: ", line->file_name, line->line_nr);
65 vfprintf (stderr, msg, ap);
70 notify (const line_ref *line, char *msg, ...)
74 fprintf (stdout, "%s %d: info: ", line->file_name, line->line_nr);
76 vfprintf (stdout, msg, ap);
83 void *memory = malloc (size);
85 ERROR ("zalloc failed");
86 memset (memory, 0, size);
96 unsigned long long num = 0;
102 if (strcmp (a, "true") == 0 || strcmp (a, "TRUE") == 0)
105 if (strcmp (a, "false") == 0 || strcmp (a, "FALSE") == 0)
116 if (a[1] == 'x' || a[1] == 'X')
121 else if (a[1] == 'b' || a[1] == 'B')
142 if (ch >= '0' && ch <= '1')
144 num = (num * 2) + (ch - '0');
153 if (ch >= '0' && ch <= '9')
155 num = (num * 10) + (ch - '0');
164 if (ch >= '0' && ch <= '7')
166 num = (num * 8) + (ch - '0');
175 if (ch >= '0' && ch <= '9')
177 num = (num * 16) + (ch - '0');
179 else if (ch >= 'a' && ch <= 'f')
181 num = (num * 16) + (ch - 'a' + 10);
183 else if (ch >= 'A' && ch <= 'F')
185 num = (num * 16) + (ch - 'A' + 10);
202 target_a2i (int ms_bit_nr, const char *a)
205 return (ms_bit_nr - a2i (a));
211 i2target (int ms_bit_nr, unsigned bit)
214 return ms_bit_nr - bit;
221 name2i (const char *names, const name_map * map)
223 const name_map *curr;
224 const char *name = names;
225 while (*name != '\0')
228 char *end = strchr (name, ',');
233 end = strchr (name, '\0');
243 while (curr->name != NULL)
245 if (strncmp (curr->name, name, len) == 0
246 && strlen (curr->name) == len)
252 /* nothing found, possibly return a default */
254 while (curr->name != NULL)
259 error (NULL, "%s contains no valid names", names);
264 i2name (const int i, const name_map * map)
266 while (map->name != NULL)
272 error (NULL, "map lookup failed for %d\n", i);