xref: /netbsd-src/external/gpl3/gdb/dist/sim/igen/misc.h (revision 71f621822dbfd5073a314948bec169b7bb05f7be)
14e98e3e1Schristos /* The IGEN simulator generator for GDB, the GNU Debugger.
24e98e3e1Schristos 
3*71f62182Schristos    Copyright 2002-2024 Free Software Foundation, Inc.
44e98e3e1Schristos 
54e98e3e1Schristos    Contributed by Andrew Cagney.
64e98e3e1Schristos 
74e98e3e1Schristos    This file is part of GDB.
84e98e3e1Schristos 
94e98e3e1Schristos    This program is free software; you can redistribute it and/or modify
104e98e3e1Schristos    it under the terms of the GNU General Public License as published by
114e98e3e1Schristos    the Free Software Foundation; either version 3 of the License, or
124e98e3e1Schristos    (at your option) any later version.
134e98e3e1Schristos 
144e98e3e1Schristos    This program is distributed in the hope that it will be useful,
154e98e3e1Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
164e98e3e1Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
174e98e3e1Schristos    GNU General Public License for more details.
184e98e3e1Schristos 
194e98e3e1Schristos    You should have received a copy of the GNU General Public License
204e98e3e1Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
214e98e3e1Schristos 
22*71f62182Schristos #ifndef IGEN_MISC_H
23*71f62182Schristos #define IGEN_MISC_H
244e98e3e1Schristos 
254e98e3e1Schristos /* Frustrating header junk */
264e98e3e1Schristos 
274e98e3e1Schristos enum
284e98e3e1Schristos {
294e98e3e1Schristos   default_insn_bit_size = 32,
304e98e3e1Schristos   max_insn_bit_size = 64,
314e98e3e1Schristos };
324e98e3e1Schristos 
334e98e3e1Schristos 
344e98e3e1Schristos #include <ctype.h>
354b169a6bSchristos #include <stdint.h>
364b169a6bSchristos #include <stdio.h>
374e98e3e1Schristos #include <stdlib.h>
384b169a6bSchristos #include <string.h>
394e98e3e1Schristos 
404b169a6bSchristos #include "ansidecl.h"
414e98e3e1Schristos 
424e98e3e1Schristos #include "filter_host.h"
434e98e3e1Schristos 
444e98e3e1Schristos typedef struct _line_ref line_ref;
454e98e3e1Schristos struct _line_ref
464e98e3e1Schristos {
474e98e3e1Schristos   const char *file_name;
484e98e3e1Schristos   int line_nr;
494e98e3e1Schristos };
504e98e3e1Schristos 
514e98e3e1Schristos /* Error appends a new line, warning and notify do not */
524b169a6bSchristos typedef void error_func (const line_ref *line, const char *msg, ...)
53*71f62182Schristos   ATTRIBUTE_PRINTF_2;
544e98e3e1Schristos 
55*71f62182Schristos extern error_func error ATTRIBUTE_PRINTF_2 ATTRIBUTE_NORETURN;
56*71f62182Schristos extern error_func warning ATTRIBUTE_PRINTF_2;
57*71f62182Schristos extern error_func notify ATTRIBUTE_PRINTF_2;
584e98e3e1Schristos 
594e98e3e1Schristos 
60*71f62182Schristos #define ERROR(EXPRESSION, args...) \
614e98e3e1Schristos do { \
624e98e3e1Schristos   line_ref line; \
634e98e3e1Schristos   line.file_name = filter_filename (__FILE__); \
644e98e3e1Schristos   line.line_nr = __LINE__; \
65*71f62182Schristos   error (&line, EXPRESSION "\n", ## args); \
664e98e3e1Schristos } while (0)
674e98e3e1Schristos 
684e98e3e1Schristos #define ASSERT(EXPRESSION) \
694e98e3e1Schristos do { \
704e98e3e1Schristos   if (!(EXPRESSION)) { \
714e98e3e1Schristos     line_ref line; \
724e98e3e1Schristos     line.file_name = filter_filename (__FILE__); \
734e98e3e1Schristos     line.line_nr = __LINE__; \
744e98e3e1Schristos     error (&line, "assertion failed - %s\n", #EXPRESSION); \
754e98e3e1Schristos   } \
764e98e3e1Schristos } while (0)
774e98e3e1Schristos 
784e98e3e1Schristos #define ZALLOC(TYPE) ((TYPE*) zalloc (sizeof(TYPE)))
794e98e3e1Schristos #define NZALLOC(TYPE,N) ((TYPE*) zalloc (sizeof(TYPE) * (N)))
804e98e3e1Schristos 
814e98e3e1Schristos extern void *zalloc (long size);
824e98e3e1Schristos 
834e98e3e1Schristos extern unsigned target_a2i (int ms_bit_nr, const char *a);
844e98e3e1Schristos 
854e98e3e1Schristos extern unsigned i2target (int ms_bit_nr, unsigned bit);
864e98e3e1Schristos 
874e98e3e1Schristos extern unsigned long long a2i (const char *a);
884e98e3e1Schristos 
894e98e3e1Schristos 
904e98e3e1Schristos /* Try looking for name in the map table (returning the corresponding
914e98e3e1Schristos    integer value).
924e98e3e1Schristos 
934e98e3e1Schristos    If the the sentinal (NAME == NULL) its value if >= zero is returned
944e98e3e1Schristos    as the default. */
954e98e3e1Schristos 
964e98e3e1Schristos typedef struct _name_map
974e98e3e1Schristos {
984e98e3e1Schristos   const char *name;
994e98e3e1Schristos   int i;
1004e98e3e1Schristos }
1014e98e3e1Schristos name_map;
1024e98e3e1Schristos 
1034e98e3e1Schristos extern int name2i (const char *name, const name_map * map);
1044e98e3e1Schristos 
1054e98e3e1Schristos extern const char *i2name (const int i, const name_map * map);
106*71f62182Schristos 
107*71f62182Schristos #endif /* IGEN_MISC_H */
108