summaryrefslogtreecommitdiff
path: root/test/rlhc.d/case/high1.c-C-G0--goto-backend.in
blob: 595fee8c262e521a68365344333e5d6e2fa0933c (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
host( "working/high1.rl", 1 ) @{/*
	* @@LANG: c
	* @@PROHIBIT_GENFLAGS: -F0 -F1
	*/
	
	/**
	* Test a high character to make sure signedness 
	* isn't messing us up.
	*/
	
	#include <stdio.h>
	#include <stdlib.h>
	#include <string.h>
	
	struct high
	{
		int cs;
	};
	
	
	
}@
array s8 _high_actions( 0, 3 ) = { 0, 1, 0, 1, 2, 1, 3, 2, 0, 2, 2, 1, 2, 0 };

array s8 _high_nfa_targs( 0, 0 ) = { 0, 0 };

array s8 _high_nfa_offsets( 0, 0 ) = { 0, 0 };

array s8 _high_nfa_push_actions( 0, 0 ) = { 0, 0 };

array s8 _high_nfa_pop_trans( 0, 0 ) = { 0, 0 };

value int high_start = 0;
value int high_first_final = 0;
value int high_error = -1;

value int high_en_main = 0;

host( "working/high1.rl", 36 ) @{
	
	void high_init( struct high *fsm )
	{
	}@
	{
		host( "-", 1 ) ={ fsm->cs}= = cast(int)high_start;
	}
	host( "working/high1.rl", 40 ) @{
	}
	
	void high_execute( struct high *fsm, const unsigned int *_data, int _len )
	{
		const unsigned int *p = _data;
		const unsigned int *pe = _data+_len;
		
	}@
	{
		index s8 _acts;
		uint _nacts;
		
		if ( p == pe )
		goto _test_eof;
		_resume:
		switch ( host( "-", 1 ) ={ fsm->cs}= ) {
			case 0:
			if ( ( deref( data, p )) == u(4026531840) ) {
				goto ctr3;
			}
			if ( ( deref( data, p )) < u(32) ) {
				{
					goto ctr0;
				}
			} else if ( ( deref( data, p )) > u(511) ) {
				if ( ( deref( data, p )) > u(4261412864) ) {
					{
						goto ctr0;
					}
				} else if ( ( deref( data, p )) >= u(4026531841) ) {
					goto ctr4;
				}
			} else {
				goto ctr1;
			}
			{
				goto ctr2;
			}
		}
		
		ctr0: host( "-", 1 ) ={ fsm->cs}= = 0; goto f0;
		ctr1: host( "-", 1 ) ={ fsm->cs}= = 0; goto f1;
		ctr2: host( "-", 1 ) ={ fsm->cs}= = 0; goto f2;
		ctr3: host( "-", 1 ) ={ fsm->cs}= = 0; goto f3;
		ctr4: host( "-", 1 ) ={ fsm->cs}= = 0; goto f4;
		
		f1: _acts = offset( _high_actions, 1 ); goto execFuncs;
		f4: _acts = offset( _high_actions, 3 ); goto execFuncs;
		f0: _acts = offset( _high_actions, 5 ); goto execFuncs;
		f2: _acts = offset( _high_actions, 7 ); goto execFuncs;
		f3: _acts = offset( _high_actions, 10 ); goto execFuncs;
		
		execFuncs:
		_nacts = cast(uint)deref( _high_actions, _acts );
		_acts += 1;
		while ( _nacts > 0 ) {
			switch ( deref( _high_actions, _acts ) ) {
				case 0{
					host( "working/high1.rl", 28 ) ${printf("gothigh1\n");}$
				}
				case 1{
					host( "working/high1.rl", 29 ) ${printf("gothigh1\n");}$
				}
				case 2{
					host( "working/high1.rl", 30 ) ${printf("gothigh2\n");}$
				}
				case 3{
					host( "working/high1.rl", 31 ) ${printf("else\n");}$
				}
			}
			_acts += 1;
			_nacts -= 1;
		}
		
		goto _again;
		
		_again:
		p += 1;
		if ( p != pe )
		goto _resume;
		_test_eof: {}
	}
	host( "working/high1.rl", 48 ) @{
	}
	
	int high_finish( struct high *fsm )
	{
		if ( fsm->cs == high_error )
		return -1;
		if ( fsm->cs >= high_first_final )
		return 1;
		return 0;
	}
	
	struct high high;
	
	#define BUFSIZE 1024
	char cbuf[BUFSIZE];
	unsigned int buf[BUFSIZE];
	int buflen = 0;
	char numbuf[9];
	int numlen = 0;
	
	struct tokenizer
	{
		int cs;
	};
	
	
	
}@
array s8 _tokenizer_actions( 0, 2 ) = { 0, 1, 0, 1, 1, 1, 2, 2, 1, 2, 0 };

array s8 _tokenizer_eof_actions( 0, 7 ) = { 0, 5, 7, 0 };

array s8 _tokenizer_nfa_targs( 0, 0 ) = { 0, 0 };

array s8 _tokenizer_nfa_offsets( 0, 0 ) = { 0, 0, 0, 0 };

array s8 _tokenizer_nfa_push_actions( 0, 0 ) = { 0, 0 };

array s8 _tokenizer_nfa_pop_trans( 0, 0 ) = { 0, 0 };

value int tokenizer_start = 1;
value int tokenizer_first_final = 1;
value int tokenizer_error = 0;

value int tokenizer_en_main = 1;

host( "working/high1.rl", 110 ) @{
	
	void tokenizer_init( struct tokenizer *fsm )
	{
	}@
	{
		host( "-", 1 ) ={ fsm->cs}= = cast(int)tokenizer_start;
	}
	host( "working/high1.rl", 114 ) @{
	}
	
	void tokenizer_execute( struct tokenizer *fsm, const char *_data, int _len )
	{
		const char *p = _data;
		const char *pe = _data+_len;
		const char *eof = pe;
		
	}@
	{
		index s8 _acts;
		uint _nacts;
		
		if ( p == pe )
		goto _test_eof;
		if ( host( "-", 1 ) ={ fsm->cs}= == 0 )
		goto _out;
		_resume:
		switch ( host( "-", 1 ) ={ fsm->cs}= ) {
			case 1:
			if ( ( deref( data, p )) == 32 ) {
				goto ctr0;
			}
			if ( ( deref( data, p )) < 48 ) {
				if ( 9 <= ( deref( data, p )) && ( deref( data, p )) <= 13 ) {
					goto ctr0;
				}
			} else if ( ( deref( data, p )) > 57 ) {
				if ( 97 <= ( deref( data, p )) && ( deref( data, p )) <= 102 ) {
					goto ctr2;
				}
			} else {
				goto ctr2;
			}
			{
				goto ctr1;
			}
			case 0:
			goto _out;
			case 2:
			if ( ( deref( data, p )) == 32 ) {
				goto ctr3;
			}
			if ( ( deref( data, p )) < 48 ) {
				if ( 9 <= ( deref( data, p )) && ( deref( data, p )) <= 13 ) {
					goto ctr3;
				}
			} else if ( ( deref( data, p )) > 57 ) {
				if ( 97 <= ( deref( data, p )) && ( deref( data, p )) <= 102 ) {
					goto ctr2;
				}
			} else {
				goto ctr2;
			}
			{
				goto ctr1;
			}
		}
		
		ctr1: host( "-", 1 ) ={ fsm->cs}= = 0; goto _again;
		ctr0: host( "-", 1 ) ={ fsm->cs}= = 1; goto _again;
		ctr3: host( "-", 1 ) ={ fsm->cs}= = 1; goto f3;
		ctr2: host( "-", 1 ) ={ fsm->cs}= = 2; goto f1;
		
		f1: _acts = offset( _tokenizer_actions, 1 ); goto execFuncs;
		f3: _acts = offset( _tokenizer_actions, 3 ); goto execFuncs;
		
		execFuncs:
		_nacts = cast(uint)deref( _tokenizer_actions, _acts );
		_acts += 1;
		while ( _nacts > 0 ) {
			switch ( deref( _tokenizer_actions, _acts ) ) {
				case 0{
					host( "working/high1.rl", 77 ) ${
						if ( numlen < 8 )
						numbuf[numlen++] = ={( deref( data, p ))}=;
					}$
				}
				case 1{
					host( "working/high1.rl", 82 ) ${
						/* Null terminate the buffer storing the number and reset. */
						numbuf[numlen] = 0;
						numlen = 0;
						
						/* Store the number in the buf. If the buf is full then 
						* flush and reset the buffer. */
						buf[buflen++] = strtoul( numbuf, 0, 16 );
						if ( buflen == BUFSIZE ) {
							high_execute( &high, buf, BUFSIZE );
							buflen = 0;
						}
					}$
				}
			}
			_acts += 1;
			_nacts -= 1;
		}
		
		goto _again;
		
		_again:
		if ( host( "-", 1 ) ={ fsm->cs}= == 0 )
		goto _out;
		p += 1;
		if ( p != pe )
		goto _resume;
		_test_eof: {}
		if ( p == eof )
		{
			index s8 __acts;
			uint __nacts;
			__acts = offset( _tokenizer_actions, _tokenizer_eof_actions[host( "-", 1 ) ={ fsm->cs}=] );
			__nacts = cast(uint)deref( _tokenizer_actions, __acts ); __acts += 1;
			while ( __nacts > 0 ) {
				switch ( deref( _tokenizer_actions, __acts ) ) {
					case 1{
						host( "working/high1.rl", 82 ) ${
							/* Null terminate the buffer storing the number and reset. */
							numbuf[numlen] = 0;
							numlen = 0;
							
							/* Store the number in the buf. If the buf is full then 
							* flush and reset the buffer. */
							buf[buflen++] = strtoul( numbuf, 0, 16 );
							if ( buflen == BUFSIZE ) {
								high_execute( &high, buf, BUFSIZE );
								buflen = 0;
							}
						}$
					}
					case 2{
						host( "working/high1.rl", 96 ) ${
							if ( buflen > 0 )
							high_execute( &high, buf, buflen );
							if ( high_finish( &high ) > 0 )
							printf("ACCEPT\n");
							else
							printf("FAIL\n");
						}$
					}
				}
				__acts += 1;
				__nacts -= 1;
			}
		}
		
		_out: {}
	}
	host( "working/high1.rl", 123 ) @{
	}
	
	int tokenizer_finish( struct tokenizer *fsm )
	{
		if ( fsm->cs == tokenizer_error )
		return -1;
		if ( fsm->cs >= tokenizer_first_final )
		return 1;
		return 0;
	}
	
	struct tokenizer tok;
	
	void test( char *cbuf )
	{
		int len = strlen( cbuf );
		high_init( &high );
		tokenizer_init( &tok );
		tokenizer_execute( &tok, cbuf, len );
		if ( tokenizer_finish( &tok ) <= 0 )
		printf("Tokenizer FAIL\n");
	}
	
	char data[] =
	"10 20 30 40 50 200 300 400 \n"
	"d0000000 f0000000 fd000000 fe000000\n"
	"ff000000 ffffffffffffffffffffffffff\n"
	"ff\n";
	
	int main()
	{
		test( data );
		return 0;
	}
	
}@