5 * Generate `mptypes.h' header file for current architecture
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Header files ------------------------------------------------------*/
37 #if __STDC_VERSION__ >= 199900l
39 # include <inttypes.h>
42 /*----- Data types --------------------------------------------------------*/
44 /* --- Hack for GCC --- *
46 * WG14 in their infinite wisdom decided not to use the GCC constant name.
49 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 91)
50 # define EXT __extension__
55 #if defined(ULONG_LONG_MAX) && !defined(ULLONG_MAX)
56 # define ULLONG_MAX ULONG_LONG_MAX
59 /* --- Choose the largest integer type --- */
61 #if defined(UINTMAX_MAX) && defined(PRIuMAX)
62 typedef uintmax_t umax;
63 # define P_UMAX PRIuMAX
64 #elif defined(ULLONG_MAX)
65 EXT typedef unsigned long long umax;
68 typedef unsigned long umax;
72 /* --- Table of interesting types --- *
74 * These are in preference order.
89 { "unsigned int", "u", UINT_MAX, 0 },
90 { "unsigned short", "u", USHRT_MAX, 0 },
91 { "unsigned long", "ul", ULONG_MAX, 0 },
93 { "unsigned long long", "ull", EXT ULLONG_MAX, f_ext },
96 { "uintmax_t", "u", UINTMAX_MAX, f_stdint },
101 typedef struct itype itype;
103 /*----- Main code ---------------------------------------------------------*/
105 int main(int argc, char *argv[])
108 itype *largest, *mpw, *mpd;
109 const static char *extstr = "CATACOMB_MPTYPES_EXTENSION ";
112 /* --- Find the bitcounts --- */
114 for (i = tytab; i->name; i++) {
117 for (bits = 0; u; bits++)
122 /* --- Now try to find the interesting types --- *
124 * The first thing to do is to find the largest type. Then I find the
125 * `best' type which is less than half that size, and then the `best' type
126 * which is twice as big as that one.
129 #if defined(FORCE_MPW_CUSSID)
130 largest = mpd = &tytab[3];
132 mpw->bits = 19; mpw->max = 0x7ffff;
133 mpd->bits = 38; mpd->max = 0x3fffffffffll;
134 #elif defined(FORCE_MPW_SHORT)
135 largest = mpd = &tytab[2];
137 mpw->bits = 16; mpw->max = 0xffff;
138 mpd->bits = 32; mpd->max = 0xffffffff;
141 for (i = tytab; i->name; i++) {
142 if (i->bits > largest->bits)
145 for (mpw = 0, i = tytab; i->name; i++) {
146 if (i->bits * 2 <= largest->bits && (!mpw || i->bits > mpw->bits))
151 for (mpd = 0, i = tytab; i->name; i++) {
152 if (i->bits >= mpw->bits * 2 && (!mpd || i->bits < mpd->bits))
158 w.bits /= 2; w.max = ~(~((umax)0) << w.bits);
159 d.bits = w.bits * 2; d.max = ~(~((umax)0) << d.bits);
163 for (p2 = 1; (p2 << 1) < mpw->bits; p2 <<= 1);
165 /* --- Output time --- */
170 * mptypes.h [generated]\n\
173 #ifndef CATACOMB_MPTYPES_H\n\
174 #define CATACOMB_MPTYPES_H\n\
176 if ((mpd->flags | mpw->flags) & f_stdint) {
178 #if __STDC_VERSION__ >= 199900l\n\
179 # include <stdint.h>\n\
183 if ((mpd->flags | mpw->flags) & f_ext) {
185 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 91)\n\
186 # define %s __extension__\n\
194 #define MPW_BITS %u\n\
196 #define MPW_MAX %s%" P_UMAX "%s\n\
199 #define MPD_BITS %u\n\
200 #define MPD_MAX %s%" P_UMAX "%s\n\
204 mpw->flags & f_ext ? extstr : "", mpw->name,
206 mpw->flags & f_ext ? extstr : "", mpw->max, mpw->suff,
207 mpd->flags & f_ext ? extstr : "", mpd->name,
209 mpd->flags & f_ext ? extstr : "", mpd->max, mpd->suff);
214 /*----- That's all, folks -------------------------------------------------*/