symcpu.pas 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. {
  2. Copyright (c) 2014 by Florian Klaempfl
  3. Symbol table overrides for i8086
  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. globtype,
  22. symconst,symtype,symdef,symsym,symx86,symi86;
  23. type
  24. { defs }
  25. tcpufiledef = class(tfiledef)
  26. end;
  27. tcpufiledefclass = class of tcpufiledef;
  28. tcpuvariantdef = class(tvariantdef)
  29. end;
  30. tcpuvariantdefclass = class of tcpuvariantdef;
  31. tcpuformaldef = class(tformaldef)
  32. end;
  33. tcpuformaldefclass = class of tcpuformaldef;
  34. tcpuforwarddef = class(tforwarddef)
  35. end;
  36. tcpuforwarddefclass = class of tcpuforwarddef;
  37. tcpuundefineddef = class(tundefineddef)
  38. end;
  39. tcpuundefineddefclass = class of tcpuundefineddef;
  40. tcpuerrordef = class(terrordef)
  41. end;
  42. tcpuerrordefclass = class of tcpuerrordef;
  43. tcpupointerdef = class(tx86pointerdef)
  44. class function default_x86_data_pointer_type: tx86pointertyp; override;
  45. end;
  46. tcpupointerdefclass = class of tcpupointerdef;
  47. tcpurecorddef = class(trecorddef)
  48. end;
  49. tcpurecorddefclass = class of tcpurecorddef;
  50. tcpuimplementedinterface = class(timplementedinterface)
  51. end;
  52. tcpuimplementedinterfaceclass = class of tcpuimplementedinterface;
  53. tcpuobjectdef = class(tobjectdef)
  54. end;
  55. tcpuobjectdefclass = class of tcpuobjectdef;
  56. tcpuclassrefdef = class(tclassrefdef)
  57. end;
  58. tcpuclassrefdefclass = class of tcpuclassrefdef;
  59. tcpuarraydef = class(tarraydef)
  60. end;
  61. tcpuarraydefclass = class of tcpuarraydef;
  62. tcpuorddef = class(torddef)
  63. end;
  64. tcpuorddefclass = class of tcpuorddef;
  65. tcpufloatdef = class(tfloatdef)
  66. end;
  67. tcpufloatdefclass = class of tcpufloatdef;
  68. { tcpuprocvardef }
  69. tcpuprocvardef = class(ti86procvardef)
  70. constructor create(level:byte);override;
  71. function is_far:boolean;
  72. end;
  73. tcpuprocvardefclass = class of tcpuprocvardef;
  74. { tcpuprocdef }
  75. tcpuprocdef = class(ti86procdef)
  76. private
  77. { returns whether the function is far by default, i.e. whether it would be
  78. far if _all_ of the following conditions are true:
  79. - we're in a far code memory model
  80. - it has no 'near' or 'far' specifiers
  81. - it is compiled in a $F- state }
  82. function default_far:boolean;
  83. public
  84. constructor create(level:byte);override;
  85. function address_type:tdef;override;
  86. procedure declared_far;override;
  87. procedure declared_near;override;
  88. function is_far:boolean;
  89. end;
  90. tcpuprocdefclass = class of tcpuprocdef;
  91. tcpustringdef = class(tstringdef)
  92. end;
  93. tcpustringdefclass = class of tcpustringdef;
  94. tcpuenumdef = class(tenumdef)
  95. end;
  96. tcpuenumdefclass = class of tcpuenumdef;
  97. tcpusetdef = class(tsetdef)
  98. end;
  99. tcpusetdefclass = class of tcpusetdef;
  100. { syms }
  101. tcpulabelsym = class(tlabelsym)
  102. end;
  103. tcpulabelsymclass = class of tcpulabelsym;
  104. tcpuunitsym = class(tunitsym)
  105. end;
  106. tcpuunitsymclass = class of tcpuunitsym;
  107. tcpunamespacesym = class(tnamespacesym)
  108. end;
  109. tcpunamespacesymclass = class of tcpunamespacesym;
  110. tcpuprocsym = class(tprocsym)
  111. end;
  112. tcpuprocsymclass = class of tcpuprocsym;
  113. tcputypesym = class(ttypesym)
  114. end;
  115. tcpuypesymclass = class of tcputypesym;
  116. tcpufieldvarsym = class(tfieldvarsym)
  117. end;
  118. tcpufieldvarsymclass = class of tcpufieldvarsym;
  119. tcpulocalvarsym = class(tlocalvarsym)
  120. end;
  121. tcpulocalvarsymclass = class of tcpulocalvarsym;
  122. tcpuparavarsym = class(tparavarsym)
  123. end;
  124. tcpuparavarsymclass = class of tcpuparavarsym;
  125. tcpustaticvarsym = class(tstaticvarsym)
  126. end;
  127. tcpustaticvarsymclass = class of tcpustaticvarsym;
  128. tcpuabsolutevarsym = class(ti86absolutevarsym)
  129. protected
  130. procedure ppuload_platform(ppufile: tcompilerppufile); override;
  131. procedure ppuwrite_platform(ppufile: tcompilerppufile); override;
  132. public
  133. addrsegment : aword;
  134. end;
  135. tcpuabsolutevarsymclass = class of tcpuabsolutevarsym;
  136. tcpupropertysym = class(tpropertysym)
  137. end;
  138. tcpupropertysymclass = class of tcpupropertysym;
  139. tcpuconstsym = class(tconstsym)
  140. end;
  141. tcpuconstsymclass = class of tcpuconstsym;
  142. tcpuenumsym = class(tenumsym)
  143. end;
  144. tcpuenumsymclass = class of tcpuenumsym;
  145. tcpusyssym = class(tsyssym)
  146. end;
  147. tcpusyssymclass = class of tcpusyssym;
  148. const
  149. pbestrealtype : ^tdef = @s80floattype;
  150. function is_proc_far(p: tabstractprocdef): boolean;
  151. implementation
  152. uses
  153. globals, cpuinfo, verbose;
  154. function is_proc_far(p: tabstractprocdef): boolean;
  155. begin
  156. if p is tcpuprocdef then
  157. result:=tcpuprocdef(p).is_far
  158. else if p is tcpuprocvardef then
  159. result:=tcpuprocvardef(p).is_far
  160. else
  161. internalerror(2014041301);
  162. end;
  163. {****************************************************************************
  164. tcpuprocdef
  165. ****************************************************************************}
  166. constructor tcpuprocdef.create(level: byte);
  167. begin
  168. inherited create(level);
  169. if (current_settings.x86memorymodel in x86_far_code_models) and
  170. ((cs_huge_code in current_settings.moduleswitches) or
  171. (cs_force_far_calls in current_settings.localswitches)) then
  172. procoptions:=procoptions+[po_far];
  173. end;
  174. function tcpuprocdef.address_type: tdef;
  175. begin
  176. if is_far then
  177. result:=voidfarpointertype
  178. else
  179. result:=voidnearpointertype;
  180. end;
  181. procedure tcpuprocdef.declared_far;
  182. begin
  183. if current_settings.x86memorymodel in x86_far_code_models then
  184. include(procoptions,po_far)
  185. else
  186. inherited declared_far;
  187. end;
  188. procedure tcpuprocdef.declared_near;
  189. begin
  190. if (current_settings.x86memorymodel in x86_far_code_models) and
  191. not (cs_huge_code in current_settings.moduleswitches) then
  192. exclude(procoptions,po_far)
  193. else
  194. inherited declared_near;
  195. end;
  196. function tcpuprocdef.default_far: boolean;
  197. begin
  198. if proctypeoption in [potype_proginit,potype_unitinit,potype_unitfinalize,
  199. potype_constructor,potype_destructor,
  200. potype_class_constructor,potype_class_destructor,
  201. potype_propgetter,potype_propsetter] then
  202. exit(true);
  203. if (procoptions*[po_classmethod,po_virtualmethod,po_abstractmethod,
  204. po_finalmethod,po_staticmethod,po_overridingmethod,
  205. po_external,po_public,po_interrupt])<>[] then
  206. exit(true);
  207. if is_methodpointer then
  208. exit(true);
  209. result:=not (visibility in [vis_private,vis_hidden]);
  210. end;
  211. function tcpuprocdef.is_far: boolean;
  212. begin
  213. result:=(current_settings.x86memorymodel in x86_far_code_models) and
  214. ((po_far in procoptions) or default_far);
  215. end;
  216. {****************************************************************************
  217. tcpuprocvardef
  218. ****************************************************************************}
  219. constructor tcpuprocvardef.create(level: byte);
  220. begin
  221. inherited create(level);
  222. { procvars are always far in the far code memory models }
  223. if current_settings.x86memorymodel in x86_far_code_models then
  224. procoptions:=procoptions+[po_far];
  225. end;
  226. function tcpuprocvardef.is_far: boolean;
  227. begin
  228. { procvars are always far in the far code memory models }
  229. result:=current_settings.x86memorymodel in x86_far_code_models;
  230. end;
  231. {****************************************************************************
  232. tcpupointerdef
  233. ****************************************************************************}
  234. class function tcpupointerdef.default_x86_data_pointer_type: tx86pointertyp;
  235. begin
  236. if current_settings.x86memorymodel in x86_far_data_models then
  237. result:=x86pt_far
  238. else
  239. result:=inherited;
  240. end;
  241. {****************************************************************************
  242. tcpuabsolutevarsym
  243. ****************************************************************************}
  244. procedure tcpuabsolutevarsym.ppuload_platform(ppufile: tcompilerppufile);
  245. begin
  246. inherited;
  247. if absseg then
  248. addrsegment:=ppufile.getaword;
  249. end;
  250. procedure tcpuabsolutevarsym.ppuwrite_platform(ppufile: tcompilerppufile);
  251. begin
  252. inherited;
  253. if absseg then
  254. ppufile.putaword(addrsegment);
  255. end;
  256. begin
  257. { used tdef classes }
  258. cfiledef:=tcpufiledef;
  259. cvariantdef:=tcpuvariantdef;
  260. cformaldef:=tcpuformaldef;
  261. cforwarddef:=tcpuforwarddef;
  262. cundefineddef:=tcpuundefineddef;
  263. cerrordef:=tcpuerrordef;
  264. cpointerdef:=tcpupointerdef;
  265. crecorddef:=tcpurecorddef;
  266. cimplementedinterface:=tcpuimplementedinterface;
  267. cobjectdef:=tcpuobjectdef;
  268. cclassrefdef:=tcpuclassrefdef;
  269. carraydef:=tcpuarraydef;
  270. corddef:=tcpuorddef;
  271. cfloatdef:=tcpufloatdef;
  272. cprocvardef:=tcpuprocvardef;
  273. cprocdef:=tcpuprocdef;
  274. cstringdef:=tcpustringdef;
  275. cenumdef:=tcpuenumdef;
  276. csetdef:=tcpusetdef;
  277. { used tsym classes }
  278. clabelsym:=tcpulabelsym;
  279. cunitsym:=tcpuunitsym;
  280. cnamespacesym:=tcpunamespacesym;
  281. cprocsym:=tcpuprocsym;
  282. ctypesym:=tcputypesym;
  283. cfieldvarsym:=tcpufieldvarsym;
  284. clocalvarsym:=tcpulocalvarsym;
  285. cparavarsym:=tcpuparavarsym;
  286. cstaticvarsym:=tcpustaticvarsym;
  287. cabsolutevarsym:=tcpuabsolutevarsym;
  288. cpropertysym:=tcpupropertysym;
  289. cconstsym:=tcpuconstsym;
  290. cenumsym:=tcpuenumsym;
  291. csyssym:=tcpusyssym;
  292. end.