psystem.pas 34 KB

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