Commit | Line | Data |
---|---|---|
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 | ||
25 | jit_int16_t _szs[jit_code_last_code]; | |
26 | ||
27 | int | |
28 | main(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__) | |
102 | fprintf(fp, "#endif /* " | |
103 | # if !_CALL_SYSV | |
104 | "!" | |
105 | # endif | |
106 | "_CALL_SYSV" | |
107 | " */\n"); | |
108 | fprintf(fp, "#endif /* __BYTE_ORDER */\n"); | |
109 | fprintf(fp, "#endif /* __powerpc__ */\n"); | |
110 | #endif | |
111 | #if __X64 || __X32 | |
112 | # if __X64 | |
113 | fprintf(fp, "# endif /* __X64_32 */\n"); | |
114 | fprintf(fp, "#endif /* __X64 */\n"); | |
115 | # else | |
116 | fprintf(fp, "#endif /* __X32 */\n"); | |
117 | # endif | |
118 | #else | |
119 | fprintf(fp, "#endif /* __WORDSIZE */\n"); | |
120 | #endif | |
121 | ||
122 | fclose(fp); | |
123 | ||
124 | return (0); | |
125 | } |