1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995, 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.
42 error (char *msg, ...)
54 void *memory = malloc(size);
56 error("zalloc failed\n");
57 memset(memory, 0, size);
62 dumpf (int indent, char *msg, ...)
65 for (; indent > 0; indent--)
78 unsigned long long num = 0;
90 if (a[1] == 'x' || a[1] == 'X') {
93 } else if (a[1] == 'b' || a[1] == 'b') {
111 if (ch >= '0' && ch <= '1') {
112 num = (num * 2) + (ch - '0');
119 if (ch >= '0' && ch <= '9') {
120 num = (num * 10) + (ch - '0');
127 if (ch >= '0' && ch <= '7') {
128 num = (num * 8) + (ch - '0');
135 if (ch >= '0' && ch <= '9') {
136 num = (num * 16) + (ch - '0');
137 } else if (ch >= 'a' && ch <= 'f') {
138 num = (num * 16) + (ch - 'a' + 10);
139 } else if (ch >= 'A' && ch <= 'F') {
140 num = (num * 16) + (ch - 'A' + 10);
155 target_a2i(int ms_bit_nr,
159 return (ms_bit_nr - a2i(a));
165 i2target(int ms_bit_nr,
169 return ms_bit_nr - bit;
176 name2i(const char *names,
179 const name_map *curr;
180 const char *name = names;
181 while (*name != '\0') {
183 char *end = strchr(name, ',');
187 end = strchr(name, '\0');
196 while (curr->name != NULL) {
197 if (strncmp(curr->name, name, len) == 0
198 && strlen(curr->name) == len)
204 /* nothing found, possibly return a default */
206 while (curr->name != NULL)
211 error("%s contains no valid names\n", names);
219 while (map->name != NULL) {
224 error("map lookup failed for %d\n", i);