1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 /* NB: Because warning and error can be interchanged, neither append a
45 error (const line_ref *line,
51 fprintf (stderr, "%s:%d: ", line->file_name, line->line_nr);
53 vfprintf (stderr, msg, ap);
59 warning (const line_ref *line,
65 fprintf (stderr, "%s:%d: warning: ", line->file_name, line->line_nr);
67 vfprintf (stderr, msg, ap);
72 notify (const line_ref *line,
78 fprintf (stdout, "%s %d: info: ", line->file_name, line->line_nr);
80 vfprintf (stdout, msg, ap);
87 void *memory = malloc(size);
89 ERROR ("zalloc failed");
90 memset(memory, 0, size);
100 unsigned long long num = 0;
106 if (strcmp (a, "true") == 0
107 || strcmp (a, "TRUE") == 0)
110 if (strcmp (a, "false") == 0
111 || strcmp (a, "false") == 0)
122 if (a[1] == 'x' || a[1] == 'X')
127 else if (a[1] == 'b' || a[1] == 'b')
148 if (ch >= '0' && ch <= '1')
150 num = (num * 2) + (ch - '0');
159 if (ch >= '0' && ch <= '9')
161 num = (num * 10) + (ch - '0');
170 if (ch >= '0' && ch <= '7')
172 num = (num * 8) + (ch - '0');
181 if (ch >= '0' && ch <= '9')
183 num = (num * 16) + (ch - '0');
185 else if (ch >= 'a' && ch <= 'f')
187 num = (num * 16) + (ch - 'a' + 10);
189 else if (ch >= 'A' && ch <= 'F')
191 num = (num * 16) + (ch - 'A' + 10);
208 target_a2i(int ms_bit_nr,
212 return (ms_bit_nr - a2i(a));
218 i2target(int ms_bit_nr,
222 return ms_bit_nr - bit;
229 name2i (const char *names,
232 const name_map *curr;
233 const char *name = names;
234 while (*name != '\0')
237 char *end = strchr(name, ',');
242 end = strchr(name, '\0');
252 while (curr->name != NULL)
254 if (strncmp (curr->name, name, len) == 0
255 && strlen (curr->name) == len)
261 /* nothing found, possibly return a default */
263 while (curr->name != NULL)
268 error (NULL, "%s contains no valid names", names);
276 while (map->name != NULL)
282 error (NULL, "map lookup failed for %d\n", i);