symcpu.pas 10 KB

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