demand_copy_C_string NUL check
[binutils-gdb.git] / sim / igen / misc.h
1 /* The IGEN simulator generator for GDB, the GNU Debugger.
2
3 Copyright 2002-2021 Free Software Foundation, Inc.
4
5 Contributed by Andrew Cagney.
6
7 This file is part of GDB.
8
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.
13
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.
18
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/>. */
21
22
23
24 /* Frustrating header junk */
25
26 #include "config.h"
27
28
29 enum
30 {
31 default_insn_bit_size = 32,
32 max_insn_bit_size = 64,
33 };
34
35
36 /* Define a 64bit data type */
37
38 #if defined __GNUC__ || defined _WIN32
39 #ifdef __GNUC__
40
41 typedef long long signed64;
42 typedef unsigned long long unsigned64;
43
44 #else /* _WIN32 */
45
46 typedef __int64 signed64;
47 typedef unsigned __int64 unsigned64;
48
49 #endif /* _WIN32 */
50 #else /* Not GNUC or WIN32 */
51 /* Not supported */
52 #endif
53
54
55 #include <stdio.h>
56 #include <ctype.h>
57 #include <string.h>
58 #include <stdlib.h>
59
60 #if !defined (__attribute__) && (!defined(__GNUC__) || __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7))
61 #define __attribute__(arg)
62 #endif
63
64
65
66 #include "filter_host.h"
67
68 typedef struct _line_ref line_ref;
69 struct _line_ref
70 {
71 const char *file_name;
72 int line_nr;
73 };
74
75 /* Error appends a new line, warning and notify do not */
76 typedef void error_func (const line_ref *line, char *msg, ...);
77
78 extern error_func error;
79 extern error_func warning;
80 extern error_func notify;
81
82
83 #define ERROR(EXPRESSION) \
84 do { \
85 line_ref line; \
86 line.file_name = filter_filename (__FILE__); \
87 line.line_nr = __LINE__; \
88 error (&line, EXPRESSION); \
89 } while (0)
90
91 #define ASSERT(EXPRESSION) \
92 do { \
93 if (!(EXPRESSION)) { \
94 line_ref line; \
95 line.file_name = filter_filename (__FILE__); \
96 line.line_nr = __LINE__; \
97 error(&line, "assertion failed - %s\n", #EXPRESSION); \
98 } \
99 } while (0)
100
101 #define ZALLOC(TYPE) ((TYPE*) zalloc (sizeof(TYPE)))
102 #define NZALLOC(TYPE,N) ((TYPE*) zalloc (sizeof(TYPE) * (N)))
103
104 extern void *zalloc (long size);
105
106 extern unsigned target_a2i (int ms_bit_nr, const char *a);
107
108 extern unsigned i2target (int ms_bit_nr, unsigned bit);
109
110 extern unsigned long long a2i (const char *a);
111
112
113 /* Try looking for name in the map table (returning the corresponding
114 integer value).
115
116 If the the sentinal (NAME == NULL) its value if >= zero is returned
117 as the default. */
118
119 typedef struct _name_map
120 {
121 const char *name;
122 int i;
123 }
124 name_map;
125
126 extern int name2i (const char *name, const name_map * map);
127
128 extern const char *i2name (const int i, const name_map * map);