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; | |
ba86ff93 PC |
43 | for (offset = 0; offset < jit_code_last_code; offset++) { |
44 | #if defined(__ia64__) | |
45 | if (_szs[offset] > 16) | |
46 | _szs[offset] = _szs[offset] / 3 + 16 & -16; | |
47 | #endif | |
4a71579b PC |
48 | if (max < _szs[offset]) |
49 | max = _szs[offset]; | |
ba86ff93 | 50 | } |
4a71579b PC |
51 | |
52 | if ((fp = fopen(JIT_SIZE_PATH, "w")) == NULL) | |
53 | exit(-1); | |
54 | ||
55 | ||
56 | #if __X64 || __X32 | |
57 | # if __X64 | |
58 | fprintf(fp, "#if __X64\n"); | |
59 | # if __X64_32 | |
60 | fprintf(fp, "# if __X64_32\n"); | |
61 | # else | |
62 | fprintf(fp, "# if !__X64_32\n"); | |
63 | # endif | |
64 | # else | |
65 | fprintf(fp, "#if __X32\n"); | |
66 | # endif | |
67 | #else | |
68 | fprintf(fp, "#if __WORDSIZE == %d\n", __WORDSIZE); | |
69 | #endif | |
70 | #if defined(__arm__) | |
71 | # if defined(__ARM_PCS_VFP) | |
72 | fprintf(fp, "#if defined(__ARM_PCS_VFP)\n"); | |
73 | # else | |
74 | fprintf(fp, "#if !defined(__ARM_PCS_VFP)\n"); | |
75 | # endif | |
4a71579b PC |
76 | #elif defined(__powerpc__) |
77 | fprintf(fp, "#if defined(__powerpc__)\n"); | |
78 | fprintf(fp, "#if __BYTE_ORDER == %s\n", | |
79 | __BYTE_ORDER == __BIG_ENDIAN ? "__BIG_ENDIAN" : "__LITTLE_ENDIAN"); | |
80 | # if __WORDSIZE == 32 | |
81 | fprintf(fp, "#if %s\n", | |
82 | # if !_CALL_SYSV | |
83 | "!" | |
84 | # endif | |
85 | "_CALL_SYSV" | |
86 | ); | |
87 | # endif | |
88 | #endif | |
89 | fprintf(fp, "#define JIT_INSTR_MAX %d\n", max); | |
90 | for (offset = 0; offset < jit_code_last_code; offset++) | |
91 | fprintf(fp, " %d, /* %s */\n", _szs[offset], code_name[offset]); | |
92 | #if defined(__arm__) | |
93 | fprintf(fp, "#endif /* __ARM_PCS_VFP */\n"); | |
4a71579b | 94 | #elif defined(__powerpc__) |
c0c16242 | 95 | # if __WORDSIZE == 32 |
4a71579b | 96 | fprintf(fp, "#endif /* " |
c0c16242 | 97 | # if !_CALL_SYSV |
4a71579b | 98 | "!" |
c0c16242 | 99 | # endif |
4a71579b PC |
100 | "_CALL_SYSV" |
101 | " */\n"); | |
c0c16242 | 102 | # endif |
4a71579b PC |
103 | fprintf(fp, "#endif /* __BYTE_ORDER */\n"); |
104 | fprintf(fp, "#endif /* __powerpc__ */\n"); | |
105 | #endif | |
106 | #if __X64 || __X32 | |
107 | # if __X64 | |
108 | fprintf(fp, "# endif /* __X64_32 */\n"); | |
109 | fprintf(fp, "#endif /* __X64 */\n"); | |
110 | # else | |
111 | fprintf(fp, "#endif /* __X32 */\n"); | |
112 | # endif | |
113 | #else | |
114 | fprintf(fp, "#endif /* __WORDSIZE */\n"); | |
115 | #endif | |
116 | ||
117 | fclose(fp); | |
118 | ||
119 | return (0); | |
120 | } |