psystem.pas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Load the system unit, create required defs for systemunit
  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 psystem;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symbase;
  22. procedure create_intern_symbols;
  23. procedure create_intern_types;
  24. procedure load_intern_types;
  25. procedure registernodes;
  26. procedure registertais;
  27. implementation
  28. uses
  29. globals,globtype,verbose,constexp,cpuinfo,
  30. systems,
  31. symconst,symtype,symsym,symdef,symcpu,symtable,
  32. aasmtai,aasmdata,aasmcpu,
  33. ncgutil,ncgrtti,fmodule,
  34. node,nbas,nflw,nset,ncon,ncnv,nld,nmem,ncal,nmat,nadd,ninl,nopt
  35. ;
  36. procedure create_intern_symbols;
  37. {
  38. all intern procedures for the system unit
  39. }
  40. begin
  41. systemunit.insert(csyssym.create('Concat',in_concat_x));
  42. systemunit.insert(csyssym.create('Write',in_write_x));
  43. systemunit.insert(csyssym.create('WriteLn',in_writeln_x));
  44. systemunit.insert(csyssym.create('WriteStr',in_writestr_x));
  45. systemunit.insert(csyssym.create('Assigned',in_assigned_x));
  46. systemunit.insert(csyssym.create('Read',in_read_x));
  47. systemunit.insert(csyssym.create('ReadLn',in_readln_x));
  48. systemunit.insert(csyssym.create('ReadStr',in_readstr_x));
  49. systemunit.insert(csyssym.create('Ofs',in_ofs_x));
  50. systemunit.insert(csyssym.create('SizeOf',in_sizeof_x));
  51. systemunit.insert(csyssym.create('BitSizeOf',in_bitsizeof_x));
  52. systemunit.insert(csyssym.create('TypeOf',in_typeof_x));
  53. systemunit.insert(csyssym.create('Low',in_low_x));
  54. systemunit.insert(csyssym.create('High',in_high_x));
  55. systemunit.insert(csyssym.create('Slice',in_slice_x));
  56. systemunit.insert(csyssym.create('Seg',in_seg_x));
  57. systemunit.insert(csyssym.create('Ord',in_ord_x));
  58. systemunit.insert(csyssym.create('Pred',in_pred_x));
  59. systemunit.insert(csyssym.create('Succ',in_succ_x));
  60. systemunit.insert(csyssym.create('Exclude',in_exclude_x_y));
  61. systemunit.insert(csyssym.create('Include',in_include_x_y));
  62. systemunit.insert(csyssym.create('Pack',in_pack_x_y_z));
  63. systemunit.insert(csyssym.create('Unpack',in_unpack_x_y_z));
  64. systemunit.insert(csyssym.create('Break',in_break));
  65. systemunit.insert(csyssym.create('Exit',in_exit));
  66. systemunit.insert(csyssym.create('Continue',in_continue));
  67. systemunit.insert(csyssym.create('Leave',in_leave)); {macpas only}
  68. systemunit.insert(csyssym.create('Cycle',in_cycle)); {macpas only}
  69. systemunit.insert(csyssym.create('Dec',in_dec_x));
  70. systemunit.insert(csyssym.create('Inc',in_inc_x));
  71. systemunit.insert(csyssym.create('Str',in_str_x_string));
  72. systemunit.insert(csyssym.create('Assert',in_assert_x_y));
  73. systemunit.insert(csyssym.create('Val',in_val_x));
  74. systemunit.insert(csyssym.create('Addr',in_addr_x));
  75. systemunit.insert(csyssym.create('TypeInfo',in_typeinfo_x));
  76. systemunit.insert(csyssym.create('SetLength',in_setlength_x));
  77. systemunit.insert(csyssym.create('Copy',in_copy_x));
  78. systemunit.insert(csyssym.create('Initialize',in_initialize_x));
  79. systemunit.insert(csyssym.create('Finalize',in_finalize_x));
  80. systemunit.insert(csyssym.create('Length',in_length_x));
  81. systemunit.insert(csyssym.create('New',in_new_x));
  82. systemunit.insert(csyssym.create('Dispose',in_dispose_x));
  83. {$ifdef SUPPORT_GET_FRAME}
  84. systemunit.insert(csyssym.create('Get_Frame',in_get_frame));
  85. {$endif SUPPORT_GET_FRAME}
  86. systemunit.insert(csyssym.create('Unaligned',in_unaligned_x));
  87. systemunit.insert(csyssym.create('Aligned',in_aligned_x));
  88. systemunit.insert(csyssym.create('ObjCSelector',in_objc_selector_x)); { objc only }
  89. systemunit.insert(csyssym.create('ObjCEncode',in_objc_encode_x)); { objc only }
  90. systemunit.insert(csyssym.create('Default',in_default_x));
  91. systemunit.insert(cconstsym.create_ord('False',constord,0,pasbool8type));
  92. systemunit.insert(cconstsym.create_ord('True',constord,1,pasbool8type));
  93. end;
  94. procedure set_default_int_types;
  95. begin
  96. {$ifdef cpu64bitaddr}
  97. uinttype:=u64inttype;
  98. sinttype:=s64inttype;
  99. ptruinttype:=u64inttype;
  100. ptrsinttype:=s64inttype;
  101. {$endif cpu64bitaddr}
  102. {$ifdef cpu32bitaddr}
  103. uinttype:=u32inttype;
  104. sinttype:=s32inttype;
  105. ptruinttype:=u32inttype;
  106. ptrsinttype:=s32inttype;
  107. {$endif cpu32bitaddr}
  108. {$ifdef cpu32bitalu}
  109. uinttype:=u32inttype;
  110. sinttype:=s32inttype;
  111. {$endif cpu32bitalu}
  112. {$ifdef cpu16bitaddr}
  113. ptruinttype:=u16inttype;
  114. ptrsinttype:=s16inttype;
  115. {$endif cpu16bitaddr}
  116. {$ifdef cpu16bitalu}
  117. uinttype:=u16inttype;
  118. sinttype:=s16inttype;
  119. {$endif cpu16bitalu}
  120. {$ifdef cpu8bitalu}
  121. uinttype:=u8inttype;
  122. sinttype:=s8inttype;
  123. {$endif cpu8bitalu}
  124. {$ifndef avr}
  125. osuinttype:=uinttype;
  126. ossinttype:=sinttype;
  127. {$else avr}
  128. osuinttype:=u16inttype;
  129. ossinttype:=s16inttype;
  130. {$endif avr}
  131. end;
  132. procedure set_default_ptr_types;
  133. begin
  134. {$ifdef i8086}
  135. if current_settings.x86memorymodel in x86_far_code_models then
  136. voidcodepointertype:=voidfarpointertype
  137. else
  138. voidcodepointertype:=voidnearpointertype;
  139. voidstackpointertype:=voidnearsspointertype;
  140. {$else i8086}
  141. voidcodepointertype:=voidpointertype;
  142. voidstackpointertype:=voidpointertype;
  143. {$endif i8086}
  144. end;
  145. procedure create_intern_types;
  146. {
  147. all the types inserted into the system unit
  148. }
  149. function addtype(const s:string;def:tdef):ttypesym;
  150. begin
  151. result:=ctypesym.create(s,def);
  152. systemunit.insert(result);
  153. end;
  154. procedure addfield(recst:tabstractrecordsymtable;sym:tfieldvarsym);
  155. begin
  156. recst.insert(sym);
  157. recst.addfield(sym,vis_hidden);
  158. end;
  159. procedure create_fpu_types;
  160. begin
  161. if init_settings.fputype<>fpu_none then
  162. begin
  163. s32floattype:=cfloatdef.create(s32real);
  164. s64floattype:=cfloatdef.create(s64real);
  165. s80floattype:=cfloatdef.create(s80real);
  166. sc80floattype:=cfloatdef.create(sc80real);
  167. end else begin
  168. s32floattype:=nil;
  169. s64floattype:=nil;
  170. s80floattype:=nil;
  171. sc80floattype:=nil;
  172. end;
  173. end;
  174. var
  175. hrecst : trecordsymtable;
  176. begin
  177. symtablestack.push(systemunit);
  178. cundefinedtype:=cundefineddef.create;
  179. cformaltype:=cformaldef.create(false);
  180. ctypedformaltype:=cformaldef.create(true);
  181. voidtype:=corddef.create(uvoid,0,0);
  182. voidpointertype:=cpointerdef.create(voidtype);
  183. u8inttype:=corddef.create(u8bit,0,255);
  184. s8inttype:=corddef.create(s8bit,int64(-128),127);
  185. u16inttype:=corddef.create(u16bit,0,65535);
  186. s16inttype:=corddef.create(s16bit,int64(-32768),32767);
  187. u32inttype:=corddef.create(u32bit,0,high(longword));
  188. s32inttype:=corddef.create(s32bit,int64(low(longint)),int64(high(longint)));
  189. u64inttype:=corddef.create(u64bit,low(qword),high(qword));
  190. s64inttype:=corddef.create(s64bit,low(int64),high(int64));
  191. pasbool8type:=corddef.create(pasbool8,0,1);
  192. pasbool16type:=corddef.create(pasbool16,0,1);
  193. pasbool32type:=corddef.create(pasbool32,0,1);
  194. pasbool64type:=corddef.create(pasbool64,0,1);
  195. bool8type:=corddef.create(bool8bit,low(int64),high(int64));
  196. bool16type:=corddef.create(bool16bit,low(int64),high(int64));
  197. bool32type:=corddef.create(bool32bit,low(int64),high(int64));
  198. bool64type:=corddef.create(bool64bit,low(int64),high(int64));
  199. cansichartype:=corddef.create(uchar,0,255);
  200. cwidechartype:=corddef.create(uwidechar,0,65535);
  201. cshortstringtype:=cstringdef.createshort(255);
  202. { should we give a length to the default long and ansi string definition ?? }
  203. clongstringtype:=cstringdef.createlong(-1);
  204. cansistringtype:=cstringdef.createansi(0);
  205. if target_info.system in systems_windows then
  206. cwidestringtype:=cstringdef.createwide
  207. else
  208. cwidestringtype:=cstringdef.createunicode;
  209. cunicodestringtype:=cstringdef.createunicode;
  210. { length=0 for shortstring is open string (needed for readln(string) }
  211. openshortstringtype:=cstringdef.createshort(0);
  212. openchararraytype:=carraydef.create(0,-1,s32inttype);
  213. tarraydef(openchararraytype).elementdef:=cansichartype;
  214. {$ifdef x86}
  215. create_fpu_types;
  216. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  217. if target_info.system=system_x86_64_win64 then
  218. begin
  219. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  220. pbestrealtype:=@s64floattype;
  221. end
  222. else
  223. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  224. s64currencytype:=cfloatdef.create(s64currency);
  225. {$endif x86}
  226. {$ifdef powerpc}
  227. create_fpu_types;
  228. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  229. {$endif powerpc}
  230. {$ifdef POWERPC64}
  231. create_fpu_types;
  232. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  233. {$endif POWERPC64}
  234. {$ifdef sparc}
  235. create_fpu_types;
  236. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  237. {$endif sparc}
  238. {$ifdef m68k}
  239. create_fpu_types;
  240. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  241. {$endif}
  242. {$ifdef arm}
  243. create_fpu_types;
  244. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  245. {$endif arm}
  246. {$ifdef avr}
  247. s32floattype:=cfloatdef.create(s32real);
  248. s64floattype:=cfloatdef.create(s64real);
  249. s80floattype:=cfloatdef.create(s80real);
  250. sc80floattype:=cfloatdef.create(sc80real);
  251. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  252. {$endif avr}
  253. {$ifdef mips}
  254. create_fpu_types;
  255. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  256. {$endif mips}
  257. {$ifdef jvm}
  258. create_fpu_types;
  259. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  260. {$endif jvm}
  261. set_default_int_types;
  262. { some other definitions }
  263. charpointertype:=cpointerdef.create(cansichartype);
  264. widecharpointertype:=cpointerdef.create(cwidechartype);
  265. {$ifdef i8086}
  266. parentfpvoidpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near);
  267. {$else i8086}
  268. parentfpvoidpointertype:=cpointerdef.create(voidtype);
  269. {$endif i8086}
  270. {$ifdef x86}
  271. voidnearpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near);
  272. voidnearcspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_cs);
  273. voidneardspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ds);
  274. voidnearsspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ss);
  275. voidnearespointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_es);
  276. voidnearfspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_fs);
  277. voidneargspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_gs);
  278. {$ifdef i8086}
  279. voidfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_far);
  280. voidhugepointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_huge);
  281. charnearpointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_near);
  282. charfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_far);
  283. bytefarpointertype:=tcpupointerdefclass(cpointerdef).createx86(u8inttype,x86pt_far);
  284. wordfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(u16inttype,x86pt_far);
  285. longintfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(s32inttype,x86pt_far);
  286. {$endif i8086}
  287. {$endif x86}
  288. set_default_ptr_types;
  289. cfiletype:=cfiledef.createuntyped;
  290. cvarianttype:=cvariantdef.create(vt_normalvariant);
  291. colevarianttype:=cvariantdef.create(vt_olevariant);
  292. {$ifdef cpufpemu}
  293. { Normal types }
  294. (* we use the same types as without emulator, the only
  295. difference is that direct calls to the emulator are generated
  296. if (cs_fp_emulation in current_settings.moduleswitches) then
  297. begin
  298. addtype('Single',s32floattype);
  299. { extended size is the best real type for the target }
  300. addtype('Real',s32floattype);
  301. pbestrealtype:=@s32floattype;
  302. { extended size is the best real type for the target }
  303. addtype('Extended',pbestrealtype^);
  304. end
  305. else
  306. *)
  307. {$endif cpufpemu}
  308. if init_settings.fputype <> fpu_none then
  309. begin
  310. addtype('Single',s32floattype);
  311. addtype('Double',s64floattype);
  312. { extended size is the best real type for the target }
  313. addtype('Extended',pbestrealtype^);
  314. { CExtended corresponds to the C version of the Extended type
  315. (either "long double" or "double") }
  316. if target_info.system in systems_android then
  317. { Android has "long double"="double" even for x86 }
  318. addtype('CExtended',s64floattype)
  319. else
  320. if tfloatdef(pbestrealtype^).floattype=s80real then
  321. addtype('CExtended',sc80floattype)
  322. else
  323. addtype('CExtended',pbestrealtype^);
  324. end;
  325. {$ifdef x86}
  326. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  327. if target_info.system<>system_x86_64_win64 then
  328. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  329. addtype('Comp',cfloatdef.create(s64comp));
  330. {$endif x86}
  331. addtype('Currency',s64currencytype);
  332. addtype('Pointer',voidpointertype);
  333. {$ifdef x86}
  334. addtype('NearPointer',voidnearpointertype);
  335. addtype('NearCsPointer',voidnearcspointertype);
  336. addtype('NearDsPointer',voidneardspointertype);
  337. addtype('NearSsPointer',voidnearsspointertype);
  338. addtype('NearEsPointer',voidnearespointertype);
  339. addtype('NearFsPointer',voidnearfspointertype);
  340. addtype('NearGsPointer',voidneargspointertype);
  341. {$ifdef i8086}
  342. addtype('FarPointer',voidfarpointertype);
  343. addtype('HugePointer',voidhugepointertype);
  344. {$endif i8086}
  345. {$endif x86}
  346. addtype('ShortString',cshortstringtype);
  347. {$ifdef support_longstring}
  348. addtype('LongString',clongstringtype);
  349. {$endif support_longstring}
  350. addtype('AnsiString',cansistringtype);
  351. addtype('WideString',cwidestringtype);
  352. addtype('UnicodeString',cunicodestringtype);
  353. addtype('OpenString',openshortstringtype);
  354. addtype('Boolean',pasbool8type);
  355. addtype('Boolean16',pasbool16type);
  356. addtype('Boolean32',pasbool32type);
  357. addtype('Boolean64',pasbool64type);
  358. addtype('ByteBool',bool8type);
  359. addtype('WordBool',bool16type);
  360. addtype('LongBool',bool32type);
  361. addtype('QWordBool',bool64type);
  362. addtype('Byte',u8inttype);
  363. addtype('ShortInt',s8inttype);
  364. addtype('Word',u16inttype);
  365. addtype('SmallInt',s16inttype);
  366. addtype('LongWord',u32inttype);
  367. addtype('LongInt',s32inttype);
  368. addtype('QWord',u64inttype);
  369. addtype('Int64',s64inttype);
  370. addtype('Char',cansichartype);
  371. addtype('WideChar',cwidechartype);
  372. addtype('Text',cfiledef.createtext);
  373. addtype('TypedFile',cfiledef.createtyped(voidtype));
  374. addtype('Variant',cvarianttype);
  375. addtype('OleVariant',colevarianttype);
  376. { Internal types }
  377. addtype('$undefined',cundefinedtype);
  378. addtype('$formal',cformaltype);
  379. addtype('$typedformal',ctypedformaltype);
  380. addtype('$void',voidtype);
  381. addtype('$void_pointer',voidpointertype);
  382. addtype('$byte',u8inttype);
  383. addtype('$shortint',s8inttype);
  384. addtype('$word',u16inttype);
  385. addtype('$smallint',s16inttype);
  386. addtype('$ulong',u32inttype);
  387. addtype('$longint',s32inttype);
  388. addtype('$qword',u64inttype);
  389. addtype('$int64',s64inttype);
  390. addtype('$char',cansichartype);
  391. addtype('$widechar',cwidechartype);
  392. addtype('$shortstring',cshortstringtype);
  393. addtype('$longstring',clongstringtype);
  394. addtype('$ansistring',cansistringtype);
  395. addtype('$widestring',cwidestringtype);
  396. addtype('$unicodestring',cunicodestringtype);
  397. addtype('$openshortstring',openshortstringtype);
  398. addtype('$boolean',pasbool8type);
  399. addtype('$boolean16',pasbool16type);
  400. addtype('$boolean32',pasbool32type);
  401. addtype('$boolean64',pasbool64type);
  402. addtype('$bytebool',bool8type);
  403. addtype('$wordbool',bool16type);
  404. addtype('$longbool',bool32type);
  405. addtype('$qwordbool',bool64type);
  406. addtype('$char_pointer',charpointertype);
  407. addtype('$widechar_pointer',widecharpointertype);
  408. addtype('$parentfp_void_pointer',parentfpvoidpointertype);
  409. {$ifdef x86}
  410. addtype('$void_nearpointer',voidnearpointertype);
  411. addtype('$void_nearcspointer',voidnearcspointertype);
  412. addtype('$void_neardspointer',voidneardspointertype);
  413. addtype('$void_nearsspointer',voidnearsspointertype);
  414. addtype('$void_nearespointer',voidnearespointertype);
  415. addtype('$void_nearfspointer',voidnearfspointertype);
  416. addtype('$void_neargspointer',voidneargspointertype);
  417. {$ifdef i8086}
  418. addtype('$void_farpointer',voidfarpointertype);
  419. addtype('$void_hugepointer',voidhugepointertype);
  420. addtype('$char_nearpointer',charnearpointertype);
  421. addtype('$char_farpointer',charfarpointertype);
  422. addtype('$byte_farpointer',bytefarpointertype);
  423. addtype('$word_farpointer',wordfarpointertype);
  424. addtype('$longint_farpointer',longintfarpointertype);
  425. {$endif i8086}
  426. {$endif x86}
  427. addtype('$openchararray',openchararraytype);
  428. addtype('$file',cfiletype);
  429. addtype('$variant',cvarianttype);
  430. addtype('$olevariant',colevarianttype);
  431. if init_settings.fputype<>fpu_none then
  432. begin
  433. addtype('$s32real',s32floattype);
  434. addtype('$s64real',s64floattype);
  435. addtype('$s80real',s80floattype);
  436. addtype('$sc80real',sc80floattype);
  437. end;
  438. addtype('$s64currency',s64currencytype);
  439. if not(target_info.system in systems_managed_vm) then
  440. begin
  441. { Add a type for virtual method tables }
  442. hrecst:=trecordsymtable.create('',current_settings.packrecords);
  443. vmttype:=crecorddef.create('',hrecst);
  444. pvmttype:=cpointerdef.create(vmttype);
  445. { can't use addtype for pvmt because the rtti of the pointed
  446. type is not available. The rtti for pvmt will be written implicitly
  447. by thev tblarray below }
  448. systemunit.insert(ctypesym.create('$pvmt',pvmttype));
  449. addfield(hrecst,cfieldvarsym.create('$length',vs_value,ptrsinttype,[]));
  450. addfield(hrecst,cfieldvarsym.create('$mlength',vs_value,ptrsinttype,[]));
  451. addfield(hrecst,cfieldvarsym.create('$parent',vs_value,pvmttype,[]));
  452. { it seems vmttype is used both for TP objects and Delphi classes,
  453. so the next entry could either be the first virtual method (vm1)
  454. (object) or the class name (class). We can't easily create separate
  455. vtable formats for both, as gdb is hard coded to search for
  456. __vtbl_ptr_type in all cases (JM) }
  457. addfield(hrecst,cfieldvarsym.create('$vm1_or_classname',vs_value,cpointerdef.create(cshortstringtype),[]));
  458. vmtarraytype:=carraydef.create(0,0,s32inttype);
  459. tarraydef(vmtarraytype).elementdef:=voidpointertype;
  460. addfield(hrecst,cfieldvarsym.create('$__pfn',vs_value,vmtarraytype,[]));
  461. addtype('$__vtbl_ptr_type',vmttype);
  462. vmtarraytype:=carraydef.create(0,1,s32inttype);
  463. tarraydef(vmtarraytype).elementdef:=pvmttype;
  464. addtype('$vtblarray',vmtarraytype);
  465. { Add a type for methodpointers }
  466. hrecst:=trecordsymtable.create('',1);
  467. {$ifdef i8086}
  468. if current_settings.x86memorymodel in x86_far_code_models then
  469. addfield(hrecst,cfieldvarsym.create('$proc',vs_value,voidfarpointertype,[]))
  470. else
  471. addfield(hrecst,cfieldvarsym.create('$proc',vs_value,voidnearpointertype,[]));
  472. {$else i8086}
  473. addfield(hrecst,cfieldvarsym.create('$proc',vs_value,voidpointertype,[]));
  474. {$endif i8086}
  475. addfield(hrecst,cfieldvarsym.create('$self',vs_value,voidpointertype,[]));
  476. methodpointertype:=crecorddef.create('',hrecst);
  477. addtype('$methodpointer',methodpointertype);
  478. end;
  479. symtablestack.pop(systemunit);
  480. end;
  481. procedure load_intern_types;
  482. {
  483. Load all default definitions for consts from the system unit
  484. }
  485. procedure loadtype(const s:string;var def:tdef);
  486. var
  487. srsym : ttypesym;
  488. begin
  489. srsym:=search_system_type(s);
  490. def:=srsym.typedef;
  491. end;
  492. var
  493. oldcurrentmodule : tmodule;
  494. begin
  495. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  496. if target_info.system=system_x86_64_win64 then
  497. pbestrealtype:=@s64floattype;
  498. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  499. oldcurrentmodule:=current_module;
  500. set_current_module(nil);
  501. loadtype('byte',u8inttype);
  502. loadtype('shortint',s8inttype);
  503. loadtype('word',u16inttype);
  504. loadtype('smallint',s16inttype);
  505. loadtype('ulong',u32inttype);
  506. loadtype('longint',s32inttype);
  507. loadtype('qword',u64inttype);
  508. loadtype('int64',s64inttype);
  509. loadtype('undefined',cundefinedtype);
  510. loadtype('formal',cformaltype);
  511. loadtype('typedformal',ctypedformaltype);
  512. loadtype('void',voidtype);
  513. loadtype('void_pointer',voidpointertype);
  514. loadtype('char',cansichartype);
  515. loadtype('widechar',cwidechartype);
  516. loadtype('shortstring',cshortstringtype);
  517. loadtype('longstring',clongstringtype);
  518. loadtype('ansistring',cansistringtype);
  519. loadtype('widestring',cwidestringtype);
  520. loadtype('unicodestring',cunicodestringtype);
  521. loadtype('openshortstring',openshortstringtype);
  522. loadtype('openchararray',openchararraytype);
  523. if init_settings.fputype <> fpu_none then
  524. begin
  525. loadtype('s32real',s32floattype);
  526. loadtype('s64real',s64floattype);
  527. loadtype('s80real',s80floattype);
  528. loadtype('sc80real',sc80floattype);
  529. end;
  530. loadtype('s64currency',s64currencytype);
  531. loadtype('boolean',pasbool8type);
  532. loadtype('boolean16',pasbool16type);
  533. loadtype('boolean32',pasbool32type);
  534. loadtype('boolean64',pasbool64type);
  535. loadtype('bytebool',bool8type);
  536. loadtype('wordbool',bool16type);
  537. loadtype('longbool',bool32type);
  538. loadtype('qwordbool',bool64type);
  539. loadtype('char_pointer',charpointertype);
  540. loadtype('widechar_pointer',widecharpointertype);
  541. loadtype('parentfp_void_pointer',parentfpvoidpointertype);
  542. {$ifdef x86}
  543. loadtype('void_nearpointer',voidnearpointertype);
  544. loadtype('void_nearcspointer',voidnearcspointertype);
  545. loadtype('void_neardspointer',voidneardspointertype);
  546. loadtype('void_nearsspointer',voidnearsspointertype);
  547. loadtype('void_nearespointer',voidnearespointertype);
  548. loadtype('void_nearfspointer',voidnearfspointertype);
  549. loadtype('void_neargspointer',voidneargspointertype);
  550. {$ifdef i8086}
  551. loadtype('void_farpointer',voidfarpointertype);
  552. loadtype('void_hugepointer',voidhugepointertype);
  553. loadtype('char_nearpointer',charnearpointertype);
  554. loadtype('char_farpointer',charfarpointertype);
  555. loadtype('byte_farpointer',bytefarpointertype);
  556. loadtype('word_farpointer',wordfarpointertype);
  557. loadtype('longint_farpointer',longintfarpointertype);
  558. {$endif i8086}
  559. {$endif x86}
  560. loadtype('file',cfiletype);
  561. if not(target_info.system in systems_managed_vm) then
  562. begin
  563. loadtype('pvmt',pvmttype);
  564. loadtype('vtblarray',vmtarraytype);
  565. loadtype('__vtbl_ptr_type',vmttype);
  566. end;
  567. loadtype('variant',cvarianttype);
  568. loadtype('olevariant',colevarianttype);
  569. loadtype('methodpointer',methodpointertype);
  570. loadtype('HRESULT',hresultdef);
  571. set_default_int_types;
  572. set_default_ptr_types;
  573. set_current_module(oldcurrentmodule);
  574. end;
  575. procedure registernodes;
  576. {
  577. Register all possible nodes in the nodeclass array that
  578. will be used for loading the nodes from a ppu
  579. }
  580. begin
  581. nodeclass[addn]:=caddnode;
  582. nodeclass[muln]:=caddnode;
  583. nodeclass[subn]:=caddnode;
  584. nodeclass[divn]:=cmoddivnode;
  585. nodeclass[symdifn]:=caddnode;
  586. nodeclass[modn]:=cmoddivnode;
  587. nodeclass[assignn]:=cassignmentnode;
  588. nodeclass[loadn]:=cloadnode;
  589. nodeclass[rangen]:=crangenode;
  590. nodeclass[ltn]:=caddnode;
  591. nodeclass[lten]:=caddnode;
  592. nodeclass[gtn]:=caddnode;
  593. nodeclass[gten]:=caddnode;
  594. nodeclass[equaln]:=caddnode;
  595. nodeclass[unequaln]:=caddnode;
  596. nodeclass[inn]:=cinnode;
  597. nodeclass[orn]:=caddnode;
  598. nodeclass[xorn]:=caddnode;
  599. nodeclass[shrn]:=cshlshrnode;
  600. nodeclass[shln]:=cshlshrnode;
  601. nodeclass[slashn]:=caddnode;
  602. nodeclass[andn]:=caddnode;
  603. nodeclass[subscriptn]:=csubscriptnode;
  604. nodeclass[derefn]:=cderefnode;
  605. nodeclass[addrn]:=caddrnode;
  606. nodeclass[ordconstn]:=cordconstnode;
  607. nodeclass[typeconvn]:=ctypeconvnode;
  608. nodeclass[calln]:=ccallnode;
  609. nodeclass[callparan]:=ccallparanode;
  610. nodeclass[realconstn]:=crealconstnode;
  611. nodeclass[unaryminusn]:=cunaryminusnode;
  612. nodeclass[unaryplusn]:=cunaryplusnode;
  613. nodeclass[asmn]:=casmnode;
  614. nodeclass[vecn]:=cvecnode;
  615. nodeclass[pointerconstn]:=cpointerconstnode;
  616. nodeclass[stringconstn]:=cstringconstnode;
  617. nodeclass[notn]:=cnotnode;
  618. nodeclass[inlinen]:=cinlinenode;
  619. nodeclass[niln]:=cnilnode;
  620. nodeclass[errorn]:=cerrornode;
  621. nodeclass[typen]:=ctypenode;
  622. nodeclass[setelementn]:=csetelementnode;
  623. nodeclass[setconstn]:=csetconstnode;
  624. nodeclass[blockn]:=cblocknode;
  625. nodeclass[statementn]:=cstatementnode;
  626. nodeclass[ifn]:=cifnode;
  627. nodeclass[breakn]:=cbreaknode;
  628. nodeclass[continuen]:=ccontinuenode;
  629. nodeclass[whilerepeatn]:=cwhilerepeatnode;
  630. nodeclass[forn]:=cfornode;
  631. nodeclass[exitn]:=cexitnode;
  632. nodeclass[withn]:=cwithnode;
  633. nodeclass[casen]:=ccasenode;
  634. nodeclass[labeln]:=clabelnode;
  635. nodeclass[goton]:=cgotonode;
  636. nodeclass[tryexceptn]:=ctryexceptnode;
  637. nodeclass[raisen]:=craisenode;
  638. nodeclass[tryfinallyn]:=ctryfinallynode;
  639. nodeclass[onn]:=connode;
  640. nodeclass[isn]:=cisnode;
  641. nodeclass[asn]:=casnode;
  642. nodeclass[starstarn]:=caddnode;
  643. nodeclass[arrayconstructorn]:=carrayconstructornode;
  644. nodeclass[arrayconstructorrangen]:=carrayconstructorrangenode;
  645. nodeclass[tempcreaten]:=ctempcreatenode;
  646. nodeclass[temprefn]:=ctemprefnode;
  647. nodeclass[tempdeleten]:=ctempdeletenode;
  648. nodeclass[addoptn]:=caddnode;
  649. nodeclass[nothingn]:=cnothingnode;
  650. nodeclass[loadvmtaddrn]:=cloadvmtaddrnode;
  651. nodeclass[guidconstn]:=cguidconstnode;
  652. nodeclass[rttin]:=crttinode;
  653. nodeclass[loadparentfpn]:=cloadparentfpnode;
  654. end;
  655. procedure registertais;
  656. {
  657. Register all possible tais in the taiclass array that
  658. will be used for loading the tais from a ppu
  659. }
  660. begin
  661. aiclass[ait_none]:=nil;
  662. aiclass[ait_align]:=tai_align;
  663. aiclass[ait_section]:=tai_section;
  664. aiclass[ait_comment]:=tai_comment;
  665. aiclass[ait_string]:=tai_string;
  666. aiclass[ait_instruction]:=taicpu;
  667. aiclass[ait_datablock]:=tai_datablock;
  668. aiclass[ait_symbol]:=tai_symbol;
  669. aiclass[ait_symbol_end]:=tai_symbol_end;
  670. aiclass[ait_directive]:=tai_directive;
  671. aiclass[ait_label]:=tai_label;
  672. aiclass[ait_const]:=tai_const;
  673. aiclass[ait_real_32bit]:=tai_real_32bit;
  674. aiclass[ait_real_64bit]:=tai_real_64bit;
  675. aiclass[ait_real_80bit]:=tai_real_80bit;
  676. aiclass[ait_comp_64bit]:=tai_comp_64bit;
  677. aiclass[ait_stab]:=tai_stab;
  678. aiclass[ait_force_line]:=tai_force_line;
  679. aiclass[ait_function_name]:=tai_function_name;
  680. {$ifdef alpha}
  681. { the follow is for the DEC Alpha }
  682. aiclass[ait_frame]:=tai_frame;
  683. {$endif alpha}
  684. {$ifdef m68k}
  685. { TODO: FIXME: tai_labeled_instruction doesn't exists}
  686. // aiclass[ait_labeled_instruction]:=tai_labeled_instruction;
  687. {$endif m68k}
  688. {$ifdef ia64}
  689. aiclass[ait_bundle]:=tai_bundle;
  690. aiclass[ait_stop]:=tai_stop;
  691. {$endif ia64}
  692. {$ifdef SPARC}
  693. // aiclass[ait_labeled_instruction]:=tai_labeled_instruction;
  694. {$endif SPARC}
  695. {$ifdef arm}
  696. aiclass[ait_thumb_func]:=tai_thumb_func;
  697. aiclass[ait_thumb_set]:=tai_thumb_set;
  698. {$endif arm}
  699. aiclass[ait_set]:=tai_set;
  700. aiclass[ait_weak]:=tai_weak;
  701. aiclass[ait_cutobject]:=tai_cutobject;
  702. aiclass[ait_regalloc]:=tai_regalloc;
  703. aiclass[ait_tempalloc]:=tai_tempalloc;
  704. aiclass[ait_marker]:=tai_marker;
  705. aiclass[ait_seh_directive]:=tai_seh_directive;
  706. {$ifdef JVM}
  707. aiclass[ait_jvar]:=tai_jvar;
  708. aiclass[ait_jcatch]:=tai_jcatch;
  709. {$endif JVM}
  710. end;
  711. end.