]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/ppc/misc.c
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/binutils-gdb.git] / sim / ppc / misc.c
CommitLineData
a983c8f0
MM
1/* This file is part of the program psim.
2
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
4
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.
9
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.
14
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.
18
19 */
20
21
22#include <stdio.h>
23#include <stdarg.h>
24#include <stdlib.h>
25#include <string.h>
26
27#include "misc.h"
28
29void
30error (char *msg, ...)
31{
32 va_list ap;
33 va_start(ap, msg);
34 vprintf(msg, ap);
35 va_end(ap);
36 exit (1);
37}
38
39void *
40zalloc(long size)
41{
42 void *memory = malloc(size);
43 if (memory == NULL)
44 error("zalloc failed\n");
45 bzero(memory, size);
46 return memory;
47}
48
49void
50dumpf (int indent, char *msg, ...)
51{
52 va_list ap;
53 for (; indent > 0; indent--)
54 printf(" ");
55 va_start(ap, msg);
56 vprintf(msg, ap);
57 va_end(ap);
58}
59
60
61int
62it_is(const char *flag,
63 const char *flags)
64{
65 int flag_len = strlen(flag);
66 while (*flags != '\0') {
67 if (!strncmp(flags, flag, flag_len)
68 && (flags[flag_len] == ',' || flags[flag_len] == '\0'))
69 return 1;
70 while (*flags != ',') {
71 if (*flags == '\0')
72 return 0;
73 flags++;
74 }
75 flags++;
76 }
77 return 0;
78}
79
80
81unsigned
82a2i(const char *a)
83{
84 return strtoul(a, 0, 0);
85}
86
87unsigned
88target_a2i(int ms_bit_nr,
89 const char *a)
90{
91 if (ms_bit_nr)
92 return (ms_bit_nr - strtoul(a, 0, 0));
93 else
94 return strtoul(a, 0, 0);
95}
96
97unsigned
98i2target(int ms_bit_nr,
99 unsigned bit)
100{
101 if (ms_bit_nr)
102 return ms_bit_nr - bit;
103 else
104 return bit;
105}
106
107