1 /**
2  * Global variables for PARSER
3  *
4  * Compiler implementation of the
5  * $(LINK2 https://www.dlang.org, D programming language).
6  *
7  * Copyright:   Copyright (C) 1985-1998 by Symantec
8  *              Copyright (C) 2000-2023 by The D Language Foundation, All Rights Reserved
9  * Authors:     $(LINK2 https://www.digitalmars.com, Walter Bright)
10  * License:     $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
11  * Source:      $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/backend/var.d, backend/var.d)
12  */
13 
14 module dmd.backend.var;
15 
16 import core.stdc.stdio;
17 
18 import dmd.backend.cc;
19 import dmd.backend.cdef;
20 import dmd.backend.code;
21 import dmd.backend.dlist;
22 import dmd.backend.goh;
23 import dmd.backend.obj;
24 import dmd.backend.oper;
25 import dmd.backend.symtab;
26 import dmd.backend.ty;
27 import dmd.backend.type;
28 
29 
30 nothrow:
31 @safe:
32 
33 __gshared:
34 
35 /* Global flags:
36  */
37 
38 char PARSER = 0;                    // indicate we're in the parser
39 char OPTIMIZER = 0;                 // indicate we're in the optimizer
40 int structalign;                /* alignment for members of structures  */
41 char dbcs = 0;                      // current double byte character set
42 
43 // These change depending on memory model
44 int TYptrdiff = TYint;
45 int TYsize = TYuint;
46 int TYsize_t = TYuint;
47 int TYaarray = TYnptr;
48 int TYdelegate = TYllong;
49 int TYdarray = TYullong;
50 
51 char debuga = 0; /// cg - watch assignaddr()
52 char debugb = 0; /// watch block optimization
53 char debugc = 0; /// watch code generated
54 char debugd = 0; /// watch debug information generated
55 char debuge = 0; /// dump eh info
56 char debugf = 0; /// trees after dooptim
57 char debugg = 0; /// trees for code generator
58 char debugo = 0; /// watch optimizer
59 char debugr = 0; /// watch register allocation
60 char debugs = 0; /// watch common subexp eliminator
61 char debugt = 0; /// do test points
62 char debugu = 0;
63 char debugw = 0; /// watch progress
64 char debugx = 0; /// suppress predefined CPP stuff
65 char debugy = 0; /// watch output to il buffer
66 
67 /* File variables: */
68 
69 char *argv0;                    // argv[0] (program name)
70 extern (C)
71 {
72 FILE *fdep = null;              // dependency file stream pointer
73 FILE *flst = null;              // list file stream pointer
74 FILE *fin = null;               // input file
75 }
76 
77 // htod
78 char *fdmodulename = null;
79 extern (C) FILE *fdmodule = null;
80 
81 char*   foutdir = null,       // directory to place output files in
82         finname = null,
83         foutname = null,
84         fsymname = null,
85         fphreadname = null,
86         ftdbname = null,
87         fdepname = null,
88         flstname = null;       /* the filename strings                 */
89 
90 int pathsysi;                   // -isystem= index
91 list_t headers;                 /* pre-include files                    */
92 
93 /* Data from lexical analyzer: */
94 
95 uint idhash = 0;    // hash value of identifier
96 int xc = ' ';           // character last read
97 
98 /* Data for pragma processor:
99  */
100 
101 int colnumber = 0;              /* current column number                */
102 
103 /* Other variables: */
104 
105 int level = 0;                  /* declaration level                    */
106                                 /* 0: top level                         */
107                                 /* 1: function parameter declarations   */
108                                 /* 2: function local declarations       */
109                                 /* 3+: compound statement decls         */
110 
111 param_t *paramlst = null;       /* function parameter list              */
112 tym_t pointertype = TYnptr;     /* default data pointer type            */
113 
114 /* From util.c */
115 
116 /*****************************
117  * SCxxxx types.
118  */
119 
120 char[SCMAX] sytab =
121 [
122     /* unde */     SCEXP|SCKEP|SCSCT,      /* undefined                            */
123     /* auto */     SCEXP|SCSS|SCRD  ,      /* automatic (stack)                    */
124     /* static */   SCEXP|SCKEP|SCSCT,      /* statically allocated                 */
125     /* thread */   SCEXP|SCKEP      ,      /* thread local                         */
126     /* extern */   SCEXP|SCKEP|SCSCT,      /* external                             */
127     /* register */ SCEXP|SCSS|SCRD  ,      /* registered variable                  */
128     /* pseudo */   SCEXP            ,      /* pseudo register variable             */
129     /* global */   SCEXP|SCKEP|SCSCT,      /* top level global definition          */
130     /* comdat */   SCEXP|SCKEP|SCSCT,      /* initialized common block             */
131     /* parameter */SCEXP|SCSS       ,      /* function parameter                   */
132     /* regpar */   SCEXP|SCSS       ,      /* function register parameter          */
133     /* fastpar */  SCEXP|SCSS       ,      /* function parameter passed in register */
134     /* shadowreg */SCEXP|SCSS       ,      /* function parameter passed in register, shadowed on stack */
135     /* typedef */  0                ,      /* type definition                      */
136     /* explicit */ 0                ,      /* explicit                             */
137     /* mutable */  0                ,      /* mutable                              */
138     /* label */    0                ,      /* goto label                           */
139     /* struct */   SCKEP            ,      /* struct/class/union tag name          */
140     /* enum */     0                ,      /* enum tag name                        */
141     /* field */    SCEXP|SCKEP      ,      /* bit field of struct or union         */
142     /* const */    SCEXP|SCSCT      ,      /* constant integer                     */
143     /* member */   SCEXP|SCKEP|SCSCT,      /* member of struct or union            */
144     /* anon */     0                ,      /* member of anonymous union            */
145     /* inline */   SCEXP|SCKEP      ,      /* for inline functions                 */
146     /* sinline */  SCEXP|SCKEP      ,      /* for static inline functions          */
147     /* einline */  SCEXP|SCKEP      ,      /* for extern inline functions          */
148     /* overload */ SCEXP            ,      /* for overloaded function names        */
149     /* friend */   0                ,      /* friend of a class                    */
150     /* virtual */  0                ,      /* virtual function                     */
151     /* locstat */  SCEXP|SCSCT      ,      /* static, but local to a function      */
152     /* template */ 0                ,      /* class template                       */
153     /* functempl */0                ,      /* function template                    */
154     /* ftexpspec */0                ,      /* function template explicit specialization */
155     /* linkage */  0                ,      /* function linkage symbol              */
156     /* public */   SCEXP|SCKEP|SCSCT,      /* generate a pubdef for this           */
157     /* comdef */   SCEXP|SCKEP|SCSCT,      /* uninitialized common block           */
158     /* bprel */    SCEXP|SCSS       ,      /* variable at fixed offset from frame pointer */
159     /* namespace */0                ,      /* namespace                            */
160     /* alias */    0                ,      /* alias to another symbol              */
161     /* funcalias */0                ,      /* alias to another function symbol     */
162     /* memalias */ 0                ,      /* alias to base class member           */
163     /* stack */    SCEXP|SCSS       ,      /* offset from stack pointer (not frame pointer) */
164     /* adl */      0                ,      /* list of ADL symbols for overloading  */
165 ];
166 
167 extern (C) int controlc_saw = 0;              /* a control C was seen         */
168 symtab_t globsym;               /* global symbol table                  */
169 Pstate pstate;                  // parser state
170 Cstate cstate;                  // compiler state
171 
172 uint numcse;        // number of common subexpressions
173 
174 GlobalOptimizer go;
175 
176 /* From debug.c */
177 const(char)*[32] regstring = ["AX","CX","DX","BX","SP","BP","SI","DI",
178                              "R8","R9","R10","R11","R12","R13","R14","R15",
179                              "XMM0","XMM1","XMM2","XMM3","XMM4","XMM5","XMM6","XMM7",
180                              "ES","PSW","STACK","ST0","ST01","NOREG","RMload","RMstore"];
181 
182 /* From nwc.c */
183 
184 type *chartype;                 /* default 'char' type                  */
185 
186 Obj objmod = null;
187 
188 __gshared uint[256] tytab = tytab_init;
189 extern (D) private enum tytab_init =
190 () {
191     uint[256] tab;
192     foreach (i; TXptr)        { tab[i] |= TYFLptr; }
193     foreach (i; TXptr_nflat)  { tab[i] |= TYFLptr; }
194     foreach (i; TXreal)       { tab[i] |= TYFLreal; }
195     foreach (i; TXintegral)   { tab[i] |= TYFLintegral; }
196     foreach (i; TXimaginary)  { tab[i] |= TYFLimaginary; }
197     foreach (i; TXcomplex)    { tab[i] |= TYFLcomplex; }
198     foreach (i; TXuns)        { tab[i] |= TYFLuns; }
199     foreach (i; TXmptr)       { tab[i] |= TYFLmptr; }
200     foreach (i; TXfv)         { tab[i] |= TYFLfv; }
201     foreach (i; TXfarfunc)    { tab[i] |= TYFLfarfunc; }
202     foreach (i; TXpasfunc)    { tab[i] |= TYFLpascal; }
203     foreach (i; TXrevfunc)    { tab[i] |= TYFLrevparam; }
204     foreach (i; TXshort)      { tab[i] |= TYFLshort; }
205     foreach (i; TXaggregate)  { tab[i] |= TYFLaggregate; }
206     foreach (i; TXref)        { tab[i] |= TYFLref; }
207     foreach (i; TXfunc)       { tab[i] |= TYFLfunc; }
208     foreach (i; TXnullptr)    { tab[i] |= TYFLnullptr; }
209     foreach (i; TXpasfunc_nf) { tab[i] |= TYFLpascal; }
210     foreach (i; TXrevfunc_nf) { tab[i] |= TYFLrevparam; }
211     foreach (i; TXref_nflat)  { tab[i] |= TYFLref; }
212     foreach (i; TXfunc_nflat) { tab[i] |= TYFLfunc; }
213     foreach (i; TXxmmreg)     { tab[i] |= TYFLxmmreg; }
214     foreach (i; TXsimd)       { tab[i] |= TYFLsimd; }
215     return tab;
216 } ();
217 
218 /// Give an ascii string for a type
219 extern (C) __gshared const(char)*[TYMAX] tystring =
220 () {
221     const(char)*[TYMAX] ret = [
222         TYbool    : "bool",
223         TYchar    : "char",
224         TYchar8   : "char8_t",
225         TYchar16  : "char16_t",
226         TYshort   : "short",
227 
228         TYenum    : "enum",
229         TYint     : "int",
230 
231         TYlong    : "long",
232         TYdchar   : "dchar",
233         TYcent    : "cent",
234         TYucent   : "ucent",
235         TYfloat   : "float",
236         TYdouble  : "double",
237         TYdouble_alias : "double alias",
238 
239         TYfloat4  : "float4",
240         TYdouble2 : "double2",
241         TYshort8  : "short8",
242         TYlong4   : "int4",
243 
244         TYfloat8  : "float8",
245         TYdouble4 : "double4",
246         TYshort16 : "short16",
247         TYlong8   : "int8",
248 
249         TYfloat16 : "float16",
250         TYdouble8 : "double8",
251         TYshort32 : "short32",
252         TYlong16  : "int16",
253 
254         TYnptr    : "*",
255         TYref     : "&",
256         TYvoid    : "void",
257         TYnoreturn : "noreturn",
258         TYstruct  : "struct",
259         TYarray   : "array",
260         TYnfunc   : "C func",
261         TYnpfunc  : "Pascal func",
262         TYnsfunc  : "std func",
263         TYptr     : "*",
264         TYmfunc   : "member func",
265         TYjfunc   : "D func",
266         TYhfunc   : "C func",
267         TYnref    : "__near &",
268 
269         TYsptr     : "__ss *",
270         TYcptr     : "__cs *",
271         TYf16ptr   : "__far16 *",
272         TYfptr     : "__far *",
273         TYhptr     : "__huge *",
274         TYvptr     : "__handle *",
275         TYimmutPtr : "__immutable *",
276         TYsharePtr : "__shared *",
277         TYrestrictPtr : "__restrict *",
278         TYfgPtr    : "__fg *",
279         TYffunc    : "far C func",
280         TYfpfunc   : "far Pascal func",
281         TYfsfunc   : "far std func",
282         TYf16func  : "_far16 Pascal func",
283         TYnsysfunc : "sys func",
284         TYfsysfunc : "far sys func",
285         TYfref     : "__far &",
286 
287         TYifunc    : "interrupt func",
288         TYmemptr   : "memptr",
289         TYident    : "ident",
290         TYtemplate : "template",
291         TYvtshape  : "vtshape",
292 
293         TYschar     : "byte",
294         TYuchar     : "ubyte",
295         TYwchar_t   : "wchar",
296 
297         TYnullptr   : "typeof(null)",
298 
299         TYushort    : "ushort",
300         TYuint      : "uint",
301         TYulong     : "ulong",
302 
303         TYldouble   : "real",
304 
305         TYifloat    : "ifloat",
306         TYidouble   : "idouble",
307         TYildouble  : "ireal",
308 
309         TYcfloat    : "cfloat",
310         TYcdouble   : "cdouble",
311         TYcldouble  : "creal",
312 
313         TYschar16   : "byte[16]",
314         TYuchar16   : "ubyte[16]",
315         TYushort8   : "ushort[8]",
316         TYulong4    : "ulong[4]", // c_ulong
317         TYllong2    : "long[2]",
318         TYullong2   : "ulong[2]",
319 
320         TYschar32   : "byte[32]",
321         TYuchar32   : "ubyte[32]",
322         TYushort16  : "ushort[16]",
323         TYulong8    : "ulong[8]", // c_ulong
324         TYllong4    : "long[4]",
325         TYullong4   : "ulong[4]",
326 
327         TYschar64   : "byte[64]",
328         TYuchar64   : "ubyte[64]",
329         TYushort32  : "ushort[32]",
330         TYulong16   : "ulong[16]", // c_ulong
331         TYllong8    : "long[8]",
332         TYullong8   : "ulong[8]",
333     ];
334 
335     ret[TYullong] = ret[TYulong]; // c_ulong
336     ret[TYllong] = ret[TYlong]; // c_long
337 
338     return ret;
339 } ();
340 
341 /// Map to unsigned version of type
342 __gshared tym_t[256] tytouns = tytouns_init;
343 extern (D) private enum tytouns_init =
344 () {
345     tym_t[256] tab;
346     foreach (ty; 0 .. TYMAX)
347     {
348         tym_t tym;
349         switch (ty)
350         {
351             case TYchar:      tym = TYuchar;    break;
352             case TYschar:     tym = TYuchar;    break;
353             case TYshort:     tym = TYushort;   break;
354             case TYushort:    tym = TYushort;   break;
355 
356             case TYenum:      tym = TYuint;     break;
357             case TYint:       tym = TYuint;     break;
358 
359             case TYlong:      tym = TYulong;    break;
360             case TYllong:     tym = TYullong;   break;
361             case TYcent:      tym = TYucent;    break;
362 
363             case TYschar16:   tym = TYuchar16;  break;
364             case TYshort8:    tym = TYushort8;  break;
365             case TYlong4:     tym = TYulong4;   break;
366             case TYllong2:    tym = TYullong2;  break;
367 
368             case TYschar32:   tym = TYuchar32;  break;
369             case TYshort16:   tym = TYushort16; break;
370             case TYlong8:     tym = TYulong8;   break;
371             case TYllong4:    tym = TYullong4;  break;
372 
373             case TYschar64:   tym = TYuchar64;  break;
374             case TYshort32:   tym = TYushort32; break;
375             case TYlong16:    tym = TYulong16;  break;
376             case TYllong8:    tym = TYullong8;  break;
377 
378             default:          tym = ty;         break;
379         }
380         tab[ty] = tym;
381     }
382     return tab;
383 } ();
384 
385 /// Map to relaxed version of type
386 __gshared ubyte[TYMAX] _tyrelax = _tyrelax_init;
387 extern(D) private enum _tyrelax_init = (){
388     ubyte[TYMAX] tab;
389     foreach (ty; 0 .. TYMAX)
390     {
391         tym_t tym;
392         switch (ty)
393         {
394             case TYbool:      tym = TYchar;  break;
395             case TYschar:     tym = TYchar;  break;
396             case TYuchar:     tym = TYchar;  break;
397             case TYchar8:     tym = TYchar;  break;
398             case TYchar16:    tym = TYint;   break;
399 
400             case TYshort:     tym = TYint;   break;
401             case TYushort:    tym = TYint;   break;
402             case TYwchar_t:   tym = TYint;   break;
403 
404             case TYenum:      tym = TYint;   break;
405             case TYuint:      tym = TYint;   break;
406 
407             case TYulong:     tym = TYlong;  break;
408             case TYdchar:     tym = TYlong;  break;
409             case TYullong:    tym = TYllong; break;
410             case TYucent:     tym = TYcent;  break;
411 
412             case TYnullptr:   tym = TYptr;   break;
413 
414             default:          tym = ty;      break;
415         }
416         tab[ty] = cast(ubyte)tym;
417     }
418     return tab;
419 } ();
420 
421 /// Map to equivalent version of type
422 __gshared ubyte[TYMAX] tyequiv = tyequiv_init;
423 extern (D) private enum tyequiv_init =
424 () {
425     ubyte[TYMAX] tab;
426     foreach (ty; 0 .. TYMAX)
427     {
428         tym_t tym;
429         switch (ty)
430         {
431             case TYchar:      tym = TYschar;  break;    // chars are signed by default
432             case TYint:       tym = TYshort;  break;    // adjusted in util_set32()
433             case TYuint:      tym = TYushort; break;    // adjusted in util_set32()
434 
435             default:          tym = ty;       break;
436         }
437         tab[ty] = cast(ubyte)tym;
438     }
439     return tab;
440 } ();
441 
442 /// Map to Codeview 1 type in debugger record
443 __gshared ubyte[TYMAX] dttab =
444 [
445     TYbool    : 0x80,
446     TYchar    : 0x80,
447     TYschar   : 0x80,
448     TYuchar   : 0x84,
449     TYchar8   : 0x84,
450     TYchar16  : 0x85,
451     TYshort   : 0x81,
452     TYwchar_t : 0x85,
453     TYushort  : 0x85,
454 
455     TYenum    : 0x81,
456     TYint     : 0x85,
457     TYuint    : 0x85,
458 
459     TYlong    : 0x82,
460     TYulong   : 0x86,
461     TYdchar   : 0x86,
462     TYllong   : 0x82,
463     TYullong  : 0x86,
464     TYcent    : 0x82,
465     TYucent   : 0x86,
466     TYfloat   : 0x88,
467     TYdouble  : 0x89,
468     TYdouble_alias : 0x89,
469     TYldouble : 0x89,
470 
471     TYifloat   : 0x88,
472     TYidouble  : 0x89,
473     TYildouble : 0x89,
474 
475     TYcfloat   : 0x88,
476     TYcdouble  : 0x89,
477     TYcldouble : 0x89,
478 
479     TYfloat4  : 0x00,
480     TYdouble2 : 0x00,
481     TYschar16 : 0x00,
482     TYuchar16 : 0x00,
483     TYshort8  : 0x00,
484     TYushort8 : 0x00,
485     TYlong4   : 0x00,
486     TYulong4  : 0x00,
487     TYllong2  : 0x00,
488     TYullong2 : 0x00,
489 
490     TYfloat8  : 0x00,
491     TYdouble4 : 0x00,
492     TYschar32 : 0x00,
493     TYuchar32 : 0x00,
494     TYshort16 : 0x00,
495     TYushort16 : 0x00,
496     TYlong8   : 0x00,
497     TYulong8  : 0x00,
498     TYllong4  : 0x00,
499     TYullong4 : 0x00,
500 
501     TYfloat16 : 0x00,
502     TYdouble8 : 0x00,
503     TYschar64 : 0x00,
504     TYuchar64 : 0x00,
505     TYshort32 : 0x00,
506     TYushort32 : 0x00,
507     TYlong16  : 0x00,
508     TYulong16 : 0x00,
509     TYllong8  : 0x00,
510     TYullong8 : 0x00,
511 
512     TYnullptr : 0x20,
513     TYnptr    : 0x20,
514     TYref     : 0x00,
515     TYvoid    : 0x85,
516     TYnoreturn : 0x85, // same as TYvoid
517     TYstruct  : 0x00,
518     TYarray   : 0x78,
519     TYnfunc   : 0x63,
520     TYnpfunc  : 0x74,
521     TYnsfunc  : 0x63,
522     TYptr     : 0x20,
523     TYmfunc   : 0x64,
524     TYjfunc   : 0x74,
525     TYhfunc   : 0x00,
526     TYnref    : 0x00,
527 
528     TYsptr     : 0x20,
529     TYcptr     : 0x20,
530     TYf16ptr   : 0x40,
531     TYfptr     : 0x40,
532     TYhptr     : 0x40,
533     TYvptr     : 0x40,
534     TYimmutPtr : 0x20,
535     TYsharePtr : 0x20,
536     TYrestrictPtr : 0x20,
537     TYfgPtr    : 0x20,
538     TYffunc    : 0x64,
539     TYfpfunc   : 0x73,
540     TYfsfunc   : 0x64,
541     TYf16func  : 0x63,
542     TYnsysfunc : 0x63,
543     TYfsysfunc : 0x64,
544     TYfref     : 0x00,
545 
546     TYifunc    : 0x64,
547     TYmemptr   : 0x00,
548     TYident    : 0x00,
549     TYtemplate : 0x00,
550     TYvtshape  : 0x00,
551 ];
552 
553 /// Map to Codeview 4 type in debugger record
554 __gshared ushort[TYMAX] dttab4 =
555 [
556     TYbool    : 0x30,
557     TYchar    : 0x70,
558     TYschar   : 0x10,
559     TYuchar   : 0x20,
560     TYchar8   : 0x20,
561     TYchar16  : 0x21,
562     TYshort   : 0x11,
563     TYwchar_t : 0x71,
564     TYushort  : 0x21,
565 
566     TYenum    : 0x72,
567     TYint     : 0x72,
568     TYuint    : 0x73,
569 
570     TYlong    : 0x12,
571     TYulong   : 0x22,
572     TYdchar   : 0x7b, // UTF32
573     TYllong   : 0x13,
574     TYullong  : 0x23,
575     TYcent    : 0x603,
576     TYucent   : 0x603,
577     TYfloat   : 0x40,
578     TYdouble  : 0x41,
579     TYdouble_alias : 0x41,
580     TYldouble : 0x42,
581 
582     TYifloat   : 0x40,
583     TYidouble  : 0x41,
584     TYildouble : 0x42,
585 
586     TYcfloat   : 0x50,
587     TYcdouble  : 0x51,
588     TYcldouble : 0x52,
589 
590     TYfloat4  : 0x00,
591     TYdouble2 : 0x00,
592     TYschar16 : 0x00,
593     TYuchar16 : 0x00,
594     TYshort8  : 0x00,
595     TYushort8 : 0x00,
596     TYlong4   : 0x00,
597     TYulong4  : 0x00,
598     TYllong2  : 0x00,
599     TYullong2 : 0x00,
600 
601     TYfloat8  : 0x00,
602     TYdouble4 : 0x00,
603     TYschar32 : 0x00,
604     TYuchar32 : 0x00,
605     TYshort16 : 0x00,
606     TYushort16 : 0x00,
607     TYlong8   : 0x00,
608     TYulong8  : 0x00,
609     TYllong4  : 0x00,
610     TYullong4 : 0x00,
611 
612     TYfloat16 : 0x00,
613     TYdouble8 : 0x00,
614     TYschar64 : 0x00,
615     TYuchar64 : 0x00,
616     TYshort32 : 0x00,
617     TYushort32 : 0x00,
618     TYlong16  : 0x00,
619     TYulong16 : 0x00,
620     TYllong8  : 0x00,
621     TYullong8 : 0x00,
622 
623     TYnullptr : 0x100,
624     TYnptr    : 0x100,
625     TYref     : 0x00,
626     TYvoid    : 0x03,
627     TYnoreturn : 0x03, // same as TYvoid
628     TYstruct  : 0x00,
629     TYarray   : 0x00,
630     TYnfunc   : 0x00,
631     TYnpfunc  : 0x00,
632     TYnsfunc  : 0x00,
633     TYptr     : 0x100,
634     TYmfunc   : 0x00,
635     TYjfunc   : 0x00,
636     TYhfunc   : 0x00,
637     TYnref    : 0x00,
638 
639     TYsptr     : 0x100,
640     TYcptr     : 0x100,
641     TYf16ptr   : 0x200,
642     TYfptr     : 0x200,
643     TYhptr     : 0x300,
644     TYvptr     : 0x200,
645     TYimmutPtr : 0x100,
646     TYsharePtr : 0x100,
647     TYrestrictPtr : 0x100,
648     TYfgPtr    : 0x100,
649     TYffunc    : 0x00,
650     TYfpfunc   : 0x00,
651     TYfsfunc   : 0x00,
652     TYf16func  : 0x00,
653     TYnsysfunc : 0x00,
654     TYfsysfunc : 0x00,
655     TYfref     : 0x00,
656 
657     TYifunc    : 0x00,
658     TYmemptr   : 0x00,
659     TYident    : 0x00,
660     TYtemplate : 0x00,
661     TYvtshape  : 0x00,
662 ];
663 
664 /// Size of a type
665 /// -1 means error
666 __gshared byte[256] _tysize =
667 [
668     TYbool    : 1,
669     TYchar    : 1,
670     TYschar   : 1,
671     TYuchar   : 1,
672     TYchar8   : 1,
673     TYchar16  : 2,
674     TYshort   : SHORTSIZE,
675     TYwchar_t : 2,
676     TYushort  : SHORTSIZE,
677 
678     TYenum    : -1,
679     TYint     : 2,
680     TYuint    : 2,
681 
682     TYlong    : LONGSIZE,
683     TYulong   : LONGSIZE,
684     TYdchar   : 4,
685     TYllong   : LLONGSIZE,
686     TYullong  : LLONGSIZE,
687     TYcent    : 16,
688     TYucent   : 16,
689     TYfloat   : FLOATSIZE,
690     TYdouble  : DOUBLESIZE,
691     TYdouble_alias : 8,
692     TYldouble : -1,
693 
694     TYifloat   : FLOATSIZE,
695     TYidouble  : DOUBLESIZE,
696     TYildouble : -1,
697 
698     TYcfloat   : 2*FLOATSIZE,
699     TYcdouble  : 2*DOUBLESIZE,
700     TYcldouble : -1,
701 
702     TYfloat4  : 16,
703     TYdouble2 : 16,
704     TYschar16 : 16,
705     TYuchar16 : 16,
706     TYshort8  : 16,
707     TYushort8 : 16,
708     TYlong4   : 16,
709     TYulong4  : 16,
710     TYllong2  : 16,
711     TYullong2 : 16,
712 
713     TYfloat8  : 32,
714     TYdouble4 : 32,
715     TYschar32 : 32,
716     TYuchar32 : 32,
717     TYshort16 : 32,
718     TYushort16 : 32,
719     TYlong8   : 32,
720     TYulong8  : 32,
721     TYllong4  : 32,
722     TYullong4 : 32,
723 
724     TYfloat16 : 64,
725     TYdouble8 : 64,
726     TYschar64 : 64,
727     TYuchar64 : 64,
728     TYshort32 : 64,
729     TYushort32 : 64,
730     TYlong16  : 64,
731     TYulong16 : 64,
732     TYllong8  : 64,
733     TYullong8 : 64,
734 
735     TYnullptr : 2,
736     TYnptr    : 2,
737     TYref     : -1,
738     TYvoid    : -1,
739     TYnoreturn : 0,
740     TYstruct  : -1,
741     TYarray   : -1,
742     TYnfunc   : -1,
743     TYnpfunc  : -1,
744     TYnsfunc  : -1,
745     TYptr     : 2,
746     TYmfunc   : -1,
747     TYjfunc   : -1,
748     TYhfunc   : -1,
749     TYnref    : 2,
750 
751     TYsptr     : 2,
752     TYcptr     : 2,
753     TYf16ptr   : 4,
754     TYfptr     : 4,
755     TYhptr     : 4,
756     TYvptr     : 4,
757     TYimmutPtr : 2,
758     TYsharePtr : 2,
759     TYrestrictPtr : 2,
760     TYfgPtr    : 2,
761     TYffunc    : -1,
762     TYfpfunc   : -1,
763     TYfsfunc   : -1,
764     TYf16func  : -1,
765     TYnsysfunc : -1,
766     TYfsysfunc : -1,
767     TYfref     : 4,
768 
769     TYifunc    : -1,
770     TYmemptr   : -1,
771     TYident    : -1,
772     TYtemplate : -1,
773     TYvtshape  : -1,
774 ];
775 
776 // set alignment after we know the target
777 enum SET_ALIGN = -1;
778 
779 /// Size of a type to use for alignment
780 /// -1 means error
781 __gshared byte[256] _tyalignsize =
782 [
783     TYbool    : 1,
784     TYchar    : 1,
785     TYschar   : 1,
786     TYuchar   : 1,
787     TYchar8   : 1,
788     TYchar16  : 2,
789     TYshort   : SHORTSIZE,
790     TYwchar_t : 2,
791     TYushort  : SHORTSIZE,
792 
793     TYenum    : -1,
794     TYint     : 2,
795     TYuint    : 2,
796 
797     TYlong    : LONGSIZE,
798     TYulong   : LONGSIZE,
799     TYdchar   : 4,
800     TYllong   : LLONGSIZE,
801     TYullong  : LLONGSIZE,
802     TYcent    : 8,
803     TYucent   : 8,
804     TYfloat   : FLOATSIZE,
805     TYdouble  : DOUBLESIZE,
806     TYdouble_alias : 8,
807     TYldouble : SET_ALIGN,
808 
809     TYifloat   : FLOATSIZE,
810     TYidouble  : DOUBLESIZE,
811     TYildouble : SET_ALIGN,
812 
813     TYcfloat   : 2*FLOATSIZE,
814     TYcdouble  : DOUBLESIZE,
815     TYcldouble : SET_ALIGN,
816 
817     TYfloat4  : 16,
818     TYdouble2 : 16,
819     TYschar16 : 16,
820     TYuchar16 : 16,
821     TYshort8  : 16,
822     TYushort8 : 16,
823     TYlong4   : 16,
824     TYulong4  : 16,
825     TYllong2  : 16,
826     TYullong2 : 16,
827 
828     TYfloat8  : 32,
829     TYdouble4 : 32,
830     TYschar32 : 32,
831     TYuchar32 : 32,
832     TYshort16 : 32,
833     TYushort16 : 32,
834     TYlong8   : 32,
835     TYulong8  : 32,
836     TYllong4  : 32,
837     TYullong4 : 32,
838 
839     TYfloat16 : 64,
840     TYdouble8 : 64,
841     TYschar64 : 64,
842     TYuchar64 : 64,
843     TYshort32 : 64,
844     TYushort32 : 64,
845     TYlong16  : 64,
846     TYulong16 : 64,
847     TYllong8  : 64,
848     TYullong8 : 64,
849 
850     TYnullptr : 2,
851     TYnptr    : 2,
852     TYref     : -1,
853     TYvoid    : -1,
854     TYnoreturn : 0,
855     TYstruct  : -1,
856     TYarray   : -1,
857     TYnfunc   : -1,
858     TYnpfunc  : -1,
859     TYnsfunc  : -1,
860     TYptr     : 2,
861     TYmfunc   : -1,
862     TYjfunc   : -1,
863     TYhfunc   : -1,
864     TYnref    : 2,
865 
866     TYsptr     : 2,
867     TYcptr     : 2,
868     TYf16ptr   : 4,
869     TYfptr     : 4,
870     TYhptr     : 4,
871     TYvptr     : 4,
872     TYimmutPtr : 2,
873     TYsharePtr : 2,
874     TYrestrictPtr : 2,
875     TYfgPtr    : 2,
876     TYffunc    : -1,
877     TYfpfunc   : -1,
878     TYfsfunc   : -1,
879     TYf16func  : -1,
880     TYnsysfunc : -1,
881     TYfsysfunc : -1,
882     TYfref     : 4,
883 
884     TYifunc    : -1,
885     TYmemptr   : -1,
886     TYident    : -1,
887     TYtemplate : -1,
888     TYvtshape  : -1,
889 ];
890 
891 
892 private:
893 extern(D):
894 
895 static immutable TXptr        = [ TYnptr ];
896 static immutable TXptr_nflat  = [ TYsptr,TYcptr,TYf16ptr,TYfptr,TYhptr,TYvptr,TYimmutPtr,TYsharePtr,TYrestrictPtr,TYfgPtr ];
897 static immutable TXreal       = [ TYfloat,TYdouble,TYdouble_alias,TYldouble,
898                      TYfloat4,TYdouble2,
899                      TYfloat8,TYdouble4,
900                      TYfloat16,TYdouble8,
901                    ];
902 static immutable TXimaginary  = [ TYifloat,TYidouble,TYildouble, ];
903 static immutable TXcomplex    = [ TYcfloat,TYcdouble,TYcldouble, ];
904 static immutable TXintegral   = [ TYbool,TYchar,TYschar,TYuchar,TYshort,
905                      TYwchar_t,TYushort,TYenum,TYint,TYuint,
906                      TYlong,TYulong,TYllong,TYullong,TYdchar,
907                      TYschar16,TYuchar16,TYshort8,TYushort8,
908                      TYlong4,TYulong4,TYllong2,TYullong2,
909                      TYschar32,TYuchar32,TYshort16,TYushort16,
910                      TYlong8,TYulong8,TYllong4,TYullong4,
911                      TYschar64,TYuchar64,TYshort32,TYushort32,
912                      TYlong16,TYulong16,TYllong8,TYullong8,
913                      TYchar16,TYcent,TYucent,
914                    ];
915 static immutable TXref        = [ TYnref,TYref ];
916 static immutable TXfunc       = [ TYnfunc,TYnpfunc,TYnsfunc,TYifunc,TYmfunc,TYjfunc,TYhfunc ];
917 static immutable TXref_nflat  = [ TYfref ];
918 static immutable TXfunc_nflat = [ TYffunc,TYfpfunc,TYf16func,TYfsfunc,TYnsysfunc,TYfsysfunc, ];
919 static immutable TXuns        = [ TYuchar,TYushort,TYuint,TYulong,
920                      TYwchar_t,
921                      TYuchar16,TYushort8,TYulong4,TYullong2,
922                      TYdchar,TYullong,TYucent,TYchar16 ];
923 static immutable TXmptr       = [ TYmemptr ];
924 static immutable TXnullptr    = [ TYnullptr ];
925 static immutable TXfv         = [ TYfptr, TYvptr ];
926 static immutable TXfarfunc    = [ TYffunc,TYfpfunc,TYfsfunc,TYfsysfunc ];
927 static immutable TXpasfunc    = [ TYnpfunc,TYnsfunc,TYmfunc,TYjfunc ];
928 static immutable TXpasfunc_nf = [ TYfpfunc,TYf16func,TYfsfunc, ];
929 static immutable TXrevfunc    = [ TYnpfunc,TYjfunc ];
930 static immutable TXrevfunc_nf = [ TYfpfunc,TYf16func, ];
931 static immutable TXshort      = [ TYbool,TYchar,TYschar,TYuchar,TYshort,
932                       TYwchar_t,TYushort,TYchar16 ];
933 static immutable TXaggregate  = [ TYstruct,TYarray ];
934 static immutable TXxmmreg     = [
935                      TYfloat,TYdouble,TYifloat,TYidouble,
936                      //TYcfloat,TYcdouble,
937                      TYfloat4,TYdouble2,
938                      TYschar16,TYuchar16,TYshort8,TYushort8,
939                      TYlong4,TYulong4,TYllong2,TYullong2,
940                      TYfloat8,TYdouble4,
941                      TYschar32,TYuchar32,TYshort16,TYushort16,
942                      TYlong8,TYulong8,TYllong4,TYullong4,
943                      TYschar64,TYuchar64,TYshort32,TYushort32,
944                      TYlong16,TYulong16,TYllong8,TYullong8,
945                      TYfloat16,TYdouble8,
946                     ];
947 static immutable TXsimd       = [
948                      TYfloat4,TYdouble2,
949                      TYschar16,TYuchar16,TYshort8,TYushort8,
950                      TYlong4,TYulong4,TYllong2,TYullong2,
951                      TYfloat8,TYdouble4,
952                      TYschar32,TYuchar32,TYshort16,TYushort16,
953                      TYlong8,TYulong8,TYllong4,TYullong4,
954                      TYschar64,TYuchar64,TYshort32,TYushort32,
955                      TYlong16,TYulong16,TYllong8,TYullong8,
956                      TYfloat16,TYdouble8,
957                     ];