/src/CMake/Utilities/cmllpkgc/llpkgc_whitespace__internal.c
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. |
2 | | See accompanying file LICENSE.rst for details. */ |
3 | | /* This code was generated by llpkgc, do not edit it by hand |
4 | | See: https://gitlab.kitware.com/utils/llpkgc */ |
5 | | |
6 | | |
7 | | #include <stdlib.h> |
8 | | #include <stdint.h> |
9 | | #include <string.h> |
10 | | |
11 | | #ifdef __SSE4_2__ |
12 | | #ifdef _MSC_VER |
13 | | #include <nmmintrin.h> |
14 | | #else /* !_MSC_VER */ |
15 | | #include <x86intrin.h> |
16 | | #endif /* _MSC_VER */ |
17 | | #endif /* __SSE4_2__ */ |
18 | | |
19 | | #if defined(__ARM_NEON__) || defined(__ARM_NEON) |
20 | | #include <arm_neon.h> |
21 | | #endif /* __ARM_NEON__ */ |
22 | | |
23 | | #ifdef __wasm__ |
24 | | #include <wasm_simd128.h> |
25 | | #endif /* __wasm__ */ |
26 | | |
27 | | #ifdef _MSC_VER |
28 | | #define ALIGN(n) _declspec(align(n)) |
29 | | #define UNREACHABLE __assume(0) |
30 | | #else /* !_MSC_VER */ |
31 | | #define ALIGN(n) __attribute__((aligned(n))) |
32 | 0 | #define UNREACHABLE __builtin_unreachable() |
33 | | #endif /* _MSC_VER */ |
34 | | |
35 | | #include "llpkgc_whitespace__internal.h" |
36 | | |
37 | | typedef int (*llpkgc_whitespace__internal__span_cb)( |
38 | | llpkgc_whitespace__internal_t*, const char*, const char*); |
39 | | |
40 | | enum llparse_state_e { |
41 | | s_error, |
42 | | s_n_llpkgc_whitespace__internal__n_whitespace, |
43 | | s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span, |
44 | | s_n_llpkgc_whitespace__internal__n_lf, |
45 | | s_n_llpkgc_whitespace__internal__n_cr, |
46 | | s_n_llpkgc_whitespace__internal__n_escaped, |
47 | | s_n_llpkgc_whitespace__internal__n_start, |
48 | | }; |
49 | | typedef enum llparse_state_e llparse_state_t; |
50 | | |
51 | | int llpkgc_file__deferred_span( |
52 | | llpkgc_whitespace__internal_t* s, const unsigned char* p, |
53 | | const unsigned char* endp); |
54 | | |
55 | 209k | int llpkgc_whitespace__internal_init(llpkgc_whitespace__internal_t* state) { |
56 | 209k | memset(state, 0, sizeof(*state)); |
57 | 209k | state->_current = (void*) (intptr_t) s_n_llpkgc_whitespace__internal__n_start; |
58 | 209k | return 0; |
59 | 209k | } |
60 | | |
61 | | static llparse_state_t llpkgc_whitespace__internal__run( |
62 | | llpkgc_whitespace__internal_t* state, |
63 | | const unsigned char* p, |
64 | 209k | const unsigned char* endp) { |
65 | 209k | int match; |
66 | 209k | switch ((llparse_state_t) (intptr_t) state->_current) { |
67 | 0 | case s_n_llpkgc_whitespace__internal__n_whitespace: |
68 | 269k | s_n_llpkgc_whitespace__internal__n_whitespace: { |
69 | 269k | if (p == endp) { |
70 | 207k | return s_n_llpkgc_whitespace__internal__n_whitespace; |
71 | 207k | } |
72 | 62.0k | switch (*p) { |
73 | 8.75k | case 9: { |
74 | 8.75k | p++; |
75 | 8.75k | goto s_n_llpkgc_whitespace__internal__n_whitespace; |
76 | 0 | } |
77 | 8.31k | case 11: { |
78 | 8.31k | p++; |
79 | 8.31k | goto s_n_llpkgc_whitespace__internal__n_whitespace; |
80 | 0 | } |
81 | 3.67k | case 12: { |
82 | 3.67k | p++; |
83 | 3.67k | goto s_n_llpkgc_whitespace__internal__n_whitespace; |
84 | 0 | } |
85 | 38.1k | case ' ': { |
86 | 38.1k | p++; |
87 | 38.1k | goto s_n_llpkgc_whitespace__internal__n_whitespace; |
88 | 0 | } |
89 | 3.17k | default: { |
90 | 3.17k | goto s_n_llpkgc_whitespace__internal__n_span_end_llpkgc_file__deferred_span; |
91 | 0 | } |
92 | 62.0k | } |
93 | 62.0k | UNREACHABLE; |
94 | 62.0k | } |
95 | 0 | case s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span: |
96 | 210k | s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span: { |
97 | 210k | if (p == endp) { |
98 | 0 | return s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span; |
99 | 0 | } |
100 | 210k | state->_span_pos0 = (void*) p; |
101 | 210k | p++; |
102 | 210k | goto s_n_llpkgc_whitespace__internal__n_whitespace; |
103 | 210k | UNREACHABLE; |
104 | 210k | } |
105 | 0 | case s_n_llpkgc_whitespace__internal__n_lf: |
106 | 1.63k | s_n_llpkgc_whitespace__internal__n_lf: { |
107 | 1.63k | if (p == endp) { |
108 | 551 | return s_n_llpkgc_whitespace__internal__n_lf; |
109 | 551 | } |
110 | 1.08k | switch (*p) { |
111 | 481 | case 13: { |
112 | 481 | p++; |
113 | 481 | goto s_n_llpkgc_whitespace__internal__n_start; |
114 | 0 | } |
115 | 601 | default: { |
116 | 601 | goto s_n_llpkgc_whitespace__internal__n_start; |
117 | 0 | } |
118 | 1.08k | } |
119 | 1.08k | UNREACHABLE; |
120 | 1.08k | } |
121 | 0 | case s_n_llpkgc_whitespace__internal__n_cr: |
122 | 2.71k | s_n_llpkgc_whitespace__internal__n_cr: { |
123 | 2.71k | if (p == endp) { |
124 | 898 | return s_n_llpkgc_whitespace__internal__n_cr; |
125 | 898 | } |
126 | 1.81k | switch (*p) { |
127 | 1.10k | case 10: { |
128 | 1.10k | p++; |
129 | 1.10k | goto s_n_llpkgc_whitespace__internal__n_start; |
130 | 0 | } |
131 | 715 | default: { |
132 | 715 | goto s_n_llpkgc_whitespace__internal__n_start; |
133 | 0 | } |
134 | 1.81k | } |
135 | 1.81k | UNREACHABLE; |
136 | 1.81k | } |
137 | 0 | case s_n_llpkgc_whitespace__internal__n_escaped: |
138 | 4.34k | s_n_llpkgc_whitespace__internal__n_escaped: { |
139 | 4.34k | if (p == endp) { |
140 | 0 | return s_n_llpkgc_whitespace__internal__n_escaped; |
141 | 0 | } |
142 | 4.34k | switch (*p) { |
143 | 1.63k | case 10: { |
144 | 1.63k | p++; |
145 | 1.63k | goto s_n_llpkgc_whitespace__internal__n_lf; |
146 | 0 | } |
147 | 2.71k | case 13: { |
148 | 2.71k | p++; |
149 | 2.71k | goto s_n_llpkgc_whitespace__internal__n_cr; |
150 | 0 | } |
151 | 0 | default: { |
152 | 0 | goto s_n_llpkgc_whitespace__internal__n_error; |
153 | 0 | } |
154 | 4.34k | } |
155 | 4.34k | UNREACHABLE; |
156 | 4.34k | } |
157 | 209k | case s_n_llpkgc_whitespace__internal__n_start: |
158 | 215k | s_n_llpkgc_whitespace__internal__n_start: { |
159 | 215k | if (p == endp) { |
160 | 650 | return s_n_llpkgc_whitespace__internal__n_start; |
161 | 650 | } |
162 | 214k | switch (*p) { |
163 | 24.1k | case 9: { |
164 | 24.1k | goto s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span; |
165 | 0 | } |
166 | 2.35k | case 11: { |
167 | 2.35k | goto s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span; |
168 | 0 | } |
169 | 2.50k | case 12: { |
170 | 2.50k | goto s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span; |
171 | 0 | } |
172 | 181k | case ' ': { |
173 | 181k | goto s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span; |
174 | 0 | } |
175 | 4.34k | case 92: { |
176 | 4.34k | p++; |
177 | 4.34k | goto s_n_llpkgc_whitespace__internal__n_escaped; |
178 | 0 | } |
179 | 0 | default: { |
180 | 0 | goto s_n_llpkgc_whitespace__internal__n_error; |
181 | 0 | } |
182 | 214k | } |
183 | 214k | UNREACHABLE; |
184 | 214k | } |
185 | 0 | default: |
186 | 0 | UNREACHABLE; |
187 | 209k | } |
188 | 3.17k | s_n_llpkgc_whitespace__internal__n_span_end_llpkgc_file__deferred_span: { |
189 | 3.17k | const unsigned char* start; |
190 | 3.17k | int err; |
191 | | |
192 | 3.17k | start = state->_span_pos0; |
193 | 3.17k | state->_span_pos0 = NULL; |
194 | 3.17k | err = llpkgc_file__deferred_span(state, start, p); |
195 | 3.17k | if (err != 0) { |
196 | 0 | state->error = err; |
197 | 0 | state->error_pos = (const char*) p; |
198 | 0 | state->_current = (void*) (intptr_t) s_n_llpkgc_whitespace__internal__n_start; |
199 | 0 | return s_error; |
200 | 0 | } |
201 | 3.17k | goto s_n_llpkgc_whitespace__internal__n_start; |
202 | 3.17k | UNREACHABLE; |
203 | 3.17k | } |
204 | 0 | s_n_llpkgc_whitespace__internal__n_error: { |
205 | 0 | state->error = 0x5; |
206 | 0 | state->reason = "Invalid deferred whitespace range"; |
207 | 0 | state->error_pos = (const char*) p; |
208 | 0 | state->_current = (void*) (intptr_t) s_error; |
209 | 0 | return s_error; |
210 | 3.17k | UNREACHABLE; |
211 | 3.17k | } |
212 | 3.17k | } |
213 | | |
214 | 209k | int llpkgc_whitespace__internal_execute(llpkgc_whitespace__internal_t* state, const char* p, const char* endp) { |
215 | 209k | llparse_state_t next; |
216 | | |
217 | | /* check lingering errors */ |
218 | 209k | if (state->error != 0) { |
219 | 0 | return state->error; |
220 | 0 | } |
221 | | |
222 | | /* restart spans */ |
223 | 209k | if (state->_span_pos0 != NULL) { |
224 | 0 | state->_span_pos0 = (void*) p; |
225 | 0 | } |
226 | | |
227 | 209k | next = llpkgc_whitespace__internal__run(state, (const unsigned char*) p, (const unsigned char*) endp); |
228 | 209k | if (next == s_error) { |
229 | 0 | return state->error; |
230 | 0 | } |
231 | 209k | state->_current = (void*) (intptr_t) next; |
232 | | |
233 | | /* execute spans */ |
234 | 209k | if (state->_span_pos0 != NULL) { |
235 | 207k | int error; |
236 | | |
237 | 207k | error = llpkgc_file__deferred_span(state, state->_span_pos0, (const char*) endp); |
238 | 207k | if (error != 0) { |
239 | 0 | state->error = error; |
240 | 0 | state->error_pos = endp; |
241 | 0 | return error; |
242 | 0 | } |
243 | 207k | } |
244 | | |
245 | 209k | return 0; |
246 | 209k | } |