git subrepo pull --force deps/lightning
[pcsx_rearmed.git] / deps / lightning / size.c
CommitLineData
4a71579b
PC
1/*
2 * Copyright (C) 2013-2019 Free Software Foundation, Inc.
3 *
4 * This file is part of GNU lightning.
5 *
6 * GNU lightning is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 3, or (at your option)
9 * any later version.
10 *
11 * GNU lightning is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 * License for more details.
15 *
16 * Authors:
17 * Paulo Cesar Pereira de Andrade
18 */
19
20#include <lightning.h>
21#include <lightning/jit_private.h>
22#include <stdio.h>
23#include "lib/jit_names.c"
24
25jit_int16_t _szs[jit_code_last_code];
26
27int
28main(int argc, char *argv[])
29{
30 FILE *fp;
31 jit_word_t offset;
32 int code, size, max;
33
34 if ((fp = fopen(JIT_SIZE_PATH, "r")) == NULL)
35 exit(-1);
36 while (fscanf(fp, "%d %d\n", &code, &size) == 2) {
37 if (_szs[code] < size)
38 _szs[code] = size;
39 }
40 fclose(fp);
41
42 max = 0;
43 for (offset = 0; offset < jit_code_last_code; offset++)
44 if (max < _szs[offset])
45 max = _szs[offset];
46
47 if ((fp = fopen(JIT_SIZE_PATH, "w")) == NULL)
48 exit(-1);
49
50
51#if __X64 || __X32
52# if __X64
53 fprintf(fp, "#if __X64\n");
54# if __X64_32
55 fprintf(fp, "# if __X64_32\n");
56# else
57 fprintf(fp, "# if !__X64_32\n");
58# endif
59# else
60 fprintf(fp, "#if __X32\n");
61# endif
62#else
63 fprintf(fp, "#if __WORDSIZE == %d\n", __WORDSIZE);
64#endif
65#if defined(__arm__)
66# if defined(__ARM_PCS_VFP)
67 fprintf(fp, "#if defined(__ARM_PCS_VFP)\n");
68# else
69 fprintf(fp, "#if !defined(__ARM_PCS_VFP)\n");
70# endif
71#elif defined(__mips__)
72# if __WORDSIZE == 32
73# if NEW_ABI
74 fprintf(fp, "#if NEW_ABI\n");
75# else
76 fprintf(fp, "#if !NEW_ABI\n");
77# endif
78# endif
79#elif defined(__powerpc__)
80 fprintf(fp, "#if defined(__powerpc__)\n");
81 fprintf(fp, "#if __BYTE_ORDER == %s\n",
82 __BYTE_ORDER == __BIG_ENDIAN ? "__BIG_ENDIAN" : "__LITTLE_ENDIAN");
83# if __WORDSIZE == 32
84 fprintf(fp, "#if %s\n",
85# if !_CALL_SYSV
86 "!"
87# endif
88 "_CALL_SYSV"
89 );
90# endif
91#endif
92 fprintf(fp, "#define JIT_INSTR_MAX %d\n", max);
93 for (offset = 0; offset < jit_code_last_code; offset++)
94 fprintf(fp, " %d, /* %s */\n", _szs[offset], code_name[offset]);
95#if defined(__arm__)
96 fprintf(fp, "#endif /* __ARM_PCS_VFP */\n");
97#elif defined(__mips__)
98# if __WORDSIZE == 32
99 fprintf(fp, "#endif /* NEW_ABI */\n");
100# endif
101#elif defined(__powerpc__)
c0c16242 102# if __WORDSIZE == 32
4a71579b 103 fprintf(fp, "#endif /* "
c0c16242 104# if !_CALL_SYSV
4a71579b 105 "!"
c0c16242 106# endif
4a71579b
PC
107 "_CALL_SYSV"
108 " */\n");
c0c16242 109# endif
4a71579b
PC
110 fprintf(fp, "#endif /* __BYTE_ORDER */\n");
111 fprintf(fp, "#endif /* __powerpc__ */\n");
112#endif
113#if __X64 || __X32
114# if __X64
115 fprintf(fp, "# endif /* __X64_32 */\n");
116 fprintf(fp, "#endif /* __X64 */\n");
117# else
118 fprintf(fp, "#endif /* __X32 */\n");
119# endif
120#else
121 fprintf(fp, "#endif /* __WORDSIZE */\n");
122#endif
123
124 fclose(fp);
125
126 return (0);
127}