symcpu.pas 7.4 KB

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