annotate dmd/backend/elem.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents 10317f0c89a5
children 9d194c848e3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 0
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Port;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Complex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.backend.targ_types;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.backend.PARAM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.backend.Classsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.backend.Srcpos;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 /*********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 * Union of all data types. Storage allocated must be the right
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 * size of the data on the TARGET, not the host.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 union eve
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 targ_char Vchar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 targ_schar Vschar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 targ_uchar Vuchar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 targ_short Vshort;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 targ_ushort Vushort;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 targ_int Vint; // also used for tmp numbers (FLtmp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 targ_uns Vuns;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 targ_long Vlong;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 targ_ulong Vulong;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 targ_llong Vllong;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 targ_ullong Vullong;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 targ_float Vfloat;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 targ_double Vdouble;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 targ_ldouble Vldouble;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 Complex!(float) Vcfloat;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 Complex!(double)Vcdouble;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 Complex!(real) Vcldouble;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 targ_size_t Vpointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 targ_ptrdiff_t Vptrdiff;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 targ_uchar Vreg; // register number for OPreg elems
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 struct VFP // 48 bit 386 far pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 { targ_long Voff;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 targ_ushort Vseg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 } VFP Vfp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 struct SP
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 targ_size_t Voffset;// offset from symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 Symbol* Vsym; // pointer to symbol table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 union SPU
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 PARAM* Vtal; // template-argument-list for SCfunctempl,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 // used only to transmit it to cpp_overload()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 LIST* Erd; // OPvar: reaching definitions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 } SPU spu;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 } SP sp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 struct SM
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 targ_size_t Voffset;// member pointer offset
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 Classsym* Vsym; // struct tag
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 elem* ethis; // OPrelconst: 'this' for member pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 } SM sm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 struct SS
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 targ_size_t Voffset;// offset from string
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 char* Vstring; // pointer to string (OPstring or OPasm)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 targ_size_t Vstrlen;// length of string
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 } SS ss;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 struct EOP
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 elem* Eleft; // left child for unary & binary nodes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 elem* Eright; // right child for binary nodes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 Symbol* Edtor; // OPctor: destructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 } EOP eop;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 } // variants for each type of elem
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 /******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 * Elems:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 * Elems are the basic tree element. They can be either
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 * terminal elems (leaves), unary elems (left subtree exists)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 * or binary elems (left and right subtrees exist).
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 struct elem
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 ushort id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 ubyte Eoper; // operator (OPxxxx)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 ubyte Ecount; // # of parents of this elem - 1,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 // always 0 until CSE elimination is done
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 eve EV; // variants for each type of elem
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 ref elem* E1()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 return EV.eop.Eleft; /* left child */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 ref elem* E2()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 return EV.eop.Eright; /* right child */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 ref LIST* Erd()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 return EV.sp.spu.Erd; // reaching definition
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 union
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 // PARSER
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 TYPE* ET; // pointer to type of elem
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 ubyte PEFflags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 // OPTIMIZER
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 tym_t Ety; // data type (TYxxxx)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 uint Eexp; // index into expnod[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 // These flags are all temporary markers, used once and then
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 // thrown away.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 ubyte Nflags; // NFLxxx
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 version (MARS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 ubyte Ejty; // original Jupiter/Mars type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 // CODGEN
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 // Ety2: Must be in same position as Ety!
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 tym_t Ety2; // data type (TYxxxx)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 ubyte Ecomsub; // number of remaining references to
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 // this common subexp (used to determine
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 // first, intermediate, and last references
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 // to a CSE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 version (TARGET_POWERPC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 ubyte Gflags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 targ_size_t Enumbytes; // number of bytes for type if TYstruct | TYarray
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 // TARGET_structELEM // target specific additions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 Srcpos Esrcpos; // source file position
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 }