annotate dmd/backend/elem.d @ 0:10317f0c89a5

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