1 {
2     Copyright (c) 2014 by Florian Klaempfl
3 
4     Symbol table overrides for PowerPC64
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 
20  ****************************************************************************
21 }
22 unit symcpu;
23 
24 {$i fpcdefs.inc}
25 
26 interface
27 
28 uses
29   symtype,symdef,symsym;
30 
31 type
32   { defs }
33   tcpufiledef = class(tfiledef)
34   end;
35   tcpufiledefclass = class of tcpufiledef;
36 
37   tcpuvariantdef = class(tvariantdef)
38   end;
39   tcpuvariantdefclass = class of tcpuvariantdef;
40 
41   tcpuformaldef = class(tformaldef)
42   end;
43   tcpuformaldefclass = class of tcpuformaldef;
44 
45   tcpuforwarddef = class(tforwarddef)
46   end;
47   tcpuforwarddefclass = class of tcpuforwarddef;
48 
49   tcpuundefineddef = class(tundefineddef)
50   end;
51   tcpuundefineddefclass = class of tcpuundefineddef;
52 
53   tcpuerrordef = class(terrordef)
54   end;
55   tcpuerrordefclass = class of tcpuerrordef;
56 
57   tcpupointerdef = class(tpointerdef)
58   end;
59   tcpupointerdefclass = class of tcpupointerdef;
60 
61   tcpurecorddef = class(trecorddef)
62     { returns whether the record's elements (including arrays) all have
63       the same floating point or vector type; returns that type in the "def"
64       parameter if so }
has_single_type_elfv2null65     function has_single_type_elfv2(out def: tdef): boolean;
66   end;
67   tcpurecorddefclass = class of tcpurecorddef;
68 
69   tcpuimplementedinterface = class(timplementedinterface)
70   end;
71   tcpuimplementedinterfaceclass = class of tcpuimplementedinterface;
72 
73   tcpuobjectdef = class(tobjectdef)
74   end;
75   tcpuobjectdefclass = class of tcpuobjectdef;
76 
77   tcpuclassrefdef = class(tclassrefdef)
78   end;
79   tcpuclassrefdefclass = class of tcpuclassrefdef;
80 
81   tcpuarraydef = class(tarraydef)
82     { see tcpurecorddef.has_single_type_elfv2 }
has_single_type_elfv2null83     function has_single_type_elfv2(out def: tdef): boolean;
84   end;
85   tcpuarraydefclass = class of tcpuarraydef;
86 
87   tcpuorddef = class(torddef)
88   end;
89   tcpuorddefclass = class of tcpuorddef;
90 
91   tcpufloatdef = class(tfloatdef)
92   end;
93   tcpufloatdefclass = class of tcpufloatdef;
94 
95   tcpuprocvardef = class(tprocvardef)
96   end;
97   tcpuprocvardefclass = class of tcpuprocvardef;
98 
99   tcpuprocdef = class(tprocdef)
100   end;
101   tcpuprocdefclass = class of tcpuprocdef;
102 
103   tcpustringdef = class(tstringdef)
104   end;
105   tcpustringdefclass = class of tcpustringdef;
106 
107   tcpuenumdef = class(tenumdef)
108   end;
109   tcpuenumdefclass = class of tcpuenumdef;
110 
111   tcpusetdef = class(tsetdef)
112   end;
113   tcpusetdefclass = class of tcpusetdef;
114 
115   { syms }
116   tcpulabelsym = class(tlabelsym)
117   end;
118   tcpulabelsymclass = class of tcpulabelsym;
119 
120   tcpuunitsym = class(tunitsym)
121   end;
122   tcpuunitsymclass = class of tcpuunitsym;
123 
124   tcpuprogramparasym = class(tprogramparasym)
125   end;
126   tcpuprogramparasymclass = class(tprogramparasym);
127 
128   tcpunamespacesym = class(tnamespacesym)
129   end;
130   tcpunamespacesymclass = class of tcpunamespacesym;
131 
132   tcpuprocsym = class(tprocsym)
133   end;
134   tcpuprocsymclass = class of tcpuprocsym;
135 
136   tcputypesym = class(ttypesym)
137   end;
138   tcpuypesymclass = class of tcputypesym;
139 
140   tcpufieldvarsym = class(tfieldvarsym)
141   end;
142   tcpufieldvarsymclass = class of tcpufieldvarsym;
143 
144   tcpulocalvarsym = class(tlocalvarsym)
145   end;
146   tcpulocalvarsymclass = class of tcpulocalvarsym;
147 
148   tcpuparavarsym = class(tparavarsym)
149   end;
150   tcpuparavarsymclass = class of tcpuparavarsym;
151 
152   tcpustaticvarsym = class(tstaticvarsym)
153   end;
154   tcpustaticvarsymclass = class of tcpustaticvarsym;
155 
156   tcpuabsolutevarsym = class(tabsolutevarsym)
157   end;
158   tcpuabsolutevarsymclass = class of tcpuabsolutevarsym;
159 
160   tcpupropertysym = class(tpropertysym)
161   end;
162   tcpupropertysymclass = class of tcpupropertysym;
163 
164   tcpuconstsym = class(tconstsym)
165   end;
166   tcpuconstsymclass = class of tcpuconstsym;
167 
168   tcpuenumsym = class(tenumsym)
169   end;
170   tcpuenumsymclass = class of tcpuenumsym;
171 
172   tcpusyssym = class(tsyssym)
173   end;
174   tcpusyssymclass = class of tcpusyssym;
175 
176 
177 const
178   pbestrealtype : ^tdef = @s64floattype;
179 
180 
181 implementation
182 
183   uses
184     symconst, defutil, defcmp;
185 
186 { tcpurecorddef }
187 
tcpurecorddef.has_single_type_elfv2null188   function tcpurecorddef.has_single_type_elfv2(out def: tdef): boolean;
189     var
190       i: longint;
191       checkdef, tmpdef: tdef;
192     begin
193       def:=nil;
194       tmpdef:=nil;
195       result:=false;
196       for i:=0 to symtable.SymList.Count-1 do
197         begin
198           if (tsym(symtable.symlist[i]).typ=fieldvarsym) and
199              not(sp_static in tsym(symtable.symlist[i]).symoptions) then
200             begin
201               checkdef:=tfieldvarsym(symtable.symlist[i]).vardef;
202               repeat
203                 case checkdef.typ of
204                   floatdef:
205                     ;
206                   arraydef:
207                     if not is_special_array(checkdef) then
208                       checkdef:=tarraydef(checkdef).elementdef
209                     else
210                       exit;
211                   recorddef:
212                     if not tcpurecorddef(checkdef).has_single_type_elfv2(checkdef) then
213                       exit;
214                   else
215                     exit;
216                   end;
217               until checkdef.typ=floatdef;
218               if not assigned(def) then
219                 def:=checkdef
220               else if not equal_defs(def,checkdef) then
221                 exit;
222             end;
223         end;
224       if assigned(def) then
225         result:=true;
226     end;
227 
228 
229   { tcpuarraydef }
230 
tcpuarraydef.has_single_type_elfv2null231   function tcpuarraydef.has_single_type_elfv2(out def: tdef): boolean;
232     var
233       checkdef: tdef;
234     begin
235       result:=false;
236       checkdef:=self;
237       while (checkdef.typ=arraydef) and
238             not is_special_array(checkdef) do
239         checkdef:=tarraydef(checkdef).elementdef;
240       case checkdef.typ of
241         recorddef:
242           result:=tcpurecorddef(checkdef).has_single_type_elfv2(def);
243         floatdef:
244           begin
245             def:=checkdef;
246             result:=true;
247             exit;
248           end;
249         else
250           exit;
251         end;
252     end;
253 
254 
255 begin
256   { used tdef classes }
257   cfiledef:=tcpufiledef;
258   cvariantdef:=tcpuvariantdef;
259   cformaldef:=tcpuformaldef;
260   cforwarddef:=tcpuforwarddef;
261   cundefineddef:=tcpuundefineddef;
262   cerrordef:=tcpuerrordef;
263   cpointerdef:=tcpupointerdef;
264   crecorddef:=tcpurecorddef;
265   cimplementedinterface:=tcpuimplementedinterface;
266   cobjectdef:=tcpuobjectdef;
267   cclassrefdef:=tcpuclassrefdef;
268   carraydef:=tcpuarraydef;
269   corddef:=tcpuorddef;
270   cfloatdef:=tcpufloatdef;
271   cprocvardef:=tcpuprocvardef;
272   cprocdef:=tcpuprocdef;
273   cstringdef:=tcpustringdef;
274   cenumdef:=tcpuenumdef;
275   csetdef:=tcpusetdef;
276 
277   { used tsym classes }
278   clabelsym:=tcpulabelsym;
279   cunitsym:=tcpuunitsym;
280   cprogramparasym:=tcpuprogramparasym;
281   cnamespacesym:=tcpunamespacesym;
282   cprocsym:=tcpuprocsym;
283   ctypesym:=tcputypesym;
284   cfieldvarsym:=tcpufieldvarsym;
285   clocalvarsym:=tcpulocalvarsym;
286   cparavarsym:=tcpuparavarsym;
287   cstaticvarsym:=tcpustaticvarsym;
288   cabsolutevarsym:=tcpuabsolutevarsym;
289   cpropertysym:=tcpupropertysym;
290   cconstsym:=tcpuconstsym;
291   cenumsym:=tcpuenumsym;
292   csyssym:=tcpusyssym;
293 end.
294 
295