• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 1 "tccgen.c"
2# 1 "<built-in>"
3# 1 "<command-line>"
4# 1 "tccgen.c"
5# 21 "tccgen.c"
6# 1 "tcc.h" 1
7# 25 "tcc.h"
8# 1 "config.h" 1
9# 26 "tcc.h" 2
10
11# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/stdlib.h" 1
12# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_defines.h" 1
13# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/stdlib.h" 2
14# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_typedefs.h" 1
15
16
17
18typedef int size_t;
19typedef int __builtin_va_list;
20typedef int __gnuc_va_list;
21typedef int va_list;
22typedef int __int8_t;
23typedef int __uint8_t;
24typedef int __int16_t;
25typedef int __uint16_t;
26typedef int __int_least16_t;
27typedef int __uint_least16_t;
28typedef int __int32_t;
29typedef int __uint32_t;
30typedef int __int64_t;
31typedef int __uint64_t;
32typedef int __int_least32_t;
33typedef int __uint_least32_t;
34typedef int __s8;
35typedef int __u8;
36typedef int __s16;
37typedef int __u16;
38typedef int __s32;
39typedef int __u32;
40typedef int __s64;
41typedef int __u64;
42typedef int _LOCK_T;
43typedef int _LOCK_RECURSIVE_T;
44typedef int _off_t;
45typedef int __dev_t;
46typedef int __uid_t;
47typedef int __gid_t;
48typedef int _off64_t;
49typedef int _fpos_t;
50typedef int _ssize_t;
51typedef int wint_t;
52typedef int _mbstate_t;
53typedef int _flock_t;
54typedef int _iconv_t;
55typedef int __ULong;
56typedef int __FILE;
57typedef int ptrdiff_t;
58typedef int wchar_t;
59typedef int __off_t;
60typedef int __pid_t;
61typedef int __loff_t;
62typedef int u_char;
63typedef int u_short;
64typedef int u_int;
65typedef int u_long;
66typedef int ushort;
67typedef int uint;
68typedef int clock_t;
69typedef int time_t;
70typedef int daddr_t;
71typedef int caddr_t;
72typedef int ino_t;
73typedef int off_t;
74typedef int dev_t;
75typedef int uid_t;
76typedef int gid_t;
77typedef int pid_t;
78typedef int key_t;
79typedef int ssize_t;
80typedef int mode_t;
81typedef int nlink_t;
82typedef int fd_mask;
83typedef int _types_fd_set;
84typedef int clockid_t;
85typedef int timer_t;
86typedef int useconds_t;
87typedef int suseconds_t;
88typedef int FILE;
89typedef int fpos_t;
90typedef int cookie_read_function_t;
91typedef int cookie_write_function_t;
92typedef int cookie_seek_function_t;
93typedef int cookie_close_function_t;
94typedef int cookie_io_functions_t;
95typedef int div_t;
96typedef int ldiv_t;
97typedef int lldiv_t;
98typedef int sigset_t;
99typedef int __sigset_t;
100typedef int _sig_func_ptr;
101typedef int sig_atomic_t;
102typedef int __tzrule_type;
103typedef int __tzinfo_type;
104typedef int mbstate_t;
105typedef int sem_t;
106typedef int pthread_t;
107typedef int pthread_attr_t;
108typedef int pthread_mutex_t;
109typedef int pthread_mutexattr_t;
110typedef int pthread_cond_t;
111typedef int pthread_condattr_t;
112typedef int pthread_key_t;
113typedef int pthread_once_t;
114typedef int pthread_rwlock_t;
115typedef int pthread_rwlockattr_t;
116typedef int pthread_spinlock_t;
117typedef int pthread_barrier_t;
118typedef int pthread_barrierattr_t;
119typedef int jmp_buf;
120typedef int rlim_t;
121typedef int sa_family_t;
122typedef int sigjmp_buf;
123typedef int stack_t;
124typedef int siginfo_t;
125typedef int z_stream;
126
127
128typedef int int8_t;
129typedef int uint8_t;
130typedef int int16_t;
131typedef int uint16_t;
132typedef int int32_t;
133typedef int uint32_t;
134typedef int int64_t;
135typedef int uint64_t;
136
137
138typedef int int_least8_t;
139typedef int uint_least8_t;
140typedef int int_least16_t;
141typedef int uint_least16_t;
142typedef int int_least32_t;
143typedef int uint_least32_t;
144typedef int int_least64_t;
145typedef int uint_least64_t;
146
147
148typedef int int_fast8_t;
149typedef int uint_fast8_t;
150typedef int int_fast16_t;
151typedef int uint_fast16_t;
152typedef int int_fast32_t;
153typedef int uint_fast32_t;
154typedef int int_fast64_t;
155typedef int uint_fast64_t;
156
157
158typedef int intptr_t;
159typedef int uintptr_t;
160
161
162typedef int intmax_t;
163typedef int uintmax_t;
164
165
166typedef _Bool bool;
167
168
169typedef void* MirEGLNativeWindowType;
170typedef void* MirEGLNativeDisplayType;
171typedef struct MirConnection MirConnection;
172typedef struct MirSurface MirSurface;
173typedef struct MirSurfaceSpec MirSurfaceSpec;
174typedef struct MirScreencast MirScreencast;
175typedef struct MirPromptSession MirPromptSession;
176typedef struct MirBufferStream MirBufferStream;
177typedef struct MirPersistentId MirPersistentId;
178typedef struct MirBlob MirBlob;
179typedef struct MirDisplayConfig MirDisplayConfig;
180
181
182typedef struct xcb_connection_t xcb_connection_t;
183typedef uint32_t xcb_window_t;
184typedef uint32_t xcb_visualid_t;
185# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/stdlib.h" 2
186# 28 "tcc.h" 2
187# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/stdio.h" 1
188# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_defines.h" 1
189# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/stdio.h" 2
190# 29 "tcc.h" 2
191# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/stdarg.h" 1
192# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_defines.h" 1
193# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/stdarg.h" 2
194# 30 "tcc.h" 2
195# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/string.h" 1
196# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_defines.h" 1
197# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/string.h" 2
198# 31 "tcc.h" 2
199# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/errno.h" 1
200# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_defines.h" 1
201# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/errno.h" 2
202# 32 "tcc.h" 2
203# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/math.h" 1
204# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_defines.h" 1
205# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/math.h" 2
206# 33 "tcc.h" 2
207# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/fcntl.h" 1
208# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_defines.h" 1
209# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/fcntl.h" 2
210# 34 "tcc.h" 2
211# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/setjmp.h" 1
212# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_defines.h" 1
213# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/setjmp.h" 2
214# 35 "tcc.h" 2
215# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/time.h" 1
216# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_defines.h" 1
217# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/time.h" 2
218# 36 "tcc.h" 2
219
220
221# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/unistd.h" 1
222# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_defines.h" 1
223# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/unistd.h" 2
224# 39 "tcc.h" 2
225# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/sys/time.h" 1
226# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_defines.h" 1
227# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/sys/time.h" 2
228# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_typedefs.h" 1
229# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/sys/time.h" 2
230# 40 "tcc.h" 2
231
232# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/dlfcn.h" 1
233# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_defines.h" 1
234# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/dlfcn.h" 2
235# 42 "tcc.h" 2
236
237
238extern float strtof (const char *__nptr, char **__endptr);
239extern long double strtold (const char *__nptr, char **__endptr);
240# 283 "tcc.h"
241# 1 "libtcc.h" 1
242# 12 "libtcc.h"
243struct TCCState;
244
245typedef struct TCCState TCCState;
246
247
248 TCCState *tcc_new(void);
249
250
251 void tcc_delete(TCCState *s);
252
253
254 void tcc_set_lib_path(TCCState *s, const char *path);
255
256
257 void tcc_set_error_func(TCCState *s, void *error_opaque,
258    void (*error_func)(void *opaque, const char *msg));
259
260
261 void tcc_set_options(TCCState *s, const char *str);
262
263
264
265
266
267 int tcc_add_include_path(TCCState *s, const char *pathname);
268
269
270 int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
271
272
273 void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
274
275
276 void tcc_undefine_symbol(TCCState *s, const char *sym);
277
278
279
280
281
282 int tcc_add_file(TCCState *s, const char *filename);
283
284
285 int tcc_compile_string(TCCState *s, const char *buf);
286
287
288
289
290
291 int tcc_set_output_type(TCCState *s, int output_type);
292
293
294
295
296
297
298
299 int tcc_add_library_path(TCCState *s, const char *pathname);
300
301
302 int tcc_add_library(TCCState *s, const char *libraryname);
303
304
305 int tcc_add_symbol(TCCState *s, const char *name, const void *val);
306
307
308
309 int tcc_output_file(TCCState *s, const char *filename);
310
311
312
313 int tcc_run(TCCState *s, int argc, char **argv);
314
315
316 int tcc_relocate(TCCState *s1, void *ptr);
317# 94 "libtcc.h"
318 void *tcc_get_symbol(TCCState *s, const char *name);
319# 284 "tcc.h" 2
320# 1 "elf.h" 1
321# 23 "elf.h"
322# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/inttypes.h" 1
323# 1 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/_fake_defines.h" 1
324# 2 "/usr/local/google/home/eliben/eli/pycparser/utils/fake_libc_include/inttypes.h" 2
325# 24 "elf.h" 2
326# 41 "elf.h"
327typedef uint16_t Elf32_Half;
328typedef uint16_t Elf64_Half;
329
330
331typedef uint32_t Elf32_Word;
332typedef int32_t Elf32_Sword;
333typedef uint32_t Elf64_Word;
334typedef int32_t Elf64_Sword;
335
336
337typedef uint64_t Elf32_Xword;
338typedef int64_t Elf32_Sxword;
339typedef uint64_t Elf64_Xword;
340typedef int64_t Elf64_Sxword;
341
342
343typedef uint32_t Elf32_Addr;
344typedef uint64_t Elf64_Addr;
345
346
347typedef uint32_t Elf32_Off;
348typedef uint64_t Elf64_Off;
349
350
351typedef uint16_t Elf32_Section;
352typedef uint16_t Elf64_Section;
353
354
355typedef Elf32_Half Elf32_Versym;
356typedef Elf64_Half Elf64_Versym;
357
358
359
360
361
362
363typedef struct
364{
365  unsigned char e_ident[(16)];
366  Elf32_Half e_type;
367  Elf32_Half e_machine;
368  Elf32_Word e_version;
369  Elf32_Addr e_entry;
370  Elf32_Off e_phoff;
371  Elf32_Off e_shoff;
372  Elf32_Word e_flags;
373  Elf32_Half e_ehsize;
374  Elf32_Half e_phentsize;
375  Elf32_Half e_phnum;
376  Elf32_Half e_shentsize;
377  Elf32_Half e_shnum;
378  Elf32_Half e_shstrndx;
379} Elf32_Ehdr;
380
381typedef struct
382{
383  unsigned char e_ident[(16)];
384  Elf64_Half e_type;
385  Elf64_Half e_machine;
386  Elf64_Word e_version;
387  Elf64_Addr e_entry;
388  Elf64_Off e_phoff;
389  Elf64_Off e_shoff;
390  Elf64_Word e_flags;
391  Elf64_Half e_ehsize;
392  Elf64_Half e_phentsize;
393  Elf64_Half e_phnum;
394  Elf64_Half e_shentsize;
395  Elf64_Half e_shnum;
396  Elf64_Half e_shstrndx;
397} Elf64_Ehdr;
398# 282 "elf.h"
399typedef struct
400{
401  Elf32_Word sh_name;
402  Elf32_Word sh_type;
403  Elf32_Word sh_flags;
404  Elf32_Addr sh_addr;
405  Elf32_Off sh_offset;
406  Elf32_Word sh_size;
407  Elf32_Word sh_link;
408  Elf32_Word sh_info;
409  Elf32_Word sh_addralign;
410  Elf32_Word sh_entsize;
411} Elf32_Shdr;
412
413typedef struct
414{
415  Elf64_Word sh_name;
416  Elf64_Word sh_type;
417  Elf64_Xword sh_flags;
418  Elf64_Addr sh_addr;
419  Elf64_Off sh_offset;
420  Elf64_Xword sh_size;
421  Elf64_Word sh_link;
422  Elf64_Word sh_info;
423  Elf64_Xword sh_addralign;
424  Elf64_Xword sh_entsize;
425} Elf64_Shdr;
426# 392 "elf.h"
427typedef struct
428{
429  Elf32_Word st_name;
430  Elf32_Addr st_value;
431  Elf32_Word st_size;
432  unsigned char st_info;
433  unsigned char st_other;
434  Elf32_Section st_shndx;
435} Elf32_Sym;
436
437typedef struct
438{
439  Elf64_Word st_name;
440  unsigned char st_info;
441  unsigned char st_other;
442  Elf64_Section st_shndx;
443  Elf64_Addr st_value;
444  Elf64_Xword st_size;
445} Elf64_Sym;
446
447
448
449
450typedef struct
451{
452  Elf32_Half si_boundto;
453  Elf32_Half si_flags;
454} Elf32_Syminfo;
455
456typedef struct
457{
458  Elf64_Half si_boundto;
459  Elf64_Half si_flags;
460} Elf64_Syminfo;
461# 507 "elf.h"
462typedef struct
463{
464  Elf32_Addr r_offset;
465  Elf32_Word r_info;
466} Elf32_Rel;
467
468
469
470
471
472
473typedef struct
474{
475  Elf64_Addr r_offset;
476  Elf64_Xword r_info;
477} Elf64_Rel;
478
479
480
481typedef struct
482{
483  Elf32_Addr r_offset;
484  Elf32_Word r_info;
485  Elf32_Sword r_addend;
486} Elf32_Rela;
487
488typedef struct
489{
490  Elf64_Addr r_offset;
491  Elf64_Xword r_info;
492  Elf64_Sxword r_addend;
493} Elf64_Rela;
494# 552 "elf.h"
495typedef struct
496{
497  Elf32_Word p_type;
498  Elf32_Off p_offset;
499  Elf32_Addr p_vaddr;
500  Elf32_Addr p_paddr;
501  Elf32_Word p_filesz;
502  Elf32_Word p_memsz;
503  Elf32_Word p_flags;
504  Elf32_Word p_align;
505} Elf32_Phdr;
506
507typedef struct
508{
509  Elf64_Word p_type;
510  Elf64_Word p_flags;
511  Elf64_Off p_offset;
512  Elf64_Addr p_vaddr;
513  Elf64_Addr p_paddr;
514  Elf64_Xword p_filesz;
515  Elf64_Xword p_memsz;
516  Elf64_Xword p_align;
517} Elf64_Phdr;
518# 658 "elf.h"
519typedef struct
520{
521  Elf32_Sword d_tag;
522  union
523    {
524      Elf32_Word d_val;
525      Elf32_Addr d_ptr;
526    } d_un;
527} Elf32_Dyn;
528
529typedef struct
530{
531  Elf64_Sxword d_tag;
532  union
533    {
534      Elf64_Xword d_val;
535      Elf64_Addr d_ptr;
536    } d_un;
537} Elf64_Dyn;
538# 834 "elf.h"
539typedef struct
540{
541  Elf32_Half vd_version;
542  Elf32_Half vd_flags;
543  Elf32_Half vd_ndx;
544  Elf32_Half vd_cnt;
545  Elf32_Word vd_hash;
546  Elf32_Word vd_aux;
547  Elf32_Word vd_next;
548
549} Elf32_Verdef;
550
551typedef struct
552{
553  Elf64_Half vd_version;
554  Elf64_Half vd_flags;
555  Elf64_Half vd_ndx;
556  Elf64_Half vd_cnt;
557  Elf64_Word vd_hash;
558  Elf64_Word vd_aux;
559  Elf64_Word vd_next;
560
561} Elf64_Verdef;
562# 876 "elf.h"
563typedef struct
564{
565  Elf32_Word vda_name;
566  Elf32_Word vda_next;
567
568} Elf32_Verdaux;
569
570typedef struct
571{
572  Elf64_Word vda_name;
573  Elf64_Word vda_next;
574
575} Elf64_Verdaux;
576
577
578
579
580typedef struct
581{
582  Elf32_Half vn_version;
583  Elf32_Half vn_cnt;
584  Elf32_Word vn_file;
585
586  Elf32_Word vn_aux;
587  Elf32_Word vn_next;
588
589} Elf32_Verneed;
590
591typedef struct
592{
593  Elf64_Half vn_version;
594  Elf64_Half vn_cnt;
595  Elf64_Word vn_file;
596
597  Elf64_Word vn_aux;
598  Elf64_Word vn_next;
599
600} Elf64_Verneed;
601# 923 "elf.h"
602typedef struct
603{
604  Elf32_Word vna_hash;
605  Elf32_Half vna_flags;
606  Elf32_Half vna_other;
607  Elf32_Word vna_name;
608  Elf32_Word vna_next;
609
610} Elf32_Vernaux;
611
612typedef struct
613{
614  Elf64_Word vna_hash;
615  Elf64_Half vna_flags;
616  Elf64_Half vna_other;
617  Elf64_Word vna_name;
618  Elf64_Word vna_next;
619
620} Elf64_Vernaux;
621# 957 "elf.h"
622typedef struct
623{
624  uint32_t a_type;
625  union
626    {
627      uint32_t a_val;
628
629
630
631    } a_un;
632} Elf32_auxv_t;
633
634typedef struct
635{
636  uint64_t a_type;
637  union
638    {
639      uint64_t a_val;
640
641
642
643    } a_un;
644} Elf64_auxv_t;
645# 1041 "elf.h"
646typedef struct
647{
648  Elf32_Word n_namesz;
649  Elf32_Word n_descsz;
650  Elf32_Word n_type;
651} Elf32_Nhdr;
652
653typedef struct
654{
655  Elf64_Word n_namesz;
656  Elf64_Word n_descsz;
657  Elf64_Word n_type;
658} Elf64_Nhdr;
659# 1105 "elf.h"
660typedef struct
661{
662  Elf32_Xword m_value;
663  Elf32_Word m_info;
664  Elf32_Word m_poffset;
665  Elf32_Half m_repeat;
666  Elf32_Half m_stride;
667} Elf32_Move;
668
669typedef struct
670{
671  Elf64_Xword m_value;
672  Elf64_Xword m_info;
673  Elf64_Xword m_poffset;
674  Elf64_Half m_repeat;
675  Elf64_Half m_stride;
676} Elf64_Move;
677# 1489 "elf.h"
678typedef union
679{
680  struct
681    {
682      Elf32_Word gt_current_g_value;
683      Elf32_Word gt_unused;
684    } gt_header;
685  struct
686    {
687      Elf32_Word gt_g_value;
688      Elf32_Word gt_bytes;
689    } gt_entry;
690} Elf32_gptab;
691
692
693
694typedef struct
695{
696  Elf32_Word ri_gprmask;
697  Elf32_Word ri_cprmask[4];
698  Elf32_Sword ri_gp_value;
699} Elf32_RegInfo;
700
701
702
703typedef struct
704{
705  unsigned char kind;
706
707  unsigned char size;
708  Elf32_Section section;
709
710  Elf32_Word info;
711} Elf_Options;
712# 1565 "elf.h"
713typedef struct
714{
715  Elf32_Word hwp_flags1;
716  Elf32_Word hwp_flags2;
717} Elf_Options_Hw;
718# 1726 "elf.h"
719typedef struct
720{
721  Elf32_Word l_name;
722  Elf32_Word l_time_stamp;
723  Elf32_Word l_checksum;
724  Elf32_Word l_version;
725  Elf32_Word l_flags;
726} Elf32_Lib;
727
728typedef struct
729{
730  Elf64_Word l_name;
731  Elf64_Word l_time_stamp;
732  Elf64_Word l_checksum;
733  Elf64_Word l_version;
734  Elf64_Word l_flags;
735} Elf64_Lib;
736# 1757 "elf.h"
737typedef Elf32_Addr Elf32_Conflict;
738# 285 "tcc.h" 2
739# 1 "stab.h" 1
740# 9 "stab.h"
741enum __stab_debug_code
742{
743# 1 "stab.def" 1
744# 24 "stab.def"
745N_GSYM=0x20,
746
747
748
749N_FNAME=0x22,
750
751
752
753
754N_FUN=0x24,
755
756
757
758N_STSYM=0x26,
759
760
761N_LCSYM=0x28,
762
763
764
765N_MAIN=0x2a,
766
767
768
769N_PC=0x30,
770
771
772N_NSYMS=0x32,
773
774
775N_NOMAP=0x34,
776
777
778
779N_OBJ=0x38,
780
781
782
783
784N_OPT=0x3c,
785
786
787N_RSYM=0x40,
788
789
790N_M2C=0x42,
791
792
793
794N_SLINE=0x44,
795
796
797N_DSLINE=0x46,
798
799
800N_BSLINE=0x48,
801
802
803
804
805N_BROWS=0x48,
806
807
808
809
810
811N_DEFD=0x4a,
812
813
814
815
816N_EHDECL=0x50,
817
818N_MOD2=0x50,
819
820
821
822
823
824
825N_CATCH=0x54,
826
827
828N_SSYM=0x60,
829
830
831
832N_SO=0x64,
833
834
835
836N_LSYM=0x80,
837
838
839
840
841N_BINCL=0x82,
842
843
844
845N_SOL=0x84,
846
847
848
849N_PSYM=0xa0,
850
851
852
853
854
855N_EINCL=0xa2,
856
857
858N_ENTRY=0xa4,
859
860
861
862
863
864N_LBRAC=0xc0,
865
866
867
868
869
870N_EXCL=0xc2,
871
872
873N_SCOPE=0xc4,
874
875
876
877N_RBRAC=0xe0,
878
879
880N_BCOMM=0xe2,
881
882
883
884N_ECOMM=0xe4,
885
886
887
888N_ECOML=0xe8,
889
890
891
892
893N_NBTEXT=0xF0,
894N_NBDATA=0xF2,
895N_NBBSS=0xF4,
896N_NBSTS=0xF6,
897N_NBLCS=0xF8,
898
899
900
901N_LENG=0xfe,
902# 12 "stab.h" 2
903LAST_UNUSED_STAB_CODE
904};
905# 286 "tcc.h" 2
906# 320 "tcc.h"
907# 1 "x86_64-gen.c" 1
908# 57 "x86_64-gen.c"
909enum {
910    TREG_RAX = 0,
911    TREG_RCX = 1,
912    TREG_RDX = 2,
913    TREG_RSP = 4,
914    TREG_RSI = 6,
915    TREG_RDI = 7,
916
917    TREG_R8 = 8,
918    TREG_R9 = 9,
919    TREG_R10 = 10,
920    TREG_R11 = 11,
921
922    TREG_XMM0 = 16,
923    TREG_XMM1 = 17,
924    TREG_XMM2 = 18,
925    TREG_XMM3 = 19,
926    TREG_XMM4 = 20,
927    TREG_XMM5 = 21,
928    TREG_XMM6 = 22,
929    TREG_XMM7 = 23,
930
931    TREG_ST0 = 24,
932
933    TREG_MEM = 0x20
934};
935# 321 "tcc.h" 2
936# 1 "x86_64-link.c" 1
937# 322 "tcc.h" 2
938# 381 "tcc.h"
939typedef struct TokenSym {
940    struct TokenSym *hash_next;
941    struct Sym *sym_define;
942    struct Sym *sym_label;
943    struct Sym *sym_struct;
944    struct Sym *sym_identifier;
945    int tok;
946    int len;
947    char str[1];
948} TokenSym;
949
950
951
952
953typedef int nwchar_t;
954
955
956typedef struct CString {
957    int size;
958    void *data;
959    int size_allocated;
960} CString;
961
962
963typedef struct CType {
964    int t;
965    struct Sym *ref;
966} CType;
967
968
969typedef union CValue {
970    long double ld;
971    double d;
972    float f;
973    uint64_t i;
974    struct {
975        int size;
976        const void *data;
977    } str;
978    int tab[16/4];
979} CValue;
980
981
982typedef struct SValue {
983    CType type;
984    unsigned short r;
985    unsigned short r2;
986
987    CValue c;
988    struct Sym *sym;
989
990} SValue;
991
992
993struct SymAttr {
994    unsigned short
995    aligned : 5,
996    packed : 1,
997    weak : 1,
998    visibility : 2,
999    dllexport : 1,
1000    dllimport : 1,
1001    unused : 5;
1002};
1003
1004
1005struct FuncAttr {
1006    unsigned
1007    func_call : 3,
1008    func_type : 2,
1009    func_args : 8;
1010};
1011
1012
1013typedef struct AttributeDef {
1014    struct SymAttr a;
1015    struct FuncAttr f;
1016    struct Section *section;
1017    int alias_target;
1018    int asm_label;
1019    char attr_mode;
1020} AttributeDef;
1021
1022
1023typedef struct Sym {
1024    int v;
1025    unsigned short r;
1026    struct SymAttr a;
1027    union {
1028        struct {
1029            int c;
1030            union {
1031                int sym_scope;
1032                int jnext;
1033                struct FuncAttr f;
1034                int auxtype;
1035            };
1036        };
1037        long long enum_val;
1038        int *d;
1039    };
1040    CType type;
1041    union {
1042        struct Sym *next;
1043        int asm_label;
1044    };
1045    struct Sym *prev;
1046    struct Sym *prev_tok;
1047} Sym;
1048
1049
1050typedef struct Section {
1051    unsigned long data_offset;
1052    unsigned char *data;
1053    unsigned long data_allocated;
1054    int sh_name;
1055    int sh_num;
1056    int sh_type;
1057    int sh_flags;
1058    int sh_info;
1059    int sh_addralign;
1060    int sh_entsize;
1061    unsigned long sh_size;
1062    Elf64_Addr sh_addr;
1063    unsigned long sh_offset;
1064    int nb_hashed_syms;
1065    struct Section *link;
1066    struct Section *reloc;
1067    struct Section *hash;
1068    struct Section *prev;
1069    char name[1];
1070} Section;
1071
1072typedef struct DLLReference {
1073    int level;
1074    void *handle;
1075    char name[1];
1076} DLLReference;
1077# 554 "tcc.h"
1078typedef struct BufferedFile {
1079    uint8_t *buf_ptr;
1080    uint8_t *buf_end;
1081    int fd;
1082    struct BufferedFile *prev;
1083    int line_num;
1084    int line_ref;
1085    int ifndef_macro;
1086    int ifndef_macro_saved;
1087    int *ifdef_stack_ptr;
1088    int include_next_index;
1089    char filename[1024];
1090    char *true_filename;
1091    unsigned char unget[4];
1092    unsigned char buffer[1];
1093} BufferedFile;
1094
1095
1096
1097
1098
1099typedef struct TokenString {
1100    int *str;
1101    int len;
1102    int lastlen;
1103    int allocated_len;
1104    int last_line_num;
1105    int save_line_num;
1106
1107    struct TokenString *prev;
1108    const int *prev_ptr;
1109    char alloc;
1110} TokenString;
1111
1112
1113typedef struct InlineFunc {
1114    TokenString *func_str;
1115    Sym *sym;
1116    char filename[1];
1117} InlineFunc;
1118
1119
1120
1121typedef struct CachedInclude {
1122    int ifndef_macro;
1123    int once;
1124    int hash_next;
1125    char filename[1];
1126} CachedInclude;
1127
1128
1129
1130
1131typedef struct ExprValue {
1132    uint64_t v;
1133    Sym *sym;
1134    int pcrel;
1135} ExprValue;
1136
1137
1138typedef struct ASMOperand {
1139    int id;
1140    char *constraint;
1141    char asm_str[16];
1142    SValue *vt;
1143    int ref_index;
1144    int input_index;
1145    int priority;
1146    int reg;
1147    int is_llong;
1148    int is_memory;
1149    int is_rw;
1150} ASMOperand;
1151
1152
1153
1154struct sym_attr {
1155    unsigned got_offset;
1156    unsigned plt_offset;
1157    int plt_sym;
1158    int dyn_index;
1159
1160
1161
1162};
1163
1164struct TCCState {
1165
1166    int verbose;
1167    int nostdinc;
1168    int nostdlib;
1169    int nocommon;
1170    int static_link;
1171    int rdynamic;
1172    int symbolic;
1173    int alacarte_link;
1174
1175    char *tcc_lib_path;
1176    char *soname;
1177    char *rpath;
1178    int enable_new_dtags;
1179
1180
1181    int output_type;
1182
1183    int output_format;
1184
1185
1186    int char_is_unsigned;
1187    int leading_underscore;
1188    int ms_extensions;
1189    int dollars_in_identifiers;
1190    int ms_bitfields;
1191
1192
1193    int warn_write_strings;
1194    int warn_unsupported;
1195    int warn_error;
1196    int warn_none;
1197    int warn_implicit_function_declaration;
1198    int warn_gcc_compat;
1199
1200
1201    int do_debug;
1202
1203
1204    int do_bounds_check;
1205
1206
1207
1208
1209    int run_test;
1210
1211    Elf64_Addr text_addr;
1212    int has_text_addr;
1213
1214    unsigned section_align;
1215
1216    char *init_symbol;
1217    char *fini_symbol;
1218
1219
1220
1221
1222
1223    int nosse;
1224
1225
1226
1227    DLLReference **loaded_dlls;
1228    int nb_loaded_dlls;
1229
1230
1231    char **include_paths;
1232    int nb_include_paths;
1233
1234    char **sysinclude_paths;
1235    int nb_sysinclude_paths;
1236
1237
1238    char **library_paths;
1239    int nb_library_paths;
1240
1241
1242    char **crt_paths;
1243    int nb_crt_paths;
1244
1245
1246    char **cmd_include_files;
1247    int nb_cmd_include_files;
1248
1249
1250    void *error_opaque;
1251    void (*error_func)(void *opaque, const char *msg);
1252    int error_set_jmp_enabled;
1253    jmp_buf error_jmp_buf;
1254    int nb_errors;
1255
1256
1257    FILE *ppfp;
1258    enum {
1259 LINE_MACRO_OUTPUT_FORMAT_GCC,
1260 LINE_MACRO_OUTPUT_FORMAT_NONE,
1261 LINE_MACRO_OUTPUT_FORMAT_STD,
1262    LINE_MACRO_OUTPUT_FORMAT_P10 = 11
1263    } Pflag;
1264    char dflag;
1265
1266
1267    char **target_deps;
1268    int nb_target_deps;
1269
1270
1271    BufferedFile *include_stack[32];
1272    BufferedFile **include_stack_ptr;
1273
1274    int ifdef_stack[64];
1275    int *ifdef_stack_ptr;
1276
1277
1278    int cached_includes_hash[32];
1279    CachedInclude **cached_includes;
1280    int nb_cached_includes;
1281
1282
1283    int pack_stack[8];
1284    int *pack_stack_ptr;
1285    char **pragma_libs;
1286    int nb_pragma_libs;
1287
1288
1289
1290    struct InlineFunc **inline_fns;
1291    int nb_inline_fns;
1292
1293
1294    Section **sections;
1295    int nb_sections;
1296
1297    Section **priv_sections;
1298    int nb_priv_sections;
1299
1300
1301    Section *got;
1302    Section *plt;
1303
1304
1305    Section *dynsymtab_section;
1306
1307    Section *dynsym;
1308
1309    Section *symtab;
1310
1311    struct sym_attr *sym_attrs;
1312    int nb_sym_attrs;
1313# 805 "tcc.h"
1314    const char *runtime_main;
1315    void **runtime_mem;
1316    int nb_runtime_mem;
1317
1318
1319
1320    struct filespec **files;
1321    int nb_files;
1322    int nb_libraries;
1323    int filetype;
1324    char *outfile;
1325    int option_r;
1326    int do_bench;
1327    int gen_deps;
1328    char *deps_outfile;
1329    int option_pthread;
1330    int argc;
1331    char **argv;
1332};
1333
1334struct filespec {
1335    char type;
1336    char alacarte;
1337    char name[1];
1338};
1339# 1070 "tcc.h"
1340enum tcc_token {
1341    TOK_LAST = 256 - 1
1342
1343# 1 "tcctok.h" 1
1344
1345     ,TOK_INT
1346     ,TOK_VOID
1347     ,TOK_CHAR
1348     ,TOK_IF
1349     ,TOK_ELSE
1350     ,TOK_WHILE
1351     ,TOK_BREAK
1352     ,TOK_RETURN
1353     ,TOK_FOR
1354     ,TOK_EXTERN
1355     ,TOK_STATIC
1356     ,TOK_UNSIGNED
1357     ,TOK_GOTO
1358     ,TOK_DO
1359     ,TOK_CONTINUE
1360     ,TOK_SWITCH
1361     ,TOK_CASE
1362
1363     ,TOK_CONST1
1364     ,TOK_CONST2
1365     ,TOK_CONST3
1366     ,TOK_VOLATILE1
1367     ,TOK_VOLATILE2
1368     ,TOK_VOLATILE3
1369     ,TOK_LONG
1370     ,TOK_REGISTER
1371     ,TOK_SIGNED1
1372     ,TOK_SIGNED2
1373     ,TOK_SIGNED3
1374     ,TOK_AUTO
1375     ,TOK_INLINE1
1376     ,TOK_INLINE2
1377     ,TOK_INLINE3
1378     ,TOK_RESTRICT1
1379     ,TOK_RESTRICT2
1380     ,TOK_RESTRICT3
1381     ,TOK_EXTENSION
1382
1383     ,TOK_GENERIC
1384
1385     ,TOK_FLOAT
1386     ,TOK_DOUBLE
1387     ,TOK_BOOL
1388     ,TOK_SHORT
1389     ,TOK_STRUCT
1390     ,TOK_UNION
1391     ,TOK_TYPEDEF
1392     ,TOK_DEFAULT
1393     ,TOK_ENUM
1394     ,TOK_SIZEOF
1395     ,TOK_ATTRIBUTE1
1396     ,TOK_ATTRIBUTE2
1397     ,TOK_ALIGNOF1
1398     ,TOK_ALIGNOF2
1399     ,TOK_TYPEOF1
1400     ,TOK_TYPEOF2
1401     ,TOK_TYPEOF3
1402     ,TOK_LABEL
1403     ,TOK_ASM1
1404     ,TOK_ASM2
1405     ,TOK_ASM3
1406# 71 "tcctok.h"
1407     ,TOK_DEFINE
1408     ,TOK_INCLUDE
1409     ,TOK_INCLUDE_NEXT
1410     ,TOK_IFDEF
1411     ,TOK_IFNDEF
1412     ,TOK_ELIF
1413     ,TOK_ENDIF
1414     ,TOK_DEFINED
1415     ,TOK_UNDEF
1416     ,TOK_ERROR
1417     ,TOK_WARNING
1418     ,TOK_LINE
1419     ,TOK_PRAGMA
1420     ,TOK___LINE__
1421     ,TOK___FILE__
1422     ,TOK___DATE__
1423     ,TOK___TIME__
1424     ,TOK___FUNCTION__
1425     ,TOK___VA_ARGS__
1426     ,TOK___COUNTER__
1427
1428
1429     ,TOK___FUNC__
1430
1431
1432     ,TOK___NAN__
1433     ,TOK___SNAN__
1434     ,TOK___INF__
1435
1436
1437
1438     ,TOK_SECTION1
1439     ,TOK_SECTION2
1440     ,TOK_ALIGNED1
1441     ,TOK_ALIGNED2
1442     ,TOK_PACKED1
1443     ,TOK_PACKED2
1444     ,TOK_WEAK1
1445     ,TOK_WEAK2
1446     ,TOK_ALIAS1
1447     ,TOK_ALIAS2
1448     ,TOK_UNUSED1
1449     ,TOK_UNUSED2
1450     ,TOK_CDECL1
1451     ,TOK_CDECL2
1452     ,TOK_CDECL3
1453     ,TOK_STDCALL1
1454     ,TOK_STDCALL2
1455     ,TOK_STDCALL3
1456     ,TOK_FASTCALL1
1457     ,TOK_FASTCALL2
1458     ,TOK_FASTCALL3
1459     ,TOK_REGPARM1
1460     ,TOK_REGPARM2
1461
1462     ,TOK_MODE
1463     ,TOK_MODE_QI
1464     ,TOK_MODE_DI
1465     ,TOK_MODE_HI
1466     ,TOK_MODE_SI
1467     ,TOK_MODE_word
1468
1469     ,TOK_DLLEXPORT
1470     ,TOK_DLLIMPORT
1471     ,TOK_NORETURN1
1472     ,TOK_NORETURN2
1473     ,TOK_VISIBILITY1
1474     ,TOK_VISIBILITY2
1475
1476     ,TOK_builtin_types_compatible_p
1477     ,TOK_builtin_choose_expr
1478     ,TOK_builtin_constant_p
1479     ,TOK_builtin_frame_address
1480     ,TOK_builtin_return_address
1481     ,TOK_builtin_expect
1482
1483
1484
1485
1486     ,TOK_builtin_va_arg_types
1487
1488
1489
1490
1491
1492
1493     ,TOK_pack
1494
1495
1496
1497
1498
1499     ,TOK_comment
1500     ,TOK_lib
1501     ,TOK_push_macro
1502     ,TOK_pop_macro
1503     ,TOK_once
1504     ,TOK_option
1505
1506
1507
1508     ,TOK_memcpy
1509     ,TOK_memmove
1510     ,TOK_memset
1511     ,TOK___divdi3
1512     ,TOK___moddi3
1513     ,TOK___udivdi3
1514     ,TOK___umoddi3
1515     ,TOK___ashrdi3
1516     ,TOK___lshrdi3
1517     ,TOK___ashldi3
1518     ,TOK___floatundisf
1519     ,TOK___floatundidf
1520
1521     ,TOK___floatundixf
1522     ,TOK___fixunsxfdi
1523
1524     ,TOK___fixunssfdi
1525     ,TOK___fixunsdfdi
1526# 251 "tcctok.h"
1527     ,TOK_alloca
1528# 285 "tcctok.h"
1529     ,TOK___bound_ptr_add
1530     ,TOK___bound_ptr_indir1
1531     ,TOK___bound_ptr_indir2
1532     ,TOK___bound_ptr_indir4
1533     ,TOK___bound_ptr_indir8
1534     ,TOK___bound_ptr_indir12
1535     ,TOK___bound_ptr_indir16
1536     ,TOK___bound_main_arg
1537     ,TOK___bound_local_new
1538     ,TOK___bound_local_delete
1539
1540
1541
1542
1543
1544
1545
1546     ,TOK_strlen
1547     ,TOK_strcpy
1548
1549
1550
1551 ,TOK_ASMDIR_byte
1552 ,TOK_ASMDIR_word
1553 ,TOK_ASMDIR_align
1554 ,TOK_ASMDIR_balign
1555 ,TOK_ASMDIR_p2align
1556 ,TOK_ASMDIR_set
1557 ,TOK_ASMDIR_skip
1558 ,TOK_ASMDIR_space
1559 ,TOK_ASMDIR_string
1560 ,TOK_ASMDIR_asciz
1561 ,TOK_ASMDIR_ascii
1562 ,TOK_ASMDIR_file
1563 ,TOK_ASMDIR_globl
1564 ,TOK_ASMDIR_global
1565 ,TOK_ASMDIR_weak
1566 ,TOK_ASMDIR_hidden
1567 ,TOK_ASMDIR_ident
1568 ,TOK_ASMDIR_size
1569 ,TOK_ASMDIR_type
1570 ,TOK_ASMDIR_text
1571 ,TOK_ASMDIR_data
1572 ,TOK_ASMDIR_bss
1573 ,TOK_ASMDIR_previous
1574 ,TOK_ASMDIR_pushsection
1575 ,TOK_ASMDIR_popsection
1576 ,TOK_ASMDIR_fill
1577 ,TOK_ASMDIR_rept
1578 ,TOK_ASMDIR_endr
1579 ,TOK_ASMDIR_org
1580 ,TOK_ASMDIR_quad
1581
1582
1583
1584
1585 ,TOK_ASMDIR_code64
1586
1587 ,TOK_ASMDIR_short
1588 ,TOK_ASMDIR_long
1589 ,TOK_ASMDIR_int
1590 ,TOK_ASMDIR_section
1591
1592
1593# 1 "i386-tok.h" 1
1594
1595
1596
1597
1598 ,TOK_ASM_al
1599 ,TOK_ASM_cl
1600 ,TOK_ASM_dl
1601 ,TOK_ASM_bl
1602 ,TOK_ASM_ah
1603 ,TOK_ASM_ch
1604 ,TOK_ASM_dh
1605 ,TOK_ASM_bh
1606 ,TOK_ASM_ax
1607 ,TOK_ASM_cx
1608 ,TOK_ASM_dx
1609 ,TOK_ASM_bx
1610 ,TOK_ASM_sp
1611 ,TOK_ASM_bp
1612 ,TOK_ASM_si
1613 ,TOK_ASM_di
1614 ,TOK_ASM_eax
1615 ,TOK_ASM_ecx
1616 ,TOK_ASM_edx
1617 ,TOK_ASM_ebx
1618 ,TOK_ASM_esp
1619 ,TOK_ASM_ebp
1620 ,TOK_ASM_esi
1621 ,TOK_ASM_edi
1622
1623 ,TOK_ASM_rax
1624 ,TOK_ASM_rcx
1625 ,TOK_ASM_rdx
1626 ,TOK_ASM_rbx
1627 ,TOK_ASM_rsp
1628 ,TOK_ASM_rbp
1629 ,TOK_ASM_rsi
1630 ,TOK_ASM_rdi
1631
1632 ,TOK_ASM_mm0
1633 ,TOK_ASM_mm1
1634 ,TOK_ASM_mm2
1635 ,TOK_ASM_mm3
1636 ,TOK_ASM_mm4
1637 ,TOK_ASM_mm5
1638 ,TOK_ASM_mm6
1639 ,TOK_ASM_mm7
1640 ,TOK_ASM_xmm0
1641 ,TOK_ASM_xmm1
1642 ,TOK_ASM_xmm2
1643 ,TOK_ASM_xmm3
1644 ,TOK_ASM_xmm4
1645 ,TOK_ASM_xmm5
1646 ,TOK_ASM_xmm6
1647 ,TOK_ASM_xmm7
1648 ,TOK_ASM_cr0
1649 ,TOK_ASM_cr1
1650 ,TOK_ASM_cr2
1651 ,TOK_ASM_cr3
1652 ,TOK_ASM_cr4
1653 ,TOK_ASM_cr5
1654 ,TOK_ASM_cr6
1655 ,TOK_ASM_cr7
1656 ,TOK_ASM_tr0
1657 ,TOK_ASM_tr1
1658 ,TOK_ASM_tr2
1659 ,TOK_ASM_tr3
1660 ,TOK_ASM_tr4
1661 ,TOK_ASM_tr5
1662 ,TOK_ASM_tr6
1663 ,TOK_ASM_tr7
1664 ,TOK_ASM_db0
1665 ,TOK_ASM_db1
1666 ,TOK_ASM_db2
1667 ,TOK_ASM_db3
1668 ,TOK_ASM_db4
1669 ,TOK_ASM_db5
1670 ,TOK_ASM_db6
1671 ,TOK_ASM_db7
1672 ,TOK_ASM_dr0
1673 ,TOK_ASM_dr1
1674 ,TOK_ASM_dr2
1675 ,TOK_ASM_dr3
1676 ,TOK_ASM_dr4
1677 ,TOK_ASM_dr5
1678 ,TOK_ASM_dr6
1679 ,TOK_ASM_dr7
1680 ,TOK_ASM_es
1681 ,TOK_ASM_cs
1682 ,TOK_ASM_ss
1683 ,TOK_ASM_ds
1684 ,TOK_ASM_fs
1685 ,TOK_ASM_gs
1686 ,TOK_ASM_st
1687 ,TOK_ASM_rip
1688
1689
1690
1691
1692 ,TOK_ASM_spl
1693 ,TOK_ASM_bpl
1694 ,TOK_ASM_sil
1695 ,TOK_ASM_dil
1696
1697
1698 ,TOK_ASM_movb ,TOK_ASM_movw ,TOK_ASM_movl ,TOK_ASM_movq ,TOK_ASM_mov
1699
1700 ,TOK_ASM_addb ,TOK_ASM_addw ,TOK_ASM_addl ,TOK_ASM_addq ,TOK_ASM_add
1701 ,TOK_ASM_orb ,TOK_ASM_orw ,TOK_ASM_orl ,TOK_ASM_orq ,TOK_ASM_or
1702 ,TOK_ASM_adcb ,TOK_ASM_adcw ,TOK_ASM_adcl ,TOK_ASM_adcq ,TOK_ASM_adc
1703 ,TOK_ASM_sbbb ,TOK_ASM_sbbw ,TOK_ASM_sbbl ,TOK_ASM_sbbq ,TOK_ASM_sbb
1704 ,TOK_ASM_andb ,TOK_ASM_andw ,TOK_ASM_andl ,TOK_ASM_andq ,TOK_ASM_and
1705 ,TOK_ASM_subb ,TOK_ASM_subw ,TOK_ASM_subl ,TOK_ASM_subq ,TOK_ASM_sub
1706 ,TOK_ASM_xorb ,TOK_ASM_xorw ,TOK_ASM_xorl ,TOK_ASM_xorq ,TOK_ASM_xor
1707 ,TOK_ASM_cmpb ,TOK_ASM_cmpw ,TOK_ASM_cmpl ,TOK_ASM_cmpq ,TOK_ASM_cmp
1708
1709
1710 ,TOK_ASM_incb ,TOK_ASM_incw ,TOK_ASM_incl ,TOK_ASM_incq ,TOK_ASM_inc
1711 ,TOK_ASM_decb ,TOK_ASM_decw ,TOK_ASM_decl ,TOK_ASM_decq ,TOK_ASM_dec
1712 ,TOK_ASM_notb ,TOK_ASM_notw ,TOK_ASM_notl ,TOK_ASM_notq ,TOK_ASM_not
1713 ,TOK_ASM_negb ,TOK_ASM_negw ,TOK_ASM_negl ,TOK_ASM_negq ,TOK_ASM_neg
1714 ,TOK_ASM_mulb ,TOK_ASM_mulw ,TOK_ASM_mull ,TOK_ASM_mulq ,TOK_ASM_mul
1715 ,TOK_ASM_imulb ,TOK_ASM_imulw ,TOK_ASM_imull ,TOK_ASM_imulq ,TOK_ASM_imul
1716 ,TOK_ASM_divb ,TOK_ASM_divw ,TOK_ASM_divl ,TOK_ASM_divq ,TOK_ASM_div
1717 ,TOK_ASM_idivb ,TOK_ASM_idivw ,TOK_ASM_idivl ,TOK_ASM_idivq ,TOK_ASM_idiv
1718
1719 ,TOK_ASM_xchgb ,TOK_ASM_xchgw ,TOK_ASM_xchgl ,TOK_ASM_xchgq ,TOK_ASM_xchg
1720 ,TOK_ASM_testb ,TOK_ASM_testw ,TOK_ASM_testl ,TOK_ASM_testq ,TOK_ASM_test
1721
1722
1723 ,TOK_ASM_rolb ,TOK_ASM_rolw ,TOK_ASM_roll ,TOK_ASM_rolq ,TOK_ASM_rol
1724 ,TOK_ASM_rorb ,TOK_ASM_rorw ,TOK_ASM_rorl ,TOK_ASM_rorq ,TOK_ASM_ror
1725 ,TOK_ASM_rclb ,TOK_ASM_rclw ,TOK_ASM_rcll ,TOK_ASM_rclq ,TOK_ASM_rcl
1726 ,TOK_ASM_rcrb ,TOK_ASM_rcrw ,TOK_ASM_rcrl ,TOK_ASM_rcrq ,TOK_ASM_rcr
1727 ,TOK_ASM_shlb ,TOK_ASM_shlw ,TOK_ASM_shll ,TOK_ASM_shlq ,TOK_ASM_shl
1728 ,TOK_ASM_shrb ,TOK_ASM_shrw ,TOK_ASM_shrl ,TOK_ASM_shrq ,TOK_ASM_shr
1729 ,TOK_ASM_sarb ,TOK_ASM_sarw ,TOK_ASM_sarl ,TOK_ASM_sarq ,TOK_ASM_sar
1730
1731 ,TOK_ASM_shldw ,TOK_ASM_shldl ,TOK_ASM_shldq ,TOK_ASM_shld
1732 ,TOK_ASM_shrdw ,TOK_ASM_shrdl ,TOK_ASM_shrdq ,TOK_ASM_shrd
1733
1734 ,TOK_ASM_pushw
1735 ,TOK_ASM_pushl
1736
1737 ,TOK_ASM_pushq
1738
1739 ,TOK_ASM_push
1740
1741 ,TOK_ASM_popw
1742 ,TOK_ASM_popl
1743
1744 ,TOK_ASM_popq
1745
1746 ,TOK_ASM_pop
1747
1748 ,TOK_ASM_inb ,TOK_ASM_inw ,TOK_ASM_inl ,TOK_ASM_in
1749 ,TOK_ASM_outb ,TOK_ASM_outw ,TOK_ASM_outl ,TOK_ASM_out
1750
1751 ,TOK_ASM_movzbw ,TOK_ASM_movzbl ,TOK_ASM_movzbq ,TOK_ASM_movzb
1752 ,TOK_ASM_movzwl
1753 ,TOK_ASM_movsbw
1754 ,TOK_ASM_movsbl
1755 ,TOK_ASM_movswl
1756
1757 ,TOK_ASM_movsbq
1758 ,TOK_ASM_movswq
1759 ,TOK_ASM_movzwq
1760 ,TOK_ASM_movslq
1761
1762
1763 ,TOK_ASM_leaw ,TOK_ASM_leal ,TOK_ASM_leaq ,TOK_ASM_lea
1764
1765 ,TOK_ASM_les
1766 ,TOK_ASM_lds
1767 ,TOK_ASM_lss
1768 ,TOK_ASM_lfs
1769 ,TOK_ASM_lgs
1770
1771 ,TOK_ASM_call
1772 ,TOK_ASM_jmp
1773 ,TOK_ASM_lcall
1774 ,TOK_ASM_ljmp
1775
1776 ,TOK_ASM_jo ,TOK_ASM_jno ,TOK_ASM_jb ,TOK_ASM_jc ,TOK_ASM_jnae ,TOK_ASM_jnb ,TOK_ASM_jnc ,TOK_ASM_jae ,TOK_ASM_je ,TOK_ASM_jz ,TOK_ASM_jne ,TOK_ASM_jnz ,TOK_ASM_jbe ,TOK_ASM_jna ,TOK_ASM_jnbe ,TOK_ASM_ja ,TOK_ASM_js ,TOK_ASM_jns ,TOK_ASM_jp ,TOK_ASM_jpe ,TOK_ASM_jnp ,TOK_ASM_jpo ,TOK_ASM_jl ,TOK_ASM_jnge ,TOK_ASM_jnl ,TOK_ASM_jge ,TOK_ASM_jle ,TOK_ASM_jng ,TOK_ASM_jnle ,TOK_ASM_jg
1777
1778 ,TOK_ASM_seto ,TOK_ASM_setno ,TOK_ASM_setb ,TOK_ASM_setc ,TOK_ASM_setnae ,TOK_ASM_setnb ,TOK_ASM_setnc ,TOK_ASM_setae ,TOK_ASM_sete ,TOK_ASM_setz ,TOK_ASM_setne ,TOK_ASM_setnz ,TOK_ASM_setbe ,TOK_ASM_setna ,TOK_ASM_setnbe ,TOK_ASM_seta ,TOK_ASM_sets ,TOK_ASM_setns ,TOK_ASM_setp ,TOK_ASM_setpe ,TOK_ASM_setnp ,TOK_ASM_setpo ,TOK_ASM_setl ,TOK_ASM_setnge ,TOK_ASM_setnl ,TOK_ASM_setge ,TOK_ASM_setle ,TOK_ASM_setng ,TOK_ASM_setnle ,TOK_ASM_setg
1779 ,TOK_ASM_setob ,TOK_ASM_setnob ,TOK_ASM_setbb ,TOK_ASM_setcb ,TOK_ASM_setnaeb ,TOK_ASM_setnbb ,TOK_ASM_setncb ,TOK_ASM_setaeb ,TOK_ASM_seteb ,TOK_ASM_setzb ,TOK_ASM_setneb ,TOK_ASM_setnzb ,TOK_ASM_setbeb ,TOK_ASM_setnab ,TOK_ASM_setnbeb ,TOK_ASM_setab ,TOK_ASM_setsb ,TOK_ASM_setnsb ,TOK_ASM_setpb ,TOK_ASM_setpeb ,TOK_ASM_setnpb ,TOK_ASM_setpob ,TOK_ASM_setlb ,TOK_ASM_setngeb ,TOK_ASM_setnlb ,TOK_ASM_setgeb ,TOK_ASM_setleb ,TOK_ASM_setngb ,TOK_ASM_setnleb ,TOK_ASM_setgb
1780 ,TOK_ASM_cmovo ,TOK_ASM_cmovno ,TOK_ASM_cmovb ,TOK_ASM_cmovc ,TOK_ASM_cmovnae ,TOK_ASM_cmovnb ,TOK_ASM_cmovnc ,TOK_ASM_cmovae ,TOK_ASM_cmove ,TOK_ASM_cmovz ,TOK_ASM_cmovne ,TOK_ASM_cmovnz ,TOK_ASM_cmovbe ,TOK_ASM_cmovna ,TOK_ASM_cmovnbe ,TOK_ASM_cmova ,TOK_ASM_cmovs ,TOK_ASM_cmovns ,TOK_ASM_cmovp ,TOK_ASM_cmovpe ,TOK_ASM_cmovnp ,TOK_ASM_cmovpo ,TOK_ASM_cmovl ,TOK_ASM_cmovnge ,TOK_ASM_cmovnl ,TOK_ASM_cmovge ,TOK_ASM_cmovle ,TOK_ASM_cmovng ,TOK_ASM_cmovnle ,TOK_ASM_cmovg
1781
1782 ,TOK_ASM_bsfw ,TOK_ASM_bsfl ,TOK_ASM_bsfq ,TOK_ASM_bsf
1783 ,TOK_ASM_bsrw ,TOK_ASM_bsrl ,TOK_ASM_bsrq ,TOK_ASM_bsr
1784 ,TOK_ASM_btw ,TOK_ASM_btl ,TOK_ASM_btq ,TOK_ASM_bt
1785 ,TOK_ASM_btsw ,TOK_ASM_btsl ,TOK_ASM_btsq ,TOK_ASM_bts
1786 ,TOK_ASM_btrw ,TOK_ASM_btrl ,TOK_ASM_btrq ,TOK_ASM_btr
1787 ,TOK_ASM_btcw ,TOK_ASM_btcl ,TOK_ASM_btcq ,TOK_ASM_btc
1788
1789 ,TOK_ASM_larw ,TOK_ASM_larl ,TOK_ASM_larq ,TOK_ASM_lar
1790 ,TOK_ASM_lslw ,TOK_ASM_lsll ,TOK_ASM_lslq ,TOK_ASM_lsl
1791
1792
1793 ,TOK_ASM_fadd ,TOK_ASM_faddp ,TOK_ASM_fadds ,TOK_ASM_fiaddl ,TOK_ASM_faddl ,TOK_ASM_fiadds
1794 ,TOK_ASM_fmul ,TOK_ASM_fmulp ,TOK_ASM_fmuls ,TOK_ASM_fimull ,TOK_ASM_fmull ,TOK_ASM_fimuls
1795
1796 ,TOK_ASM_fcom
1797 ,TOK_ASM_fcom_1
1798 ,TOK_ASM_fcoms ,TOK_ASM_ficoml ,TOK_ASM_fcoml ,TOK_ASM_ficoms
1799
1800 ,TOK_ASM_fcomp ,TOK_ASM_fcompp ,TOK_ASM_fcomps ,TOK_ASM_ficompl ,TOK_ASM_fcompl ,TOK_ASM_ficomps
1801 ,TOK_ASM_fsub ,TOK_ASM_fsubp ,TOK_ASM_fsubs ,TOK_ASM_fisubl ,TOK_ASM_fsubl ,TOK_ASM_fisubs
1802 ,TOK_ASM_fsubr ,TOK_ASM_fsubrp ,TOK_ASM_fsubrs ,TOK_ASM_fisubrl ,TOK_ASM_fsubrl ,TOK_ASM_fisubrs
1803 ,TOK_ASM_fdiv ,TOK_ASM_fdivp ,TOK_ASM_fdivs ,TOK_ASM_fidivl ,TOK_ASM_fdivl ,TOK_ASM_fidivs
1804 ,TOK_ASM_fdivr ,TOK_ASM_fdivrp ,TOK_ASM_fdivrs ,TOK_ASM_fidivrl ,TOK_ASM_fdivrl ,TOK_ASM_fidivrs
1805
1806 ,TOK_ASM_xaddb ,TOK_ASM_xaddw ,TOK_ASM_xaddl ,TOK_ASM_xaddq ,TOK_ASM_xadd
1807 ,TOK_ASM_cmpxchgb ,TOK_ASM_cmpxchgw ,TOK_ASM_cmpxchgl ,TOK_ASM_cmpxchgq ,TOK_ASM_cmpxchg
1808
1809
1810 ,TOK_ASM_cmpsb ,TOK_ASM_cmpsw ,TOK_ASM_cmpsl ,TOK_ASM_cmpsq ,TOK_ASM_cmps
1811 ,TOK_ASM_scmpb ,TOK_ASM_scmpw ,TOK_ASM_scmpl ,TOK_ASM_scmpq ,TOK_ASM_scmp
1812 ,TOK_ASM_insb ,TOK_ASM_insw ,TOK_ASM_insl ,TOK_ASM_ins
1813 ,TOK_ASM_outsb ,TOK_ASM_outsw ,TOK_ASM_outsl ,TOK_ASM_outs
1814 ,TOK_ASM_lodsb ,TOK_ASM_lodsw ,TOK_ASM_lodsl ,TOK_ASM_lodsq ,TOK_ASM_lods
1815 ,TOK_ASM_slodb ,TOK_ASM_slodw ,TOK_ASM_slodl ,TOK_ASM_slodq ,TOK_ASM_slod
1816 ,TOK_ASM_movsb ,TOK_ASM_movsw ,TOK_ASM_movsl ,TOK_ASM_movsq ,TOK_ASM_movs
1817 ,TOK_ASM_smovb ,TOK_ASM_smovw ,TOK_ASM_smovl ,TOK_ASM_smovq ,TOK_ASM_smov
1818 ,TOK_ASM_scasb ,TOK_ASM_scasw ,TOK_ASM_scasl ,TOK_ASM_scasq ,TOK_ASM_scas
1819 ,TOK_ASM_sscab ,TOK_ASM_sscaw ,TOK_ASM_sscal ,TOK_ASM_sscaq ,TOK_ASM_ssca
1820 ,TOK_ASM_stosb ,TOK_ASM_stosw ,TOK_ASM_stosl ,TOK_ASM_stosq ,TOK_ASM_stos
1821 ,TOK_ASM_sstob ,TOK_ASM_sstow ,TOK_ASM_sstol ,TOK_ASM_sstoq ,TOK_ASM_ssto
1822# 238 "i386-tok.h"
1823# 1 "x86_64-asm.h" 1
1824     ,TOK_ASM_clc
1825     ,TOK_ASM_cld
1826     ,TOK_ASM_cli
1827     ,TOK_ASM_clts
1828     ,TOK_ASM_cmc
1829     ,TOK_ASM_lahf
1830     ,TOK_ASM_sahf
1831     ,TOK_ASM_pushfq
1832     ,TOK_ASM_popfq
1833     ,TOK_ASM_pushf
1834     ,TOK_ASM_popf
1835     ,TOK_ASM_stc
1836     ,TOK_ASM_std
1837     ,TOK_ASM_sti
1838     ,TOK_ASM_aaa
1839     ,TOK_ASM_aas
1840     ,TOK_ASM_daa
1841     ,TOK_ASM_das
1842     ,TOK_ASM_aad
1843     ,TOK_ASM_aam
1844     ,TOK_ASM_cbw
1845     ,TOK_ASM_cwd
1846     ,TOK_ASM_cwde
1847     ,TOK_ASM_cdq
1848     ,TOK_ASM_cbtw
1849     ,TOK_ASM_cwtl
1850     ,TOK_ASM_cwtd
1851     ,TOK_ASM_cltd
1852     ,TOK_ASM_cqto
1853     ,TOK_ASM_int3
1854     ,TOK_ASM_into
1855     ,TOK_ASM_iret
1856     ,TOK_ASM_rsm
1857     ,TOK_ASM_hlt
1858     ,TOK_ASM_wait
1859     ,TOK_ASM_nop
1860     ,TOK_ASM_pause
1861     ,TOK_ASM_xlat
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900     ,TOK_ASM_lock
1901     ,TOK_ASM_rep
1902     ,TOK_ASM_repe
1903     ,TOK_ASM_repz
1904     ,TOK_ASM_repne
1905     ,TOK_ASM_repnz
1906
1907     ,TOK_ASM_invd
1908     ,TOK_ASM_wbinvd
1909     ,TOK_ASM_cpuid
1910     ,TOK_ASM_wrmsr
1911     ,TOK_ASM_rdtsc
1912     ,TOK_ASM_rdmsr
1913     ,TOK_ASM_rdpmc
1914
1915     ,TOK_ASM_syscall
1916     ,TOK_ASM_sysret
1917
1918     ,TOK_ASM_ud2
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050    ,TOK_ASM_leave
2051    ,TOK_ASM_ret
2052    ,TOK_ASM_retq
2053
2054
2055    ,TOK_ASM_lret
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084     ,TOK_ASM_fucompp
2085     ,TOK_ASM_ftst
2086     ,TOK_ASM_fxam
2087     ,TOK_ASM_fld1
2088     ,TOK_ASM_fldl2t
2089     ,TOK_ASM_fldl2e
2090     ,TOK_ASM_fldpi
2091     ,TOK_ASM_fldlg2
2092     ,TOK_ASM_fldln2
2093     ,TOK_ASM_fldz
2094
2095     ,TOK_ASM_f2xm1
2096     ,TOK_ASM_fyl2x
2097     ,TOK_ASM_fptan
2098     ,TOK_ASM_fpatan
2099     ,TOK_ASM_fxtract
2100     ,TOK_ASM_fprem1
2101     ,TOK_ASM_fdecstp
2102     ,TOK_ASM_fincstp
2103     ,TOK_ASM_fprem
2104     ,TOK_ASM_fyl2xp1
2105     ,TOK_ASM_fsqrt
2106     ,TOK_ASM_fsincos
2107     ,TOK_ASM_frndint
2108     ,TOK_ASM_fscale
2109     ,TOK_ASM_fsin
2110     ,TOK_ASM_fcos
2111     ,TOK_ASM_fchs
2112     ,TOK_ASM_fabs
2113     ,TOK_ASM_fninit
2114     ,TOK_ASM_fnclex
2115     ,TOK_ASM_fnop
2116     ,TOK_ASM_fwait
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148    ,TOK_ASM_fxch
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159    ,TOK_ASM_fnstsw
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241    ,TOK_ASM_emms
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343# 239 "i386-tok.h" 2
2344# 250 "i386-tok.h"
2345# 1 "x86_64-asm.h" 1
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439     ,TOK_ASM_sysretq
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565    ,TOK_ASM_ljmpw
2566    ,TOK_ASM_ljmpl
2567
2568
2569
2570
2571    ,TOK_ASM_enter
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581    ,TOK_ASM_loopne
2582    ,TOK_ASM_loopnz
2583    ,TOK_ASM_loope
2584    ,TOK_ASM_loopz
2585    ,TOK_ASM_loop
2586    ,TOK_ASM_jecxz
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641    ,TOK_ASM_fld
2642    ,TOK_ASM_fldl
2643    ,TOK_ASM_flds
2644
2645    ,TOK_ASM_fildl
2646    ,TOK_ASM_fildq
2647    ,TOK_ASM_fildll
2648    ,TOK_ASM_fldt
2649    ,TOK_ASM_fbld
2650
2651
2652    ,TOK_ASM_fst
2653    ,TOK_ASM_fstl
2654    ,TOK_ASM_fsts
2655    ,TOK_ASM_fstps
2656
2657    ,TOK_ASM_fstpl
2658    ,TOK_ASM_fist
2659    ,TOK_ASM_fistp
2660    ,TOK_ASM_fistl
2661    ,TOK_ASM_fistpl
2662
2663    ,TOK_ASM_fstp
2664    ,TOK_ASM_fistpq
2665    ,TOK_ASM_fistpll
2666    ,TOK_ASM_fstpt
2667    ,TOK_ASM_fbstp
2668
2669
2670
2671
2672
2673
2674    ,TOK_ASM_fucom
2675    ,TOK_ASM_fucomp
2676
2677    ,TOK_ASM_finit
2678    ,TOK_ASM_fldcw
2679    ,TOK_ASM_fnstcw
2680    ,TOK_ASM_fstcw
2681
2682
2683
2684    ,TOK_ASM_fstsw
2685
2686
2687    ,TOK_ASM_fclex
2688    ,TOK_ASM_fnstenv
2689    ,TOK_ASM_fstenv
2690    ,TOK_ASM_fldenv
2691    ,TOK_ASM_fnsave
2692    ,TOK_ASM_fsave
2693    ,TOK_ASM_frstor
2694    ,TOK_ASM_ffree
2695    ,TOK_ASM_ffreep
2696    ,TOK_ASM_fxsave
2697    ,TOK_ASM_fxrstor
2698
2699
2700
2701
2702    ,TOK_ASM_fxsaveq
2703    ,TOK_ASM_fxrstorq
2704
2705
2706    ,TOK_ASM_arpl
2707
2708    ,TOK_ASM_lgdt
2709    ,TOK_ASM_lgdtq
2710    ,TOK_ASM_lidt
2711    ,TOK_ASM_lidtq
2712    ,TOK_ASM_lldt
2713    ,TOK_ASM_lmsw
2714
2715    ,TOK_ASM_ltr
2716    ,TOK_ASM_sgdt
2717    ,TOK_ASM_sgdtq
2718    ,TOK_ASM_sidt
2719    ,TOK_ASM_sidtq
2720    ,TOK_ASM_sldt
2721    ,TOK_ASM_smsw
2722    ,TOK_ASM_str
2723
2724
2725    ,TOK_ASM_verr
2726    ,TOK_ASM_verw
2727    ,TOK_ASM_swapgs
2728
2729
2730
2731    ,TOK_ASM_bswap
2732    ,TOK_ASM_bswapl
2733    ,TOK_ASM_bswapq
2734
2735
2736
2737    ,TOK_ASM_invlpg
2738
2739
2740    ,TOK_ASM_cmpxchg8b
2741
2742
2743    ,TOK_ASM_cmpxchg16b
2744
2745
2746
2747
2748    ,TOK_ASM_fcmovb
2749    ,TOK_ASM_fcmove
2750    ,TOK_ASM_fcmovbe
2751    ,TOK_ASM_fcmovu
2752    ,TOK_ASM_fcmovnb
2753    ,TOK_ASM_fcmovne
2754    ,TOK_ASM_fcmovnbe
2755    ,TOK_ASM_fcmovnu
2756
2757    ,TOK_ASM_fucomi
2758    ,TOK_ASM_fcomi
2759    ,TOK_ASM_fucomip
2760    ,TOK_ASM_fcomip
2761
2762
2763
2764    ,TOK_ASM_movd
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777    ,TOK_ASM_packssdw
2778    ,TOK_ASM_packsswb
2779    ,TOK_ASM_packuswb
2780    ,TOK_ASM_paddb
2781    ,TOK_ASM_paddw
2782    ,TOK_ASM_paddd
2783    ,TOK_ASM_paddsb
2784    ,TOK_ASM_paddsw
2785    ,TOK_ASM_paddusb
2786    ,TOK_ASM_paddusw
2787    ,TOK_ASM_pand
2788    ,TOK_ASM_pandn
2789    ,TOK_ASM_pcmpeqb
2790    ,TOK_ASM_pcmpeqw
2791    ,TOK_ASM_pcmpeqd
2792    ,TOK_ASM_pcmpgtb
2793    ,TOK_ASM_pcmpgtw
2794    ,TOK_ASM_pcmpgtd
2795    ,TOK_ASM_pmaddwd
2796    ,TOK_ASM_pmulhw
2797    ,TOK_ASM_pmullw
2798    ,TOK_ASM_por
2799    ,TOK_ASM_psllw
2800
2801    ,TOK_ASM_pslld
2802
2803    ,TOK_ASM_psllq
2804
2805    ,TOK_ASM_psraw
2806
2807    ,TOK_ASM_psrad
2808
2809    ,TOK_ASM_psrlw
2810
2811    ,TOK_ASM_psrld
2812
2813    ,TOK_ASM_psrlq
2814
2815    ,TOK_ASM_psubb
2816    ,TOK_ASM_psubw
2817    ,TOK_ASM_psubd
2818    ,TOK_ASM_psubsb
2819    ,TOK_ASM_psubsw
2820    ,TOK_ASM_psubusb
2821    ,TOK_ASM_psubusw
2822    ,TOK_ASM_punpckhbw
2823    ,TOK_ASM_punpckhwd
2824    ,TOK_ASM_punpckhdq
2825    ,TOK_ASM_punpcklbw
2826    ,TOK_ASM_punpcklwd
2827    ,TOK_ASM_punpckldq
2828    ,TOK_ASM_pxor
2829
2830
2831    ,TOK_ASM_movups
2832
2833    ,TOK_ASM_movaps
2834
2835    ,TOK_ASM_movhps
2836
2837    ,TOK_ASM_addps
2838    ,TOK_ASM_cvtpi2ps
2839    ,TOK_ASM_cvtps2pi
2840    ,TOK_ASM_cvttps2pi
2841    ,TOK_ASM_divps
2842    ,TOK_ASM_maxps
2843    ,TOK_ASM_minps
2844    ,TOK_ASM_mulps
2845    ,TOK_ASM_pavgb
2846    ,TOK_ASM_pavgw
2847    ,TOK_ASM_pmaxsw
2848    ,TOK_ASM_pmaxub
2849    ,TOK_ASM_pminsw
2850    ,TOK_ASM_pminub
2851    ,TOK_ASM_rcpss
2852    ,TOK_ASM_rsqrtps
2853    ,TOK_ASM_sqrtps
2854    ,TOK_ASM_subps
2855
2856    ,TOK_ASM_prefetchnta
2857    ,TOK_ASM_prefetcht0
2858    ,TOK_ASM_prefetcht1
2859    ,TOK_ASM_prefetcht2
2860    ,TOK_ASM_prefetchw
2861    ,TOK_ASM_lfence
2862    ,TOK_ASM_mfence
2863    ,TOK_ASM_sfence
2864    ,TOK_ASM_clflush
2865# 251 "i386-tok.h" 2
2866# 350 "tcctok.h" 2
2867# 1074 "tcc.h" 2
2868
2869};
2870
2871
2872
2873
2874
2875
2876
2877static int gnu_ext;
2878
2879static int tcc_ext;
2880
2881static struct TCCState *tcc_state;
2882
2883
2884static char *pstrcpy(char *buf, int buf_size, const char *s);
2885static char *pstrcat(char *buf, int buf_size, const char *s);
2886static char *pstrncpy(char *out, const char *in, size_t num);
2887 char *tcc_basename(const char *name);
2888 char *tcc_fileextension (const char *name);
2889
2890
2891 void tcc_free(void *ptr);
2892 void *tcc_malloc(unsigned long size);
2893 void *tcc_mallocz(unsigned long size);
2894 void *tcc_realloc(void *ptr, unsigned long size);
2895 char *tcc_strdup(const char *str);
2896# 1120 "tcc.h"
2897 void tcc_memcheck(void);
2898 void tcc_error_noabort(const char *fmt, ...);
2899 void tcc_error(const char *fmt, ...);
2900 void tcc_warning(const char *fmt, ...);
2901
2902
2903static void dynarray_add(void *ptab, int *nb_ptr, void *data);
2904static void dynarray_reset(void *pp, int *n);
2905static inline void cstr_ccat(CString *cstr, int ch);
2906static void cstr_cat(CString *cstr, const char *str, int len);
2907static void cstr_wccat(CString *cstr, int ch);
2908static void cstr_new(CString *cstr);
2909static void cstr_free(CString *cstr);
2910static void cstr_reset(CString *cstr);
2911
2912static inline void sym_free(Sym *sym);
2913static Sym *sym_push2(Sym **ps, int v, int t, int c);
2914static Sym *sym_find2(Sym *s, int v);
2915static Sym *sym_push(int v, CType *type, int r, int c);
2916static void sym_pop(Sym **ptop, Sym *b, int keep);
2917static inline Sym *struct_find(int v);
2918static inline Sym *sym_find(int v);
2919static Sym *global_identifier_push(int v, int t, int c);
2920
2921static void tcc_open_bf(TCCState *s1, const char *filename, int initlen);
2922static int tcc_open(TCCState *s1, const char *filename);
2923static void tcc_close(void);
2924
2925static int tcc_add_file_internal(TCCState *s1, const char *filename, int flags);
2926# 1166 "tcc.h"
2927static int tcc_add_crt(TCCState *s, const char *filename);
2928static int tcc_add_dll(TCCState *s, const char *filename, int flags);
2929static void tcc_add_pragma_libs(TCCState *s1);
2930 int tcc_add_library_err(TCCState *s, const char *f);
2931 void tcc_print_stats(TCCState *s, unsigned total_time);
2932 int tcc_parse_args(TCCState *s, int *argc, char ***argv, int optind);
2933# 1188 "tcc.h"
2934static struct BufferedFile *file;
2935static int ch, tok;
2936static CValue tokc;
2937static const int *macro_ptr;
2938static int parse_flags;
2939static int tok_flags;
2940static CString tokcstr;
2941
2942
2943static int total_lines;
2944static int total_bytes;
2945static int tok_ident;
2946static TokenSym **table_ident;
2947# 1222 "tcc.h"
2948static TokenSym *tok_alloc(const char *str, int len);
2949static const char *get_tok_str(int v, CValue *cv);
2950static void begin_macro(TokenString *str, int alloc);
2951static void end_macro(void);
2952static int set_idnum(int c, int val);
2953static inline void tok_str_new(TokenString *s);
2954static TokenString *tok_str_alloc(void);
2955static void tok_str_free(TokenString *s);
2956static void tok_str_free_str(int *str);
2957static void tok_str_add(TokenString *s, int t);
2958static void tok_str_add_tok(TokenString *s);
2959static inline void define_push(int v, int macro_type, int *str, Sym *first_arg);
2960static void define_undef(Sym *s);
2961static inline Sym *define_find(int v);
2962static void free_defines(Sym *b);
2963static Sym *label_find(int v);
2964static Sym *label_push(Sym **ptop, int v, int flags);
2965static void label_pop(Sym **ptop, Sym *slast, int keep);
2966static void parse_define(void);
2967static void preprocess(int is_bof);
2968static void next_nomacro(void);
2969static void next(void);
2970static inline void unget_tok(int last_tok);
2971static void preprocess_start(TCCState *s1, int is_asm);
2972static void preprocess_end(TCCState *s1);
2973static void tccpp_new(TCCState *s);
2974static void tccpp_delete(TCCState *s);
2975static int tcc_preprocess(TCCState *s1);
2976static void skip(int c);
2977static void expect(const char *msg);
2978
2979
2980static inline int is_space(int ch) {
2981    return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
2982}
2983static inline int isid(int c) {
2984    return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
2985}
2986static inline int isnum(int c) {
2987    return c >= '0' && c <= '9';
2988}
2989static inline int isoct(int c) {
2990    return c >= '0' && c <= '7';
2991}
2992static inline int toup(int c) {
2993    return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c;
2994}
2995
2996
2997
2998
2999static Sym *sym_free_first;
3000static void **sym_pools;
3001static int nb_sym_pools;
3002
3003static Sym *global_stack;
3004static Sym *local_stack;
3005static Sym *local_label_stack;
3006static Sym *global_label_stack;
3007static Sym *define_stack;
3008static CType char_pointer_type, func_old_type, int_type, size_type;
3009static SValue __vstack[1+ 256], *vtop, *pvtop;
3010
3011static int rsym, anon_sym, ind, loc;
3012
3013static int const_wanted;
3014static int nocode_wanted;
3015static int global_expr;
3016static CType func_vt;
3017static int func_var;
3018static int func_vc;
3019static int last_line_num, last_ind, func_ind;
3020static const char *funcname;
3021static int g_debug;
3022
3023static void tcc_debug_start(TCCState *s1);
3024static void tcc_debug_end(TCCState *s1);
3025static void tcc_debug_funcstart(TCCState *s1, Sym *sym);
3026static void tcc_debug_funcend(TCCState *s1, int size);
3027static void tcc_debug_line(TCCState *s1);
3028
3029static int tccgen_compile(TCCState *s1);
3030static void free_inline_functions(TCCState *s);
3031static void check_vstack(void);
3032
3033static inline int is_float(int t);
3034static int ieee_finite(double d);
3035static void test_lvalue(void);
3036static void vpushi(int v);
3037static Elf64_Sym *elfsym(Sym *);
3038static void update_storage(Sym *sym);
3039static Sym *external_global_sym(int v, CType *type, int r);
3040static void vset(CType *type, int r, int v);
3041static void vswap(void);
3042static void vpush_global_sym(CType *type, int v);
3043static void vrote(SValue *e, int n);
3044static void vrott(int n);
3045static void vrotb(int n);
3046
3047
3048
3049
3050static void vpushv(SValue *v);
3051static void save_reg(int r);
3052static void save_reg_upstack(int r, int n);
3053static int get_reg(int rc);
3054static void save_regs(int n);
3055static void gaddrof(void);
3056static int gv(int rc);
3057static void gv2(int rc1, int rc2);
3058static void vpop(void);
3059static void gen_op(int op);
3060static int type_size(CType *type, int *a);
3061static void mk_pointer(CType *type);
3062static void vstore(void);
3063static void inc(int post, int c);
3064static void parse_mult_str (CString *astr, const char *msg);
3065static void parse_asm_str(CString *astr);
3066static int lvalue_type(int t);
3067static void indir(void);
3068static void unary(void);
3069static void expr_prod(void);
3070static void expr_sum(void);
3071static void gexpr(void);
3072static int expr_const(void);
3073
3074static Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size);
3075
3076
3077static int classify_x86_64_va_arg(CType *ty);
3078# 1362 "tcc.h"
3079typedef struct {
3080    unsigned int n_strx;
3081    unsigned char n_type;
3082    unsigned char n_other;
3083    unsigned short n_desc;
3084    unsigned int n_value;
3085} Stab_Sym;
3086
3087static Section *text_section, *data_section, *bss_section;
3088static Section *common_section;
3089static Section *cur_text_section;
3090
3091static Section *last_text_section;
3092
3093
3094
3095static Section *bounds_section;
3096static Section *lbounds_section;
3097static void tccelf_bounds_new(TCCState *s);
3098
3099
3100static Section *symtab_section;
3101
3102static Section *stab_section, *stabstr_section;
3103
3104static void tccelf_new(TCCState *s);
3105static void tccelf_delete(TCCState *s);
3106static void tccelf_stab_new(TCCState *s);
3107static void tccelf_begin_file(TCCState *s1);
3108static void tccelf_end_file(TCCState *s1);
3109
3110static Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
3111static void section_realloc(Section *sec, unsigned long new_size);
3112static size_t section_add(Section *sec, Elf64_Addr size, int align);
3113static void *section_ptr_add(Section *sec, Elf64_Addr size);
3114static void section_reserve(Section *sec, unsigned long size);
3115static Section *find_section(TCCState *s1, const char *name);
3116static Section *new_symtab(TCCState *s1, const char *symtab_name, int sh_type, int sh_flags, const char *strtab_name, const char *hash_name, int hash_sh_flags);
3117
3118static void put_extern_sym2(Sym *sym, int sh_num, Elf64_Addr value, unsigned long size, int can_add_underscore);
3119static void put_extern_sym(Sym *sym, Section *section, Elf64_Addr value, unsigned long size);
3120
3121
3122
3123static void greloca(Section *s, Sym *sym, unsigned long offset, int type, Elf64_Addr addend);
3124
3125static int put_elf_str(Section *s, const char *sym);
3126static int put_elf_sym(Section *s, Elf64_Addr value, unsigned long size, int info, int other, int shndx, const char *name);
3127static int set_elf_sym(Section *s, Elf64_Addr value, unsigned long size, int info, int other, int shndx, const char *name);
3128static int find_elf_sym(Section *s, const char *name);
3129static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);
3130static void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, int type, int symbol, Elf64_Addr addend);
3131
3132static void put_stabs(const char *str, int type, int other, int desc, unsigned long value);
3133static void put_stabs_r(const char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index);
3134static void put_stabn(int type, int other, int desc, int value);
3135static void put_stabd(int type, int other, int desc);
3136
3137static void resolve_common_syms(TCCState *s1);
3138static void relocate_syms(TCCState *s1, Section *symtab, int do_resolve);
3139static void relocate_section(TCCState *s1, Section *s);
3140
3141static int tcc_object_type(int fd, Elf64_Ehdr *h);
3142static int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset);
3143static int tcc_load_archive(TCCState *s1, int fd);
3144static void tcc_add_bcheck(TCCState *s1);
3145static void tcc_add_runtime(TCCState *s1);
3146
3147static void build_got_entries(TCCState *s1);
3148static struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc);
3149static void squeeze_multi_relocs(Section *sec, size_t oldrelocoffset);
3150
3151static Elf64_Addr get_elf_sym_addr(TCCState *s, const char *name, int err);
3152
3153static void *tcc_get_symbol_err(TCCState *s, const char *name);
3154
3155
3156
3157static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
3158static int tcc_load_ldscript(TCCState *s1);
3159static uint8_t *parse_comment(uint8_t *p);
3160static void minp(void);
3161static inline void inp(void);
3162static int handle_eob(void);
3163
3164
3165
3166
3167
3168
3169enum gotplt_entry {
3170    NO_GOTPLT_ENTRY,
3171    BUILD_GOT_ONLY,
3172    AUTO_GOTPLT_ENTRY,
3173    ALWAYS_GOTPLT_ENTRY
3174};
3175
3176static int code_reloc (int reloc_type);
3177static int gotplt_entry_type (int reloc_type);
3178static unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);
3179static void relocate_init(Section *sr);
3180static void relocate(TCCState *s1, Elf64_Rela *rel, int type, unsigned char *ptr, Elf64_Addr addr, Elf64_Addr val);
3181static void relocate_plt(TCCState *s1);
3182
3183
3184
3185static const int reg_classes[25];
3186
3187static void gsym_addr(int t, int a);
3188static void gsym(int t);
3189static void load(int r, SValue *sv);
3190static void store(int r, SValue *v);
3191static int gfunc_sret(CType *vt, int variadic, CType *ret, int *align, int *regsize);
3192static void gfunc_call(int nb_args);
3193static void gfunc_prolog(CType *func_type);
3194static void gfunc_epilog(void);
3195static int gjmp(int t);
3196static void gjmp_addr(int a);
3197static int gtst(int inv, int t);
3198
3199static void gtst_addr(int inv, int a);
3200
3201
3202
3203static void gen_opi(int op);
3204static void gen_opf(int op);
3205static void gen_cvt_ftoi(int t);
3206static void gen_cvt_ftof(int t);
3207static void ggoto(void);
3208
3209static void o(unsigned int c);
3210
3211
3212static void gen_cvt_itof(int t);
3213
3214static void gen_vla_sp_save(int addr);
3215static void gen_vla_sp_restore(int addr);
3216static void gen_vla_alloc(CType *type, int align);
3217
3218static inline uint16_t read16le(unsigned char *p) {
3219    return p[0] | (uint16_t)p[1] << 8;
3220}
3221static inline void write16le(unsigned char *p, uint16_t x) {
3222    p[0] = x & 255; p[1] = x >> 8 & 255;
3223}
3224static inline uint32_t read32le(unsigned char *p) {
3225  return read16le(p) | (uint32_t)read16le(p + 2) << 16;
3226}
3227static inline void write32le(unsigned char *p, uint32_t x) {
3228    write16le(p, x); write16le(p + 2, x >> 16);
3229}
3230static inline void add32le(unsigned char *p, int32_t x) {
3231    write32le(p, read32le(p) + x);
3232}
3233static inline uint64_t read64le(unsigned char *p) {
3234  return read32le(p) | (uint64_t)read32le(p + 4) << 32;
3235}
3236static inline void write64le(unsigned char *p, uint64_t x) {
3237    write32le(p, x); write32le(p + 4, x >> 32);
3238}
3239static inline void add64le(unsigned char *p, int64_t x) {
3240    write64le(p, read64le(p) + x);
3241}
3242
3243
3244
3245static void g(int c);
3246static void gen_le16(int c);
3247static void gen_le32(int c);
3248static void gen_addr32(int r, Sym *sym, int c);
3249static void gen_addrpc32(int r, Sym *sym, int c);
3250
3251
3252
3253static void gen_bounded_ptr_add(void);
3254static void gen_bounded_ptr_deref(void);
3255
3256
3257
3258
3259static void gen_addr64(int r, Sym *sym, int64_t c);
3260static void gen_opl(int op);
3261# 1580 "tcc.h"
3262static void asm_instr(void);
3263static void asm_global_instr(void);
3264
3265static int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp);
3266static Sym* get_asm_sym(int name, Sym *csym);
3267static void asm_expr(TCCState *s1, ExprValue *pe);
3268static int asm_int_expr(TCCState *s1);
3269static int tcc_assemble(TCCState *s1, int do_preprocess);
3270
3271static void gen_expr32(ExprValue *pe);
3272
3273static void gen_expr64(ExprValue *pe);
3274
3275static void asm_opcode(TCCState *s1, int opcode);
3276static int asm_parse_regvar(int t);
3277static void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg);
3278static void subst_asm_operand(CString *add_str, SValue *sv, int modifier);
3279static void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg);
3280static void asm_clobber(uint8_t *clobber_regs, const char *str);
3281# 1634 "tcc.h"
3282static int rt_num_callers;
3283static const char **rt_bound_error_msg;
3284static void *rt_prog_main;
3285static void tcc_set_num_callers(int n);
3286
3287static void tcc_run_free(TCCState *s1);
3288# 22 "tccgen.c" 2
3289# 31 "tccgen.c"
3290static int rsym, anon_sym, ind, loc;
3291
3292static Sym *sym_free_first;
3293static void **sym_pools;
3294static int nb_sym_pools;
3295
3296static Sym *global_stack;
3297static Sym *local_stack;
3298static Sym *define_stack;
3299static Sym *global_label_stack;
3300static Sym *local_label_stack;
3301static int local_scope;
3302static int in_sizeof;
3303static int section_sym;
3304
3305static int vlas_in_scope;
3306static int vla_sp_root_loc;
3307static int vla_sp_loc;
3308
3309static SValue __vstack[1+256], *vtop, *pvtop;
3310
3311static int const_wanted;
3312static int nocode_wanted;
3313
3314
3315static int global_expr;
3316static CType func_vt;
3317static int func_var;
3318static int func_vc;
3319static int last_line_num, last_ind, func_ind;
3320static const char *funcname;
3321static int g_debug;
3322
3323static CType char_pointer_type, func_old_type, int_type, size_type, ptrdiff_type;
3324
3325static struct switch_t {
3326    struct case_t {
3327        int64_t v1, v2;
3328 int sym;
3329    } **p; int n;
3330    int def_sym;
3331} *cur_switch;
3332
3333
3334
3335static void gen_cast(CType *type);
3336static void gen_cast_s(int t);
3337static inline CType *pointed_type(CType *type);
3338static int is_compatible_types(CType *type1, CType *type2);
3339static int parse_btype(CType *type, AttributeDef *ad);
3340static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td);
3341static void parse_expr_type(CType *type);
3342static void init_putv(CType *type, Section *sec, unsigned long c);
3343static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only);
3344static void block(int *bsym, int *csym, int is_expr);
3345static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope);
3346static void decl(int l);
3347static int decl0(int l, int is_for_loop_init, Sym *);
3348static void expr_eq(void);
3349static void vla_runtime_type_size(CType *type, int *a);
3350static void vla_sp_restore(void);
3351static void vla_sp_restore_root(void);
3352static int is_compatible_unqualified_types(CType *type1, CType *type2);
3353static inline int64_t expr_const64(void);
3354static void vpush64(int ty, unsigned long long v);
3355static void vpush(CType *type);
3356static int gvtst(int inv, int t);
3357static void gen_inline_functions(TCCState *s);
3358static void skip_or_save_block(TokenString **str);
3359static void gv_dup(void);
3360
3361static inline int is_float(int t)
3362{
3363    int bt;
3364    bt = t & 0x000f;
3365    return bt == 10 || bt == 9 || bt == 8 || bt == 14;
3366}
3367
3368
3369
3370
3371static int ieee_finite(double d)
3372{
3373    int p[4];
3374    memcpy(p, &d, sizeof(double));
3375    return ((unsigned)((p[1] | 0x800fffff) + 1)) >> 31;
3376}
3377
3378
3379
3380
3381
3382
3383
3384static void test_lvalue(void)
3385{
3386    if (!(vtop->r & 0x0100))
3387        expect("lvalue");
3388}
3389
3390static void check_vstack(void)
3391{
3392    if (pvtop != vtop)
3393        tcc_error("internal compiler error: vstack leak (%d)", vtop - pvtop);
3394}
3395# 154 "tccgen.c"
3396static void tcc_debug_start(TCCState *s1)
3397{
3398    if (s1->do_debug) {
3399        char buf[512];
3400
3401
3402        section_sym = put_elf_sym(symtab_section, 0, 0,
3403                                  ((((0)) << 4) + (((3)) & 0xf)), 0,
3404                                  text_section->sh_num, 0);
3405        getcwd(buf, sizeof(buf));
3406
3407
3408
3409        pstrcat(buf, sizeof(buf), "/");
3410        put_stabs_r(buf, N_SO, 0, 0,
3411                    text_section->data_offset, text_section, section_sym);
3412        put_stabs_r(file->filename, N_SO, 0, 0,
3413                    text_section->data_offset, text_section, section_sym);
3414        last_ind = 0;
3415        last_line_num = 0;
3416    }
3417
3418
3419
3420    put_elf_sym(symtab_section, 0, 0,
3421                ((((0)) << 4) + (((4)) & 0xf)), 0,
3422                0xfff1, file->filename);
3423}
3424
3425
3426static void tcc_debug_end(TCCState *s1)
3427{
3428    if (!s1->do_debug)
3429        return;
3430    put_stabs_r(0, N_SO, 0, 0,
3431        text_section->data_offset, text_section, section_sym);
3432
3433}
3434
3435
3436static void tcc_debug_line(TCCState *s1)
3437{
3438    if (!s1->do_debug)
3439        return;
3440    if ((last_line_num != file->line_num || last_ind != ind)) {
3441        put_stabn(N_SLINE, 0, file->line_num, ind - func_ind);
3442        last_ind = ind;
3443        last_line_num = file->line_num;
3444    }
3445}
3446
3447
3448static void tcc_debug_funcstart(TCCState *s1, Sym *sym)
3449{
3450    char buf[512];
3451
3452    if (!s1->do_debug)
3453        return;
3454
3455
3456
3457    snprintf(buf, sizeof(buf), "%s:%c1",
3458             funcname, sym->type.t & 0x00002000 ? 'f' : 'F');
3459    put_stabs_r(buf, N_FUN, 0, file->line_num, 0,
3460                cur_text_section, sym->c);
3461
3462    put_stabn(N_SLINE, 0, file->line_num, 0);
3463
3464    last_ind = 0;
3465    last_line_num = 0;
3466}
3467
3468
3469static void tcc_debug_funcend(TCCState *s1, int size)
3470{
3471    if (!s1->do_debug)
3472        return;
3473    put_stabn(N_FUN, 0, 0, size);
3474}
3475
3476
3477static int tccgen_compile(TCCState *s1)
3478{
3479    cur_text_section = 0;
3480    funcname = "";
3481    anon_sym = 0x10000000;
3482    section_sym = 0;
3483    const_wanted = 0;
3484    nocode_wanted = 0x80000000;
3485
3486
3487    int_type.t = 3;
3488    char_pointer_type.t = 1;
3489    mk_pointer(&char_pointer_type);
3490
3491
3492
3493
3494
3495
3496
3497    size_type.t = 0x0800 | 4 | 0x0010;
3498    ptrdiff_type.t = 0x0800 | 4;
3499
3500    func_old_type.t = 6;
3501    func_old_type.ref = sym_push(0x20000000, &int_type, 0, 0);
3502    func_old_type.ref->f.func_call = 0;
3503    func_old_type.ref->f.func_type = 2;
3504
3505    tcc_debug_start(s1);
3506# 273 "tccgen.c"
3507    parse_flags = 0x0001 | 0x0002 | 0x0040;
3508    next();
3509    decl(0x0030);
3510    gen_inline_functions(s1);
3511    check_vstack();
3512
3513    tcc_debug_end(s1);
3514    return 0;
3515}
3516
3517
3518static Elf64_Sym *elfsym(Sym *s)
3519{
3520  if (!s || !s->c)
3521    return 0;
3522  return &((Elf64_Sym *)symtab_section->data)[s->c];
3523}
3524
3525
3526static void update_storage(Sym *sym)
3527{
3528    Elf64_Sym *esym;
3529    int sym_bind, old_sym_bind;
3530
3531    esym = elfsym(sym);
3532    if (!esym)
3533        return;
3534
3535    if (sym->a.visibility)
3536        esym->st_other = (esym->st_other & ~((-1) & 0x03))
3537            | sym->a.visibility;
3538
3539    if (sym->type.t & 0x00002000)
3540        sym_bind = 0;
3541    else if (sym->a.weak)
3542        sym_bind = 2;
3543    else
3544        sym_bind = 1;
3545    old_sym_bind = (((unsigned char) (esym->st_info)) >> 4);
3546    if (sym_bind != old_sym_bind) {
3547        esym->st_info = ((((sym_bind)) << 4) + (((((esym->st_info) & 0xf))) & 0xf));
3548    }
3549# 332 "tccgen.c"
3550}
3551
3552
3553
3554
3555
3556static void put_extern_sym2(Sym *sym, int sh_num,
3557                            Elf64_Addr value, unsigned long size,
3558                            int can_add_underscore)
3559{
3560    int sym_type, sym_bind, info, other, t;
3561    Elf64_Sym *esym;
3562    const char *name;
3563    char buf1[256];
3564
3565    char buf[32];
3566
3567
3568    if (!sym->c) {
3569        name = get_tok_str(sym->v, 0);
3570
3571        if (tcc_state->do_bounds_check) {
3572
3573
3574
3575            switch(sym->v) {
3576# 366 "tccgen.c"
3577            case TOK_memcpy:
3578            case TOK_memmove:
3579            case TOK_memset:
3580            case TOK_strlen:
3581            case TOK_strcpy:
3582            case TOK_alloca:
3583                strcpy(buf, "__bound_");
3584                strcat(buf, name);
3585                name = buf;
3586                break;
3587            }
3588        }
3589
3590        t = sym->type.t;
3591        if ((t & 0x000f) == 6) {
3592            sym_type = 2;
3593        } else if ((t & 0x000f) == 0) {
3594            sym_type = 0;
3595        } else {
3596            sym_type = 1;
3597        }
3598        if (t & 0x00002000)
3599            sym_bind = 0;
3600        else
3601            sym_bind = 1;
3602        other = 0;
3603# 403 "tccgen.c"
3604        if (tcc_state->leading_underscore && can_add_underscore) {
3605            buf1[0] = '_';
3606            pstrcpy(buf1 + 1, sizeof(buf1) - 1, name);
3607            name = buf1;
3608        }
3609        if (sym->asm_label)
3610            name = get_tok_str(sym->asm_label, 0);
3611        info = ((((sym_bind)) << 4) + (((sym_type)) & 0xf));
3612        sym->c = put_elf_sym(symtab_section, value, size, info, other, sh_num, name);
3613    } else {
3614        esym = elfsym(sym);
3615        esym->st_value = value;
3616        esym->st_size = size;
3617        esym->st_shndx = sh_num;
3618    }
3619    update_storage(sym);
3620}
3621
3622static void put_extern_sym(Sym *sym, Section *section,
3623                           Elf64_Addr value, unsigned long size)
3624{
3625    int sh_num = section ? section->sh_num : 0;
3626    put_extern_sym2(sym, sh_num, value, size, 1);
3627}
3628
3629
3630static void greloca(Section *s, Sym *sym, unsigned long offset, int type,
3631                     Elf64_Addr addend)
3632{
3633    int c = 0;
3634
3635    if (nocode_wanted && s == cur_text_section)
3636        return;
3637
3638    if (sym) {
3639        if (0 == sym->c)
3640            put_extern_sym(sym, 0, 0, 0);
3641        c = sym->c;
3642    }
3643
3644
3645    put_elf_reloca(symtab_section, s, offset, type, c, addend);
3646}
3647# 456 "tccgen.c"
3648static Sym *__sym_malloc(void)
3649{
3650    Sym *sym_pool, *sym, *last_sym;
3651    int i;
3652
3653    sym_pool = tcc_malloc((8192 / sizeof(Sym)) * sizeof(Sym));
3654    dynarray_add(&sym_pools, &nb_sym_pools, sym_pool);
3655
3656    last_sym = sym_free_first;
3657    sym = sym_pool;
3658    for(i = 0; i < (8192 / sizeof(Sym)); i++) {
3659        sym->next = last_sym;
3660        last_sym = sym;
3661        sym++;
3662    }
3663    sym_free_first = last_sym;
3664    return last_sym;
3665}
3666
3667static inline Sym *sym_malloc(void)
3668{
3669    Sym *sym;
3670
3671    sym = sym_free_first;
3672    if (!sym)
3673        sym = __sym_malloc();
3674    sym_free_first = sym->next;
3675    return sym;
3676
3677
3678
3679
3680}
3681
3682static inline void sym_free(Sym *sym)
3683{
3684
3685    sym->next = sym_free_first;
3686    sym_free_first = sym;
3687
3688
3689
3690}
3691
3692
3693static Sym *sym_push2(Sym **ps, int v, int t, int c)
3694{
3695    Sym *s;
3696
3697    s = sym_malloc();
3698    memset(s, 0, sizeof *s);
3699    s->v = v;
3700    s->type.t = t;
3701    s->c = c;
3702
3703    s->prev = *ps;
3704    *ps = s;
3705    return s;
3706}
3707
3708
3709
3710static Sym *sym_find2(Sym *s, int v)
3711{
3712    while (s) {
3713        if (s->v == v)
3714            return s;
3715        else if (s->v == -1)
3716            return 0;
3717        s = s->prev;
3718    }
3719    return 0;
3720}
3721
3722
3723static inline Sym *struct_find(int v)
3724{
3725    v -= 256;
3726    if ((unsigned)v >= (unsigned)(tok_ident - 256))
3727        return 0;
3728    return table_ident[v]->sym_struct;
3729}
3730
3731
3732static inline Sym *sym_find(int v)
3733{
3734    v -= 256;
3735    if ((unsigned)v >= (unsigned)(tok_ident - 256))
3736        return 0;
3737    return table_ident[v]->sym_identifier;
3738}
3739
3740
3741static Sym *sym_push(int v, CType *type, int r, int c)
3742{
3743    Sym *s, **ps;
3744    TokenSym *ts;
3745
3746    if (local_stack)
3747        ps = &local_stack;
3748    else
3749        ps = &global_stack;
3750    s = sym_push2(ps, v, type->t, c);
3751    s->type.ref = type->ref;
3752    s->r = r;
3753
3754
3755    if (!(v & 0x20000000) && (v & ~0x40000000) < 0x10000000) {
3756
3757        ts = table_ident[(v & ~0x40000000) - 256];
3758        if (v & 0x40000000)
3759            ps = &ts->sym_struct;
3760        else
3761            ps = &ts->sym_identifier;
3762        s->prev_tok = *ps;
3763        *ps = s;
3764        s->sym_scope = local_scope;
3765        if (s->prev_tok && s->prev_tok->sym_scope == s->sym_scope)
3766            tcc_error("redeclaration of '%s'",
3767                get_tok_str(v & ~0x40000000, 0));
3768    }
3769    return s;
3770}
3771
3772
3773static Sym *global_identifier_push(int v, int t, int c)
3774{
3775    Sym *s, **ps;
3776    s = sym_push2(&global_stack, v, t, c);
3777
3778    if (v < 0x10000000) {
3779        ps = &table_ident[v - 256]->sym_identifier;
3780
3781
3782        while (*ps != 0 && (*ps)->sym_scope)
3783            ps = &(*ps)->prev_tok;
3784        s->prev_tok = *ps;
3785        *ps = s;
3786    }
3787    return s;
3788}
3789
3790
3791
3792static void sym_pop(Sym **ptop, Sym *b, int keep)
3793{
3794    Sym *s, *ss, **ps;
3795    TokenSym *ts;
3796    int v;
3797
3798    s = *ptop;
3799    while(s != b) {
3800        ss = s->prev;
3801        v = s->v;
3802
3803
3804        if (!(v & 0x20000000) && (v & ~0x40000000) < 0x10000000) {
3805            ts = table_ident[(v & ~0x40000000) - 256];
3806            if (v & 0x40000000)
3807                ps = &ts->sym_struct;
3808            else
3809                ps = &ts->sym_identifier;
3810            *ps = s->prev_tok;
3811        }
3812 if (!keep)
3813     sym_free(s);
3814        s = ss;
3815    }
3816    if (!keep)
3817 *ptop = b;
3818}
3819
3820
3821
3822static void vsetc(CType *type, int r, CValue *vc)
3823{
3824    int v;
3825
3826    if (vtop >= (__vstack + 1) + (256 - 1))
3827        tcc_error("memory full (vstack)");
3828# 649 "tccgen.c"
3829    if (vtop >= (__vstack + 1) && !nocode_wanted) {
3830        v = vtop->r & 0x003f;
3831        if (v == 0x0033 || (v & ~1) == 0x0034)
3832            gv(0x0001);
3833    }
3834
3835    vtop++;
3836    vtop->type = *type;
3837    vtop->r = r;
3838    vtop->r2 = 0x0030;
3839    vtop->c = *vc;
3840    vtop->sym = 0;
3841}
3842
3843static void vswap(void)
3844{
3845    SValue tmp;
3846
3847    if (vtop >= (__vstack + 1) && !nocode_wanted) {
3848        int v = vtop->r & 0x003f;
3849        if (v == 0x0033 || (v & ~1) == 0x0034)
3850            gv(0x0001);
3851    }
3852    tmp = vtop[0];
3853    vtop[0] = vtop[-1];
3854    vtop[-1] = tmp;
3855}
3856
3857
3858static void vpop(void)
3859{
3860    int v;
3861    v = vtop->r & 0x003f;
3862
3863
3864    if (v == TREG_ST0) {
3865        o(0xd8dd);
3866    } else
3867
3868    if (v == 0x0034 || v == 0x0035) {
3869
3870        gsym(vtop->c.i);
3871    }
3872    vtop--;
3873}
3874
3875
3876static void vpush(CType *type)
3877{
3878    vset(type, 0x0030, 0);
3879}
3880
3881
3882static void vpushi(int v)
3883{
3884    CValue cval;
3885    cval.i = v;
3886    vsetc(&int_type, 0x0030, &cval);
3887}
3888
3889
3890static void vpushs(Elf64_Addr v)
3891{
3892  CValue cval;
3893  cval.i = v;
3894  vsetc(&size_type, 0x0030, &cval);
3895}
3896
3897
3898static void vpush64(int ty, unsigned long long v)
3899{
3900    CValue cval;
3901    CType ctype;
3902    ctype.t = ty;
3903    ctype.ref = 0;
3904    cval.i = v;
3905    vsetc(&ctype, 0x0030, &cval);
3906}
3907
3908
3909static inline void vpushll(long long v)
3910{
3911    vpush64(4, v);
3912}
3913
3914static void vset(CType *type, int r, int v)
3915{
3916    CValue cval;
3917
3918    cval.i = v;
3919    vsetc(type, r, &cval);
3920}
3921
3922static void vseti(int r, int v)
3923{
3924    CType type;
3925    type.t = 3;
3926    type.ref = 0;
3927    vset(&type, r, v);
3928}
3929
3930static void vpushv(SValue *v)
3931{
3932    if (vtop >= (__vstack + 1) + (256 - 1))
3933        tcc_error("memory full (vstack)");
3934    vtop++;
3935    *vtop = *v;
3936}
3937
3938static void vdup(void)
3939{
3940    vpushv(vtop);
3941}
3942
3943
3944
3945
3946static void vrotb(int n)
3947{
3948    int i;
3949    SValue tmp;
3950
3951    tmp = vtop[-n + 1];
3952    for(i=-n+1;i!=0;i++)
3953        vtop[i] = vtop[i+1];
3954    vtop[0] = tmp;
3955}
3956
3957
3958
3959
3960static void vrote(SValue *e, int n)
3961{
3962    int i;
3963    SValue tmp;
3964
3965    tmp = *e;
3966    for(i = 0;i < n - 1; i++)
3967        e[-i] = e[-i - 1];
3968    e[-n + 1] = tmp;
3969}
3970
3971
3972
3973
3974static void vrott(int n)
3975{
3976    vrote(vtop, n);
3977}
3978
3979
3980static inline void vpushsym(CType *type, Sym *sym)
3981{
3982    CValue cval;
3983    cval.i = 0;
3984    vsetc(type, 0x0030 | 0x0200, &cval);
3985    vtop->sym = sym;
3986}
3987
3988
3989static Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size)
3990{
3991    int v;
3992    Sym *sym;
3993
3994    v = anon_sym++;
3995    sym = global_identifier_push(v, type->t | 0x00002000, 0);
3996    sym->type.ref = type->ref;
3997    sym->r = 0x0030 | 0x0200;
3998    put_extern_sym(sym, sec, offset, size);
3999    return sym;
4000}
4001
4002
4003static void vpush_ref(CType *type, Section *sec, unsigned long offset, unsigned long size)
4004{
4005    vpushsym(type, get_sym_ref(type, sec, offset, size));
4006}
4007
4008
4009static Sym *external_global_sym(int v, CType *type, int r)
4010{
4011    Sym *s;
4012
4013    s = sym_find(v);
4014    if (!s) {
4015
4016        s = global_identifier_push(v, type->t | 0x00001000, 0);
4017        s->type.ref = type->ref;
4018        s->r = r | 0x0030 | 0x0200;
4019    } else if ((((s)->type.t & (0x000f | (0 | 0x0010))) == (0 | 0x0010))) {
4020        s->type.t = type->t | (s->type.t & 0x00001000);
4021        s->type.ref = type->ref;
4022        update_storage(s);
4023    }
4024    return s;
4025}
4026
4027
4028static void patch_type(Sym *sym, CType *type)
4029{
4030    if (!(type->t & 0x00001000)) {
4031        if (!(sym->type.t & 0x00001000))
4032            tcc_error("redefinition of '%s'", get_tok_str(sym->v, 0));
4033        sym->type.t &= ~0x00001000;
4034    }
4035
4036    if ((((sym)->type.t & (0x000f | (0 | 0x0010))) == (0 | 0x0010))) {
4037
4038        sym->type.t = type->t & (sym->type.t | ~0x00002000);
4039        sym->type.ref = type->ref;
4040    }
4041
4042    if (!is_compatible_types(&sym->type, type)) {
4043        tcc_error("incompatible types for redefinition of '%s'",
4044                  get_tok_str(sym->v, 0));
4045
4046    } else if ((sym->type.t & 0x000f) == 6) {
4047        int static_proto = sym->type.t & 0x00002000;
4048
4049        if ((type->t & 0x00002000) && !static_proto && !(type->t & 0x00008000))
4050            tcc_warning("static storage ignored for redefinition of '%s'",
4051                get_tok_str(sym->v, 0));
4052
4053        if (0 == (type->t & 0x00001000)) {
4054
4055            sym->type.t = (type->t & ~0x00002000) | static_proto;
4056            if (type->t & 0x00008000)
4057                sym->type.t = type->t;
4058            sym->type.ref = type->ref;
4059        }
4060
4061    } else {
4062        if ((sym->type.t & 0x0040) && type->ref->c >= 0) {
4063
4064            if (sym->type.ref->c < 0)
4065                sym->type.ref->c = type->ref->c;
4066            else if (sym->type.ref->c != type->ref->c)
4067                tcc_error("conflicting type for '%s'", get_tok_str(sym->v, 0));
4068        }
4069        if ((type->t ^ sym->type.t) & 0x00002000)
4070            tcc_warning("storage mismatch for redefinition of '%s'",
4071                get_tok_str(sym->v, 0));
4072    }
4073}
4074
4075
4076
4077static void patch_storage(Sym *sym, AttributeDef *ad, CType *type)
4078{
4079    if (type)
4080        patch_type(sym, type);
4081
4082
4083
4084
4085
4086
4087
4088    sym->a.weak |= ad->a.weak;
4089    if (ad->a.visibility) {
4090        int vis = sym->a.visibility;
4091        int vis2 = ad->a.visibility;
4092        if (vis == 0)
4093            vis = vis2;
4094        else if (vis2 != 0)
4095            vis = (vis < vis2) ? vis : vis2;
4096        sym->a.visibility = vis;
4097    }
4098    if (ad->a.aligned)
4099        sym->a.aligned = ad->a.aligned;
4100    if (ad->asm_label)
4101        sym->asm_label = ad->asm_label;
4102    update_storage(sym);
4103}
4104
4105
4106static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad)
4107{
4108    Sym *s;
4109    s = sym_find(v);
4110    if (!s) {
4111
4112        s = sym_push(v, type, r | 0x0030 | 0x0200, 0);
4113        s->type.t |= 0x00001000;
4114        s->a = ad->a;
4115        s->sym_scope = 0;
4116    } else {
4117        if (s->type.ref == func_old_type.ref) {
4118            s->type.ref = type->ref;
4119            s->r = r | 0x0030 | 0x0200;
4120            s->type.t |= 0x00001000;
4121        }
4122        patch_storage(s, ad, type);
4123    }
4124    return s;
4125}
4126
4127
4128static void vpush_global_sym(CType *type, int v)
4129{
4130    vpushsym(type, external_global_sym(v, type, 0));
4131}
4132
4133
4134static void save_regs(int n)
4135{
4136    SValue *p, *p1;
4137    for(p = (__vstack + 1), p1 = vtop - n; p <= p1; p++)
4138        save_reg(p->r);
4139}
4140
4141
4142static void save_reg(int r)
4143{
4144    save_reg_upstack(r, 0);
4145}
4146
4147
4148
4149static void save_reg_upstack(int r, int n)
4150{
4151    int l, saved, size, align;
4152    SValue *p, *p1, sv;
4153    CType *type;
4154
4155    if ((r &= 0x003f) >= 0x0030)
4156        return;
4157    if (nocode_wanted)
4158        return;
4159
4160
4161    saved = 0;
4162    l = 0;
4163    for(p = (__vstack + 1), p1 = vtop - n; p <= p1; p++) {
4164        if ((p->r & 0x003f) == r ||
4165            ((p->type.t & 0x000f) == 4 && (p->r2 & 0x003f) == r)) {
4166
4167            if (!saved) {
4168
4169                r = p->r & 0x003f;
4170
4171                type = &p->type;
4172                if ((p->r & 0x0100) ||
4173                    (!is_float(type->t) && (type->t & 0x000f) != 4))
4174
4175                    type = &char_pointer_type;
4176
4177
4178
4179                size = type_size(type, &align);
4180                loc = (loc - size) & -align;
4181                sv.type.t = type->t;
4182                sv.r = 0x0032 | 0x0100;
4183                sv.c.i = loc;
4184                store(r, &sv);
4185
4186
4187                if (r == TREG_ST0) {
4188                    o(0xd8dd);
4189                }
4190# 1018 "tccgen.c"
4191                l = loc;
4192                saved = 1;
4193            }
4194
4195            if (p->r & 0x0100) {
4196
4197
4198
4199                p->r = (p->r & ~(0x003f | 0x8000)) | 0x0031;
4200            } else {
4201                p->r = lvalue_type(p->type.t) | 0x0032;
4202            }
4203            p->r2 = 0x0030;
4204            p->c.i = l;
4205        }
4206    }
4207}
4208# 1062 "tccgen.c"
4209static int get_reg(int rc)
4210{
4211    int r;
4212    SValue *p;
4213
4214
4215    for(r=0;r<25;r++) {
4216        if (reg_classes[r] & rc) {
4217            if (nocode_wanted)
4218                return r;
4219            for(p=(__vstack + 1);p<=vtop;p++) {
4220                if ((p->r & 0x003f) == r ||
4221                    (p->r2 & 0x003f) == r)
4222                    goto notfound;
4223            }
4224            return r;
4225        }
4226    notfound: ;
4227    }
4228
4229
4230
4231
4232    for(p=(__vstack + 1);p<=vtop;p++) {
4233
4234        r = p->r2 & 0x003f;
4235        if (r < 0x0030 && (reg_classes[r] & rc))
4236            goto save_found;
4237        r = p->r & 0x003f;
4238        if (r < 0x0030 && (reg_classes[r] & rc)) {
4239        save_found:
4240            save_reg(r);
4241            return r;
4242        }
4243    }
4244
4245    return -1;
4246}
4247
4248
4249
4250static void move_reg(int r, int s, int t)
4251{
4252    SValue sv;
4253
4254    if (r != s) {
4255        save_reg(r);
4256        sv.type.t = t;
4257        sv.type.ref = 0;
4258        sv.r = s;
4259        sv.c.i = 0;
4260        load(r, &sv);
4261    }
4262}
4263
4264
4265static void gaddrof(void)
4266{
4267    vtop->r &= ~0x0100;
4268
4269    if ((vtop->r & 0x003f) == 0x0031)
4270        vtop->r = (vtop->r & ~(0x003f | (0x1000 | 0x2000 | 0x4000))) | 0x0032 | 0x0100;
4271
4272
4273}
4274
4275
4276
4277static void gbound(void)
4278{
4279    int lval_type;
4280    CType type1;
4281
4282    vtop->r &= ~0x0800;
4283
4284    if (vtop->r & 0x0100) {
4285
4286        if (!(vtop->r & 0x8000)) {
4287            lval_type = vtop->r & ((0x1000 | 0x2000 | 0x4000) | 0x0100);
4288
4289            type1 = vtop->type;
4290            vtop->type.t = 5;
4291            gaddrof();
4292            vpushi(0);
4293            gen_bounded_ptr_add();
4294            vtop->r |= lval_type;
4295            vtop->type = type1;
4296        }
4297
4298        gen_bounded_ptr_deref();
4299    }
4300}
4301
4302
4303static void incr_bf_adr(int o)
4304{
4305    vtop->type = char_pointer_type;
4306    gaddrof();
4307    vpushi(o);
4308    gen_op('+');
4309    vtop->type.t = (vtop->type.t & ~(0x000f|0x0020))
4310        | (1|0x0010);
4311    vtop->r = (vtop->r & ~(0x1000 | 0x2000 | 0x4000))
4312        | (0x1000|0x4000|0x0100);
4313}
4314
4315
4316static void load_packed_bf(CType *type, int bit_pos, int bit_size)
4317{
4318    int n, o, bits;
4319    save_reg_upstack(vtop->r, 1);
4320    vpush64(type->t & 0x000f, 0);
4321    bits = 0, o = bit_pos >> 3, bit_pos &= 7;
4322    do {
4323        vswap();
4324        incr_bf_adr(o);
4325        vdup();
4326        n = 8 - bit_pos;
4327        if (n > bit_size)
4328            n = bit_size;
4329        if (bit_pos)
4330            vpushi(bit_pos), gen_op(0xc9), bit_pos = 0;
4331        if (n < 8)
4332            vpushi((1 << n) - 1), gen_op('&');
4333        gen_cast(type);
4334        if (bits)
4335            vpushi(bits), gen_op(0x01);
4336        vrotb(3);
4337        gen_op('|');
4338        bits += n, bit_size -= n, o = 1;
4339    } while (bit_size);
4340    vswap(), vpop();
4341    if (!(type->t & 0x0010)) {
4342        n = ((type->t & 0x000f) == 4 ? 64 : 32) - bits;
4343        vpushi(n), gen_op(0x01);
4344        vpushi(n), gen_op(0x02);
4345    }
4346}
4347
4348
4349static void store_packed_bf(int bit_pos, int bit_size)
4350{
4351    int bits, n, o, m, c;
4352
4353    c = (vtop->r & (0x003f | 0x0100 | 0x0200)) == 0x0030;
4354    vswap();
4355    save_reg_upstack(vtop->r, 1);
4356    bits = 0, o = bit_pos >> 3, bit_pos &= 7;
4357    do {
4358        incr_bf_adr(o);
4359        vswap();
4360        c ? vdup() : gv_dup();
4361        vrott(3);
4362        if (bits)
4363            vpushi(bits), gen_op(0xc9);
4364        if (bit_pos)
4365            vpushi(bit_pos), gen_op(0x01);
4366        n = 8 - bit_pos;
4367        if (n > bit_size)
4368            n = bit_size;
4369        if (n < 8) {
4370            m = ((1 << n) - 1) << bit_pos;
4371            vpushi(m), gen_op('&');
4372            vpushv(vtop-1);
4373            vpushi(m & 0x80 ? ~m & 0x7f : ~m);
4374            gen_op('&');
4375            gen_op('|');
4376        }
4377        vdup(), vtop[-1] = vtop[-2];
4378        vstore(), vpop();
4379        bits += n, bit_size -= n, bit_pos = 0, o = 1;
4380    } while (bit_size);
4381    vpop(), vpop();
4382}
4383
4384static int adjust_bf(SValue *sv, int bit_pos, int bit_size)
4385{
4386    int t;
4387    if (0 == sv->type.ref)
4388        return 0;
4389    t = sv->type.ref->auxtype;
4390    if (t != -1 && t != 7) {
4391        sv->type.t = (sv->type.t & ~0x000f) | t;
4392        sv->r = (sv->r & ~(0x1000 | 0x2000 | 0x4000)) | lvalue_type(sv->type.t);
4393    }
4394    return t;
4395}
4396
4397
4398
4399
4400static int gv(int rc)
4401{
4402    int r, bit_pos, bit_size, size, align, rc2;
4403
4404
4405    if (vtop->type.t & 0x0080) {
4406        CType type;
4407
4408        bit_pos = (((vtop->type.t) >> 20) & 0x3f);
4409        bit_size = (((vtop->type.t) >> (20 + 6)) & 0x3f);
4410
4411        vtop->type.t &= ~(((1 << (6+6)) - 1) << 20 | 0x0080);
4412
4413        type.ref = 0;
4414        type.t = vtop->type.t & 0x0010;
4415        if ((vtop->type.t & 0x000f) == 11)
4416            type.t |= 0x0010;
4417
4418        r = adjust_bf(vtop, bit_pos, bit_size);
4419
4420        if ((vtop->type.t & 0x000f) == 4)
4421            type.t |= 4;
4422        else
4423            type.t |= 3;
4424
4425        if (r == 7) {
4426            load_packed_bf(&type, bit_pos, bit_size);
4427        } else {
4428            int bits = (type.t & 0x000f) == 4 ? 64 : 32;
4429
4430            gen_cast(&type);
4431
4432            vpushi(bits - (bit_pos + bit_size));
4433            gen_op(0x01);
4434            vpushi(bits - bit_size);
4435
4436            gen_op(0x02);
4437        }
4438        r = gv(rc);
4439    } else {
4440        if (is_float(vtop->type.t) &&
4441            (vtop->r & (0x003f | 0x0100)) == 0x0030) {
4442            unsigned long offset;
4443
4444
4445            size = type_size(&vtop->type, &align);
4446            if ((nocode_wanted > 0))
4447                size = 0, align = 1;
4448            offset = section_add(data_section, size, align);
4449            vpush_ref(&vtop->type, data_section, offset, size);
4450     vswap();
4451     init_putv(&vtop->type, data_section, offset);
4452     vtop->r |= 0x0100;
4453        }
4454
4455        if (vtop->r & 0x0800)
4456            gbound();
4457
4458
4459        r = vtop->r & 0x003f;
4460        rc2 = (rc & 0x0002) ? 0x0002 : 0x0001;
4461
4462        if (rc == 0x0004)
4463            rc2 = 0x0010;
4464
4465        else if (rc == 0x1000)
4466            rc2 = 0x2000;
4467
4468
4469
4470
4471
4472
4473        if (r >= 0x0030
4474         || (vtop->r & 0x0100)
4475         || !(reg_classes[r] & rc)
4476
4477         || ((vtop->type.t & 0x000f) == 13 && !(reg_classes[vtop->r2] & rc2))
4478         || ((vtop->type.t & 0x000f) == 14 && !(reg_classes[vtop->r2] & rc2))
4479
4480
4481
4482            )
4483        {
4484            r = get_reg(rc);
4485
4486            if (((vtop->type.t & 0x000f) == 13) || ((vtop->type.t & 0x000f) == 14)) {
4487                int addr_type = 4, load_size = 8, load_type = ((vtop->type.t & 0x000f) == 13) ? 4 : 9;
4488
4489
4490
4491
4492
4493                int r2, original_type;
4494                original_type = vtop->type.t;
4495# 1360 "tccgen.c"
4496                if (vtop->r & 0x0100) {
4497# 1369 "tccgen.c"
4498                    save_reg_upstack(vtop->r, 1);
4499
4500
4501                    vtop->type.t = load_type;
4502                    load(r, vtop);
4503                    vdup();
4504                    vtop[-1].r = r;
4505
4506                    vtop->type.t = addr_type;
4507                    gaddrof();
4508                    vpushi(load_size);
4509                    gen_op('+');
4510                    vtop->r |= 0x0100;
4511                    vtop->type.t = load_type;
4512                } else {
4513
4514                    load(r, vtop);
4515                    vdup();
4516                    vtop[-1].r = r;
4517                    vtop->r = vtop[-1].r2;
4518                }
4519
4520
4521                r2 = get_reg(rc2);
4522                load(r2, vtop);
4523                vpop();
4524
4525                vtop->r2 = r2;
4526                vtop->type.t = original_type;
4527            } else if ((vtop->r & 0x0100) && !is_float(vtop->type.t)) {
4528                int t1, t;
4529
4530
4531                t = vtop->type.t;
4532                t1 = t;
4533
4534                if (vtop->r & 0x1000)
4535                    t = 1;
4536                else if (vtop->r & 0x2000)
4537                    t = 2;
4538                if (vtop->r & 0x4000)
4539                    t |= 0x0010;
4540                vtop->type.t = t;
4541                load(r, vtop);
4542
4543                vtop->type.t = t1;
4544            } else {
4545
4546                load(r, vtop);
4547            }
4548        }
4549        vtop->r = r;
4550
4551
4552
4553
4554
4555    }
4556    return r;
4557}
4558
4559
4560static void gv2(int rc1, int rc2)
4561{
4562    int v;
4563
4564
4565
4566
4567    v = vtop[0].r & 0x003f;
4568    if (v != 0x0033 && (v & ~1) != 0x0034 && rc1 <= rc2) {
4569        vswap();
4570        gv(rc1);
4571        vswap();
4572        gv(rc2);
4573
4574        if ((vtop[-1].r & 0x003f) >= 0x0030) {
4575            vswap();
4576            gv(rc1);
4577            vswap();
4578        }
4579    } else {
4580        gv(rc2);
4581        vswap();
4582        gv(rc1);
4583        vswap();
4584
4585        if ((vtop[0].r & 0x003f) >= 0x0030) {
4586            gv(rc2);
4587        }
4588    }
4589}
4590
4591
4592
4593static int rc_fret(int t)
4594{
4595
4596    if (t == 10) {
4597        return 0x0080;
4598    }
4599
4600    return 0x1000;
4601}
4602
4603
4604
4605static int reg_fret(int t)
4606{
4607
4608    if (t == 10) {
4609        return TREG_ST0;
4610    }
4611
4612    return TREG_XMM0;
4613}
4614# 1550 "tccgen.c"
4615static void gv_dup(void)
4616{
4617    int rc, t, r, r1;
4618    SValue sv;
4619
4620    t = vtop->type.t;
4621# 1577 "tccgen.c"
4622    {
4623
4624        rc = 0x0001;
4625        sv.type.t = 3;
4626        if (is_float(t)) {
4627            rc = 0x0002;
4628
4629            if ((t & 0x000f) == 10) {
4630                rc = 0x0080;
4631            }
4632
4633            sv.type.t = t;
4634        }
4635        r = gv(rc);
4636        r1 = get_reg(rc);
4637        sv.r = r;
4638        sv.c.i = 0;
4639        load(r1, &sv);
4640        vdup();
4641
4642        if (r != r1)
4643            vtop->r = r1;
4644    }
4645}
4646
4647
4648
4649
4650static int gvtst(int inv, int t)
4651{
4652    int v = vtop->r & 0x003f;
4653    if (v != 0x0033 && v != 0x0034 && v != 0x0035) {
4654        vpushi(0);
4655        gen_op(0x95);
4656    }
4657    if ((vtop->r & (0x003f | 0x0100 | 0x0200)) == 0x0030) {
4658
4659        if ((vtop->c.i != 0) != inv)
4660            t = gjmp(t);
4661        vtop--;
4662        return t;
4663    }
4664    return gtst(inv, t);
4665}
4666# 1851 "tccgen.c"
4667static uint64_t gen_opic_sdiv(uint64_t a, uint64_t b)
4668{
4669    uint64_t x = (a >> 63 ? -a : a) / (b >> 63 ? -b : b);
4670    return (a ^ b) >> 63 ? -x : x;
4671}
4672
4673static int gen_opic_lt(uint64_t a, uint64_t b)
4674{
4675    return (a ^ (uint64_t)1 << 63) < (b ^ (uint64_t)1 << 63);
4676}
4677
4678
4679
4680static void gen_opic(int op)
4681{
4682    SValue *v1 = vtop - 1;
4683    SValue *v2 = vtop;
4684    int t1 = v1->type.t & 0x000f;
4685    int t2 = v2->type.t & 0x000f;
4686    int c1 = (v1->r & (0x003f | 0x0100 | 0x0200)) == 0x0030;
4687    int c2 = (v2->r & (0x003f | 0x0100 | 0x0200)) == 0x0030;
4688    uint64_t l1 = c1 ? v1->c.i : 0;
4689    uint64_t l2 = c2 ? v2->c.i : 0;
4690    int shm = (t1 == 4) ? 63 : 31;
4691
4692    if (t1 != 4 && (8 != 8 || t1 != 5))
4693        l1 = ((uint32_t)l1 |
4694              (v1->type.t & 0x0010 ? 0 : -(l1 & 0x80000000)));
4695    if (t2 != 4 && (8 != 8 || t2 != 5))
4696        l2 = ((uint32_t)l2 |
4697              (v2->type.t & 0x0010 ? 0 : -(l2 & 0x80000000)));
4698
4699    if (c1 && c2) {
4700        switch(op) {
4701        case '+': l1 += l2; break;
4702        case '-': l1 -= l2; break;
4703        case '&': l1 &= l2; break;
4704        case '^': l1 ^= l2; break;
4705        case '|': l1 |= l2; break;
4706        case '*': l1 *= l2; break;
4707
4708        case 0xb2:
4709        case '/':
4710        case '%':
4711        case 0xb0:
4712        case 0xb1:
4713
4714            if (l2 == 0) {
4715                if (const_wanted)
4716                    tcc_error("division by zero in constant");
4717                goto general_case;
4718            }
4719            switch(op) {
4720            default: l1 = gen_opic_sdiv(l1, l2); break;
4721            case '%': l1 = l1 - l2 * gen_opic_sdiv(l1, l2); break;
4722            case 0xb0: l1 = l1 / l2; break;
4723            case 0xb1: l1 = l1 % l2; break;
4724            }
4725            break;
4726        case 0x01: l1 <<= (l2 & shm); break;
4727        case 0xc9: l1 >>= (l2 & shm); break;
4728        case 0x02:
4729            l1 = (l1 >> 63) ? ~(~l1 >> (l2 & shm)) : l1 >> (l2 & shm);
4730            break;
4731
4732        case 0x92: l1 = l1 < l2; break;
4733        case 0x93: l1 = l1 >= l2; break;
4734        case 0x94: l1 = l1 == l2; break;
4735        case 0x95: l1 = l1 != l2; break;
4736        case 0x96: l1 = l1 <= l2; break;
4737        case 0x97: l1 = l1 > l2; break;
4738        case 0x9c: l1 = gen_opic_lt(l1, l2); break;
4739        case 0x9d: l1 = !gen_opic_lt(l1, l2); break;
4740        case 0x9e: l1 = !gen_opic_lt(l2, l1); break;
4741        case 0x9f: l1 = gen_opic_lt(l2, l1); break;
4742
4743        case 0xa0: l1 = l1 && l2; break;
4744        case 0xa1: l1 = l1 || l2; break;
4745        default:
4746            goto general_case;
4747        }
4748 if (t1 != 4 && (8 != 8 || t1 != 5))
4749     l1 = ((uint32_t)l1 |
4750  (v1->type.t & 0x0010 ? 0 : -(l1 & 0x80000000)));
4751        v1->c.i = l1;
4752        vtop--;
4753    } else {
4754
4755        if (c1 && (op == '+' || op == '&' || op == '^' ||
4756                   op == '|' || op == '*')) {
4757            vswap();
4758            c2 = c1;
4759            l2 = l1;
4760        }
4761        if (!const_wanted &&
4762            c1 && ((l1 == 0 &&
4763                    (op == 0x01 || op == 0xc9 || op == 0x02)) ||
4764                   (l1 == -1 && op == 0x02))) {
4765
4766            vtop--;
4767        } else if (!const_wanted &&
4768                   c2 && ((l2 == 0 && (op == '&' || op == '*')) ||
4769                          (op == '|' &&
4770                            (l2 == -1 || (l2 == 0xFFFFFFFF && t2 != 4))) ||
4771                          (l2 == 1 && (op == '%' || op == 0xb1)))) {
4772
4773            if (l2 == 1)
4774                vtop->c.i = 0;
4775            vswap();
4776            vtop--;
4777        } else if (c2 && (((op == '*' || op == '/' || op == 0xb0 ||
4778                          op == 0xb2) &&
4779                           l2 == 1) ||
4780                          ((op == '+' || op == '-' || op == '|' || op == '^' ||
4781                            op == 0x01 || op == 0xc9 || op == 0x02) &&
4782                           l2 == 0) ||
4783                          (op == '&' &&
4784                            (l2 == -1 || (l2 == 0xFFFFFFFF && t2 != 4))))) {
4785
4786            vtop--;
4787        } else if (c2 && (op == '*' || op == 0xb2 || op == 0xb0)) {
4788
4789            if (l2 > 0 && (l2 & (l2 - 1)) == 0) {
4790                int n = -1;
4791                while (l2) {
4792                    l2 >>= 1;
4793                    n++;
4794                }
4795                vtop->c.i = n;
4796                if (op == '*')
4797                    op = 0x01;
4798                else if (op == 0xb2)
4799                    op = 0x02;
4800                else
4801                    op = 0xc9;
4802            }
4803            goto general_case;
4804        } else if (c2 && (op == '+' || op == '-') &&
4805                   (((vtop[-1].r & (0x003f | 0x0100 | 0x0200)) == (0x0030 | 0x0200))
4806                    || (vtop[-1].r & (0x003f | 0x0100)) == 0x0032)) {
4807
4808            if (op == '-')
4809                l2 = -l2;
4810     l2 += vtop[-1].c.i;
4811
4812
4813     if ((int)l2 != l2)
4814         goto general_case;
4815            vtop--;
4816            vtop->c.i = l2;
4817        } else {
4818        general_case:
4819
4820                if (t1 == 4 || t2 == 4 ||
4821                    (8 == 8 && (t1 == 5 || t2 == 5)))
4822                    gen_opl(op);
4823                else
4824                    gen_opi(op);
4825        }
4826    }
4827}
4828
4829
4830static void gen_opif(int op)
4831{
4832    int c1, c2;
4833    SValue *v1, *v2;
4834
4835
4836
4837
4838    long double f1, f2;
4839
4840    v1 = vtop - 1;
4841    v2 = vtop;
4842
4843    c1 = (v1->r & (0x003f | 0x0100 | 0x0200)) == 0x0030;
4844    c2 = (v2->r & (0x003f | 0x0100 | 0x0200)) == 0x0030;
4845    if (c1 && c2) {
4846        if (v1->type.t == 8) {
4847            f1 = v1->c.f;
4848            f2 = v2->c.f;
4849        } else if (v1->type.t == 9) {
4850            f1 = v1->c.d;
4851            f2 = v2->c.d;
4852        } else {
4853            f1 = v1->c.ld;
4854            f2 = v2->c.ld;
4855        }
4856
4857
4858
4859        if (!ieee_finite(f1) || !ieee_finite(f2))
4860            goto general_case;
4861
4862        switch(op) {
4863        case '+': f1 += f2; break;
4864        case '-': f1 -= f2; break;
4865        case '*': f1 *= f2; break;
4866        case '/':
4867            if (f2 == 0.0) {
4868                if (const_wanted)
4869                    tcc_error("division by zero in constant");
4870                goto general_case;
4871            }
4872            f1 /= f2;
4873            break;
4874
4875        default:
4876            goto general_case;
4877        }
4878
4879        if (v1->type.t == 8) {
4880            v1->c.f = f1;
4881        } else if (v1->type.t == 9) {
4882            v1->c.d = f1;
4883        } else {
4884            v1->c.ld = f1;
4885        }
4886        vtop--;
4887    } else {
4888    general_case:
4889        gen_opf(op);
4890    }
4891}
4892
4893static int pointed_size(CType *type)
4894{
4895    int align;
4896    return type_size(pointed_type(type), &align);
4897}
4898
4899static void vla_runtime_pointed_size(CType *type)
4900{
4901    int align;
4902    vla_runtime_type_size(pointed_type(type), &align);
4903}
4904
4905static inline int is_null_pointer(SValue *p)
4906{
4907    if ((p->r & (0x003f | 0x0100 | 0x0200)) != 0x0030)
4908        return 0;
4909    return ((p->type.t & 0x000f) == 3 && (uint32_t)p->c.i == 0) ||
4910        ((p->type.t & 0x000f) == 4 && p->c.i == 0) ||
4911        ((p->type.t & 0x000f) == 5 &&
4912         (8 == 4 ? (uint32_t)p->c.i == 0 : p->c.i == 0));
4913}
4914
4915static inline int is_integer_btype(int bt)
4916{
4917    return (bt == 1 || bt == 2 ||
4918            bt == 3 || bt == 4);
4919}
4920
4921
4922static void check_comparison_pointer_types(SValue *p1, SValue *p2, int op)
4923{
4924    CType *type1, *type2, tmp_type1, tmp_type2;
4925    int bt1, bt2;
4926
4927
4928    if (is_null_pointer(p1) || is_null_pointer(p2))
4929        return;
4930    type1 = &p1->type;
4931    type2 = &p2->type;
4932    bt1 = type1->t & 0x000f;
4933    bt2 = type2->t & 0x000f;
4934
4935    if ((is_integer_btype(bt1) || is_integer_btype(bt2)) && op != '-') {
4936        if (op != 0xa1 && op != 0xa0 )
4937            tcc_warning("comparison between pointer and integer");
4938        return;
4939    }
4940
4941
4942    if (bt1 == 5) {
4943        type1 = pointed_type(type1);
4944    } else if (bt1 != 6)
4945        goto invalid_operands;
4946
4947    if (bt2 == 5) {
4948        type2 = pointed_type(type2);
4949    } else if (bt2 != 6) {
4950    invalid_operands:
4951        tcc_error("invalid operands to binary %s", get_tok_str(op, 0));
4952    }
4953    if ((type1->t & 0x000f) == 0 ||
4954        (type2->t & 0x000f) == 0)
4955        return;
4956    tmp_type1 = *type1;
4957    tmp_type2 = *type2;
4958    tmp_type1.t &= ~(0x0020 | 0x0010 | 0x0100 | 0x0200);
4959    tmp_type2.t &= ~(0x0020 | 0x0010 | 0x0100 | 0x0200);
4960    if (!is_compatible_types(&tmp_type1, &tmp_type2)) {
4961
4962        if (op == '-')
4963            goto invalid_operands;
4964        else
4965            tcc_warning("comparison of distinct pointer types lacks a cast");
4966    }
4967}
4968
4969
4970static void gen_op(int op)
4971{
4972    int u, t1, t2, bt1, bt2, t;
4973    CType type1;
4974
4975redo:
4976    t1 = vtop[-1].type.t;
4977    t2 = vtop[0].type.t;
4978    bt1 = t1 & 0x000f;
4979    bt2 = t2 & 0x000f;
4980
4981    if (bt1 == 7 || bt2 == 7) {
4982        tcc_error("operation on a struct");
4983    } else if (bt1 == 6 || bt2 == 6) {
4984 if (bt2 == 6) {
4985     mk_pointer(&vtop->type);
4986     gaddrof();
4987 }
4988 if (bt1 == 6) {
4989     vswap();
4990     mk_pointer(&vtop->type);
4991     gaddrof();
4992     vswap();
4993 }
4994 goto redo;
4995    } else if (bt1 == 5 || bt2 == 5) {
4996
4997
4998        if (op >= 0x92 && op <= 0xa1) {
4999            check_comparison_pointer_types(vtop - 1, vtop, op);
5000
5001
5002            t = 4 | 0x0010;
5003
5004
5005
5006            goto std_op;
5007        }
5008
5009        if (bt1 == 5 && bt2 == 5) {
5010            if (op != '-')
5011                tcc_error("cannot use pointers here");
5012            check_comparison_pointer_types(vtop - 1, vtop, op);
5013
5014            if (vtop[-1].type.t & 0x0400) {
5015                vla_runtime_pointed_size(&vtop[-1].type);
5016            } else {
5017                vpushi(pointed_size(&vtop[-1].type));
5018            }
5019            vrott(3);
5020            gen_opic(op);
5021            vtop->type.t = ptrdiff_type.t;
5022            vswap();
5023            gen_op(0xb2);
5024        } else {
5025
5026            if (op != '-' && op != '+')
5027                tcc_error("cannot use pointers here");
5028
5029            if (bt2 == 5) {
5030                vswap();
5031                t = t1, t1 = t2, t2 = t;
5032            }
5033
5034
5035
5036
5037
5038            type1 = vtop[-1].type;
5039            type1.t &= ~0x0040;
5040            if (vtop[-1].type.t & 0x0400)
5041                vla_runtime_pointed_size(&vtop[-1].type);
5042            else {
5043                u = pointed_size(&vtop[-1].type);
5044                if (u < 0)
5045                    tcc_error("unknown array element size");
5046
5047                vpushll(u);
5048
5049
5050
5051
5052            }
5053            gen_op('*');
5054# 2267 "tccgen.c"
5055            {
5056                gen_opic(op);
5057            }
5058
5059            vtop->type = type1;
5060        }
5061    } else if (is_float(bt1) || is_float(bt2)) {
5062
5063        if (bt1 == 10 || bt2 == 10) {
5064            t = 10;
5065        } else if (bt1 == 9 || bt2 == 9) {
5066            t = 9;
5067        } else {
5068            t = 8;
5069        }
5070
5071        if (op != '+' && op != '-' && op != '*' && op != '/' &&
5072            (op < 0x92 || op > 0x9f))
5073            tcc_error("invalid operands for binary operation");
5074        goto std_op;
5075    } else if (op == 0xc9 || op == 0x02 || op == 0x01) {
5076        t = bt1 == 4 ? 4 : 3;
5077        if ((t1 & (0x000f | 0x0010 | 0x0080)) == (t | 0x0010))
5078          t |= 0x0010;
5079        t |= (0x0800 & t1);
5080        goto std_op;
5081    } else if (bt1 == 4 || bt2 == 4) {
5082
5083        t = 4 | 0x0800;
5084        if (bt1 == 4)
5085            t &= t1;
5086        if (bt2 == 4)
5087            t &= t2;
5088
5089        if ((t1 & (0x000f | 0x0010 | 0x0080)) == (4 | 0x0010) ||
5090            (t2 & (0x000f | 0x0010 | 0x0080)) == (4 | 0x0010))
5091            t |= 0x0010;
5092        goto std_op;
5093    } else {
5094
5095        t = 3 | (0x0800 & (t1 | t2));
5096
5097        if ((t1 & (0x000f | 0x0010 | 0x0080)) == (3 | 0x0010) ||
5098            (t2 & (0x000f | 0x0010 | 0x0080)) == (3 | 0x0010))
5099            t |= 0x0010;
5100    std_op:
5101
5102
5103        if (t & 0x0010) {
5104            if (op == 0x02)
5105                op = 0xc9;
5106            else if (op == '/')
5107                op = 0xb0;
5108            else if (op == '%')
5109                op = 0xb1;
5110            else if (op == 0x9c)
5111                op = 0x92;
5112            else if (op == 0x9f)
5113                op = 0x97;
5114            else if (op == 0x9e)
5115                op = 0x96;
5116            else if (op == 0x9d)
5117                op = 0x93;
5118        }
5119        vswap();
5120        type1.t = t;
5121        type1.ref = 0;
5122        gen_cast(&type1);
5123        vswap();
5124
5125
5126        if (op == 0xc9 || op == 0x02 || op == 0x01)
5127            type1.t = 3;
5128        gen_cast(&type1);
5129        if (is_float(t))
5130            gen_opif(op);
5131        else
5132            gen_opic(op);
5133        if (op >= 0x92 && op <= 0x9f) {
5134
5135            vtop->type.t = 3;
5136        } else {
5137            vtop->type.t = t;
5138        }
5139    }
5140
5141    if (vtop->r & 0x0100)
5142        gv(is_float(vtop->type.t & 0x000f) ? 0x0002 : 0x0001);
5143}
5144
5145
5146
5147static void gen_cvt_itof1(int t)
5148{
5149
5150
5151
5152    if ((vtop->type.t & (0x000f | 0x0010)) ==
5153        (4 | 0x0010)) {
5154
5155        if (t == 8)
5156            vpush_global_sym(&func_old_type, TOK___floatundisf);
5157
5158        else if (t == 10)
5159            vpush_global_sym(&func_old_type, TOK___floatundixf);
5160
5161        else
5162            vpush_global_sym(&func_old_type, TOK___floatundidf);
5163        vrott(2);
5164        gfunc_call(1);
5165        vpushi(0);
5166        vtop->r = reg_fret(t);
5167    } else {
5168        gen_cvt_itof(t);
5169    }
5170
5171}
5172
5173
5174
5175static void gen_cvt_ftoi1(int t)
5176{
5177
5178
5179
5180    int st;
5181
5182    if (t == (4 | 0x0010)) {
5183
5184        st = vtop->type.t & 0x000f;
5185        if (st == 8)
5186            vpush_global_sym(&func_old_type, TOK___fixunssfdi);
5187
5188        else if (st == 10)
5189            vpush_global_sym(&func_old_type, TOK___fixunsxfdi);
5190
5191        else
5192            vpush_global_sym(&func_old_type, TOK___fixunsdfdi);
5193        vrott(2);
5194        gfunc_call(1);
5195        vpushi(0);
5196        vtop->r = TREG_RAX;
5197        vtop->r2 = TREG_RDX;
5198    } else {
5199        gen_cvt_ftoi(t);
5200    }
5201
5202}
5203
5204
5205static void force_charshort_cast(int t)
5206{
5207    int bits, dbt;
5208
5209
5210    if ((nocode_wanted & 0xC0000000))
5211 return;
5212
5213    dbt = t & 0x000f;
5214
5215    if (dbt == 1)
5216        bits = 8;
5217    else
5218        bits = 16;
5219    if (t & 0x0010) {
5220        vpushi((1 << bits) - 1);
5221        gen_op('&');
5222    } else {
5223        if ((vtop->type.t & 0x000f) == 4)
5224            bits = 64 - bits;
5225        else
5226            bits = 32 - bits;
5227        vpushi(bits);
5228        gen_op(0x01);
5229
5230
5231
5232        vtop->type.t &= ~0x0010;
5233        vpushi(bits);
5234        gen_op(0x02);
5235    }
5236}
5237
5238
5239static void gen_cast_s(int t)
5240{
5241    CType type;
5242    type.t = t;
5243    type.ref = 0;
5244    gen_cast(&type);
5245}
5246
5247static void gen_cast(CType *type)
5248{
5249    int sbt, dbt, sf, df, c, p;
5250
5251
5252
5253
5254    if (vtop->r & 0x0400) {
5255        vtop->r &= ~0x0400;
5256        force_charshort_cast(vtop->type.t);
5257    }
5258
5259
5260    if (vtop->type.t & 0x0080) {
5261        gv(0x0001);
5262    }
5263
5264    dbt = type->t & (0x000f | 0x0010);
5265    sbt = vtop->type.t & (0x000f | 0x0010);
5266
5267    if (sbt != dbt) {
5268        sf = is_float(sbt);
5269        df = is_float(dbt);
5270        c = (vtop->r & (0x003f | 0x0100 | 0x0200)) == 0x0030;
5271        p = (vtop->r & (0x003f | 0x0100 | 0x0200)) == (0x0030 | 0x0200);
5272
5273
5274
5275        if (c) {
5276
5277
5278            if (sbt == 8)
5279                vtop->c.ld = vtop->c.f;
5280            else if (sbt == 9)
5281                vtop->c.ld = vtop->c.d;
5282
5283            if (df) {
5284                if ((sbt & 0x000f) == 4) {
5285                    if ((sbt & 0x0010) || !(vtop->c.i >> 63))
5286                        vtop->c.ld = vtop->c.i;
5287                    else
5288                        vtop->c.ld = -(long double)-vtop->c.i;
5289                } else if(!sf) {
5290                    if ((sbt & 0x0010) || !(vtop->c.i >> 31))
5291                        vtop->c.ld = (uint32_t)vtop->c.i;
5292                    else
5293                        vtop->c.ld = -(long double)-(uint32_t)vtop->c.i;
5294                }
5295
5296                if (dbt == 8)
5297                    vtop->c.f = (float)vtop->c.ld;
5298                else if (dbt == 9)
5299                    vtop->c.d = (double)vtop->c.ld;
5300            } else if (sf && dbt == (4|0x0010)) {
5301                vtop->c.i = vtop->c.ld;
5302            } else if (sf && dbt == 11) {
5303                vtop->c.i = (vtop->c.ld != 0);
5304            } else {
5305                if(sf)
5306                    vtop->c.i = vtop->c.ld;
5307                else if (sbt == (4|0x0010))
5308                    ;
5309                else if (sbt & 0x0010)
5310                    vtop->c.i = (uint32_t)vtop->c.i;
5311
5312                else if (sbt == 5)
5313                    ;
5314
5315                else if (sbt != 4)
5316                    vtop->c.i = ((uint32_t)vtop->c.i |
5317                                  -(vtop->c.i & 0x80000000));
5318
5319                if (dbt == (4|0x0010))
5320                    ;
5321                else if (dbt == 11)
5322                    vtop->c.i = (vtop->c.i != 0);
5323
5324                else if (dbt == 5)
5325                    ;
5326
5327                else if (dbt != 4) {
5328                    uint32_t m = ((dbt & 0x000f) == 1 ? 0xff :
5329                                  (dbt & 0x000f) == 2 ? 0xffff :
5330                                  0xffffffff);
5331                    vtop->c.i &= m;
5332                    if (!(dbt & 0x0010))
5333                        vtop->c.i |= -(vtop->c.i & ((m >> 1) + 1));
5334                }
5335            }
5336        } else if (p && dbt == 11) {
5337            vtop->r = 0x0030;
5338            vtop->c.i = 1;
5339        } else {
5340
5341            if (sf && df) {
5342
5343                gen_cvt_ftof(dbt);
5344            } else if (df) {
5345
5346                gen_cvt_itof1(dbt);
5347            } else if (sf) {
5348
5349                if (dbt == 11) {
5350                     vpushi(0);
5351                     gen_op(0x95);
5352                } else {
5353
5354                    if (dbt != (3 | 0x0010) &&
5355                        dbt != (4 | 0x0010) &&
5356                        dbt != 4)
5357                        dbt = 3;
5358                    gen_cvt_ftoi1(dbt);
5359                    if (dbt == 3 && (type->t & (0x000f | 0x0010)) != dbt) {
5360
5361                        vtop->type.t = dbt;
5362                        gen_cast(type);
5363                    }
5364                }
5365# 2602 "tccgen.c"
5366            } else if ((dbt & 0x000f) == 4 ||
5367                       (dbt & 0x000f) == 5 ||
5368                       (dbt & 0x000f) == 6) {
5369                if ((sbt & 0x000f) != 4 &&
5370                    (sbt & 0x000f) != 5 &&
5371                    (sbt & 0x000f) != 6) {
5372
5373                    gv(0x0001);
5374                    if (sbt != (3 | 0x0010)) {
5375
5376
5377
5378                        int r = gv(0x0001);
5379
5380                        o(0x6348);
5381                        o(0xc0 + (((r) & 7) << 3) + ((r) & 7));
5382
5383
5384
5385                    }
5386                }
5387
5388            } else if (dbt == 11) {
5389
5390                vpushi(0);
5391                gen_op(0x95);
5392            } else if ((dbt & 0x000f) == 1 ||
5393                       (dbt & 0x000f) == 2) {
5394                if (sbt == 5) {
5395                    vtop->type.t = 3;
5396                    tcc_warning("nonportable conversion from pointer to char/short");
5397                }
5398                force_charshort_cast(dbt);
5399# 2647 "tccgen.c"
5400            }
5401        }
5402    } else if ((dbt & 0x000f) == 5 && !(vtop->r & 0x0100)) {
5403
5404
5405        vtop->r = (vtop->r & ~(0x1000 | 0x2000 | 0x4000))
5406                  | (lvalue_type(type->ref->type.t) & (0x1000 | 0x2000 | 0x4000));
5407    }
5408    vtop->type = *type;
5409}
5410
5411
5412static int type_size(CType *type, int *a)
5413{
5414    Sym *s;
5415    int bt;
5416
5417    bt = type->t & 0x000f;
5418    if (bt == 7) {
5419
5420        s = type->ref;
5421        *a = s->r;
5422        return s->c;
5423    } else if (bt == 5) {
5424        if (type->t & 0x0040) {
5425            int ts;
5426
5427            s = type->ref;
5428            ts = type_size(&s->type, a);
5429
5430            if (ts < 0 && s->c < 0)
5431                ts = -ts;
5432
5433            return ts * s->c;
5434        } else {
5435            *a = 8;
5436            return 8;
5437        }
5438    } else if (((type->t & (((1 << (6+6)) - 1) << 20 | 0x0080)) == (2 << 20)) && type->ref->c == -1) {
5439        return -1;
5440    } else if (bt == 10) {
5441        *a = 16;
5442        return 16;
5443    } else if (bt == 9 || bt == 4) {
5444# 2704 "tccgen.c"
5445        *a = 8;
5446
5447        return 8;
5448    } else if (bt == 3 || bt == 8) {
5449        *a = 4;
5450        return 4;
5451    } else if (bt == 2) {
5452        *a = 2;
5453        return 2;
5454    } else if (bt == 13 || bt == 14) {
5455        *a = 8;
5456        return 16;
5457    } else {
5458
5459        *a = 1;
5460        return 1;
5461    }
5462}
5463
5464
5465
5466static void vla_runtime_type_size(CType *type, int *a)
5467{
5468    if (type->t & 0x0400) {
5469        type_size(&type->ref->type, a);
5470        vset(&int_type, 0x0032|0x0100, type->ref->c);
5471    } else {
5472        vpushi(type_size(type, a));
5473    }
5474}
5475
5476static void vla_sp_restore(void) {
5477    if (vlas_in_scope) {
5478        gen_vla_sp_restore(vla_sp_loc);
5479    }
5480}
5481
5482static void vla_sp_restore_root(void) {
5483    if (vlas_in_scope) {
5484        gen_vla_sp_restore(vla_sp_root_loc);
5485    }
5486}
5487
5488
5489static inline CType *pointed_type(CType *type)
5490{
5491    return &type->ref->type;
5492}
5493
5494
5495static void mk_pointer(CType *type)
5496{
5497    Sym *s;
5498    s = sym_push(0x20000000, type, 0, -1);
5499    type->t = 5 | (type->t & (0x00001000 | 0x00002000 | 0x00004000 | 0x00008000));
5500    type->ref = s;
5501}
5502
5503
5504static int is_compatible_func(CType *type1, CType *type2)
5505{
5506    Sym *s1, *s2;
5507
5508    s1 = type1->ref;
5509    s2 = type2->ref;
5510    if (!is_compatible_types(&s1->type, &s2->type))
5511        return 0;
5512
5513    if (s1->f.func_call != s2->f.func_call)
5514        return 0;
5515
5516    if (s1->f.func_type == 2 || s2->f.func_type == 2)
5517        return 1;
5518    if (s1->f.func_type != s2->f.func_type)
5519        return 0;
5520    while (s1 != 0) {
5521        if (s2 == 0)
5522            return 0;
5523        if (!is_compatible_unqualified_types(&s1->type, &s2->type))
5524            return 0;
5525        s1 = s1->next;
5526        s2 = s2->next;
5527    }
5528    if (s2)
5529        return 0;
5530    return 1;
5531}
5532
5533
5534
5535
5536
5537
5538static int compare_types(CType *type1, CType *type2, int unqualified)
5539{
5540    int bt1, t1, t2;
5541
5542    t1 = type1->t & (~((0x00001000 | 0x00002000 | 0x00004000 | 0x00008000)|(((1 << (6+6)) - 1) << 20 | 0x0080)));
5543    t2 = type2->t & (~((0x00001000 | 0x00002000 | 0x00004000 | 0x00008000)|(((1 << (6+6)) - 1) << 20 | 0x0080)));
5544    if (unqualified) {
5545
5546        t1 &= ~(0x0100 | 0x0200);
5547        t2 &= ~(0x0100 | 0x0200);
5548    }
5549
5550
5551    if ((t1 & 0x000f) != 1) {
5552        t1 &= ~0x0020;
5553        t2 &= ~0x0020;
5554    }
5555
5556    if (t1 != t2)
5557        return 0;
5558
5559    bt1 = t1 & 0x000f;
5560    if (bt1 == 5) {
5561        type1 = pointed_type(type1);
5562        type2 = pointed_type(type2);
5563        return is_compatible_types(type1, type2);
5564    } else if (bt1 == 7) {
5565        return (type1->ref == type2->ref);
5566    } else if (bt1 == 6) {
5567        return is_compatible_func(type1, type2);
5568    } else {
5569        return 1;
5570    }
5571}
5572
5573
5574
5575
5576static int is_compatible_types(CType *type1, CType *type2)
5577{
5578    return compare_types(type1,type2,0);
5579}
5580
5581
5582
5583static int is_compatible_unqualified_types(CType *type1, CType *type2)
5584{
5585    return compare_types(type1,type2,1);
5586}
5587
5588
5589
5590
5591
5592static void type_to_str(char *buf, int buf_size,
5593                 CType *type, const char *varstr)
5594{
5595    int bt, v, t;
5596    Sym *s, *sa;
5597    char buf1[256];
5598    const char *tstr;
5599
5600    t = type->t;
5601    bt = t & 0x000f;
5602    buf[0] = '\0';
5603
5604    if (t & 0x00001000)
5605        pstrcat(buf, buf_size, "extern ");
5606    if (t & 0x00002000)
5607        pstrcat(buf, buf_size, "static ");
5608    if (t & 0x00004000)
5609        pstrcat(buf, buf_size, "typedef ");
5610    if (t & 0x00008000)
5611        pstrcat(buf, buf_size, "inline ");
5612    if (t & 0x0200)
5613        pstrcat(buf, buf_size, "volatile ");
5614    if (t & 0x0100)
5615        pstrcat(buf, buf_size, "const ");
5616
5617    if (((t & 0x0020) && bt == 1)
5618        || ((t & 0x0010)
5619            && (bt == 2 || bt == 3 || bt == 4)
5620            && !((t & (((1 << (6+6)) - 1) << 20 | 0x0080)) == (2 << 20))
5621            ))
5622        pstrcat(buf, buf_size, (t & 0x0010) ? "unsigned " : "signed ");
5623
5624    buf_size -= strlen(buf);
5625    buf += strlen(buf);
5626
5627    switch(bt) {
5628    case 0:
5629        tstr = "void";
5630        goto add_tstr;
5631    case 11:
5632        tstr = "_Bool";
5633        goto add_tstr;
5634    case 1:
5635        tstr = "char";
5636        goto add_tstr;
5637    case 2:
5638        tstr = "short";
5639        goto add_tstr;
5640    case 3:
5641        tstr = "int";
5642        goto maybe_long;
5643    case 4:
5644        tstr = "long long";
5645    maybe_long:
5646        if (t & 0x0800)
5647            tstr = "long";
5648        if (!((t & (((1 << (6+6)) - 1) << 20 | 0x0080)) == (2 << 20)))
5649            goto add_tstr;
5650        tstr = "enum ";
5651        goto tstruct;
5652    case 8:
5653        tstr = "float";
5654        goto add_tstr;
5655    case 9:
5656        tstr = "double";
5657        goto add_tstr;
5658    case 10:
5659        tstr = "long double";
5660    add_tstr:
5661        pstrcat(buf, buf_size, tstr);
5662        break;
5663    case 7:
5664        tstr = "struct ";
5665        if (((t & ((((1 << (6+6)) - 1) << 20 | 0x0080)|0x000f)) == (1 << 20 | 7)))
5666            tstr = "union ";
5667    tstruct:
5668        pstrcat(buf, buf_size, tstr);
5669        v = type->ref->v & ~0x40000000;
5670        if (v >= 0x10000000)
5671            pstrcat(buf, buf_size, "<anonymous>");
5672        else
5673            pstrcat(buf, buf_size, get_tok_str(v, 0));
5674        break;
5675    case 6:
5676        s = type->ref;
5677        type_to_str(buf, buf_size, &s->type, varstr);
5678        pstrcat(buf, buf_size, "(");
5679        sa = s->next;
5680        while (sa != 0) {
5681            type_to_str(buf1, sizeof(buf1), &sa->type, 0);
5682            pstrcat(buf, buf_size, buf1);
5683            sa = sa->next;
5684            if (sa)
5685                pstrcat(buf, buf_size, ", ");
5686        }
5687        pstrcat(buf, buf_size, ")");
5688        goto no_var;
5689    case 5:
5690        s = type->ref;
5691        if (t & 0x0040) {
5692            snprintf(buf1, sizeof(buf1), "%s[%d]", varstr ? varstr : "", s->c);
5693            type_to_str(buf, buf_size, &s->type, buf1);
5694            goto no_var;
5695        }
5696        pstrcpy(buf1, sizeof(buf1), "*");
5697        if (t & 0x0100)
5698            pstrcat(buf1, buf_size, "const ");
5699        if (t & 0x0200)
5700            pstrcat(buf1, buf_size, "volatile ");
5701        if (varstr)
5702            pstrcat(buf1, sizeof(buf1), varstr);
5703        type_to_str(buf, buf_size, &s->type, buf1);
5704        goto no_var;
5705    }
5706    if (varstr) {
5707        pstrcat(buf, buf_size, " ");
5708        pstrcat(buf, buf_size, varstr);
5709    }
5710 no_var: ;
5711}
5712
5713
5714
5715static void gen_assign_cast(CType *dt)
5716{
5717    CType *st, *type1, *type2;
5718    char buf1[256], buf2[256];
5719    int dbt, sbt;
5720
5721    st = &vtop->type;
5722    dbt = dt->t & 0x000f;
5723    sbt = st->t & 0x000f;
5724    if (sbt == 0 || dbt == 0) {
5725 if (sbt == 0 && dbt == 0)
5726     ;
5727# 2994 "tccgen.c"
5728 else
5729         tcc_error("cannot cast from/to void");
5730    }
5731    if (dt->t & 0x0100)
5732        tcc_warning("assignment of read-only location");
5733    switch(dbt) {
5734    case 5:
5735
5736
5737        if (is_null_pointer(vtop))
5738            goto type_ok;
5739
5740        if (is_integer_btype(sbt)) {
5741            tcc_warning("assignment makes pointer from integer without a cast");
5742            goto type_ok;
5743        }
5744        type1 = pointed_type(dt);
5745
5746        if (sbt == 6) {
5747            if ((type1->t & 0x000f) != 0 &&
5748                !is_compatible_types(pointed_type(dt), st))
5749                tcc_warning("assignment from incompatible pointer type");
5750            goto type_ok;
5751        }
5752        if (sbt != 5)
5753            goto error;
5754        type2 = pointed_type(st);
5755        if ((type1->t & 0x000f) == 0 ||
5756            (type2->t & 0x000f) == 0) {
5757
5758        } else {
5759
5760
5761            if (!is_compatible_unqualified_types(type1, type2)) {
5762
5763
5764
5765
5766  if ((type1->t & (0x000f|0x0800)) != (type2->t & (0x000f|0x0800))
5767                    || ((type1->t & (((1 << (6+6)) - 1) << 20 | 0x0080)) == (2 << 20)) || ((type2->t & (((1 << (6+6)) - 1) << 20 | 0x0080)) == (2 << 20))
5768                    )
5769      tcc_warning("assignment from incompatible pointer type");
5770     }
5771        }
5772
5773        if ((!(type1->t & 0x0100) && (type2->t & 0x0100)) ||
5774            (!(type1->t & 0x0200) && (type2->t & 0x0200)))
5775            tcc_warning("assignment discards qualifiers from pointer target type");
5776        break;
5777    case 1:
5778    case 2:
5779    case 3:
5780    case 4:
5781        if (sbt == 5 || sbt == 6) {
5782            tcc_warning("assignment makes integer from pointer without a cast");
5783        } else if (sbt == 7) {
5784            goto case_VT_STRUCT;
5785        }
5786
5787        break;
5788    case 7:
5789    case_VT_STRUCT:
5790        if (!is_compatible_unqualified_types(dt, st)) {
5791        error:
5792            type_to_str(buf1, sizeof(buf1), st, 0);
5793            type_to_str(buf2, sizeof(buf2), dt, 0);
5794            tcc_error("cannot cast '%s' to '%s'", buf1, buf2);
5795        }
5796        break;
5797    }
5798 type_ok:
5799    gen_cast(dt);
5800}
5801
5802
5803static void vstore(void)
5804{
5805    int sbt, dbt, ft, r, t, size, align, bit_size, bit_pos, rc, delayed_cast;
5806
5807    ft = vtop[-1].type.t;
5808    sbt = vtop->type.t & 0x000f;
5809    dbt = ft & 0x000f;
5810    if ((((sbt == 3 || sbt == 2) && dbt == 1) ||
5811         (sbt == 3 && dbt == 2))
5812 && !(vtop->type.t & 0x0080)) {
5813
5814        delayed_cast = 0x0400;
5815        vtop->type.t = ft & (~((0x00001000 | 0x00002000 | 0x00004000 | 0x00008000)|(((1 << (6+6)) - 1) << 20 | 0x0080)));
5816
5817        if (ft & 0x0100)
5818            tcc_warning("assignment of read-only location");
5819    } else {
5820        delayed_cast = 0;
5821        if (!(ft & 0x0080))
5822            gen_assign_cast(&vtop[-1].type);
5823    }
5824
5825    if (sbt == 7) {
5826
5827
5828
5829            size = type_size(&vtop->type, &align);
5830
5831
5832            vswap();
5833            vtop->type.t = 5;
5834            gaddrof();
5835# 3111 "tccgen.c"
5836            vpush_global_sym(&func_old_type, TOK_memmove);
5837
5838            vswap();
5839
5840            vpushv(vtop - 2);
5841            vtop->type.t = 5;
5842            gaddrof();
5843
5844            vpushi(size);
5845            gfunc_call(3);
5846
5847
5848    } else if (ft & 0x0080) {
5849
5850
5851
5852        vdup(), vtop[-1] = vtop[-2];
5853
5854        bit_pos = (((ft) >> 20) & 0x3f);
5855        bit_size = (((ft) >> (20 + 6)) & 0x3f);
5856
5857        vtop[-1].type.t = ft & ~(((1 << (6+6)) - 1) << 20 | 0x0080);
5858
5859        if ((ft & 0x000f) == 11) {
5860            gen_cast(&vtop[-1].type);
5861            vtop[-1].type.t = (vtop[-1].type.t & ~0x000f) | (1 | 0x0010);
5862        }
5863
5864        r = adjust_bf(vtop - 1, bit_pos, bit_size);
5865        if (r == 7) {
5866            gen_cast_s((ft & 0x000f) == 4 ? 4 : 3);
5867            store_packed_bf(bit_pos, bit_size);
5868        } else {
5869            unsigned long long mask = (1ULL << bit_size) - 1;
5870            if ((ft & 0x000f) != 11) {
5871
5872                if ((vtop[-1].type.t & 0x000f) == 4)
5873                    vpushll(mask);
5874                else
5875                    vpushi((unsigned)mask);
5876                gen_op('&');
5877            }
5878
5879            vpushi(bit_pos);
5880            gen_op(0x01);
5881            vswap();
5882
5883            vdup();
5884            vrott(3);
5885
5886            if ((vtop->type.t & 0x000f) == 4)
5887                vpushll(~(mask << bit_pos));
5888            else
5889                vpushi(~((unsigned)mask << bit_pos));
5890            gen_op('&');
5891            gen_op('|');
5892
5893            vstore();
5894
5895            vpop();
5896        }
5897    } else if (dbt == 0) {
5898        --vtop;
5899    } else {
5900
5901
5902            if (vtop[-1].r & 0x0800) {
5903                vswap();
5904                gbound();
5905                vswap();
5906            }
5907
5908            rc = 0x0001;
5909            if (is_float(ft)) {
5910                rc = 0x0002;
5911
5912                if ((ft & 0x000f) == 10) {
5913                    rc = 0x0080;
5914                } else if ((ft & 0x000f) == 14) {
5915                    rc = 0x1000;
5916                }
5917
5918            }
5919            r = gv(rc);
5920
5921            if ((vtop[-1].r & 0x003f) == 0x0031) {
5922                SValue sv;
5923                t = get_reg(0x0001);
5924
5925                sv.type.t = 5;
5926
5927
5928
5929                sv.r = 0x0032 | 0x0100;
5930                sv.c.i = vtop[-1].c.i;
5931                load(t, &sv);
5932                vtop[-1].r = t | 0x0100;
5933            }
5934
5935
5936            if (((ft & 0x000f) == 13) || ((ft & 0x000f) == 14)) {
5937                int addr_type = 4, load_size = 8, load_type = ((vtop->type.t & 0x000f) == 13) ? 4 : 9;
5938
5939
5940
5941
5942                vtop[-1].type.t = load_type;
5943                store(r, vtop - 1);
5944                vswap();
5945
5946                vtop->type.t = addr_type;
5947                gaddrof();
5948                vpushi(load_size);
5949                gen_op('+');
5950                vtop->r |= 0x0100;
5951                vswap();
5952                vtop[-1].type.t = load_type;
5953
5954                store(vtop->r2, vtop - 1);
5955            } else {
5956                store(r, vtop - 1);
5957            }
5958
5959        vswap();
5960        vtop--;
5961        vtop->r |= delayed_cast;
5962    }
5963}
5964
5965
5966static void inc(int post, int c)
5967{
5968    test_lvalue();
5969    vdup();
5970    if (post) {
5971        gv_dup();
5972        vrotb(3);
5973        vrotb(3);
5974    }
5975
5976    vpushi(c - 0xa3);
5977    gen_op('+');
5978    vstore();
5979    if (post)
5980        vpop();
5981}
5982
5983static void parse_mult_str (CString *astr, const char *msg)
5984{
5985
5986    if (tok != 0xb9)
5987        expect(msg);
5988    cstr_new(astr);
5989    while (tok == 0xb9) {
5990
5991        cstr_cat(astr, tokc.str.data, -1);
5992        next();
5993    }
5994    cstr_ccat(astr, '\0');
5995}
5996
5997
5998
5999static int exact_log2p1(int i)
6000{
6001  int ret;
6002  if (!i)
6003    return 0;
6004  for (ret = 1; i >= 1 << 8; ret += 8)
6005    i >>= 8;
6006  if (i >= 1 << 4)
6007    ret += 4, i >>= 4;
6008  if (i >= 1 << 2)
6009    ret += 2, i >>= 2;
6010  if (i >= 1 << 1)
6011    ret++;
6012  return ret;
6013}
6014
6015
6016static void parse_attribute(AttributeDef *ad)
6017{
6018    int t, n;
6019    CString astr;
6020
6021redo:
6022    if (tok != TOK_ATTRIBUTE1 && tok != TOK_ATTRIBUTE2)
6023        return;
6024    next();
6025    skip('(');
6026    skip('(');
6027    while (tok != ')') {
6028        if (tok < 256)
6029            expect("attribute name");
6030        t = tok;
6031        next();
6032        switch(t) {
6033        case TOK_SECTION1:
6034        case TOK_SECTION2:
6035            skip('(');
6036     parse_mult_str(&astr, "section name");
6037            ad->section = find_section(tcc_state, (char *)astr.data);
6038            skip(')');
6039     cstr_free(&astr);
6040            break;
6041        case TOK_ALIAS1:
6042        case TOK_ALIAS2:
6043            skip('(');
6044     parse_mult_str(&astr, "alias(\"target\")");
6045            ad->alias_target =
6046              tok_alloc((char*)astr.data, astr.size-1)->tok;
6047            skip(')');
6048     cstr_free(&astr);
6049            break;
6050 case TOK_VISIBILITY1:
6051 case TOK_VISIBILITY2:
6052            skip('(');
6053     parse_mult_str(&astr,
6054      "visibility(\"default|hidden|internal|protected\")");
6055     if (!strcmp (astr.data, "default"))
6056         ad->a.visibility = 0;
6057     else if (!strcmp (astr.data, "hidden"))
6058         ad->a.visibility = 2;
6059     else if (!strcmp (astr.data, "internal"))
6060         ad->a.visibility = 1;
6061     else if (!strcmp (astr.data, "protected"))
6062         ad->a.visibility = 3;
6063     else
6064                expect("visibility(\"default|hidden|internal|protected\")");
6065            skip(')');
6066     cstr_free(&astr);
6067            break;
6068        case TOK_ALIGNED1:
6069        case TOK_ALIGNED2:
6070            if (tok == '(') {
6071                next();
6072                n = expr_const();
6073                if (n <= 0 || (n & (n - 1)) != 0)
6074                    tcc_error("alignment must be a positive power of two");
6075                skip(')');
6076            } else {
6077                n = 16;
6078            }
6079            ad->a.aligned = exact_log2p1(n);
6080     if (n != 1 << (ad->a.aligned - 1))
6081       tcc_error("alignment of %d is larger than implemented", n);
6082            break;
6083        case TOK_PACKED1:
6084        case TOK_PACKED2:
6085            ad->a.packed = 1;
6086            break;
6087        case TOK_WEAK1:
6088        case TOK_WEAK2:
6089            ad->a.weak = 1;
6090            break;
6091        case TOK_UNUSED1:
6092        case TOK_UNUSED2:
6093
6094
6095            break;
6096        case TOK_NORETURN1:
6097        case TOK_NORETURN2:
6098
6099
6100            break;
6101        case TOK_CDECL1:
6102        case TOK_CDECL2:
6103        case TOK_CDECL3:
6104            ad->f.func_call = 0;
6105            break;
6106        case TOK_STDCALL1:
6107        case TOK_STDCALL2:
6108        case TOK_STDCALL3:
6109            ad->f.func_call = 1;
6110            break;
6111# 3405 "tccgen.c"
6112        case TOK_MODE:
6113            skip('(');
6114            switch(tok) {
6115                case TOK_MODE_DI:
6116                    ad->attr_mode = 4 + 1;
6117                    break;
6118                case TOK_MODE_QI:
6119                    ad->attr_mode = 1 + 1;
6120                    break;
6121                case TOK_MODE_HI:
6122                    ad->attr_mode = 2 + 1;
6123                    break;
6124                case TOK_MODE_SI:
6125                case TOK_MODE_word:
6126                    ad->attr_mode = 3 + 1;
6127                    break;
6128                default:
6129                    tcc_warning("__mode__(%s) not supported\n", get_tok_str(tok, 0));
6130                    break;
6131            }
6132            next();
6133            skip(')');
6134            break;
6135        case TOK_DLLEXPORT:
6136            ad->a.dllexport = 1;
6137            break;
6138        case TOK_DLLIMPORT:
6139            ad->a.dllimport = 1;
6140            break;
6141        default:
6142            if (tcc_state->warn_unsupported)
6143                tcc_warning("'%s' attribute ignored", get_tok_str(t, 0));
6144
6145            if (tok == '(') {
6146                int parenthesis = 0;
6147                do {
6148                    if (tok == '(')
6149                        parenthesis++;
6150                    else if (tok == ')')
6151                        parenthesis--;
6152                    next();
6153                } while (parenthesis && tok != -1);
6154            }
6155            break;
6156        }
6157        if (tok != ',')
6158            break;
6159        next();
6160    }
6161    skip(')');
6162    skip(')');
6163    goto redo;
6164}
6165
6166static Sym * find_field (CType *type, int v)
6167{
6168    Sym *s = type->ref;
6169    v |= 0x20000000;
6170    while ((s = s->next) != 0) {
6171 if ((s->v & 0x20000000) &&
6172     (s->type.t & 0x000f) == 7 &&
6173     (s->v & ~0x20000000) >= 0x10000000) {
6174     Sym *ret = find_field (&s->type, v);
6175     if (ret)
6176         return ret;
6177 }
6178 if (s->v == v)
6179   break;
6180    }
6181    return s;
6182}
6183
6184static void struct_add_offset (Sym *s, int offset)
6185{
6186    while ((s = s->next) != 0) {
6187 if ((s->v & 0x20000000) &&
6188     (s->type.t & 0x000f) == 7 &&
6189     (s->v & ~0x20000000) >= 0x10000000) {
6190     struct_add_offset(s->type.ref, offset);
6191 } else
6192   s->c += offset;
6193    }
6194}
6195
6196static void struct_layout(CType *type, AttributeDef *ad)
6197{
6198    int size, align, maxalign, offset, c, bit_pos, bit_size;
6199    int packed, a, bt, prevbt, prev_bit_size;
6200    int pcc = !tcc_state->ms_bitfields;
6201    int pragma_pack = *tcc_state->pack_stack_ptr;
6202    Sym *f;
6203
6204    maxalign = 1;
6205    offset = 0;
6206    c = 0;
6207    bit_pos = 0;
6208    prevbt = 7;
6209    prev_bit_size = 0;
6210
6211
6212
6213    for (f = type->ref->next; f; f = f->next) {
6214        if (f->type.t & 0x0080)
6215            bit_size = (((f->type.t) >> (20 + 6)) & 0x3f);
6216        else
6217            bit_size = -1;
6218        size = type_size(&f->type, &align);
6219        a = f->a.aligned ? 1 << (f->a.aligned - 1) : 0;
6220        packed = 0;
6221
6222        if (pcc && bit_size == 0) {
6223
6224
6225        } else {
6226
6227            if (pcc && (f->a.packed || ad->a.packed))
6228                align = packed = 1;
6229
6230
6231            if (pragma_pack) {
6232                packed = 1;
6233                if (pragma_pack < align)
6234                    align = pragma_pack;
6235
6236                if (pcc && pragma_pack < a)
6237                    a = 0;
6238            }
6239        }
6240
6241        if (a)
6242            align = a;
6243
6244        if (type->ref->type.t == (1 << 20 | 7)) {
6245     if (pcc && bit_size >= 0)
6246         size = (bit_size + 7) >> 3;
6247     offset = 0;
6248     if (size > c)
6249         c = size;
6250
6251 } else if (bit_size < 0) {
6252            if (pcc)
6253                c += (bit_pos + 7) >> 3;
6254     c = (c + align - 1) & -align;
6255     offset = c;
6256     if (size > 0)
6257         c += size;
6258     bit_pos = 0;
6259     prevbt = 7;
6260     prev_bit_size = 0;
6261
6262 } else {
6263
6264
6265            if (pcc) {
6266
6267
6268
6269
6270
6271
6272                if (bit_size == 0) {
6273            new_field:
6274      c = (c + ((bit_pos + 7) >> 3) + align - 1) & -align;
6275      bit_pos = 0;
6276                } else if (f->a.aligned) {
6277                    goto new_field;
6278                } else if (!packed) {
6279                    int a8 = align * 8;
6280             int ofs = ((c * 8 + bit_pos) % a8 + bit_size + a8 - 1) / a8;
6281                    if (ofs > size / align)
6282                        goto new_field;
6283                }
6284
6285
6286                if (size == 8 && bit_size <= 32)
6287                    f->type.t = (f->type.t & ~0x000f) | 3, size = 4;
6288
6289                while (bit_pos >= align * 8)
6290                    c += align, bit_pos -= align * 8;
6291                offset = c;
6292
6293
6294
6295
6296  if (f->v & 0x10000000
6297
6298                    )
6299      align = 1;
6300
6301     } else {
6302  bt = f->type.t & 0x000f;
6303  if ((bit_pos + bit_size > size * 8)
6304                    || (bit_size > 0) == (bt != prevbt)
6305                    ) {
6306      c = (c + align - 1) & -align;
6307      offset = c;
6308      bit_pos = 0;
6309
6310
6311
6312
6313      if (bit_size || prev_bit_size)
6314          c += size;
6315  }
6316
6317
6318
6319
6320  if (bit_size == 0 && prevbt != bt)
6321      align = 1;
6322  prevbt = bt;
6323                prev_bit_size = bit_size;
6324     }
6325
6326     f->type.t = (f->type.t & ~(0x3f << 20))
6327          | (bit_pos << 20);
6328     bit_pos += bit_size;
6329 }
6330 if (align > maxalign)
6331     maxalign = align;
6332# 3638 "tccgen.c"
6333 if (f->v & 0x10000000 && (f->type.t & 0x000f) == 7) {
6334     Sym *ass;
6335
6336
6337
6338
6339
6340
6341
6342     int v2 = f->type.ref->v;
6343     if (!(v2 & 0x20000000) &&
6344  (v2 & ~0x40000000) < 0x10000000) {
6345  Sym **pps;
6346
6347
6348
6349
6350
6351  ass = f->type.ref;
6352  f->type.ref = sym_push(anon_sym++ | 0x20000000,
6353           &f->type.ref->type, 0,
6354           f->type.ref->c);
6355  pps = &f->type.ref->next;
6356  while ((ass = ass->next) != 0) {
6357      *pps = sym_push(ass->v, &ass->type, 0, ass->c);
6358      pps = &((*pps)->next);
6359  }
6360  *pps = 0;
6361     }
6362     struct_add_offset(f->type.ref, offset);
6363     f->c = 0;
6364 } else {
6365     f->c = offset;
6366 }
6367
6368 f->r = 0;
6369    }
6370
6371    if (pcc)
6372        c += (bit_pos + 7) >> 3;
6373
6374
6375    a = bt = ad->a.aligned ? 1 << (ad->a.aligned - 1) : 1;
6376    if (a < maxalign)
6377        a = maxalign;
6378    type->ref->r = a;
6379    if (pragma_pack && pragma_pack < maxalign && 0 == pcc) {
6380
6381
6382        a = pragma_pack;
6383        if (a < bt)
6384            a = bt;
6385    }
6386    c = (c + a - 1) & -a;
6387    type->ref->c = c;
6388
6389
6390
6391
6392
6393
6394    for (f = type->ref->next; f; f = f->next) {
6395        int s, px, cx, c0;
6396        CType t;
6397
6398        if (0 == (f->type.t & 0x0080))
6399            continue;
6400        f->type.ref = f;
6401        f->auxtype = -1;
6402        bit_size = (((f->type.t) >> (20 + 6)) & 0x3f);
6403        if (bit_size == 0)
6404            continue;
6405        bit_pos = (((f->type.t) >> 20) & 0x3f);
6406        size = type_size(&f->type, &align);
6407        if (bit_pos + bit_size <= size * 8 && f->c + size <= c)
6408            continue;
6409
6410
6411        c0 = -1, s = align = 1;
6412        for (;;) {
6413            px = f->c * 8 + bit_pos;
6414            cx = (px >> 3) & -align;
6415            px = px - (cx << 3);
6416            if (c0 == cx)
6417                break;
6418            s = (px + bit_size + 7) >> 3;
6419            if (s > 4) {
6420                t.t = 4;
6421            } else if (s > 2) {
6422                t.t = 3;
6423            } else if (s > 1) {
6424                t.t = 2;
6425            } else {
6426                t.t = 1;
6427            }
6428            s = type_size(&t, &align);
6429            c0 = cx;
6430        }
6431
6432        if (px + bit_size <= s * 8 && cx + s <= c) {
6433
6434            f->c = cx;
6435            bit_pos = px;
6436     f->type.t = (f->type.t & ~(0x3f << 20))
6437          | (bit_pos << 20);
6438            if (s != size)
6439                f->auxtype = t.t;
6440
6441
6442
6443
6444
6445
6446        } else {
6447
6448            f->auxtype = 7;
6449
6450
6451
6452
6453        }
6454    }
6455}
6456
6457
6458static void struct_decl(CType *type, int u)
6459{
6460    int v, c, size, align, flexible;
6461    int bit_size, bsize, bt;
6462    Sym *s, *ss, **ps;
6463    AttributeDef ad, ad1;
6464    CType type1, btype;
6465
6466    memset(&ad, 0, sizeof ad);
6467    next();
6468    parse_attribute(&ad);
6469    if (tok != '{') {
6470        v = tok;
6471        next();
6472
6473        if (v < 256)
6474            expect("struct/union/enum name");
6475        s = struct_find(v);
6476        if (s && (s->sym_scope == local_scope || tok != '{')) {
6477            if (u == s->type.t)
6478                goto do_decl;
6479            if (u == (2 << 20) && ((s->type.t & (((1 << (6+6)) - 1) << 20 | 0x0080)) == (2 << 20)))
6480                goto do_decl;
6481            tcc_error("redefinition of '%s'", get_tok_str(v, 0));
6482        }
6483    } else {
6484        v = anon_sym++;
6485    }
6486
6487    type1.t = u == (2 << 20) ? u | 3 | 0x0010 : u;
6488    type1.ref = 0;
6489
6490    s = sym_push(v | 0x40000000, &type1, 0, -1);
6491    s->r = 0;
6492do_decl:
6493    type->t = s->type.t;
6494    type->ref = s;
6495
6496    if (tok == '{') {
6497        next();
6498        if (s->c != -1)
6499            tcc_error("struct/union/enum already defined");
6500
6501
6502        ps = &s->next;
6503        if (u == (2 << 20)) {
6504            long long ll = 0, pl = 0, nl = 0;
6505     CType t;
6506            t.ref = s;
6507
6508            t.t = 3|0x00002000|(3 << 20);
6509            for(;;) {
6510                v = tok;
6511                if (v < TOK_DEFINE)
6512                    expect("identifier");
6513                ss = sym_find(v);
6514                if (ss && !local_stack)
6515                    tcc_error("redefinition of enumerator '%s'",
6516                              get_tok_str(v, 0));
6517                next();
6518                if (tok == '=') {
6519                    next();
6520      ll = expr_const64();
6521                }
6522                ss = sym_push(v, &t, 0x0030, 0);
6523                ss->enum_val = ll;
6524                *ps = ss, ps = &ss->next;
6525                if (ll < nl)
6526                    nl = ll;
6527                if (ll > pl)
6528                    pl = ll;
6529                if (tok != ',')
6530                    break;
6531                next();
6532                ll++;
6533
6534                if (tok == '}')
6535                    break;
6536            }
6537            skip('}');
6538
6539            t.t = 3;
6540            if (nl >= 0) {
6541                if (pl != (unsigned)pl)
6542                    t.t = (8==8 ? 4|0x0800 : 4);
6543                t.t |= 0x0010;
6544            } else if (pl != (int)pl || nl != (int)nl)
6545                t.t = (8==8 ? 4|0x0800 : 4);
6546            s->type.t = type->t = t.t | (2 << 20);
6547            s->c = 0;
6548
6549            for (ss = s->next; ss; ss = ss->next) {
6550                ll = ss->enum_val;
6551                if (ll == (int)ll)
6552                    continue;
6553                if (t.t & 0x0010) {
6554                    ss->type.t |= 0x0010;
6555                    if (ll == (unsigned)ll)
6556                        continue;
6557                }
6558                ss->type.t = (ss->type.t & ~0x000f)
6559                    | (8==8 ? 4|0x0800 : 4);
6560            }
6561        } else {
6562            c = 0;
6563            flexible = 0;
6564            while (tok != '}') {
6565                if (!parse_btype(&btype, &ad1)) {
6566      skip(';');
6567      continue;
6568  }
6569                while (1) {
6570      if (flexible)
6571          tcc_error("flexible array member '%s' not at the end of struct",
6572                              get_tok_str(v, 0));
6573                    bit_size = -1;
6574                    v = 0;
6575                    type1 = btype;
6576                    if (tok != ':') {
6577   if (tok != ';')
6578                            type_decl(&type1, &ad1, &v, 2);
6579                        if (v == 0) {
6580                         if ((type1.t & 0x000f) != 7)
6581                         expect("identifier");
6582                         else {
6583    int v = btype.ref->v;
6584    if (!(v & 0x20000000) && (v & ~0x40000000) < 0x10000000) {
6585        if (tcc_state->ms_extensions == 0)
6586                          expect("identifier");
6587    }
6588                         }
6589                        }
6590                        if (type_size(&type1, &align) < 0) {
6591       if ((u == 7) && (type1.t & 0x0040) && c)
6592           flexible = 1;
6593       else
6594           tcc_error("field '%s' has incomplete type",
6595                                      get_tok_str(v, 0));
6596                        }
6597                        if ((type1.t & 0x000f) == 6 ||
6598                            (type1.t & (0x00001000 | 0x00002000 | 0x00004000 | 0x00008000)))
6599                            tcc_error("invalid type for '%s'",
6600                                  get_tok_str(v, 0));
6601                    }
6602                    if (tok == ':') {
6603                        next();
6604                        bit_size = expr_const();
6605
6606                        if (bit_size < 0)
6607                            tcc_error("negative width in bit-field '%s'",
6608                                  get_tok_str(v, 0));
6609                        if (v && bit_size == 0)
6610                            tcc_error("zero width for bit-field '%s'",
6611                                  get_tok_str(v, 0));
6612   parse_attribute(&ad1);
6613                    }
6614                    size = type_size(&type1, &align);
6615                    if (bit_size >= 0) {
6616                        bt = type1.t & 0x000f;
6617                        if (bt != 3 &&
6618                            bt != 1 &&
6619                            bt != 2 &&
6620                            bt != 11 &&
6621                            bt != 4)
6622                            tcc_error("bitfields must have scalar type");
6623                        bsize = size * 8;
6624                        if (bit_size > bsize) {
6625                            tcc_error("width of '%s' exceeds its type",
6626                                  get_tok_str(v, 0));
6627                        } else if (bit_size == bsize
6628                                    && !ad.a.packed && !ad1.a.packed) {
6629
6630                            ;
6631                        } else if (bit_size == 64) {
6632                            tcc_error("field width 64 not implemented");
6633                        } else {
6634                            type1.t = (type1.t & ~(((1 << (6+6)) - 1) << 20 | 0x0080))
6635                                | 0x0080
6636                                | (bit_size << (20 + 6));
6637                        }
6638                    }
6639                    if (v != 0 || (type1.t & 0x000f) == 7) {
6640
6641
6642   c = 1;
6643                    }
6644
6645
6646                    if (v == 0 &&
6647   ((type1.t & 0x000f) == 7 ||
6648    bit_size >= 0)) {
6649          v = anon_sym++;
6650      }
6651                    if (v) {
6652                        ss = sym_push(v | 0x20000000, &type1, 0, 0);
6653                        ss->a = ad1.a;
6654                        *ps = ss;
6655                        ps = &ss->next;
6656                    }
6657                    if (tok == ';' || tok == (-1))
6658                        break;
6659                    skip(',');
6660                }
6661                skip(';');
6662            }
6663            skip('}');
6664     parse_attribute(&ad);
6665     struct_layout(type, &ad);
6666        }
6667    }
6668}
6669
6670static void sym_to_attr(AttributeDef *ad, Sym *s)
6671{
6672    if (s->a.aligned && 0 == ad->a.aligned)
6673        ad->a.aligned = s->a.aligned;
6674    if (s->f.func_call && 0 == ad->f.func_call)
6675        ad->f.func_call = s->f.func_call;
6676    if (s->f.func_type && 0 == ad->f.func_type)
6677        ad->f.func_type = s->f.func_type;
6678    if (s->a.packed)
6679        ad->a.packed = 1;
6680}
6681
6682
6683
6684static void parse_btype_qualify(CType *type, int qualifiers)
6685{
6686    while (type->t & 0x0040) {
6687        type->ref = sym_push(0x20000000, &type->ref->type, 0, type->ref->c);
6688        type = &type->ref->type;
6689    }
6690    type->t |= qualifiers;
6691}
6692
6693
6694
6695
6696static int parse_btype(CType *type, AttributeDef *ad)
6697{
6698    int t, u, bt, st, type_found, typespec_found, g;
6699    Sym *s;
6700    CType type1;
6701
6702    memset(ad, 0, sizeof(AttributeDef));
6703    type_found = 0;
6704    typespec_found = 0;
6705    t = 3;
6706    bt = st = -1;
6707    type->ref = 0;
6708
6709    while(1) {
6710        switch(tok) {
6711        case TOK_EXTENSION:
6712
6713            next();
6714            continue;
6715
6716
6717        case TOK_CHAR:
6718            u = 1;
6719        basic_type:
6720            next();
6721        basic_type1:
6722            if (u == 2 || u == 0x0800) {
6723                if (st != -1 || (bt != -1 && bt != 3))
6724                    tmbt: tcc_error("too many basic types");
6725                st = u;
6726            } else {
6727                if (bt != -1 || (st != -1 && u != 3))
6728                    goto tmbt;
6729                bt = u;
6730            }
6731            if (u != 3)
6732                t = (t & ~(0x000f|0x0800)) | u;
6733            typespec_found = 1;
6734            break;
6735        case TOK_VOID:
6736            u = 0;
6737            goto basic_type;
6738        case TOK_SHORT:
6739            u = 2;
6740            goto basic_type;
6741        case TOK_INT:
6742            u = 3;
6743            goto basic_type;
6744        case TOK_LONG:
6745            if ((t & 0x000f) == 9) {
6746                t = (t & ~(0x000f|0x0800)) | 10;
6747            } else if ((t & (0x000f|0x0800)) == 0x0800) {
6748                t = (t & ~(0x000f|0x0800)) | 4;
6749            } else {
6750                u = 0x0800;
6751                goto basic_type;
6752            }
6753            next();
6754            break;
6755
6756
6757
6758
6759
6760
6761
6762        case TOK_BOOL:
6763            u = 11;
6764            goto basic_type;
6765        case TOK_FLOAT:
6766            u = 8;
6767            goto basic_type;
6768        case TOK_DOUBLE:
6769            if ((t & (0x000f|0x0800)) == 0x0800) {
6770                t = (t & ~(0x000f|0x0800)) | 10;
6771            } else {
6772                u = 9;
6773                goto basic_type;
6774            }
6775            next();
6776            break;
6777        case TOK_ENUM:
6778            struct_decl(&type1, (2 << 20));
6779        basic_type2:
6780            u = type1.t;
6781            type->ref = type1.ref;
6782            goto basic_type1;
6783        case TOK_STRUCT:
6784            struct_decl(&type1, 7);
6785            goto basic_type2;
6786        case TOK_UNION:
6787            struct_decl(&type1, (1 << 20 | 7));
6788            goto basic_type2;
6789
6790
6791        case TOK_CONST1:
6792        case TOK_CONST2:
6793        case TOK_CONST3:
6794            type->t = t;
6795            parse_btype_qualify(type, 0x0100);
6796            t = type->t;
6797            next();
6798            break;
6799        case TOK_VOLATILE1:
6800        case TOK_VOLATILE2:
6801        case TOK_VOLATILE3:
6802            type->t = t;
6803            parse_btype_qualify(type, 0x0200);
6804            t = type->t;
6805            next();
6806            break;
6807        case TOK_SIGNED1:
6808        case TOK_SIGNED2:
6809        case TOK_SIGNED3:
6810            if ((t & (0x0020|0x0010)) == (0x0020|0x0010))
6811                tcc_error("signed and unsigned modifier");
6812            t |= 0x0020;
6813            next();
6814            typespec_found = 1;
6815            break;
6816        case TOK_REGISTER:
6817        case TOK_AUTO:
6818        case TOK_RESTRICT1:
6819        case TOK_RESTRICT2:
6820        case TOK_RESTRICT3:
6821            next();
6822            break;
6823        case TOK_UNSIGNED:
6824            if ((t & (0x0020|0x0010)) == 0x0020)
6825                tcc_error("signed and unsigned modifier");
6826            t |= 0x0020 | 0x0010;
6827            next();
6828            typespec_found = 1;
6829            break;
6830
6831
6832        case TOK_EXTERN:
6833            g = 0x00001000;
6834            goto storage;
6835        case TOK_STATIC:
6836            g = 0x00002000;
6837            goto storage;
6838        case TOK_TYPEDEF:
6839            g = 0x00004000;
6840            goto storage;
6841       storage:
6842            if (t & (0x00001000|0x00002000|0x00004000) & ~g)
6843                tcc_error("multiple storage classes");
6844            t |= g;
6845            next();
6846            break;
6847        case TOK_INLINE1:
6848        case TOK_INLINE2:
6849        case TOK_INLINE3:
6850            t |= 0x00008000;
6851            next();
6852            break;
6853
6854
6855        case TOK_ATTRIBUTE1:
6856        case TOK_ATTRIBUTE2:
6857            parse_attribute(ad);
6858            if (ad->attr_mode) {
6859                u = ad->attr_mode -1;
6860                t = (t & ~(0x000f|0x0800)) | u;
6861            }
6862            break;
6863
6864        case TOK_TYPEOF1:
6865        case TOK_TYPEOF2:
6866        case TOK_TYPEOF3:
6867            next();
6868            parse_expr_type(&type1);
6869
6870            type1.t &= ~((0x00001000 | 0x00002000 | 0x00004000 | 0x00008000)&~0x00004000);
6871     if (type1.ref)
6872                sym_to_attr(ad, type1.ref);
6873            goto basic_type2;
6874        default:
6875            if (typespec_found)
6876                goto the_end;
6877            s = sym_find(tok);
6878            if (!s || !(s->type.t & 0x00004000))
6879                goto the_end;
6880            t &= ~(0x000f|0x0800);
6881            u = t & ~(0x0100 | 0x0200), t ^= u;
6882            type->t = (s->type.t & ~0x00004000) | u;
6883            type->ref = s->type.ref;
6884            if (t)
6885                parse_btype_qualify(type, t);
6886            t = type->t;
6887
6888            sym_to_attr(ad, s);
6889            next();
6890            typespec_found = 1;
6891            st = bt = -2;
6892            break;
6893        }
6894        type_found = 1;
6895    }
6896the_end:
6897    if (tcc_state->char_is_unsigned) {
6898        if ((t & (0x0020|0x000f)) == 1)
6899            t |= 0x0010;
6900    }
6901
6902    bt = t & (0x000f|0x0800);
6903    if (bt == 0x0800)
6904        t |= 8 == 8 ? 4 : 3;
6905
6906
6907
6908
6909    type->t = t;
6910    return type_found;
6911}
6912
6913
6914
6915static inline void convert_parameter_type(CType *pt)
6916{
6917
6918
6919    pt->t &= ~(0x0100 | 0x0200);
6920
6921    pt->t &= ~0x0040;
6922    if ((pt->t & 0x000f) == 6) {
6923        mk_pointer(pt);
6924    }
6925}
6926
6927static void parse_asm_str(CString *astr)
6928{
6929    skip('(');
6930    parse_mult_str(astr, "string constant");
6931}
6932
6933
6934static int asm_label_instr(void)
6935{
6936    int v;
6937    CString astr;
6938
6939    next();
6940    parse_asm_str(&astr);
6941    skip(')');
6942
6943
6944
6945    v = tok_alloc(astr.data, astr.size - 1)->tok;
6946    cstr_free(&astr);
6947    return v;
6948}
6949
6950static int post_type(CType *type, AttributeDef *ad, int storage, int td)
6951{
6952    int n, l, t1, arg_size, align;
6953    Sym **plast, *s, *first;
6954    AttributeDef ad1;
6955    CType pt;
6956
6957    if (tok == '(') {
6958
6959        next();
6960 if (td && !(td & 1))
6961   return 0;
6962 if (tok == ')')
6963   l = 0;
6964 else if (parse_btype(&pt, &ad1))
6965   l = 1;
6966 else if (td)
6967   return 0;
6968 else
6969   l = 2;
6970        first = 0;
6971        plast = &first;
6972        arg_size = 0;
6973        if (l) {
6974            for(;;) {
6975
6976                if (l != 2) {
6977                    if ((pt.t & 0x000f) == 0 && tok == ')')
6978                        break;
6979                    type_decl(&pt, &ad1, &n, 2 | 1);
6980                    if ((pt.t & 0x000f) == 0)
6981                        tcc_error("parameter declared as void");
6982                    arg_size += (type_size(&pt, &align) + 8 - 1) / 8;
6983                } else {
6984                    n = tok;
6985                    if (n < TOK_DEFINE)
6986                        expect("identifier");
6987                    pt.t = 0;
6988                    next();
6989                }
6990                convert_parameter_type(&pt);
6991                s = sym_push(n | 0x20000000, &pt, 0, 0);
6992                *plast = s;
6993                plast = &s->next;
6994                if (tok == ')')
6995                    break;
6996                skip(',');
6997                if (l == 1 && tok == 0xc8) {
6998                    l = 3;
6999                    next();
7000                    break;
7001                }
7002  if (l == 1 && !parse_btype(&pt, &ad1))
7003      tcc_error("invalid type");
7004            }
7005        } else
7006
7007            l = 2;
7008        skip(')');
7009
7010
7011        type->t &= ~0x0100;
7012
7013
7014
7015        if (tok == '[') {
7016            next();
7017            skip(']');
7018            mk_pointer(type);
7019        }
7020
7021        ad->f.func_args = arg_size;
7022        ad->f.func_type = l;
7023        s = sym_push(0x20000000, type, 0, 0);
7024        s->a = ad->a;
7025        s->f = ad->f;
7026        s->next = first;
7027        type->t = 6;
7028        type->ref = s;
7029    } else if (tok == '[') {
7030 int saved_nocode_wanted = nocode_wanted;
7031
7032        next();
7033        if (tok == TOK_RESTRICT1)
7034            next();
7035        n = -1;
7036        t1 = 0;
7037        if (tok != ']') {
7038            if (!local_stack || (storage & 0x00002000))
7039                vpushi(expr_const());
7040            else {
7041
7042
7043
7044
7045  nocode_wanted = 0;
7046  gexpr();
7047     }
7048            if ((vtop->r & (0x003f | 0x0100 | 0x0200)) == 0x0030) {
7049                n = vtop->c.i;
7050                if (n < 0)
7051                    tcc_error("invalid array size");
7052            } else {
7053                if (!is_integer_btype(vtop->type.t & 0x000f))
7054                    tcc_error("size of variable length array should be an integer");
7055                t1 = 0x0400;
7056            }
7057        }
7058        skip(']');
7059
7060        post_type(type, ad, storage, 0);
7061        if (type->t == 6)
7062            tcc_error("declaration of an array of functions");
7063        t1 |= type->t & 0x0400;
7064
7065        if (t1 & 0x0400) {
7066            loc -= type_size(&int_type, &align);
7067            loc &= -align;
7068            n = loc;
7069
7070            vla_runtime_type_size(type, &align);
7071            gen_op('*');
7072            vset(&int_type, 0x0032|0x0100, n);
7073            vswap();
7074            vstore();
7075        }
7076        if (n != -1)
7077            vpop();
7078 nocode_wanted = saved_nocode_wanted;
7079
7080
7081
7082        s = sym_push(0x20000000, type, 0, n);
7083        type->t = (t1 ? 0x0400 : 0x0040) | 5;
7084        type->ref = s;
7085    }
7086    return 1;
7087}
7088# 4401 "tccgen.c"
7089static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td)
7090{
7091    CType *post, *ret;
7092    int qualifiers, storage;
7093
7094
7095    storage = type->t & (0x00001000 | 0x00002000 | 0x00004000 | 0x00008000);
7096    type->t &= ~(0x00001000 | 0x00002000 | 0x00004000 | 0x00008000);
7097    post = ret = type;
7098
7099    while (tok == '*') {
7100        qualifiers = 0;
7101    redo:
7102        next();
7103        switch(tok) {
7104        case TOK_CONST1:
7105        case TOK_CONST2:
7106        case TOK_CONST3:
7107            qualifiers |= 0x0100;
7108            goto redo;
7109        case TOK_VOLATILE1:
7110        case TOK_VOLATILE2:
7111        case TOK_VOLATILE3:
7112            qualifiers |= 0x0200;
7113            goto redo;
7114        case TOK_RESTRICT1:
7115        case TOK_RESTRICT2:
7116        case TOK_RESTRICT3:
7117            goto redo;
7118
7119 case TOK_ATTRIBUTE1:
7120 case TOK_ATTRIBUTE2:
7121     parse_attribute(ad);
7122     break;
7123        }
7124        mk_pointer(type);
7125        type->t |= qualifiers;
7126 if (ret == type)
7127
7128     ret = pointed_type(type);
7129    }
7130
7131    if (tok == '(') {
7132
7133
7134 if (!post_type(type, ad, 0, td)) {
7135
7136
7137
7138
7139     parse_attribute(ad);
7140     post = type_decl(type, ad, v, td);
7141     skip(')');
7142 }
7143    } else if (tok >= 256 && (td & 2)) {
7144
7145 *v = tok;
7146 next();
7147    } else {
7148 if (!(td & 1))
7149   expect("identifier");
7150 *v = 0;
7151    }
7152    post_type(post, ad, storage, 0);
7153    parse_attribute(ad);
7154    type->t |= storage;
7155    return ret;
7156}
7157
7158
7159static int lvalue_type(int t)
7160{
7161    int bt, r;
7162    r = 0x0100;
7163    bt = t & 0x000f;
7164    if (bt == 1 || bt == 11)
7165        r |= 0x1000;
7166    else if (bt == 2)
7167        r |= 0x2000;
7168    else
7169        return r;
7170    if (t & 0x0010)
7171        r |= 0x4000;
7172    return r;
7173}
7174
7175
7176static void indir(void)
7177{
7178    if ((vtop->type.t & 0x000f) != 5) {
7179        if ((vtop->type.t & 0x000f) == 6)
7180            return;
7181        expect("pointer");
7182    }
7183    if (vtop->r & 0x0100)
7184        gv(0x0001);
7185    vtop->type = *pointed_type(&vtop->type);
7186
7187    if (!(vtop->type.t & 0x0040) && !(vtop->type.t & 0x0400)
7188        && (vtop->type.t & 0x000f) != 6) {
7189        vtop->r |= lvalue_type(vtop->type.t);
7190
7191
7192        if (tcc_state->do_bounds_check)
7193            vtop->r |= 0x0800;
7194
7195    }
7196}
7197
7198
7199static void gfunc_param_typed(Sym *func, Sym *arg)
7200{
7201    int func_type;
7202    CType type;
7203
7204    func_type = func->f.func_type;
7205    if (func_type == 2 ||
7206        (func_type == 3 && arg == 0)) {
7207
7208        if ((vtop->type.t & 0x000f) == 8) {
7209            gen_cast_s(9);
7210        } else if (vtop->type.t & 0x0080) {
7211            type.t = vtop->type.t & (0x000f | 0x0010);
7212     type.ref = vtop->type.ref;
7213            gen_cast(&type);
7214        }
7215    } else if (arg == 0) {
7216        tcc_error("too many arguments to function");
7217    } else {
7218        type = arg->type;
7219        type.t &= ~0x0100;
7220        gen_assign_cast(&type);
7221    }
7222}
7223
7224
7225static void expr_type(CType *type, void (*expr_fn)(void))
7226{
7227    nocode_wanted++;
7228    expr_fn();
7229    *type = vtop->type;
7230    vpop();
7231    nocode_wanted--;
7232}
7233
7234
7235
7236static void parse_expr_type(CType *type)
7237{
7238    int n;
7239    AttributeDef ad;
7240
7241    skip('(');
7242    if (parse_btype(type, &ad)) {
7243        type_decl(type, &ad, &n, 1);
7244    } else {
7245        expr_type(type, gexpr);
7246    }
7247    skip(')');
7248}
7249
7250static void parse_type(CType *type)
7251{
7252    AttributeDef ad;
7253    int n;
7254
7255    if (!parse_btype(type, &ad)) {
7256        expect("type");
7257    }
7258    type_decl(type, &ad, &n, 1);
7259}
7260
7261static void parse_builtin_params(int nc, const char *args)
7262{
7263    char c, sep = '(';
7264    CType t;
7265    if (nc)
7266        nocode_wanted++;
7267    next();
7268    while ((c = *args++)) {
7269 skip(sep);
7270 sep = ',';
7271 switch (c) {
7272     case 'e': expr_eq(); continue;
7273     case 't': parse_type(&t); vpush(&t); continue;
7274     default: tcc_error("internal error"); break;
7275 }
7276    }
7277    skip(')');
7278    if (nc)
7279        nocode_wanted--;
7280}
7281
7282static void unary(void)
7283{
7284    int n, t, align, size, r, sizeof_caller;
7285    CType type;
7286    Sym *s;
7287    AttributeDef ad;
7288
7289    sizeof_caller = in_sizeof;
7290    in_sizeof = 0;
7291    type.ref = 0;
7292
7293
7294 tok_next:
7295    switch(tok) {
7296    case TOK_EXTENSION:
7297        next();
7298        goto tok_next;
7299    case 0xb4:
7300
7301
7302
7303
7304    case 0xb5:
7305    case 0xb3:
7306 t = 3;
7307 push_tokc:
7308 type.t = t;
7309 vsetc(&type, 0x0030, &tokc);
7310        next();
7311        break;
7312    case 0xb6:
7313        t = 3 | 0x0010;
7314        goto push_tokc;
7315    case 0xb7:
7316        t = 4;
7317 goto push_tokc;
7318    case 0xb8:
7319        t = 4 | 0x0010;
7320 goto push_tokc;
7321    case 0xbb:
7322        t = 8;
7323 goto push_tokc;
7324    case 0xbc:
7325        t = 9;
7326 goto push_tokc;
7327    case 0xbd:
7328        t = 10;
7329 goto push_tokc;
7330    case 0xce:
7331        t = (8 == 8 ? 4 : 3) | 0x0800;
7332 goto push_tokc;
7333    case 0xcf:
7334        t = (8 == 8 ? 4 : 3) | 0x0800 | 0x0010;
7335 goto push_tokc;
7336    case TOK___FUNCTION__:
7337        if (!gnu_ext)
7338            goto tok_identifier;
7339
7340    case TOK___FUNC__:
7341        {
7342            void *ptr;
7343            int len;
7344
7345            len = strlen(funcname) + 1;
7346
7347            type.t = 1;
7348            mk_pointer(&type);
7349            type.t |= 0x0040;
7350            type.ref->c = len;
7351            vpush_ref(&type, data_section, data_section->data_offset, len);
7352            if (!(nocode_wanted > 0)) {
7353                ptr = section_ptr_add(data_section, len);
7354                memcpy(ptr, funcname, len);
7355            }
7356            next();
7357        }
7358        break;
7359    case 0xba:
7360
7361
7362
7363        t = 3;
7364
7365        goto str_init;
7366    case 0xb9:
7367
7368        t = 1;
7369        if (tcc_state->char_is_unsigned)
7370            t = 1 | 0x0010;
7371    str_init:
7372        if (tcc_state->warn_write_strings)
7373            t |= 0x0100;
7374        type.t = t;
7375        mk_pointer(&type);
7376        type.t |= 0x0040;
7377        memset(&ad, 0, sizeof(AttributeDef));
7378        decl_initializer_alloc(&type, &ad, 0x0030, 2, 0, 0);
7379        break;
7380    case '(':
7381        next();
7382
7383        if (parse_btype(&type, &ad)) {
7384            type_decl(&type, &ad, &n, 1);
7385            skip(')');
7386
7387            if (tok == '{') {
7388
7389                if (global_expr)
7390                    r = 0x0030;
7391                else
7392                    r = 0x0032;
7393
7394                if (!(type.t & 0x0040))
7395                    r |= lvalue_type(type.t);
7396                memset(&ad, 0, sizeof(AttributeDef));
7397                decl_initializer_alloc(&type, &ad, r, 1, 0, 0);
7398            } else {
7399                if (sizeof_caller) {
7400                    vpush(&type);
7401                    return;
7402                }
7403                unary();
7404                gen_cast(&type);
7405            }
7406        } else if (tok == '{') {
7407     int saved_nocode_wanted = nocode_wanted;
7408            if (const_wanted)
7409                tcc_error("expected constant");
7410
7411            save_regs(0);
7412
7413
7414
7415
7416
7417            block(0, 0, 1);
7418     nocode_wanted = saved_nocode_wanted;
7419            skip(')');
7420        } else {
7421            gexpr();
7422            skip(')');
7423        }
7424        break;
7425    case '*':
7426        next();
7427        unary();
7428        indir();
7429        break;
7430    case '&':
7431        next();
7432        unary();
7433
7434
7435
7436
7437
7438        if ((vtop->type.t & 0x000f) != 6 &&
7439            !(vtop->type.t & 0x0040))
7440            test_lvalue();
7441        mk_pointer(&vtop->type);
7442        gaddrof();
7443        break;
7444    case '!':
7445        next();
7446        unary();
7447        if ((vtop->r & (0x003f | 0x0100 | 0x0200)) == 0x0030) {
7448            gen_cast_s(11);
7449            vtop->c.i = !vtop->c.i;
7450        } else if ((vtop->r & 0x003f) == 0x0033)
7451            vtop->c.i ^= 1;
7452        else {
7453            save_regs(1);
7454            vseti(0x0034, gvtst(1, 0));
7455        }
7456        break;
7457    case '~':
7458        next();
7459        unary();
7460        vpushi(-1);
7461        gen_op('^');
7462        break;
7463    case '+':
7464        next();
7465        unary();
7466        if ((vtop->type.t & 0x000f) == 5)
7467            tcc_error("pointer not accepted for unary plus");
7468
7469
7470
7471 if (!is_float(vtop->type.t)) {
7472     vpushi(0);
7473     gen_op('+');
7474 }
7475        break;
7476    case TOK_SIZEOF:
7477    case TOK_ALIGNOF1:
7478    case TOK_ALIGNOF2:
7479        t = tok;
7480        next();
7481        in_sizeof++;
7482        expr_type(&type, unary);
7483        s = vtop[1].sym;
7484        size = type_size(&type, &align);
7485        if (s && s->a.aligned)
7486            align = 1 << (s->a.aligned - 1);
7487        if (t == TOK_SIZEOF) {
7488            if (!(type.t & 0x0400)) {
7489                if (size < 0)
7490                    tcc_error("sizeof applied to an incomplete type");
7491                vpushs(size);
7492            } else {
7493                vla_runtime_type_size(&type, &align);
7494            }
7495        } else {
7496            vpushs(align);
7497        }
7498        vtop->type.t |= 0x0010;
7499        break;
7500
7501    case TOK_builtin_expect:
7502
7503 parse_builtin_params(0, "ee");
7504 vpop();
7505        break;
7506    case TOK_builtin_types_compatible_p:
7507 parse_builtin_params(0, "tt");
7508 vtop[-1].type.t &= ~(0x0100 | 0x0200);
7509 vtop[0].type.t &= ~(0x0100 | 0x0200);
7510 n = is_compatible_types(&vtop[-1].type, &vtop[0].type);
7511 vtop -= 2;
7512 vpushi(n);
7513        break;
7514    case TOK_builtin_choose_expr:
7515 {
7516     int64_t c;
7517     next();
7518     skip('(');
7519     c = expr_const64();
7520     skip(',');
7521     if (!c) {
7522  nocode_wanted++;
7523     }
7524     expr_eq();
7525     if (!c) {
7526  vpop();
7527  nocode_wanted--;
7528     }
7529     skip(',');
7530     if (c) {
7531  nocode_wanted++;
7532     }
7533     expr_eq();
7534     if (c) {
7535  vpop();
7536  nocode_wanted--;
7537     }
7538     skip(')');
7539 }
7540        break;
7541    case TOK_builtin_constant_p:
7542 parse_builtin_params(1, "e");
7543 n = (vtop->r & (0x003f | 0x0100 | 0x0200)) == 0x0030;
7544 vtop--;
7545 vpushi(n);
7546        break;
7547    case TOK_builtin_frame_address:
7548    case TOK_builtin_return_address:
7549        {
7550            int tok1 = tok;
7551            int level;
7552            next();
7553            skip('(');
7554            if (tok != 0xb5) {
7555                tcc_error("%s only takes positive integers",
7556                          tok1 == TOK_builtin_return_address ?
7557                          "__builtin_return_address" :
7558                          "__builtin_frame_address");
7559            }
7560            level = (uint32_t)tokc.i;
7561            next();
7562            skip(')');
7563            type.t = 0;
7564            mk_pointer(&type);
7565            vset(&type, 0x0032, 0);
7566            while (level--) {
7567                mk_pointer(&vtop->type);
7568                indir();
7569            }
7570            if (tok1 == TOK_builtin_return_address) {
7571
7572                vpushi(8);
7573                gen_op('+');
7574                mk_pointer(&vtop->type);
7575                indir();
7576            }
7577        }
7578        break;
7579# 4906 "tccgen.c"
7580    case TOK_builtin_va_arg_types:
7581 parse_builtin_params(0, "t");
7582 vpushi(classify_x86_64_va_arg(&vtop->type));
7583 vswap();
7584 vpop();
7585        break;
7586# 4942 "tccgen.c"
7587    case 0xa4:
7588    case 0xa2:
7589        t = tok;
7590        next();
7591        unary();
7592        inc(0, t);
7593        break;
7594    case '-':
7595        next();
7596        unary();
7597        t = vtop->type.t & 0x000f;
7598 if (is_float(t)) {
7599
7600
7601     vpush(&vtop->type);
7602     if (t == 8)
7603         vtop->c.f = -1.0 * 0.0;
7604     else if (t == 9)
7605         vtop->c.d = -1.0 * 0.0;
7606     else
7607         vtop->c.ld = -1.0 * 0.0;
7608 } else
7609     vpushi(0);
7610 vswap();
7611 gen_op('-');
7612        break;
7613    case 0xa0:
7614        if (!gnu_ext)
7615            goto tok_identifier;
7616        next();
7617
7618        if (tok < TOK_DEFINE)
7619            expect("label identifier");
7620        s = label_find(tok);
7621        if (!s) {
7622            s = label_push(&global_label_stack, tok, 1);
7623        } else {
7624            if (s->r == 2)
7625                s->r = 1;
7626        }
7627        if (!s->type.t) {
7628            s->type.t = 0;
7629            mk_pointer(&s->type);
7630            s->type.t |= 0x00002000;
7631        }
7632        vpushsym(&s->type, s);
7633        next();
7634        break;
7635
7636    case TOK_GENERIC:
7637    {
7638 CType controlling_type;
7639 int has_default = 0;
7640 int has_match = 0;
7641 int learn = 0;
7642 TokenString *str = 0;
7643
7644 next();
7645 skip('(');
7646 expr_type(&controlling_type, expr_eq);
7647 controlling_type.t &= ~(0x0100 | 0x0200 | 0x0040);
7648 for (;;) {
7649     learn = 0;
7650     skip(',');
7651     if (tok == TOK_DEFAULT) {
7652  if (has_default)
7653      tcc_error("too many 'default'");
7654  has_default = 1;
7655  if (!has_match)
7656      learn = 1;
7657  next();
7658     } else {
7659         AttributeDef ad_tmp;
7660  int itmp;
7661         CType cur_type;
7662  parse_btype(&cur_type, &ad_tmp);
7663  type_decl(&cur_type, &ad_tmp, &itmp, 1);
7664  if (compare_types(&controlling_type, &cur_type, 0)) {
7665      if (has_match) {
7666        tcc_error("type match twice");
7667      }
7668      has_match = 1;
7669      learn = 1;
7670  }
7671     }
7672     skip(':');
7673     if (learn) {
7674  if (str)
7675      tok_str_free(str);
7676  skip_or_save_block(&str);
7677     } else {
7678  skip_or_save_block(0);
7679     }
7680     if (tok == ')')
7681  break;
7682 }
7683 if (!str) {
7684     char buf[60];
7685     type_to_str(buf, sizeof buf, &controlling_type, 0);
7686     tcc_error("type '%s' does not match any association", buf);
7687 }
7688 begin_macro(str, 1);
7689 next();
7690 expr_eq();
7691 if (tok != (-1))
7692     expect(",");
7693 end_macro();
7694        next();
7695 break;
7696    }
7697
7698    case TOK___NAN__:
7699        vpush64(9, 0x7ff8000000000000ULL);
7700        next();
7701        break;
7702    case TOK___SNAN__:
7703        vpush64(9, 0x7ff0000000000001ULL);
7704        next();
7705        break;
7706    case TOK___INF__:
7707        vpush64(9, 0x7ff0000000000000ULL);
7708        next();
7709        break;
7710
7711    default:
7712    tok_identifier:
7713        t = tok;
7714        next();
7715        if (t < TOK_DEFINE)
7716            expect("identifier");
7717        s = sym_find(t);
7718        if (!s || (((s)->type.t & (0x000f | (0 | 0x0010))) == (0 | 0x0010))) {
7719            const char *name = get_tok_str(t, 0);
7720            if (tok != '(')
7721                tcc_error("'%s' undeclared", name);
7722
7723
7724            if (tcc_state->warn_implicit_function_declaration
7725
7726
7727
7728
7729
7730            )
7731                tcc_warning("implicit declaration of function '%s'", name);
7732            s = external_global_sym(t, &func_old_type, 0);
7733        }
7734
7735        r = s->r;
7736
7737
7738        if ((r & 0x003f) < 0x0030)
7739            r = (r & ~0x003f) | 0x0032;
7740
7741        vset(&s->type, r, s->c);
7742
7743
7744
7745 vtop->sym = s;
7746
7747        if (r & 0x0200) {
7748            vtop->c.i = 0;
7749        } else if (r == 0x0030 && ((s->type.t & (((1 << (6+6)) - 1) << 20 | 0x0080)) == (3 << 20))) {
7750            vtop->c.i = s->enum_val;
7751        }
7752        break;
7753    }
7754
7755
7756    while (1) {
7757        if (tok == 0xa4 || tok == 0xa2) {
7758            inc(1, tok);
7759            next();
7760        } else if (tok == '.' || tok == 0xc7 || tok == 0xbc) {
7761            int qualifiers;
7762
7763            if (tok == 0xc7)
7764                indir();
7765            qualifiers = vtop->type.t & (0x0100 | 0x0200);
7766            test_lvalue();
7767            gaddrof();
7768
7769            if ((vtop->type.t & 0x000f) != 7)
7770                expect("struct or union");
7771            if (tok == 0xbc)
7772                expect("field name");
7773            next();
7774            if (tok == 0xb5 || tok == 0xb6)
7775                expect("field name");
7776     s = find_field(&vtop->type, tok);
7777            if (!s)
7778                tcc_error("field not found: %s", get_tok_str(tok & ~0x20000000, &tokc));
7779
7780            vtop->type = char_pointer_type;
7781            vpushi(s->c);
7782            gen_op('+');
7783
7784            vtop->type = s->type;
7785            vtop->type.t |= qualifiers;
7786
7787            if (!(vtop->type.t & 0x0040)) {
7788                vtop->r |= lvalue_type(vtop->type.t);
7789
7790
7791                if (tcc_state->do_bounds_check && (vtop->r & 0x003f) != 0x0032)
7792                    vtop->r |= 0x0800;
7793
7794            }
7795            next();
7796        } else if (tok == '[') {
7797            next();
7798            gexpr();
7799            gen_op('+');
7800            indir();
7801            skip(']');
7802        } else if (tok == '(') {
7803            SValue ret;
7804            Sym *sa;
7805            int nb_args, ret_nregs, ret_align, regsize, variadic;
7806
7807
7808            if ((vtop->type.t & 0x000f) != 6) {
7809
7810                if ((vtop->type.t & (0x000f | 0x0040)) == 5) {
7811                    vtop->type = *pointed_type(&vtop->type);
7812                    if ((vtop->type.t & 0x000f) != 6)
7813                        goto error_func;
7814                } else {
7815                error_func:
7816                    expect("function pointer");
7817                }
7818            } else {
7819                vtop->r &= ~0x0100;
7820            }
7821
7822            s = vtop->type.ref;
7823            next();
7824            sa = s->next;
7825            nb_args = regsize = 0;
7826            ret.r2 = 0x0030;
7827
7828            if ((s->type.t & 0x000f) == 7) {
7829                variadic = (s->f.func_type == 3);
7830                ret_nregs = gfunc_sret(&s->type, variadic, &ret.type,
7831                                       &ret_align, &regsize);
7832                if (!ret_nregs) {
7833
7834                    size = type_size(&s->type, &align);
7835# 5199 "tccgen.c"
7836                    loc = (loc - size) & -align;
7837                    ret.type = s->type;
7838                    ret.r = 0x0032 | 0x0100;
7839
7840
7841                    vseti(0x0032, loc);
7842                    ret.c = vtop->c;
7843                    nb_args++;
7844                }
7845            } else {
7846                ret_nregs = 1;
7847                ret.type = s->type;
7848            }
7849
7850            if (ret_nregs) {
7851
7852                if (is_float(ret.type.t)) {
7853                    ret.r = reg_fret(ret.type.t);
7854
7855                    if ((ret.type.t & 0x000f) == 14)
7856                      ret.r2 = TREG_XMM1;
7857
7858                } else {
7859
7860
7861                    if ((ret.type.t & 0x000f) == 13)
7862
7863
7864
7865                        ret.r2 = TREG_RDX;
7866
7867                    ret.r = TREG_RAX;
7868                }
7869                ret.c.i = 0;
7870            }
7871            if (tok != ')') {
7872                for(;;) {
7873                    expr_eq();
7874                    gfunc_param_typed(s, sa);
7875                    nb_args++;
7876                    if (sa)
7877                        sa = sa->next;
7878                    if (tok == ')')
7879                        break;
7880                    skip(',');
7881                }
7882            }
7883            if (sa)
7884                tcc_error("too few arguments to function");
7885            skip(')');
7886            gfunc_call(nb_args);
7887
7888
7889            for (r = ret.r + ret_nregs + !ret_nregs; r-- > ret.r;) {
7890                vsetc(&ret.type, r, &ret.c);
7891                vtop->r2 = ret.r2;
7892            }
7893
7894
7895            if (((s->type.t & 0x000f) == 7) && ret_nregs) {
7896                int addr, offset;
7897
7898                size = type_size(&s->type, &align);
7899
7900
7901  if (regsize > align)
7902    align = regsize;
7903                loc = (loc - size) & -align;
7904                addr = loc;
7905                offset = 0;
7906                for (;;) {
7907                    vset(&ret.type, 0x0032 | 0x0100, addr + offset);
7908                    vswap();
7909                    vstore();
7910                    vtop--;
7911                    if (--ret_nregs == 0)
7912                        break;
7913                    offset += regsize;
7914                }
7915                vset(&s->type, 0x0032 | 0x0100, addr);
7916            }
7917        } else {
7918            break;
7919        }
7920    }
7921}
7922
7923static void expr_prod(void)
7924{
7925    int t;
7926
7927    unary();
7928    while (tok == '*' || tok == '/' || tok == '%') {
7929        t = tok;
7930        next();
7931        unary();
7932        gen_op(t);
7933    }
7934}
7935
7936static void expr_sum(void)
7937{
7938    int t;
7939
7940    expr_prod();
7941    while (tok == '+' || tok == '-') {
7942        t = tok;
7943        next();
7944        expr_prod();
7945        gen_op(t);
7946    }
7947}
7948
7949static void expr_shift(void)
7950{
7951    int t;
7952
7953    expr_sum();
7954    while (tok == 0x01 || tok == 0x02) {
7955        t = tok;
7956        next();
7957        expr_sum();
7958        gen_op(t);
7959    }
7960}
7961
7962static void expr_cmp(void)
7963{
7964    int t;
7965
7966    expr_shift();
7967    while ((tok >= 0x96 && tok <= 0x9f) ||
7968           tok == 0x92 || tok == 0x93) {
7969        t = tok;
7970        next();
7971        expr_shift();
7972        gen_op(t);
7973    }
7974}
7975
7976static void expr_cmpeq(void)
7977{
7978    int t;
7979
7980    expr_cmp();
7981    while (tok == 0x94 || tok == 0x95) {
7982        t = tok;
7983        next();
7984        expr_cmp();
7985        gen_op(t);
7986    }
7987}
7988
7989static void expr_and(void)
7990{
7991    expr_cmpeq();
7992    while (tok == '&') {
7993        next();
7994        expr_cmpeq();
7995        gen_op('&');
7996    }
7997}
7998
7999static void expr_xor(void)
8000{
8001    expr_and();
8002    while (tok == '^') {
8003        next();
8004        expr_and();
8005        gen_op('^');
8006    }
8007}
8008
8009static void expr_or(void)
8010{
8011    expr_xor();
8012    while (tok == '|') {
8013        next();
8014        expr_xor();
8015        gen_op('|');
8016    }
8017}
8018
8019static void expr_land(void)
8020{
8021    expr_or();
8022    if (tok == 0xa0) {
8023 int t = 0;
8024 for(;;) {
8025     if ((vtop->r & (0x003f | 0x0100 | 0x0200)) == 0x0030) {
8026                gen_cast_s(11);
8027  if (vtop->c.i) {
8028      vpop();
8029  } else {
8030      nocode_wanted++;
8031      while (tok == 0xa0) {
8032   next();
8033   expr_or();
8034   vpop();
8035      }
8036      nocode_wanted--;
8037      if (t)
8038        gsym(t);
8039      gen_cast_s(3);
8040      break;
8041  }
8042     } else {
8043  if (!t)
8044    save_regs(1);
8045  t = gvtst(1, t);
8046     }
8047     if (tok != 0xa0) {
8048  if (t)
8049    vseti(0x0035, t);
8050  else
8051    vpushi(1);
8052  break;
8053     }
8054     next();
8055     expr_or();
8056 }
8057    }
8058}
8059
8060static void expr_lor(void)
8061{
8062    expr_land();
8063    if (tok == 0xa1) {
8064 int t = 0;
8065 for(;;) {
8066     if ((vtop->r & (0x003f | 0x0100 | 0x0200)) == 0x0030) {
8067                gen_cast_s(11);
8068  if (!vtop->c.i) {
8069      vpop();
8070  } else {
8071      nocode_wanted++;
8072      while (tok == 0xa1) {
8073   next();
8074   expr_land();
8075   vpop();
8076      }
8077      nocode_wanted--;
8078      if (t)
8079        gsym(t);
8080      gen_cast_s(3);
8081      break;
8082  }
8083     } else {
8084  if (!t)
8085    save_regs(1);
8086  t = gvtst(0, t);
8087     }
8088     if (tok != 0xa1) {
8089  if (t)
8090    vseti(0x0034, t);
8091  else
8092    vpushi(0);
8093  break;
8094     }
8095     next();
8096     expr_land();
8097 }
8098    }
8099}
8100
8101
8102
8103
8104static int condition_3way(void)
8105{
8106    int c = -1;
8107    if ((vtop->r & (0x003f | 0x0100)) == 0x0030 &&
8108 (!(vtop->r & 0x0200) || !vtop->sym->a.weak)) {
8109 vdup();
8110        gen_cast_s(11);
8111 c = vtop->c.i;
8112 vpop();
8113    }
8114    return c;
8115}
8116
8117static void expr_cond(void)
8118{
8119    int tt, u, r1, r2, rc, t1, t2, bt1, bt2, islv, c, g;
8120    SValue sv;
8121    CType type, type1, type2;
8122
8123    expr_lor();
8124    if (tok == '?') {
8125        next();
8126 c = condition_3way();
8127        g = (tok == ':' && gnu_ext);
8128        if (c < 0) {
8129
8130
8131            if (is_float(vtop->type.t)) {
8132                rc = 0x0002;
8133
8134                if ((vtop->type.t & 0x000f) == 10) {
8135                    rc = 0x0080;
8136                }
8137
8138            } else
8139                rc = 0x0001;
8140            gv(rc);
8141            save_regs(1);
8142            if (g)
8143                gv_dup();
8144            tt = gvtst(1, 0);
8145
8146        } else {
8147            if (!g)
8148                vpop();
8149            tt = 0;
8150        }
8151
8152        if (1) {
8153            if (c == 0)
8154                nocode_wanted++;
8155            if (!g)
8156                gexpr();
8157
8158            type1 = vtop->type;
8159            sv = *vtop;
8160            vtop--;
8161            skip(':');
8162
8163            u = 0;
8164            if (c < 0)
8165                u = gjmp(0);
8166            gsym(tt);
8167
8168            if (c == 0)
8169                nocode_wanted--;
8170            if (c == 1)
8171                nocode_wanted++;
8172            expr_cond();
8173            if (c == 1)
8174                nocode_wanted--;
8175
8176            type2 = vtop->type;
8177            t1 = type1.t;
8178            bt1 = t1 & 0x000f;
8179            t2 = type2.t;
8180            bt2 = t2 & 0x000f;
8181            type.ref = 0;
8182
8183
8184            if (is_float(bt1) || is_float(bt2)) {
8185                if (bt1 == 10 || bt2 == 10) {
8186                    type.t = 10;
8187
8188                } else if (bt1 == 9 || bt2 == 9) {
8189                    type.t = 9;
8190                } else {
8191                    type.t = 8;
8192                }
8193            } else if (bt1 == 4 || bt2 == 4) {
8194
8195                type.t = 4 | 0x0800;
8196                if (bt1 == 4)
8197                    type.t &= t1;
8198                if (bt2 == 4)
8199                    type.t &= t2;
8200
8201                if ((t1 & (0x000f | 0x0010 | 0x0080)) == (4 | 0x0010) ||
8202                    (t2 & (0x000f | 0x0010 | 0x0080)) == (4 | 0x0010))
8203                    type.t |= 0x0010;
8204            } else if (bt1 == 5 || bt2 == 5) {
8205
8206
8207  if (is_null_pointer (vtop))
8208    type = type1;
8209  else if (is_null_pointer (&sv))
8210    type = type2;
8211
8212
8213  else
8214    type = type1;
8215            } else if (bt1 == 6 || bt2 == 6) {
8216
8217                type = bt1 == 6 ? type1 : type2;
8218            } else if (bt1 == 7 || bt2 == 7) {
8219
8220                type = bt1 == 7 ? type1 : type2;
8221            } else if (bt1 == 0 || bt2 == 0) {
8222
8223                type.t = 0;
8224            } else {
8225
8226                type.t = 3 | (0x0800 & (t1 | t2));
8227
8228                if ((t1 & (0x000f | 0x0010 | 0x0080)) == (3 | 0x0010) ||
8229                    (t2 & (0x000f | 0x0010 | 0x0080)) == (3 | 0x0010))
8230                    type.t |= 0x0010;
8231            }
8232
8233
8234            islv = (vtop->r & 0x0100) && (sv.r & 0x0100) && 7 == (type.t & 0x000f);
8235            islv &= c < 0;
8236
8237
8238            if (c != 1) {
8239                gen_cast(&type);
8240                if (islv) {
8241                    mk_pointer(&vtop->type);
8242                    gaddrof();
8243                } else if (7 == (vtop->type.t & 0x000f))
8244                    gaddrof();
8245            }
8246
8247            rc = 0x0001;
8248            if (is_float(type.t)) {
8249                rc = 0x0002;
8250
8251                if ((type.t & 0x000f) == 10) {
8252                    rc = 0x0080;
8253                }
8254
8255            } else if ((type.t & 0x000f) == 4) {
8256
8257
8258                rc = 0x0004;
8259            }
8260
8261            tt = r2 = 0;
8262            if (c < 0) {
8263                r2 = gv(rc);
8264                tt = gjmp(0);
8265            }
8266            gsym(u);
8267
8268
8269
8270            if (c != 0) {
8271                *vtop = sv;
8272                gen_cast(&type);
8273                if (islv) {
8274                    mk_pointer(&vtop->type);
8275                    gaddrof();
8276                } else if (7 == (vtop->type.t & 0x000f))
8277                    gaddrof();
8278            }
8279
8280            if (c < 0) {
8281                r1 = gv(rc);
8282                move_reg(r2, r1, type.t);
8283                vtop->r = r2;
8284                gsym(tt);
8285                if (islv)
8286                    indir();
8287            }
8288        }
8289    }
8290}
8291
8292static void expr_eq(void)
8293{
8294    int t;
8295
8296    expr_cond();
8297    if (tok == '=' ||
8298        (tok >= 0xa5 && tok <= 0xaf) ||
8299        tok == 0xde || tok == 0xfc ||
8300        tok == 0x81 || tok == 0x82) {
8301        test_lvalue();
8302        t = tok;
8303        next();
8304        if (t == '=') {
8305            expr_eq();
8306        } else {
8307            vdup();
8308            expr_eq();
8309            gen_op(t & 0x7f);
8310        }
8311        vstore();
8312    }
8313}
8314
8315static void gexpr(void)
8316{
8317    while (1) {
8318        expr_eq();
8319        if (tok != ',')
8320            break;
8321        vpop();
8322        next();
8323    }
8324}
8325
8326
8327static void expr_const1(void)
8328{
8329    const_wanted++;
8330    nocode_wanted++;
8331    expr_cond();
8332    nocode_wanted--;
8333    const_wanted--;
8334}
8335
8336
8337static inline int64_t expr_const64(void)
8338{
8339    int64_t c;
8340    expr_const1();
8341    if ((vtop->r & (0x003f | 0x0100 | 0x0200)) != 0x0030)
8342        expect("constant expression");
8343    c = vtop->c.i;
8344    vpop();
8345    return c;
8346}
8347
8348
8349
8350static int expr_const(void)
8351{
8352    int c;
8353    int64_t wc = expr_const64();
8354    c = wc;
8355    if (c != wc && (unsigned)c != wc)
8356        tcc_error("constant exceeds 32 bit");
8357    return c;
8358}
8359
8360
8361
8362static int is_label(void)
8363{
8364    int last_tok;
8365
8366
8367    if (tok < TOK_DEFINE)
8368        return 0;
8369
8370    last_tok = tok;
8371    next();
8372    if (tok == ':') {
8373        return last_tok;
8374    } else {
8375        unget_tok(last_tok);
8376        return 0;
8377    }
8378}
8379
8380
8381static void gfunc_return(CType *func_type)
8382{
8383    if ((func_type->t & 0x000f) == 7) {
8384        CType type, ret_type;
8385        int ret_align, ret_nregs, regsize;
8386        ret_nregs = gfunc_sret(func_type, func_var, &ret_type,
8387                               &ret_align, &regsize);
8388        if (0 == ret_nregs) {
8389
8390
8391            type = *func_type;
8392            mk_pointer(&type);
8393            vset(&type, 0x0032 | 0x0100, func_vc);
8394            indir();
8395            vswap();
8396
8397            vstore();
8398        } else {
8399
8400            int r, size, addr, align;
8401            size = type_size(func_type,&align);
8402            if ((vtop->r != (0x0032 | 0x0100) ||
8403                 (vtop->c.i & (ret_align-1)))
8404                && (align & (ret_align-1))) {
8405                loc = (loc - size) & -ret_align;
8406                addr = loc;
8407                type = *func_type;
8408                vset(&type, 0x0032 | 0x0100, addr);
8409                vswap();
8410                vstore();
8411                vpop();
8412                vset(&ret_type, 0x0032 | 0x0100, addr);
8413            }
8414            vtop->type = ret_type;
8415            if (is_float(ret_type.t))
8416                r = rc_fret(ret_type.t);
8417            else
8418                r = 0x0004;
8419
8420            if (ret_nregs == 1)
8421                gv(r);
8422            else {
8423                for (;;) {
8424                    vdup();
8425                    gv(r);
8426                    vpop();
8427                    if (--ret_nregs == 0)
8428                      break;
8429
8430
8431
8432                    r <<= 1;
8433                    vtop->c.i += regsize;
8434                }
8435            }
8436        }
8437    } else if (is_float(func_type->t)) {
8438        gv(rc_fret(func_type->t));
8439    } else {
8440        gv(0x0004);
8441    }
8442    vtop--;
8443}
8444
8445
8446static int case_cmp(const void *pa, const void *pb)
8447{
8448    int64_t a = (*(struct case_t**) pa)->v1;
8449    int64_t b = (*(struct case_t**) pb)->v1;
8450    return a < b ? -1 : a > b;
8451}
8452
8453static void gcase(struct case_t **base, int len, int *bsym)
8454{
8455    struct case_t *p;
8456    int e;
8457    int ll = (vtop->type.t & 0x000f) == 4;
8458    gv(0x0001);
8459    while (len > 4) {
8460
8461        p = base[len/2];
8462        vdup();
8463 if (ll)
8464     vpushll(p->v2);
8465 else
8466     vpushi(p->v2);
8467        gen_op(0x9e);
8468        e = gtst(1, 0);
8469        vdup();
8470 if (ll)
8471     vpushll(p->v1);
8472 else
8473     vpushi(p->v1);
8474        gen_op(0x9d);
8475        gtst_addr(0, p->sym);
8476
8477        gcase(base, len/2, bsym);
8478        if (cur_switch->def_sym)
8479            gjmp_addr(cur_switch->def_sym);
8480        else
8481            *bsym = gjmp(*bsym);
8482
8483        gsym(e);
8484        e = len/2 + 1;
8485        base += e; len -= e;
8486    }
8487
8488    while (len--) {
8489        p = *base++;
8490        vdup();
8491 if (ll)
8492     vpushll(p->v2);
8493 else
8494     vpushi(p->v2);
8495        if (p->v1 == p->v2) {
8496            gen_op(0x94);
8497            gtst_addr(0, p->sym);
8498        } else {
8499            gen_op(0x9e);
8500            e = gtst(1, 0);
8501            vdup();
8502     if (ll)
8503         vpushll(p->v1);
8504     else
8505         vpushi(p->v1);
8506            gen_op(0x9d);
8507            gtst_addr(0, p->sym);
8508            gsym(e);
8509        }
8510    }
8511}
8512
8513static void block(int *bsym, int *csym, int is_expr)
8514{
8515    int a, b, c, d, cond;
8516    Sym *s;
8517
8518
8519    if (tcc_state->do_debug)
8520        tcc_debug_line(tcc_state);
8521
8522    if (is_expr) {
8523
8524        vpushi(0);
8525        vtop->type.t = 0;
8526    }
8527
8528    if (tok == TOK_IF) {
8529
8530 int saved_nocode_wanted = nocode_wanted;
8531        next();
8532        skip('(');
8533        gexpr();
8534        skip(')');
8535 cond = condition_3way();
8536        if (cond == 1)
8537            a = 0, vpop();
8538        else
8539            a = gvtst(1, 0);
8540        if (cond == 0)
8541     nocode_wanted |= 0x20000000;
8542        block(bsym, csym, 0);
8543 if (cond != 1)
8544     nocode_wanted = saved_nocode_wanted;
8545        c = tok;
8546        if (c == TOK_ELSE) {
8547            next();
8548            d = gjmp(0);
8549            gsym(a);
8550     if (cond == 1)
8551         nocode_wanted |= 0x20000000;
8552            block(bsym, csym, 0);
8553            gsym(d);
8554     if (cond != 0)
8555  nocode_wanted = saved_nocode_wanted;
8556        } else
8557            gsym(a);
8558    } else if (tok == TOK_WHILE) {
8559 int saved_nocode_wanted;
8560 nocode_wanted &= ~0x20000000;
8561        next();
8562        d = ind;
8563        vla_sp_restore();
8564        skip('(');
8565        gexpr();
8566        skip(')');
8567        a = gvtst(1, 0);
8568        b = 0;
8569        ++local_scope;
8570 saved_nocode_wanted = nocode_wanted;
8571        block(&a, &b, 0);
8572 nocode_wanted = saved_nocode_wanted;
8573        --local_scope;
8574        gjmp_addr(d);
8575        gsym(a);
8576        gsym_addr(b, d);
8577    } else if (tok == '{') {
8578        Sym *llabel;
8579        int block_vla_sp_loc = vla_sp_loc, saved_vlas_in_scope = vlas_in_scope;
8580
8581        next();
8582
8583        s = local_stack;
8584        llabel = local_label_stack;
8585        ++local_scope;
8586
8587
8588        if (tok == TOK_LABEL) {
8589            next();
8590            for(;;) {
8591                if (tok < TOK_DEFINE)
8592                    expect("label identifier");
8593                label_push(&local_label_stack, tok, 2);
8594                next();
8595                if (tok == ',') {
8596                    next();
8597                } else {
8598                    skip(';');
8599                    break;
8600                }
8601            }
8602        }
8603        while (tok != '}') {
8604     if ((a = is_label()))
8605  unget_tok(a);
8606     else
8607         decl(0x0032);
8608            if (tok != '}') {
8609                if (is_expr)
8610                    vpop();
8611                block(bsym, csym, is_expr);
8612            }
8613        }
8614
8615        label_pop(&local_label_stack, llabel, is_expr);
8616
8617        --local_scope;
8618
8619
8620
8621
8622
8623
8624
8625 sym_pop(&local_stack, s, is_expr);
8626
8627
8628        if (vlas_in_scope > saved_vlas_in_scope) {
8629            vla_sp_loc = saved_vlas_in_scope ? block_vla_sp_loc : vla_sp_root_loc;
8630            vla_sp_restore();
8631        }
8632        vlas_in_scope = saved_vlas_in_scope;
8633
8634        next();
8635    } else if (tok == TOK_RETURN) {
8636        next();
8637        if (tok != ';') {
8638            gexpr();
8639            gen_assign_cast(&func_vt);
8640            if ((func_vt.t & 0x000f) == 0)
8641                vtop--;
8642            else
8643                gfunc_return(&func_vt);
8644        }
8645        skip(';');
8646
8647        if (tok != '}' || local_scope != 1)
8648            rsym = gjmp(rsym);
8649 nocode_wanted |= 0x20000000;
8650    } else if (tok == TOK_BREAK) {
8651
8652        if (!bsym)
8653            tcc_error("cannot break");
8654        *bsym = gjmp(*bsym);
8655        next();
8656        skip(';');
8657 nocode_wanted |= 0x20000000;
8658    } else if (tok == TOK_CONTINUE) {
8659
8660        if (!csym)
8661            tcc_error("cannot continue");
8662        vla_sp_restore_root();
8663        *csym = gjmp(*csym);
8664        next();
8665        skip(';');
8666    } else if (tok == TOK_FOR) {
8667        int e;
8668 int saved_nocode_wanted;
8669 nocode_wanted &= ~0x20000000;
8670        next();
8671        skip('(');
8672        s = local_stack;
8673        ++local_scope;
8674        if (tok != ';') {
8675
8676            if (!decl0(0x0032, 1, 0)) {
8677
8678                gexpr();
8679                vpop();
8680            }
8681        }
8682        skip(';');
8683        d = ind;
8684        c = ind;
8685        vla_sp_restore();
8686        a = 0;
8687        b = 0;
8688        if (tok != ';') {
8689            gexpr();
8690            a = gvtst(1, 0);
8691        }
8692        skip(';');
8693        if (tok != ')') {
8694            e = gjmp(0);
8695            c = ind;
8696            vla_sp_restore();
8697            gexpr();
8698            vpop();
8699            gjmp_addr(d);
8700            gsym(e);
8701        }
8702        skip(')');
8703 saved_nocode_wanted = nocode_wanted;
8704        block(&a, &b, 0);
8705 nocode_wanted = saved_nocode_wanted;
8706        gjmp_addr(c);
8707        gsym(a);
8708        gsym_addr(b, c);
8709        --local_scope;
8710        sym_pop(&local_stack, s, 0);
8711
8712    } else
8713    if (tok == TOK_DO) {
8714 int saved_nocode_wanted;
8715 nocode_wanted &= ~0x20000000;
8716        next();
8717        a = 0;
8718        b = 0;
8719        d = ind;
8720        vla_sp_restore();
8721 saved_nocode_wanted = nocode_wanted;
8722        block(&a, &b, 0);
8723        skip(TOK_WHILE);
8724        skip('(');
8725        gsym(b);
8726 gexpr();
8727 c = gvtst(0, 0);
8728 gsym_addr(c, d);
8729 nocode_wanted = saved_nocode_wanted;
8730        skip(')');
8731        gsym(a);
8732        skip(';');
8733    } else
8734    if (tok == TOK_SWITCH) {
8735        struct switch_t *saved, sw;
8736 int saved_nocode_wanted = nocode_wanted;
8737 SValue switchval;
8738        next();
8739        skip('(');
8740        gexpr();
8741        skip(')');
8742 switchval = *vtop--;
8743        a = 0;
8744        b = gjmp(0);
8745        sw.p = 0; sw.n = 0; sw.def_sym = 0;
8746        saved = cur_switch;
8747        cur_switch = &sw;
8748        block(&a, csym, 0);
8749 nocode_wanted = saved_nocode_wanted;
8750        a = gjmp(a);
8751
8752        gsym(b);
8753        qsort(sw.p, sw.n, sizeof(void*), case_cmp);
8754        for (b = 1; b < sw.n; b++)
8755            if (sw.p[b - 1]->v2 >= sw.p[b]->v1)
8756                tcc_error("duplicate case value");
8757
8758
8759        if ((switchval.type.t & 0x000f) == 4)
8760            switchval.type.t &= ~0x0010;
8761        vpushv(&switchval);
8762        gcase(sw.p, sw.n, &a);
8763        vpop();
8764        if (sw.def_sym)
8765          gjmp_addr(sw.def_sym);
8766        dynarray_reset(&sw.p, &sw.n);
8767        cur_switch = saved;
8768
8769        gsym(a);
8770    } else
8771    if (tok == TOK_CASE) {
8772        struct case_t *cr = tcc_malloc(sizeof(struct case_t));
8773        if (!cur_switch)
8774            expect("switch");
8775 nocode_wanted &= ~0x20000000;
8776        next();
8777        cr->v1 = cr->v2 = expr_const64();
8778        if (gnu_ext && tok == 0xc8) {
8779            next();
8780            cr->v2 = expr_const64();
8781            if (cr->v2 < cr->v1)
8782                tcc_warning("empty case range");
8783        }
8784        cr->sym = ind;
8785        dynarray_add(&cur_switch->p, &cur_switch->n, cr);
8786        skip(':');
8787        is_expr = 0;
8788        goto block_after_label;
8789    } else
8790    if (tok == TOK_DEFAULT) {
8791        next();
8792        skip(':');
8793        if (!cur_switch)
8794            expect("switch");
8795        if (cur_switch->def_sym)
8796            tcc_error("too many 'default'");
8797        cur_switch->def_sym = ind;
8798        is_expr = 0;
8799        goto block_after_label;
8800    } else
8801    if (tok == TOK_GOTO) {
8802        next();
8803        if (tok == '*' && gnu_ext) {
8804
8805            next();
8806            gexpr();
8807            if ((vtop->type.t & 0x000f) != 5)
8808                expect("pointer");
8809            ggoto();
8810        } else if (tok >= TOK_DEFINE) {
8811            s = label_find(tok);
8812
8813            if (!s) {
8814                s = label_push(&global_label_stack, tok, 1);
8815            } else {
8816                if (s->r == 2)
8817                    s->r = 1;
8818            }
8819            vla_sp_restore_root();
8820     if (s->r & 1)
8821                s->jnext = gjmp(s->jnext);
8822            else
8823                gjmp_addr(s->jnext);
8824            next();
8825        } else {
8826            expect("label identifier");
8827        }
8828        skip(';');
8829    } else if (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3) {
8830        asm_instr();
8831    } else {
8832        b = is_label();
8833        if (b) {
8834
8835     next();
8836            s = label_find(b);
8837            if (s) {
8838                if (s->r == 0)
8839                    tcc_error("duplicate label '%s'", get_tok_str(s->v, 0));
8840                gsym(s->jnext);
8841                s->r = 0;
8842            } else {
8843                s = label_push(&global_label_stack, b, 0);
8844            }
8845            s->jnext = ind;
8846            vla_sp_restore();
8847
8848        block_after_label:
8849     nocode_wanted &= ~0x20000000;
8850            if (tok == '}') {
8851                tcc_warning("deprecated use of label at end of compound statement");
8852            } else {
8853                if (is_expr)
8854                    vpop();
8855                block(bsym, csym, is_expr);
8856            }
8857        } else {
8858
8859            if (tok != ';') {
8860                if (is_expr) {
8861                    vpop();
8862                    gexpr();
8863                } else {
8864                    gexpr();
8865                    vpop();
8866                }
8867            }
8868            skip(';');
8869        }
8870    }
8871}
8872
8873
8874
8875
8876
8877
8878static void skip_or_save_block(TokenString **str)
8879{
8880    int braces = tok == '{';
8881    int level = 0;
8882    if (str)
8883      *str = tok_str_alloc();
8884
8885    while ((level > 0 || (tok != '}' && tok != ',' && tok != ';' && tok != ')'))) {
8886 int t;
8887 if (tok == (-1)) {
8888      if (str || level > 0)
8889        tcc_error("unexpected end of file");
8890      else
8891        break;
8892 }
8893 if (str)
8894   tok_str_add_tok(*str);
8895 t = tok;
8896 next();
8897 if (t == '{' || t == '(') {
8898     level++;
8899 } else if (t == '}' || t == ')') {
8900     level--;
8901     if (level == 0 && braces && t == '}')
8902       break;
8903 }
8904    }
8905    if (str) {
8906 tok_str_add(*str, -1);
8907 tok_str_add(*str, 0);
8908    }
8909}
8910
8911
8912
8913
8914static void parse_init_elem(int expr_type)
8915{
8916    int saved_global_expr;
8917    switch(expr_type) {
8918    case 1:
8919
8920        saved_global_expr = global_expr;
8921        global_expr = 1;
8922        expr_const1();
8923        global_expr = saved_global_expr;
8924
8925
8926        if (((vtop->r & (0x003f | 0x0100)) != 0x0030
8927      && ((vtop->r & (0x0200|0x0100)) != (0x0200|0x0100)
8928   || vtop->sym->v < 0x10000000))
8929
8930
8931
8932            )
8933            tcc_error("initializer element is not constant");
8934        break;
8935    case 2:
8936        expr_eq();
8937        break;
8938    }
8939}
8940
8941
8942static void init_putz(Section *sec, unsigned long c, int size)
8943{
8944    if (sec) {
8945
8946    } else {
8947        vpush_global_sym(&func_old_type, TOK_memset);
8948        vseti(0x0032, c);
8949
8950
8951
8952
8953        vpushi(0);
8954        vpushs(size);
8955
8956        gfunc_call(3);
8957    }
8958}
8959
8960
8961
8962
8963
8964
8965
8966static int decl_designator(CType *type, Section *sec, unsigned long c,
8967                           Sym **cur_field, int size_only, int al)
8968{
8969    Sym *s, *f;
8970    int index, index_last, align, l, nb_elems, elem_size;
8971    unsigned long corig = c;
8972
8973    elem_size = 0;
8974    nb_elems = 1;
8975    if (gnu_ext && (l = is_label()) != 0)
8976        goto struct_field;
8977
8978    while (nb_elems == 1 && (tok == '[' || tok == '.')) {
8979        if (tok == '[') {
8980            if (!(type->t & 0x0040))
8981                expect("array type");
8982            next();
8983            index = index_last = expr_const();
8984            if (tok == 0xc8 && gnu_ext) {
8985                next();
8986                index_last = expr_const();
8987            }
8988            skip(']');
8989            s = type->ref;
8990     if (index < 0 || (s->c >= 0 && index_last >= s->c) ||
8991  index_last < index)
8992         tcc_error("invalid index");
8993            if (cur_field)
8994  (*cur_field)->c = index_last;
8995            type = pointed_type(type);
8996            elem_size = type_size(type, &align);
8997            c += index * elem_size;
8998            nb_elems = index_last - index + 1;
8999        } else {
9000            next();
9001            l = tok;
9002        struct_field:
9003            next();
9004            if ((type->t & 0x000f) != 7)
9005                expect("struct/union type");
9006     f = find_field(type, l);
9007            if (!f)
9008                expect("field");
9009            if (cur_field)
9010                *cur_field = f;
9011     type = &f->type;
9012            c += f->c;
9013        }
9014        cur_field = 0;
9015    }
9016    if (!cur_field) {
9017        if (tok == '=') {
9018            next();
9019        } else if (!gnu_ext) {
9020     expect("=");
9021        }
9022    } else {
9023        if (type->t & 0x0040) {
9024     index = (*cur_field)->c;
9025     if (type->ref->c >= 0 && index >= type->ref->c)
9026         tcc_error("index too large");
9027            type = pointed_type(type);
9028            c += index * type_size(type, &align);
9029        } else {
9030            f = *cur_field;
9031     while (f && (f->v & 0x10000000) && (f->type.t & 0x0080))
9032         *cur_field = f = f->next;
9033            if (!f)
9034                tcc_error("too many field init");
9035     type = &f->type;
9036            c += f->c;
9037        }
9038    }
9039
9040
9041    if (!size_only && c - corig > al)
9042 init_putz(sec, corig + al, c - corig - al);
9043    decl_initializer(type, sec, c, 0, size_only);
9044
9045
9046    if (!size_only && nb_elems > 1) {
9047        unsigned long c_end;
9048        uint8_t *src, *dst;
9049        int i;
9050
9051        if (!sec) {
9052     vset(type, 0x0032|0x0100, c);
9053     for (i = 1; i < nb_elems; i++) {
9054  vset(type, 0x0032|0x0100, c + elem_size * i);
9055  vswap();
9056  vstore();
9057     }
9058     vpop();
9059        } else if (!(nocode_wanted > 0)) {
9060     c_end = c + nb_elems * elem_size;
9061     if (c_end > sec->data_allocated)
9062         section_realloc(sec, c_end);
9063     src = sec->data + c;
9064     dst = src;
9065     for(i = 1; i < nb_elems; i++) {
9066  dst += elem_size;
9067  memcpy(dst, src, elem_size);
9068     }
9069 }
9070    }
9071    c += nb_elems * type_size(type, &align);
9072    if (c - corig > al)
9073      al = c - corig;
9074    return al;
9075}
9076
9077
9078static void init_putv(CType *type, Section *sec, unsigned long c)
9079{
9080    int bt;
9081    void *ptr;
9082    CType dtype;
9083
9084    dtype = *type;
9085    dtype.t &= ~0x0100;
9086
9087    if (sec) {
9088 int size, align;
9089
9090
9091        gen_assign_cast(&dtype);
9092        bt = type->t & 0x000f;
9093
9094        if ((vtop->r & 0x0200)
9095            && bt != 5
9096            && bt != 6
9097            && (bt != (8 == 8 ? 4 : 3)
9098                || (type->t & 0x0080))
9099            && !((vtop->r & 0x0030) && vtop->sym->v >= 0x10000000)
9100            )
9101            tcc_error("initializer element is not computable at load time");
9102
9103        if ((nocode_wanted > 0)) {
9104            vtop--;
9105            return;
9106        }
9107
9108 size = type_size(type, &align);
9109 section_reserve(sec, c + size);
9110        ptr = sec->data + c;
9111
9112
9113 if ((vtop->r & (0x0200|0x0030)) == (0x0200|0x0030) &&
9114     vtop->sym->v >= 0x10000000 &&
9115# 6488 "tccgen.c"
9116     (vtop->type.t & 0x000f) != 5) {
9117
9118     Section *ssec;
9119     Elf64_Sym *esym;
9120     Elf64_Rela *rel;
9121     esym = elfsym(vtop->sym);
9122     ssec = tcc_state->sections[esym->st_shndx];
9123     memmove (ptr, ssec->data + esym->st_value, size);
9124     if (ssec->reloc) {
9125
9126
9127
9128
9129  int num_relocs = ssec->reloc->data_offset / sizeof(*rel);
9130  rel = (Elf64_Rela*)(ssec->reloc->data + ssec->reloc->data_offset);
9131  while (num_relocs--) {
9132      rel--;
9133      if (rel->r_offset >= esym->st_value + size)
9134        continue;
9135      if (rel->r_offset < esym->st_value)
9136        break;
9137
9138
9139
9140
9141
9142
9143      put_elf_reloca(symtab_section, sec,
9144       c + rel->r_offset - esym->st_value,
9145       ((rel->r_info) & 0xffffffff),
9146       ((rel->r_info) >> 32),
9147
9148       rel->r_addend
9149
9150
9151
9152      );
9153  }
9154     }
9155 } else {
9156            if (type->t & 0x0080) {
9157                int bit_pos, bit_size, bits, n;
9158                unsigned char *p, v, m;
9159                bit_pos = (((vtop->type.t) >> 20) & 0x3f);
9160                bit_size = (((vtop->type.t) >> (20 + 6)) & 0x3f);
9161                p = (unsigned char*)ptr + (bit_pos >> 3);
9162                bit_pos &= 7, bits = 0;
9163                while (bit_size) {
9164                    n = 8 - bit_pos;
9165                    if (n > bit_size)
9166                        n = bit_size;
9167                    v = vtop->c.i >> bits << bit_pos;
9168                    m = ((1 << n) - 1) << bit_pos;
9169                    *p = (*p & ~m) | (v & m);
9170                    bits += n, bit_size -= n, bit_pos = 0, ++p;
9171                }
9172            } else
9173            switch(bt) {
9174
9175
9176
9177     case 11:
9178  vtop->c.i = vtop->c.i != 0;
9179     case 1:
9180  *(char *)ptr |= vtop->c.i;
9181  break;
9182     case 2:
9183  *(short *)ptr |= vtop->c.i;
9184  break;
9185     case 8:
9186  *(float*)ptr = vtop->c.f;
9187  break;
9188     case 9:
9189  *(double *)ptr = vtop->c.d;
9190  break;
9191     case 10:
9192
9193                if (sizeof (long double) >= 10)
9194                    memcpy(ptr, &vtop->c.ld, 10);
9195
9196
9197
9198
9199                else if (vtop->c.ld == 0.0)
9200                    ;
9201                else
9202
9203                if (sizeof(long double) == 16)
9204      *(long double*)ptr = vtop->c.ld;
9205                else if (sizeof(double) == 16)
9206      *(double *)ptr = (double)vtop->c.ld;
9207                else
9208                    tcc_error("can't cross compile long double constants");
9209  break;
9210
9211
9212
9213
9214
9215     case 4:
9216
9217     case 5:
9218  {
9219      Elf64_Addr val = vtop->c.i;
9220
9221      if (vtop->r & 0x0200)
9222        greloca(sec, vtop->sym, c, 1, val);
9223      else
9224        *(Elf64_Addr *)ptr |= val;
9225
9226
9227
9228
9229
9230      break;
9231  }
9232     default:
9233  {
9234      int val = vtop->c.i;
9235
9236      if (vtop->r & 0x0200)
9237        greloca(sec, vtop->sym, c, 1, val);
9238      else
9239        *(int *)ptr |= val;
9240
9241
9242
9243
9244
9245      break;
9246  }
9247     }
9248 }
9249        vtop--;
9250    } else {
9251        vset(&dtype, 0x0032|0x0100, c);
9252        vswap();
9253        vstore();
9254        vpop();
9255    }
9256}
9257
9258
9259
9260
9261
9262
9263static void decl_initializer(CType *type, Section *sec, unsigned long c,
9264                             int first, int size_only)
9265{
9266    int len, n, no_oblock, nb, i;
9267    int size1, align1;
9268    int have_elem;
9269    Sym *s, *f;
9270    Sym indexsym;
9271    CType *t1;
9272
9273
9274
9275    have_elem = tok == '}' || tok == ',';
9276    if (!have_elem && tok != '{' &&
9277
9278
9279
9280 tok != 0xba && tok != 0xb9 &&
9281 !size_only) {
9282 parse_init_elem(!sec ? 2 : 1);
9283 have_elem = 1;
9284    }
9285
9286    if (have_elem &&
9287 !(type->t & 0x0040) &&
9288
9289
9290
9291 is_compatible_unqualified_types(type, &vtop->type)) {
9292        init_putv(type, sec, c);
9293    } else if (type->t & 0x0040) {
9294        s = type->ref;
9295        n = s->c;
9296        t1 = pointed_type(type);
9297        size1 = type_size(t1, &align1);
9298
9299        no_oblock = 1;
9300        if ((first && tok != 0xba && tok != 0xb9) ||
9301            tok == '{') {
9302            if (tok != '{')
9303                tcc_error("character array initializer must be a literal,"
9304                    " optionally enclosed in braces");
9305            skip('{');
9306            no_oblock = 0;
9307        }
9308
9309
9310
9311        if ((tok == 0xba &&
9312
9313
9314
9315             (t1->t & 0x000f) == 3
9316
9317            ) || (tok == 0xb9 && (t1->t & 0x000f) == 1)) {
9318     len = 0;
9319            while (tok == 0xb9 || tok == 0xba) {
9320                int cstr_len, ch;
9321
9322
9323                if (tok == 0xb9)
9324                    cstr_len = tokc.str.size;
9325                else
9326                    cstr_len = tokc.str.size / sizeof(nwchar_t);
9327                cstr_len--;
9328                nb = cstr_len;
9329                if (n >= 0 && nb > (n - len))
9330                    nb = n - len;
9331                if (!size_only) {
9332                    if (cstr_len > nb)
9333                        tcc_warning("initializer-string for array is too long");
9334
9335
9336
9337                    if (sec && tok == 0xb9 && size1 == 1) {
9338                        if (!(nocode_wanted > 0))
9339                            memcpy(sec->data + c + len, tokc.str.data, nb);
9340                    } else {
9341                        for(i=0;i<nb;i++) {
9342                            if (tok == 0xb9)
9343                                ch = ((unsigned char *)tokc.str.data)[i];
9344                            else
9345                                ch = ((nwchar_t *)tokc.str.data)[i];
9346       vpushi(ch);
9347                            init_putv(t1, sec, c + (len + i) * size1);
9348                        }
9349                    }
9350                }
9351                len += nb;
9352                next();
9353            }
9354
9355
9356            if (n < 0 || len < n) {
9357                if (!size_only) {
9358      vpushi(0);
9359                    init_putv(t1, sec, c + (len * size1));
9360                }
9361                len++;
9362            }
9363     len *= size1;
9364        } else {
9365     indexsym.c = 0;
9366     f = &indexsym;
9367
9368          do_init_list:
9369     len = 0;
9370     while (tok != '}' || have_elem) {
9371  len = decl_designator(type, sec, c, &f, size_only, len);
9372  have_elem = 0;
9373  if (type->t & 0x0040) {
9374      ++indexsym.c;
9375
9376
9377
9378      if (no_oblock && len >= n*size1)
9379          break;
9380  } else {
9381      if (s->type.t == (1 << 20 | 7))
9382          f = 0;
9383      else
9384          f = f->next;
9385      if (no_oblock && f == 0)
9386          break;
9387  }
9388
9389  if (tok == '}')
9390      break;
9391  skip(',');
9392     }
9393        }
9394
9395 if (!size_only && len < n*size1)
9396     init_putz(sec, c + len, n*size1 - len);
9397        if (!no_oblock)
9398            skip('}');
9399
9400        if (n < 0)
9401            s->c = size1 == 1 ? len : ((len + size1 - 1)/size1);
9402    } else if ((type->t & 0x000f) == 7) {
9403 size1 = 1;
9404        no_oblock = 1;
9405        if (first || tok == '{') {
9406            skip('{');
9407            no_oblock = 0;
9408        }
9409        s = type->ref;
9410        f = s->next;
9411        n = s->c;
9412 goto do_init_list;
9413    } else if (tok == '{') {
9414        next();
9415        decl_initializer(type, sec, c, first, size_only);
9416        skip('}');
9417    } else if (size_only) {
9418
9419
9420
9421
9422
9423
9424
9425        skip_or_save_block(0);
9426    } else {
9427 if (!have_elem) {
9428
9429
9430
9431     if (tok != 0xb9 && tok != 0xba)
9432       expect("string constant");
9433     parse_init_elem(!sec ? 2 : 1);
9434 }
9435        init_putv(type, sec, c);
9436    }
9437}
9438# 6818 "tccgen.c"
9439static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
9440                                   int has_init, int v, int scope)
9441{
9442    int size, align, addr;
9443    TokenString *init_str = 0;
9444
9445    Section *sec;
9446    Sym *flexible_array;
9447    Sym *sym = 0;
9448    int saved_nocode_wanted = nocode_wanted;
9449
9450    int bcheck = tcc_state->do_bounds_check && !(nocode_wanted > 0);
9451
9452
9453    if (type->t & 0x00002000)
9454        nocode_wanted |= (nocode_wanted > 0) ? 0x40000000 : 0x80000000;
9455
9456    flexible_array = 0;
9457    if ((type->t & 0x000f) == 7) {
9458        Sym *field = type->ref->next;
9459        if (field) {
9460            while (field->next)
9461                field = field->next;
9462            if (field->type.t & 0x0040 && field->type.ref->c < 0)
9463                flexible_array = field;
9464        }
9465    }
9466
9467    size = type_size(type, &align);
9468
9469
9470
9471
9472
9473
9474    if (size < 0 || (flexible_array && has_init)) {
9475        if (!has_init)
9476            tcc_error("unknown type size");
9477
9478        if (has_init == 2) {
9479     init_str = tok_str_alloc();
9480
9481            while (tok == 0xb9 || tok == 0xba) {
9482                tok_str_add_tok(init_str);
9483                next();
9484            }
9485     tok_str_add(init_str, -1);
9486     tok_str_add(init_str, 0);
9487        } else {
9488     skip_or_save_block(&init_str);
9489        }
9490        unget_tok(0);
9491
9492
9493        begin_macro(init_str, 1);
9494        next();
9495        decl_initializer(type, 0, 0, 1, 1);
9496
9497        macro_ptr = init_str->str;
9498        next();
9499
9500
9501        size = type_size(type, &align);
9502        if (size < 0)
9503            tcc_error("unknown type size");
9504    }
9505
9506
9507    if (flexible_array &&
9508 flexible_array->type.ref->c > 0)
9509        size += flexible_array->type.ref->c
9510         * pointed_size(&flexible_array->type);
9511
9512    if (ad->a.aligned) {
9513 int speca = 1 << (ad->a.aligned - 1);
9514        if (speca > align)
9515            align = speca;
9516    } else if (ad->a.packed) {
9517        align = 1;
9518    }
9519
9520    if ((nocode_wanted > 0))
9521        size = 0, align = 1;
9522
9523    if ((r & 0x003f) == 0x0032) {
9524        sec = 0;
9525
9526        if (bcheck && (type->t & 0x0040)) {
9527            loc--;
9528        }
9529
9530        loc = (loc - size) & -align;
9531        addr = loc;
9532
9533
9534
9535
9536        if (bcheck && (type->t & 0x0040)) {
9537            Elf64_Addr *bounds_ptr;
9538
9539            loc--;
9540
9541            bounds_ptr = section_ptr_add(lbounds_section, 2 * sizeof(Elf64_Addr));
9542            bounds_ptr[0] = addr;
9543            bounds_ptr[1] = size;
9544        }
9545
9546        if (v) {
9547
9548
9549     if (ad->asm_label) {
9550  int reg = asm_parse_regvar(ad->asm_label);
9551  if (reg >= 0)
9552      r = (r & ~0x003f) | reg;
9553     }
9554
9555            sym = sym_push(v, type, r, addr);
9556            sym->a = ad->a;
9557        } else {
9558
9559            vset(type, r, addr);
9560        }
9561    } else {
9562        if (v && scope == 0x0030) {
9563
9564            sym = sym_find(v);
9565            if (sym) {
9566                patch_storage(sym, ad, type);
9567
9568                if (!has_init && sym->c && elfsym(sym)->st_shndx != 0)
9569                    goto no_alloc;
9570            }
9571        }
9572
9573
9574        sec = ad->section;
9575        if (!sec) {
9576            if (has_init)
9577                sec = data_section;
9578            else if (tcc_state->nocommon)
9579                sec = bss_section;
9580        }
9581
9582        if (sec) {
9583     addr = section_add(sec, size, align);
9584
9585
9586            if (bcheck)
9587                section_add(sec, 1, 1);
9588
9589        } else {
9590            addr = align;
9591     sec = common_section;
9592        }
9593
9594        if (v) {
9595            if (!sym) {
9596                sym = sym_push(v, type, r | 0x0200, 0);
9597                patch_storage(sym, ad, 0);
9598            }
9599
9600
9601            sym->sym_scope = 0;
9602
9603     put_extern_sym(sym, sec, addr, size);
9604        } else {
9605
9606            sym = get_sym_ref(type, sec, addr, size);
9607     vpushsym(type, sym);
9608     vtop->r |= r;
9609        }
9610
9611
9612
9613
9614        if (bcheck) {
9615            Elf64_Addr *bounds_ptr;
9616
9617            greloca(bounds_section, sym, bounds_section->data_offset, 1, 0);
9618
9619            bounds_ptr = section_ptr_add(bounds_section, 2 * sizeof(Elf64_Addr));
9620            bounds_ptr[0] = 0;
9621            bounds_ptr[1] = size;
9622        }
9623
9624    }
9625
9626    if (type->t & 0x0400) {
9627        int a;
9628
9629        if ((nocode_wanted > 0))
9630            goto no_alloc;
9631
9632
9633        if (vlas_in_scope == 0) {
9634            if (vla_sp_root_loc == -1)
9635                vla_sp_root_loc = (loc -= 8);
9636            gen_vla_sp_save(vla_sp_root_loc);
9637        }
9638
9639        vla_runtime_type_size(type, &a);
9640        gen_vla_alloc(type, a);
9641
9642
9643
9644
9645
9646        gen_vla_sp_save(addr);
9647        vla_sp_loc = addr;
9648        vlas_in_scope++;
9649
9650    } else if (has_init) {
9651 size_t oldreloc_offset = 0;
9652 if (sec && sec->reloc)
9653   oldreloc_offset = sec->reloc->data_offset;
9654        decl_initializer(type, sec, addr, 1, 0);
9655 if (sec && sec->reloc)
9656   squeeze_multi_relocs(sec, oldreloc_offset);
9657
9658
9659        if (flexible_array)
9660            flexible_array->type.ref->c = -1;
9661    }
9662
9663 no_alloc:
9664
9665    if (init_str) {
9666        end_macro();
9667        next();
9668    }
9669
9670    nocode_wanted = saved_nocode_wanted;
9671}
9672
9673
9674
9675static void gen_function(Sym *sym)
9676{
9677    nocode_wanted = 0;
9678    ind = cur_text_section->data_offset;
9679
9680    put_extern_sym(sym, cur_text_section, ind, 0);
9681    funcname = get_tok_str(sym->v, 0);
9682    func_ind = ind;
9683
9684    vla_sp_loc = -1;
9685    vla_sp_root_loc = -1;
9686
9687    tcc_debug_funcstart(tcc_state, sym);
9688
9689    sym_push2(&local_stack, 0x20000000, 0, 0);
9690    local_scope = 1;
9691    gfunc_prolog(&sym->type);
9692    local_scope = 0;
9693    rsym = 0;
9694    block(0, 0, 0);
9695    nocode_wanted = 0;
9696    gsym(rsym);
9697    gfunc_epilog();
9698    cur_text_section->data_offset = ind;
9699    label_pop(&global_label_stack, 0, 0);
9700
9701    local_scope = 0;
9702    sym_pop(&local_stack, 0, 0);
9703
9704
9705    elfsym(sym)->st_size = ind - func_ind;
9706    tcc_debug_funcend(tcc_state, ind - func_ind);
9707
9708    cur_text_section = 0;
9709    funcname = "";
9710    func_vt.t = 0;
9711    func_var = 0;
9712    ind = 0;
9713    nocode_wanted = 0x80000000;
9714    check_vstack();
9715}
9716
9717static void gen_inline_functions(TCCState *s)
9718{
9719    Sym *sym;
9720    int inline_generated, i, ln;
9721    struct InlineFunc *fn;
9722
9723    ln = file->line_num;
9724
9725    do {
9726        inline_generated = 0;
9727        for (i = 0; i < s->nb_inline_fns; ++i) {
9728            fn = s->inline_fns[i];
9729            sym = fn->sym;
9730            if (sym && sym->c) {
9731
9732
9733                fn->sym = 0;
9734                if (file)
9735                    pstrcpy(file->filename, sizeof file->filename, fn->filename);
9736                sym->type.t &= ~0x00008000;
9737
9738                begin_macro(fn->func_str, 1);
9739                next();
9740                cur_text_section = text_section;
9741                gen_function(sym);
9742                end_macro();
9743
9744                inline_generated = 1;
9745            }
9746        }
9747    } while (inline_generated);
9748    file->line_num = ln;
9749}
9750
9751static void free_inline_functions(TCCState *s)
9752{
9753    int i;
9754
9755    for (i = 0; i < s->nb_inline_fns; ++i) {
9756        struct InlineFunc *fn = s->inline_fns[i];
9757        if (fn->sym)
9758            tok_str_free(fn->func_str);
9759    }
9760    dynarray_reset(&s->inline_fns, &s->nb_inline_fns);
9761}
9762
9763
9764
9765static int decl0(int l, int is_for_loop_init, Sym *func_sym)
9766{
9767    int v, has_init, r;
9768    CType type, btype;
9769    Sym *sym;
9770    AttributeDef ad;
9771
9772    while (1) {
9773        if (!parse_btype(&btype, &ad)) {
9774            if (is_for_loop_init)
9775                return 0;
9776
9777            if (tok == ';' && l != 0x0033) {
9778                next();
9779                continue;
9780            }
9781            if (l != 0x0030)
9782                break;
9783            if (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3) {
9784
9785                asm_global_instr();
9786                continue;
9787            }
9788            if (tok >= TOK_DEFINE) {
9789
9790
9791                btype.t = 3;
9792            } else {
9793                if (tok != (-1))
9794                    expect("declaration");
9795                break;
9796            }
9797        }
9798        if (tok == ';') {
9799     if ((btype.t & 0x000f) == 7) {
9800  int v = btype.ref->v;
9801  if (!(v & 0x20000000) && (v & ~0x40000000) >= 0x10000000)
9802             tcc_warning("unnamed struct/union that defines no instances");
9803                next();
9804                continue;
9805     }
9806            if (((btype.t & (((1 << (6+6)) - 1) << 20 | 0x0080)) == (2 << 20))) {
9807                next();
9808                continue;
9809            }
9810        }
9811        while (1) {
9812            type = btype;
9813
9814
9815
9816
9817
9818     if ((type.t & 0x0040) && type.ref->c < 0) {
9819  type.ref = sym_push(0x20000000, &type.ref->type, 0, type.ref->c);
9820     }
9821            type_decl(&type, &ad, &v, 2);
9822
9823
9824
9825
9826
9827
9828
9829            if ((type.t & 0x000f) == 6) {
9830                if ((type.t & 0x00002000) && (l == 0x0032)) {
9831                    tcc_error("function without file scope cannot be static");
9832                }
9833
9834
9835                sym = type.ref;
9836                if (sym->f.func_type == 2 && l == 0x0030)
9837                    decl0(0x0033, 0, sym);
9838            }
9839
9840            if (gnu_ext && (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3)) {
9841                ad.asm_label = asm_label_instr();
9842
9843                parse_attribute(&ad);
9844                if (tok == '{')
9845                    expect(";");
9846            }
9847# 7239 "tccgen.c"
9848            if (tok == '{') {
9849                if (l != 0x0030)
9850                    tcc_error("cannot use local functions");
9851                if ((type.t & 0x000f) != 6)
9852                    expect("function definition");
9853
9854
9855
9856                sym = type.ref;
9857                while ((sym = sym->next) != 0) {
9858                    if (!(sym->v & ~0x20000000))
9859                        expect("identifier");
9860      if (sym->type.t == 0)
9861          sym->type = int_type;
9862  }
9863
9864
9865                if ((type.t & (0x00001000 | 0x00008000)) == (0x00001000 | 0x00008000))
9866                    type.t = (type.t & ~0x00001000) | 0x00002000;
9867
9868
9869                sym = external_global_sym(v, &type, 0);
9870                type.t &= ~0x00001000;
9871                patch_storage(sym, &ad, &type);
9872
9873
9874
9875
9876                if ((type.t & (0x00008000 | 0x00002000)) ==
9877                    (0x00008000 | 0x00002000)) {
9878                    struct InlineFunc *fn;
9879                    const char *filename;
9880
9881                    filename = file ? file->filename : "";
9882                    fn = tcc_malloc(sizeof *fn + strlen(filename));
9883                    strcpy(fn->filename, filename);
9884                    fn->sym = sym;
9885      skip_or_save_block(&fn->func_str);
9886                    dynarray_add(&tcc_state->inline_fns,
9887     &tcc_state->nb_inline_fns, fn);
9888                } else {
9889
9890                    cur_text_section = ad.section;
9891                    if (!cur_text_section)
9892                        cur_text_section = text_section;
9893                    gen_function(sym);
9894                }
9895                break;
9896            } else {
9897  if (l == 0x0033) {
9898
9899      for (sym = func_sym->next; sym; sym = sym->next)
9900   if ((sym->v & ~0x20000000) == v)
9901       goto found;
9902      tcc_error("declaration for parameter '%s' but no such parameter",
9903         get_tok_str(v, 0));
9904found:
9905      if (type.t & (0x00001000 | 0x00002000 | 0x00004000 | 0x00008000))
9906          tcc_error("storage class specified for '%s'",
9907      get_tok_str(v, 0));
9908      if (sym->type.t != 0)
9909          tcc_error("redefinition of parameter '%s'",
9910      get_tok_str(v, 0));
9911      convert_parameter_type(&type);
9912      sym->type = type;
9913  } else if (type.t & 0x00004000) {
9914
9915
9916                    sym = sym_find(v);
9917                    if (sym && sym->sym_scope == local_scope) {
9918                        if (!is_compatible_types(&sym->type, &type)
9919                            || !(sym->type.t & 0x00004000))
9920                            tcc_error("incompatible redefinition of '%s'",
9921                                get_tok_str(v, 0));
9922                        sym->type = type;
9923                    } else {
9924                        sym = sym_push(v, &type, 0, 0);
9925                    }
9926                    sym->a = ad.a;
9927                    sym->f = ad.f;
9928                } else {
9929                    r = 0;
9930                    if ((type.t & 0x000f) == 6) {
9931
9932
9933                        type.ref->f = ad.f;
9934                    } else if (!(type.t & 0x0040)) {
9935
9936                        r |= lvalue_type(type.t);
9937                    }
9938                    has_init = (tok == '=');
9939                    if (has_init && (type.t & 0x0400))
9940                        tcc_error("variable length array cannot be initialized");
9941                    if (((type.t & 0x00001000) && (!has_init || l != 0x0030)) ||
9942   ((type.t & 0x000f) == 6) ||
9943                        ((type.t & 0x0040) && (type.t & 0x00002000) &&
9944                         !has_init && l == 0x0030 && type.ref->c < 0)) {
9945
9946
9947
9948
9949                        type.t |= 0x00001000;
9950                        sym = external_sym(v, &type, r, &ad);
9951                        if (ad.alias_target) {
9952                            Elf64_Sym *esym;
9953                            Sym *alias_target;
9954                            alias_target = sym_find(ad.alias_target);
9955                            esym = elfsym(alias_target);
9956                            if (!esym)
9957                                tcc_error("unsupported forward __alias__ attribute");
9958
9959
9960                            sym->sym_scope = 0;
9961                            put_extern_sym2(sym, esym->st_shndx, esym->st_value, esym->st_size, 0);
9962                        }
9963                    } else {
9964                        if (type.t & 0x00002000)
9965                            r |= 0x0030;
9966                        else
9967                            r |= l;
9968                        if (has_init)
9969                            next();
9970                        else if (l == 0x0030)
9971
9972                            type.t |= 0x00001000;
9973                        decl_initializer_alloc(&type, &ad, r, has_init, v, l);
9974                    }
9975                }
9976                if (tok != ',') {
9977                    if (is_for_loop_init)
9978                        return 1;
9979                    skip(';');
9980                    break;
9981                }
9982                next();
9983            }
9984            ad.a.aligned = 0;
9985        }
9986    }
9987    return 0;
9988}
9989
9990static void decl(int l)
9991{
9992    decl0(l, 0, 0);
9993}
9994