-
Notifications
You must be signed in to change notification settings - Fork 0
/
MkMachDep.cpp
106 lines (88 loc) · 2.49 KB
/
MkMachDep.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* XMail by Davide Libenzi (Intranet and Internet mail server)
* Copyright (C) 1999,..,2010 Davide Libenzi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Davide Libenzi <[email protected]>
*
*/
#include <stdio.h>
static int MkMachIsLE(void)
{
union MachWordBytes {
unsigned int w;
unsigned char b[sizeof(unsigned int)];
} MWB;
MWB.w = 1;
return MWB.b[0] != 0;
}
static int MkMachIsLEBF(void)
{
union MachBitField {
struct {
unsigned int b:1;
} BF;
unsigned int w;
} MWB;
MWB.w = 1;
return MWB.BF.b != 0;
}
static int MkMachGenType(int iBits, char const *pszBase)
{
fprintf(stdout,
"typedef signed %s MachInt%d;\n"
"typedef unsigned %s MachUInt%d;\n"
"#define MACH_TYPE_%dBIT %s\n\n", pszBase, iBits, pszBase, iBits, iBits, pszBase);
return 0;
}
int main(int argc, char *argv[])
{
fprintf(stdout,
"#ifndef _MACHDEFS_H\n"
"#define _MACHDEFS_H\n\n\n");
if (!MkMachIsLE())
fprintf(stdout, "#define MACH_BIG_ENDIAN_WORDS\n\n");
else
fprintf(stdout, "#undef MACH_BIG_ENDIAN_WORDS\n\n");
if (!MkMachIsLEBF())
fprintf(stdout, "#define MACH_BIG_ENDIAN_BITFIELD\n\n");
else
fprintf(stdout, "#undef MACH_BIG_ENDIAN_BITFIELD\n\n");
MkMachGenType(8, "char");
if (sizeof(short) == 2)
MkMachGenType(16, "short");
else if (sizeof(int) == 2)
MkMachGenType(16, "int");
else if (sizeof(long) == 2)
MkMachGenType(16, "long");
if (sizeof(char) == 4)
MkMachGenType(32, "char");
else if (sizeof(short) == 4)
MkMachGenType(32, "short");
else if (sizeof(int) == 4)
MkMachGenType(32, "int");
else if (sizeof(long) == 4)
MkMachGenType(32, "long");
#if defined(_MSC_VER)
MkMachGenType(64, "__int64");
#elif defined(__GNUC__) || defined(__SUNPRO_CC)
MkMachGenType(64, "long long");
#else
#error Your compiler is not supported!
#endif
fprintf(stdout, "\n\n" "#endif\n\n");
return 0;
}