psystem.pas 34 KB

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