2
0

psystem.pas 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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. {$ifdef x86}
  213. create_fpu_types;
  214. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  215. if target_info.system=system_x86_64_win64 then
  216. begin
  217. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  218. pbestrealtype:=@s64floattype;
  219. end
  220. else
  221. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  222. s64currencytype:=cfloatdef.create(s64currency);
  223. {$endif x86}
  224. {$ifdef powerpc}
  225. create_fpu_types;
  226. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  227. {$endif powerpc}
  228. {$ifdef POWERPC64}
  229. create_fpu_types;
  230. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  231. {$endif POWERPC64}
  232. {$ifdef sparc}
  233. create_fpu_types;
  234. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  235. {$endif sparc}
  236. {$ifdef m68k}
  237. create_fpu_types;
  238. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  239. {$endif}
  240. {$ifdef arm}
  241. create_fpu_types;
  242. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  243. {$endif arm}
  244. {$ifdef avr}
  245. s32floattype:=cfloatdef.create(s32real);
  246. s64floattype:=cfloatdef.create(s64real);
  247. s80floattype:=cfloatdef.create(s80real);
  248. sc80floattype:=cfloatdef.create(sc80real);
  249. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  250. {$endif avr}
  251. {$ifdef mips}
  252. create_fpu_types;
  253. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  254. {$endif mips}
  255. {$ifdef jvm}
  256. create_fpu_types;
  257. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  258. {$endif jvm}
  259. set_default_int_types;
  260. { some other definitions }
  261. openchararraytype:=carraydef.create(0,-1,ptrsinttype);
  262. tarraydef(openchararraytype).elementdef:=cansichartype;
  263. charpointertype:=cpointerdef.create(cansichartype);
  264. widecharpointertype:=cpointerdef.create(cwidechartype);
  265. {$ifdef i8086}
  266. parentfpvoidpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ss);
  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. charhugepointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_huge);
  284. bytefarpointertype:=tcpupointerdefclass(cpointerdef).createx86(u8inttype,x86pt_far);
  285. wordfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(u16inttype,x86pt_far);
  286. longintfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(s32inttype,x86pt_far);
  287. {$endif i8086}
  288. {$endif x86}
  289. set_default_ptr_types;
  290. cfiletype:=cfiledef.createuntyped;
  291. cvarianttype:=cvariantdef.create(vt_normalvariant);
  292. colevarianttype:=cvariantdef.create(vt_olevariant);
  293. {$ifdef cpufpemu}
  294. { Normal types }
  295. (* we use the same types as without emulator, the only
  296. difference is that direct calls to the emulator are generated
  297. if (cs_fp_emulation in current_settings.moduleswitches) then
  298. begin
  299. addtype('Single',s32floattype);
  300. { extended size is the best real type for the target }
  301. addtype('Real',s32floattype);
  302. pbestrealtype:=@s32floattype;
  303. { extended size is the best real type for the target }
  304. addtype('Extended',pbestrealtype^);
  305. end
  306. else
  307. *)
  308. {$endif cpufpemu}
  309. if init_settings.fputype <> fpu_none then
  310. begin
  311. addtype('Single',s32floattype);
  312. addtype('Double',s64floattype);
  313. { extended size is the best real type for the target }
  314. addtype('Extended',pbestrealtype^);
  315. { CExtended corresponds to the C version of the Extended type
  316. (either "long double" or "double") }
  317. if target_info.system in systems_android then
  318. { Android has "long double"="double" even for x86 }
  319. addtype('CExtended',s64floattype)
  320. else
  321. if tfloatdef(pbestrealtype^).floattype=s80real then
  322. addtype('CExtended',sc80floattype)
  323. else
  324. addtype('CExtended',pbestrealtype^);
  325. end;
  326. {$ifdef x86}
  327. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  328. if target_info.system<>system_x86_64_win64 then
  329. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  330. addtype('Comp',cfloatdef.create(s64comp));
  331. {$endif x86}
  332. addtype('Currency',s64currencytype);
  333. addtype('Pointer',voidpointertype);
  334. {$ifdef x86}
  335. addtype('NearPointer',voidnearpointertype);
  336. addtype('NearCsPointer',voidnearcspointertype);
  337. addtype('NearDsPointer',voidneardspointertype);
  338. addtype('NearSsPointer',voidnearsspointertype);
  339. addtype('NearEsPointer',voidnearespointertype);
  340. addtype('NearFsPointer',voidnearfspointertype);
  341. addtype('NearGsPointer',voidneargspointertype);
  342. {$ifdef i8086}
  343. addtype('FarPointer',voidfarpointertype);
  344. addtype('HugePointer',voidhugepointertype);
  345. {$endif i8086}
  346. {$endif x86}
  347. addtype('ShortString',cshortstringtype);
  348. {$ifdef support_longstring}
  349. addtype('LongString',clongstringtype);
  350. {$endif support_longstring}
  351. addtype('AnsiString',cansistringtype);
  352. addtype('WideString',cwidestringtype);
  353. addtype('UnicodeString',cunicodestringtype);
  354. addtype('OpenString',openshortstringtype);
  355. addtype('Boolean',pasbool8type);
  356. addtype('Boolean16',pasbool16type);
  357. addtype('Boolean32',pasbool32type);
  358. addtype('Boolean64',pasbool64type);
  359. addtype('ByteBool',bool8type);
  360. addtype('WordBool',bool16type);
  361. addtype('LongBool',bool32type);
  362. addtype('QWordBool',bool64type);
  363. addtype('Byte',u8inttype);
  364. addtype('ShortInt',s8inttype);
  365. addtype('Word',u16inttype);
  366. addtype('SmallInt',s16inttype);
  367. addtype('LongWord',u32inttype);
  368. addtype('LongInt',s32inttype);
  369. addtype('QWord',u64inttype);
  370. addtype('Int64',s64inttype);
  371. addtype('Char',cansichartype);
  372. addtype('WideChar',cwidechartype);
  373. addtype('Text',cfiledef.createtext);
  374. addtype('TypedFile',cfiledef.createtyped(voidtype));
  375. addtype('Variant',cvarianttype);
  376. addtype('OleVariant',colevarianttype);
  377. { Internal types }
  378. addtype('$undefined',cundefinedtype);
  379. addtype('$formal',cformaltype);
  380. addtype('$typedformal',ctypedformaltype);
  381. addtype('$void',voidtype);
  382. addtype('$void_pointer',voidpointertype);
  383. addtype('$byte',u8inttype);
  384. addtype('$shortint',s8inttype);
  385. addtype('$word',u16inttype);
  386. addtype('$smallint',s16inttype);
  387. addtype('$ulong',u32inttype);
  388. addtype('$longint',s32inttype);
  389. addtype('$qword',u64inttype);
  390. addtype('$int64',s64inttype);
  391. addtype('$char',cansichartype);
  392. addtype('$widechar',cwidechartype);
  393. addtype('$shortstring',cshortstringtype);
  394. addtype('$longstring',clongstringtype);
  395. addtype('$ansistring',cansistringtype);
  396. addtype('$widestring',cwidestringtype);
  397. addtype('$unicodestring',cunicodestringtype);
  398. addtype('$openshortstring',openshortstringtype);
  399. addtype('$boolean',pasbool8type);
  400. addtype('$boolean16',pasbool16type);
  401. addtype('$boolean32',pasbool32type);
  402. addtype('$boolean64',pasbool64type);
  403. addtype('$bytebool',bool8type);
  404. addtype('$wordbool',bool16type);
  405. addtype('$longbool',bool32type);
  406. addtype('$qwordbool',bool64type);
  407. addtype('$char_pointer',charpointertype);
  408. addtype('$widechar_pointer',widecharpointertype);
  409. addtype('$parentfp_void_pointer',parentfpvoidpointertype);
  410. {$ifdef x86}
  411. addtype('$void_nearpointer',voidnearpointertype);
  412. addtype('$void_nearcspointer',voidnearcspointertype);
  413. addtype('$void_neardspointer',voidneardspointertype);
  414. addtype('$void_nearsspointer',voidnearsspointertype);
  415. addtype('$void_nearespointer',voidnearespointertype);
  416. addtype('$void_nearfspointer',voidnearfspointertype);
  417. addtype('$void_neargspointer',voidneargspointertype);
  418. {$ifdef i8086}
  419. addtype('$void_farpointer',voidfarpointertype);
  420. addtype('$void_hugepointer',voidhugepointertype);
  421. addtype('$char_nearpointer',charnearpointertype);
  422. addtype('$char_farpointer',charfarpointertype);
  423. addtype('$char_hugepointer',charhugepointertype);
  424. addtype('$byte_farpointer',bytefarpointertype);
  425. addtype('$word_farpointer',wordfarpointertype);
  426. addtype('$longint_farpointer',longintfarpointertype);
  427. {$endif i8086}
  428. {$endif x86}
  429. addtype('$openchararray',openchararraytype);
  430. addtype('$file',cfiletype);
  431. addtype('$variant',cvarianttype);
  432. addtype('$olevariant',colevarianttype);
  433. if init_settings.fputype<>fpu_none then
  434. begin
  435. addtype('$s32real',s32floattype);
  436. addtype('$s64real',s64floattype);
  437. addtype('$s80real',s80floattype);
  438. addtype('$sc80real',sc80floattype);
  439. end;
  440. addtype('$s64currency',s64currencytype);
  441. if not(target_info.system in systems_managed_vm) then
  442. begin
  443. { Add a type for virtual method tables }
  444. hrecst:=trecordsymtable.create('',current_settings.packrecords);
  445. vmttype:=crecorddef.create('',hrecst);
  446. pvmttype:=cpointerdef.create(vmttype);
  447. { can't use addtype for pvmt because the rtti of the pointed
  448. type is not available. The rtti for pvmt will be written implicitly
  449. by thev tblarray below }
  450. systemunit.insert(ctypesym.create('$pvmt',pvmttype));
  451. addfield(hrecst,cfieldvarsym.create('$length',vs_value,ptrsinttype,[]));
  452. addfield(hrecst,cfieldvarsym.create('$mlength',vs_value,ptrsinttype,[]));
  453. addfield(hrecst,cfieldvarsym.create('$parent',vs_value,pvmttype,[]));
  454. { it seems vmttype is used both for TP objects and Delphi classes,
  455. so the next entry could either be the first virtual method (vm1)
  456. (object) or the class name (class). We can't easily create separate
  457. vtable formats for both, as gdb is hard coded to search for
  458. __vtbl_ptr_type in all cases (JM) }
  459. addfield(hrecst,cfieldvarsym.create('$vm1_or_classname',vs_value,cpointerdef.create(cshortstringtype),[]));
  460. vmtarraytype:=carraydef.create(0,0,s32inttype);
  461. tarraydef(vmtarraytype).elementdef:=voidpointertype;
  462. addfield(hrecst,cfieldvarsym.create('$__pfn',vs_value,vmtarraytype,[]));
  463. addtype('$__vtbl_ptr_type',vmttype);
  464. vmtarraytype:=carraydef.create(0,1,s32inttype);
  465. tarraydef(vmtarraytype).elementdef:=pvmttype;
  466. addtype('$vtblarray',vmtarraytype);
  467. end;
  468. { Add a type for methodpointers }
  469. hrecst:=trecordsymtable.create('',1);
  470. addfield(hrecst,cfieldvarsym.create('$proc',vs_value,voidcodepointertype,[]));
  471. addfield(hrecst,cfieldvarsym.create('$self',vs_value,voidpointertype,[]));
  472. methodpointertype:=crecorddef.create('',hrecst);
  473. addtype('$methodpointer',methodpointertype);
  474. { Add a type for nested proc pointers }
  475. hrecst:=trecordsymtable.create('',1);
  476. addfield(hrecst,cfieldvarsym.create('$proc',vs_value,voidcodepointertype,[]));
  477. addfield(hrecst,cfieldvarsym.create('$parentfp',vs_value,parentfpvoidpointertype,[]));
  478. nestedprocpointertype:=crecorddef.create('',hrecst);
  479. addtype('$nestedprocpointer',nestedprocpointertype);
  480. symtablestack.pop(systemunit);
  481. end;
  482. procedure load_intern_types;
  483. {
  484. Load all default definitions for consts from the system unit
  485. }
  486. procedure loadtype(const s:string;var def:tdef);
  487. var
  488. srsym : ttypesym;
  489. begin
  490. srsym:=search_system_type(s);
  491. def:=srsym.typedef;
  492. end;
  493. var
  494. oldcurrentmodule : tmodule;
  495. begin
  496. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  497. if target_info.system=system_x86_64_win64 then
  498. pbestrealtype:=@s64floattype;
  499. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  500. oldcurrentmodule:=current_module;
  501. set_current_module(nil);
  502. loadtype('byte',u8inttype);
  503. loadtype('shortint',s8inttype);
  504. loadtype('word',u16inttype);
  505. loadtype('smallint',s16inttype);
  506. loadtype('ulong',u32inttype);
  507. loadtype('longint',s32inttype);
  508. loadtype('qword',u64inttype);
  509. loadtype('int64',s64inttype);
  510. loadtype('undefined',cundefinedtype);
  511. loadtype('formal',cformaltype);
  512. loadtype('typedformal',ctypedformaltype);
  513. loadtype('void',voidtype);
  514. loadtype('void_pointer',voidpointertype);
  515. loadtype('char',cansichartype);
  516. loadtype('widechar',cwidechartype);
  517. loadtype('shortstring',cshortstringtype);
  518. loadtype('longstring',clongstringtype);
  519. loadtype('ansistring',cansistringtype);
  520. loadtype('widestring',cwidestringtype);
  521. loadtype('unicodestring',cunicodestringtype);
  522. loadtype('openshortstring',openshortstringtype);
  523. loadtype('openchararray',openchararraytype);
  524. if init_settings.fputype <> fpu_none then
  525. begin
  526. loadtype('s32real',s32floattype);
  527. loadtype('s64real',s64floattype);
  528. loadtype('s80real',s80floattype);
  529. loadtype('sc80real',sc80floattype);
  530. end;
  531. loadtype('s64currency',s64currencytype);
  532. loadtype('boolean',pasbool8type);
  533. loadtype('boolean16',pasbool16type);
  534. loadtype('boolean32',pasbool32type);
  535. loadtype('boolean64',pasbool64type);
  536. loadtype('bytebool',bool8type);
  537. loadtype('wordbool',bool16type);
  538. loadtype('longbool',bool32type);
  539. loadtype('qwordbool',bool64type);
  540. loadtype('char_pointer',charpointertype);
  541. loadtype('widechar_pointer',widecharpointertype);
  542. loadtype('parentfp_void_pointer',parentfpvoidpointertype);
  543. {$ifdef x86}
  544. loadtype('void_nearpointer',voidnearpointertype);
  545. loadtype('void_nearcspointer',voidnearcspointertype);
  546. loadtype('void_neardspointer',voidneardspointertype);
  547. loadtype('void_nearsspointer',voidnearsspointertype);
  548. loadtype('void_nearespointer',voidnearespointertype);
  549. loadtype('void_nearfspointer',voidnearfspointertype);
  550. loadtype('void_neargspointer',voidneargspointertype);
  551. {$ifdef i8086}
  552. loadtype('void_farpointer',voidfarpointertype);
  553. loadtype('void_hugepointer',voidhugepointertype);
  554. loadtype('char_nearpointer',charnearpointertype);
  555. loadtype('char_farpointer',charfarpointertype);
  556. loadtype('char_hugepointer',charhugepointertype);
  557. loadtype('byte_farpointer',bytefarpointertype);
  558. loadtype('word_farpointer',wordfarpointertype);
  559. loadtype('longint_farpointer',longintfarpointertype);
  560. {$endif i8086}
  561. {$endif x86}
  562. loadtype('file',cfiletype);
  563. if not(target_info.system in systems_managed_vm) then
  564. begin
  565. loadtype('pvmt',pvmttype);
  566. loadtype('vtblarray',vmtarraytype);
  567. loadtype('__vtbl_ptr_type',vmttype);
  568. end;
  569. loadtype('variant',cvarianttype);
  570. loadtype('olevariant',colevarianttype);
  571. loadtype('methodpointer',methodpointertype);
  572. loadtype('nestedprocpointer',nestedprocpointertype);
  573. loadtype('HRESULT',hresultdef);
  574. set_default_int_types;
  575. set_default_ptr_types;
  576. set_current_module(oldcurrentmodule);
  577. end;
  578. procedure registernodes;
  579. {
  580. Register all possible nodes in the nodeclass array that
  581. will be used for loading the nodes from a ppu
  582. }
  583. begin
  584. nodeclass[addn]:=caddnode;
  585. nodeclass[muln]:=caddnode;
  586. nodeclass[subn]:=caddnode;
  587. nodeclass[divn]:=cmoddivnode;
  588. nodeclass[symdifn]:=caddnode;
  589. nodeclass[modn]:=cmoddivnode;
  590. nodeclass[assignn]:=cassignmentnode;
  591. nodeclass[loadn]:=cloadnode;
  592. nodeclass[rangen]:=crangenode;
  593. nodeclass[ltn]:=caddnode;
  594. nodeclass[lten]:=caddnode;
  595. nodeclass[gtn]:=caddnode;
  596. nodeclass[gten]:=caddnode;
  597. nodeclass[equaln]:=caddnode;
  598. nodeclass[unequaln]:=caddnode;
  599. nodeclass[inn]:=cinnode;
  600. nodeclass[orn]:=caddnode;
  601. nodeclass[xorn]:=caddnode;
  602. nodeclass[shrn]:=cshlshrnode;
  603. nodeclass[shln]:=cshlshrnode;
  604. nodeclass[slashn]:=caddnode;
  605. nodeclass[andn]:=caddnode;
  606. nodeclass[subscriptn]:=csubscriptnode;
  607. nodeclass[derefn]:=cderefnode;
  608. nodeclass[addrn]:=caddrnode;
  609. nodeclass[ordconstn]:=cordconstnode;
  610. nodeclass[typeconvn]:=ctypeconvnode;
  611. nodeclass[calln]:=ccallnode;
  612. nodeclass[callparan]:=ccallparanode;
  613. nodeclass[realconstn]:=crealconstnode;
  614. nodeclass[unaryminusn]:=cunaryminusnode;
  615. nodeclass[unaryplusn]:=cunaryplusnode;
  616. nodeclass[asmn]:=casmnode;
  617. nodeclass[vecn]:=cvecnode;
  618. nodeclass[pointerconstn]:=cpointerconstnode;
  619. nodeclass[stringconstn]:=cstringconstnode;
  620. nodeclass[notn]:=cnotnode;
  621. nodeclass[inlinen]:=cinlinenode;
  622. nodeclass[niln]:=cnilnode;
  623. nodeclass[errorn]:=cerrornode;
  624. nodeclass[typen]:=ctypenode;
  625. nodeclass[setelementn]:=csetelementnode;
  626. nodeclass[setconstn]:=csetconstnode;
  627. nodeclass[blockn]:=cblocknode;
  628. nodeclass[statementn]:=cstatementnode;
  629. nodeclass[ifn]:=cifnode;
  630. nodeclass[breakn]:=cbreaknode;
  631. nodeclass[continuen]:=ccontinuenode;
  632. nodeclass[whilerepeatn]:=cwhilerepeatnode;
  633. nodeclass[forn]:=cfornode;
  634. nodeclass[exitn]:=cexitnode;
  635. nodeclass[withn]:=cwithnode;
  636. nodeclass[casen]:=ccasenode;
  637. nodeclass[labeln]:=clabelnode;
  638. nodeclass[goton]:=cgotonode;
  639. nodeclass[tryexceptn]:=ctryexceptnode;
  640. nodeclass[raisen]:=craisenode;
  641. nodeclass[tryfinallyn]:=ctryfinallynode;
  642. nodeclass[onn]:=connode;
  643. nodeclass[isn]:=cisnode;
  644. nodeclass[asn]:=casnode;
  645. nodeclass[starstarn]:=caddnode;
  646. nodeclass[arrayconstructorn]:=carrayconstructornode;
  647. nodeclass[arrayconstructorrangen]:=carrayconstructorrangenode;
  648. nodeclass[tempcreaten]:=ctempcreatenode;
  649. nodeclass[temprefn]:=ctemprefnode;
  650. nodeclass[tempdeleten]:=ctempdeletenode;
  651. nodeclass[addoptn]:=caddnode;
  652. nodeclass[nothingn]:=cnothingnode;
  653. nodeclass[loadvmtaddrn]:=cloadvmtaddrnode;
  654. nodeclass[guidconstn]:=cguidconstnode;
  655. nodeclass[rttin]:=crttinode;
  656. nodeclass[loadparentfpn]:=cloadparentfpnode;
  657. end;
  658. procedure registertais;
  659. {
  660. Register all possible tais in the taiclass array that
  661. will be used for loading the tais from a ppu
  662. }
  663. begin
  664. aiclass[ait_none]:=nil;
  665. aiclass[ait_align]:=tai_align;
  666. aiclass[ait_section]:=tai_section;
  667. aiclass[ait_comment]:=tai_comment;
  668. aiclass[ait_string]:=tai_string;
  669. aiclass[ait_instruction]:=taicpu;
  670. aiclass[ait_datablock]:=tai_datablock;
  671. aiclass[ait_symbol]:=tai_symbol;
  672. aiclass[ait_symbol_end]:=tai_symbol_end;
  673. aiclass[ait_directive]:=tai_directive;
  674. aiclass[ait_label]:=tai_label;
  675. aiclass[ait_const]:=tai_const;
  676. aiclass[ait_real_32bit]:=tai_real_32bit;
  677. aiclass[ait_real_64bit]:=tai_real_64bit;
  678. aiclass[ait_real_80bit]:=tai_real_80bit;
  679. aiclass[ait_comp_64bit]:=tai_comp_64bit;
  680. aiclass[ait_stab]:=tai_stab;
  681. aiclass[ait_force_line]:=tai_force_line;
  682. aiclass[ait_function_name]:=tai_function_name;
  683. {$ifdef alpha}
  684. { the follow is for the DEC Alpha }
  685. aiclass[ait_frame]:=tai_frame;
  686. {$endif alpha}
  687. {$ifdef m68k}
  688. { TODO: FIXME: tai_labeled_instruction doesn't exists}
  689. // aiclass[ait_labeled_instruction]:=tai_labeled_instruction;
  690. {$endif m68k}
  691. {$ifdef ia64}
  692. aiclass[ait_bundle]:=tai_bundle;
  693. aiclass[ait_stop]:=tai_stop;
  694. {$endif ia64}
  695. {$ifdef SPARC}
  696. // aiclass[ait_labeled_instruction]:=tai_labeled_instruction;
  697. {$endif SPARC}
  698. {$ifdef arm}
  699. aiclass[ait_thumb_func]:=tai_thumb_func;
  700. aiclass[ait_thumb_set]:=tai_thumb_set;
  701. {$endif arm}
  702. aiclass[ait_set]:=tai_set;
  703. aiclass[ait_weak]:=tai_weak;
  704. aiclass[ait_cutobject]:=tai_cutobject;
  705. aiclass[ait_regalloc]:=tai_regalloc;
  706. aiclass[ait_tempalloc]:=tai_tempalloc;
  707. aiclass[ait_marker]:=tai_marker;
  708. aiclass[ait_seh_directive]:=tai_seh_directive;
  709. {$ifdef JVM}
  710. aiclass[ait_jvar]:=tai_jvar;
  711. aiclass[ait_jcatch]:=tai_jcatch;
  712. {$endif JVM}
  713. end;
  714. end.