psystem.pas 36 KB

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