psystem.pas 33 KB

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