psystem.pas 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  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. {$ifdef wasm}
  347. create_fpu_types;
  348. s64currencytype:=corddef.create(scurrency,low(int64),high(int64),true);
  349. {$endif wasm}
  350. set_default_int_types;
  351. { some other definitions }
  352. charpointertype:=cpointerdef.create(cansichartype);
  353. widecharpointertype:=cpointerdef.create(cwidechartype);
  354. {$ifdef i8086}
  355. parentfpvoidpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ss);
  356. {$else i8086}
  357. parentfpvoidpointertype:=cpointerdef.create(voidtype);
  358. {$endif i8086}
  359. {$ifdef x86}
  360. voidnearpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near);
  361. voidnearcspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_cs);
  362. voidneardspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ds);
  363. voidnearsspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ss);
  364. voidnearespointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_es);
  365. voidnearfspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_fs);
  366. voidneargspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_gs);
  367. {$ifdef i8086}
  368. voidfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_far);
  369. voidhugepointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_huge);
  370. charnearpointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_near);
  371. charfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_far);
  372. charhugepointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_huge);
  373. bytefarpointertype:=tcpupointerdefclass(cpointerdef).createx86(u8inttype,x86pt_far);
  374. wordfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(u16inttype,x86pt_far);
  375. longintfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(s32inttype,x86pt_far);
  376. {$endif i8086}
  377. {$endif x86}
  378. set_default_ptr_types;
  379. openchararraytype:=carraydef.create_openarray;
  380. tarraydef(openchararraytype).elementdef:=cansichartype;
  381. cfiletype:=cfiledef.createuntyped;
  382. if f_variants in features then
  383. begin
  384. cvarianttype:=cvariantdef.create(vt_normalvariant);
  385. colevarianttype:=cvariantdef.create(vt_olevariant);
  386. end;
  387. {$ifdef cpufpemu}
  388. { Normal types }
  389. (* we use the same types as without emulator, the only
  390. difference is that direct calls to the emulator are generated
  391. if (cs_fp_emulation in current_settings.moduleswitches) then
  392. begin
  393. addtype('Single',s32floattype);
  394. { extended size is the best real type for the target }
  395. addtype('Real',s32floattype);
  396. pbestrealtype:=@s32floattype;
  397. { extended size is the best real type for the target }
  398. addtype('Extended',pbestrealtype^);
  399. end
  400. else
  401. *)
  402. {$endif cpufpemu}
  403. if init_settings.fputype<>fpu_none then
  404. begin
  405. addtype('Single',s32floattype);
  406. addtype('Double',s64floattype);
  407. { extended size is the best real type for the target }
  408. addtype('Extended',pbestrealtype^);
  409. { CExtended corresponds to the C version of the Extended type
  410. (either "long double" or "double") }
  411. if target_info.system in systems_android then
  412. { Android has "long double"="double" even for x86 }
  413. addtype('CExtended',s64floattype)
  414. else
  415. if tfloatdef(pbestrealtype^).floattype=s80real then
  416. addtype('CExtended',sc80floattype)
  417. else
  418. addtype('CExtended',pbestrealtype^);
  419. end;
  420. {$ifdef x86}
  421. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  422. if target_info.system<>system_x86_64_win64 then
  423. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  424. addtype('Comp',cfloatdef.create(s64comp,true));
  425. {$endif x86}
  426. addtype('Currency',s64currencytype);
  427. addtype('Pointer',voidpointertype);
  428. {$ifdef x86}
  429. addtype('NearPointer',voidnearpointertype);
  430. addtype('NearCsPointer',voidnearcspointertype);
  431. addtype('NearDsPointer',voidneardspointertype);
  432. addtype('NearSsPointer',voidnearsspointertype);
  433. addtype('NearEsPointer',voidnearespointertype);
  434. addtype('NearFsPointer',voidnearfspointertype);
  435. addtype('NearGsPointer',voidneargspointertype);
  436. {$ifdef i8086}
  437. addtype('FarPointer',voidfarpointertype);
  438. addtype('HugePointer',voidhugepointertype);
  439. {$endif i8086}
  440. {$endif x86}
  441. addtype('ShortString',cshortstringtype);
  442. {$ifdef support_longstring}
  443. addtype('LongString',clongstringtype);
  444. {$endif support_longstring}
  445. addtype('AnsiString',cansistringtype);
  446. addtype('WideString',cwidestringtype);
  447. addtype('UnicodeString',cunicodestringtype);
  448. addtype('OpenString',openshortstringtype);
  449. addtype('Boolean',pasbool1type);
  450. addtype('Boolean8',pasbool8type);
  451. addtype('Boolean16',pasbool16type);
  452. addtype('Boolean32',pasbool32type);
  453. addtype('Boolean64',pasbool64type);
  454. addtype('ByteBool',bool8type);
  455. addtype('WordBool',bool16type);
  456. addtype('LongBool',bool32type);
  457. addtype('QWordBool',bool64type);
  458. {$ifdef llvm}
  459. addtype('LLVMBool1',llvmbool1type);
  460. {$endif llvm}
  461. addtype('Byte',u8inttype);
  462. addtype('ShortInt',s8inttype);
  463. addtype('Word',u16inttype);
  464. addtype('SmallInt',s16inttype);
  465. addtype('LongWord',u32inttype);
  466. addtype('LongInt',s32inttype);
  467. addtype('QWord',u64inttype);
  468. addtype('Int64',s64inttype);
  469. addtype('Char',cansichartype);
  470. addtype('WideChar',cwidechartype);
  471. addtype('Text',cfiledef.createtext);
  472. addtype('TypedFile',cfiledef.createtyped(voidtype));
  473. if f_variants in features then
  474. begin
  475. addtype('Variant',cvarianttype);
  476. addtype('OleVariant',colevarianttype);
  477. end;
  478. { Internal types }
  479. addtype('$undefined',cundefinedtype);
  480. addtype('$formal',cformaltype);
  481. addtype('$typedformal',ctypedformaltype);
  482. addtype('$void',voidtype);
  483. addtype('$void_pointer',voidpointertype);
  484. addtype('$byte',u8inttype);
  485. addtype('$shortint',s8inttype);
  486. addtype('$word',u16inttype);
  487. addtype('$smallint',s16inttype);
  488. addtype('$sint24',s24inttype);
  489. addtype('$uint24',u24inttype);
  490. addtype('$ulong',u32inttype);
  491. addtype('$longint',s32inttype);
  492. addtype('$sint40',s40inttype);
  493. addtype('$uint40',u40inttype);
  494. addtype('$sint48',s48inttype);
  495. addtype('$uint48',u48inttype);
  496. addtype('$sint56',s56inttype);
  497. addtype('$uint56',u56inttype);
  498. addtype('$qword',u64inttype);
  499. addtype('$int64',s64inttype);
  500. addtype('$uint128',u128inttype);
  501. addtype('$int128',s128inttype);
  502. addtype('$char',cansichartype);
  503. addtype('$widechar',cwidechartype);
  504. addtype('$shortstring',cshortstringtype);
  505. addtype('$longstring',clongstringtype);
  506. addtype('$ansistring',cansistringtype);
  507. addtype('$widestring',cwidestringtype);
  508. addtype('$unicodestring',cunicodestringtype);
  509. addtype('$openshortstring',openshortstringtype);
  510. addtype('$boolean',pasbool1type);
  511. addtype('$boolean8',pasbool8type);
  512. addtype('$boolean16',pasbool16type);
  513. addtype('$boolean32',pasbool32type);
  514. addtype('$boolean64',pasbool64type);
  515. addtype('$bytebool',bool8type);
  516. addtype('$wordbool',bool16type);
  517. addtype('$longbool',bool32type);
  518. addtype('$qwordbool',bool64type);
  519. {$ifdef llvm}
  520. addtype('$llvmbool1',llvmbool1type);
  521. {$endif llvm}
  522. addtype('$char_pointer',charpointertype);
  523. addtype('$widechar_pointer',widecharpointertype);
  524. addtype('$parentfp_void_pointer',parentfpvoidpointertype);
  525. {$ifdef x86}
  526. addtype('$void_nearpointer',voidnearpointertype);
  527. addtype('$void_nearcspointer',voidnearcspointertype);
  528. addtype('$void_neardspointer',voidneardspointertype);
  529. addtype('$void_nearsspointer',voidnearsspointertype);
  530. addtype('$void_nearespointer',voidnearespointertype);
  531. addtype('$void_nearfspointer',voidnearfspointertype);
  532. addtype('$void_neargspointer',voidneargspointertype);
  533. {$ifdef i8086}
  534. addtype('$void_farpointer',voidfarpointertype);
  535. addtype('$void_hugepointer',voidhugepointertype);
  536. addtype('$char_nearpointer',charnearpointertype);
  537. addtype('$char_farpointer',charfarpointertype);
  538. addtype('$char_hugepointer',charhugepointertype);
  539. addtype('$byte_farpointer',bytefarpointertype);
  540. addtype('$word_farpointer',wordfarpointertype);
  541. addtype('$longint_farpointer',longintfarpointertype);
  542. {$endif i8086}
  543. {$endif x86}
  544. addtype('$openchararray',openchararraytype);
  545. addtype('$file',cfiletype);
  546. if f_variants in features then
  547. begin
  548. addtype('$variant',cvarianttype);
  549. addtype('$olevariant',colevarianttype);
  550. end;
  551. if init_settings.fputype<>fpu_none then
  552. begin
  553. addtype('$s32real',s32floattype);
  554. addtype('$s64real',s64floattype);
  555. addtype('$s80real',s80floattype);
  556. addtype('$sc80real',sc80floattype);
  557. end;
  558. addtype('$s64currency',s64currencytype);
  559. if not(target_info.system in systems_managed_vm) then
  560. begin
  561. { Add a type for virtual method tables }
  562. hrecst:=trecordsymtable.create('',current_settings.packrecords,current_settings.alignment.recordalignmin);
  563. vmttype:=crecorddef.create('',hrecst);
  564. pvmttype:=cpointerdef.create(vmttype);
  565. { can't use addtype for pvmt because the rtti of the pointed
  566. type is not available. The rtti for pvmt will be written implicitly
  567. by thev tblarray below }
  568. systemunit.insert(ctypesym.create('$pvmt',pvmttype,true));
  569. addfield(hrecst,cfieldvarsym.create('$length',vs_value,sizesinttype,[],true));
  570. addfield(hrecst,cfieldvarsym.create('$mlength',vs_value,sizesinttype,[],true));
  571. addfield(hrecst,cfieldvarsym.create('$parent',vs_value,pvmttype,[],true));
  572. { it seems vmttype is used both for TP objects and Delphi classes,
  573. so the next entry could either be the first virtual method (vm1)
  574. (object) or the class name (class). We can't easily create separate
  575. vtable formats for both, as gdb is hard coded to search for
  576. __vtbl_ptr_type in all cases (JM) }
  577. addfield(hrecst,cfieldvarsym.create('$vm1_or_classname',vs_value,cpointerdef.create(cshortstringtype),[],true));
  578. vmtarraytype:=carraydef.create(0,0,s32inttype);
  579. tarraydef(vmtarraytype).elementdef:=voidpointertype;
  580. addfield(hrecst,cfieldvarsym.create('$__pfn',vs_value,vmtarraytype,[],true));
  581. addtype('$__vtbl_ptr_type',vmttype);
  582. vmtarraytype:=carraydef.create(0,1,s32inttype);
  583. tarraydef(vmtarraytype).elementdef:=pvmttype;
  584. addtype('$vtblarray',vmtarraytype);
  585. end;
  586. { Add a type for methodpointers }
  587. hrecst:=trecordsymtable.create('',1,current_settings.alignment.recordalignmin);
  588. addfield(hrecst,cfieldvarsym.create('$proc',vs_value,voidcodepointertype,[],true));
  589. addfield(hrecst,cfieldvarsym.create('$self',vs_value,voidpointertype,[],true));
  590. methodpointertype:=crecorddef.create('',hrecst);
  591. addtype('$methodpointer',methodpointertype);
  592. { Add a type for nested proc pointers }
  593. hrecst:=trecordsymtable.create('',1,current_settings.alignment.recordalignmin);
  594. addfield(hrecst,cfieldvarsym.create('$proc',vs_value,voidcodepointertype,[],true));
  595. addfield(hrecst,cfieldvarsym.create('$parentfp',vs_value,parentfpvoidpointertype,[],true));
  596. nestedprocpointertype:=crecorddef.create('',hrecst);
  597. addtype('$nestedprocpointer',nestedprocpointertype);
  598. {$ifdef llvm}
  599. llvm_metadatatype:=cpointerdef.create(voidtype);
  600. { if this gets renamed, also adjust agllvm so it still writes the identifier of this type as "metadata" }
  601. addtype('$metadata',llvm_metadatatype);
  602. {$endif}
  603. symtablestack.pop(systemunit);
  604. end;
  605. procedure load_intern_types;
  606. {
  607. Load all default definitions for consts from the system unit
  608. }
  609. procedure loadtype(const s:string;var def:tdef);
  610. var
  611. srsym : ttypesym;
  612. begin
  613. srsym:=search_system_type(s);
  614. def:=srsym.typedef;
  615. end;
  616. var
  617. oldcurrentmodule : tmodule;
  618. begin
  619. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  620. if target_info.system=system_x86_64_win64 then
  621. pbestrealtype:=@s64floattype;
  622. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  623. oldcurrentmodule:=current_module;
  624. set_current_module(nil);
  625. loadtype('byte',u8inttype);
  626. loadtype('shortint',s8inttype);
  627. loadtype('word',u16inttype);
  628. loadtype('smallint',s16inttype);
  629. loadtype('uint24',u24inttype);
  630. loadtype('sint24',s24inttype);
  631. loadtype('ulong',u32inttype);
  632. loadtype('longint',s32inttype);
  633. loadtype('uint40',u40inttype);
  634. loadtype('sint40',s40inttype);
  635. loadtype('uint48',u48inttype);
  636. loadtype('sint48',s48inttype);
  637. loadtype('uint56',u56inttype);
  638. loadtype('sint56',s56inttype);
  639. loadtype('qword',u64inttype);
  640. loadtype('int64',s64inttype);
  641. loadtype('uint128',u128inttype);
  642. loadtype('int128',s128inttype);
  643. loadtype('undefined',cundefinedtype);
  644. loadtype('formal',cformaltype);
  645. loadtype('typedformal',ctypedformaltype);
  646. loadtype('void',voidtype);
  647. loadtype('void_pointer',voidpointertype);
  648. loadtype('char',cansichartype);
  649. loadtype('widechar',cwidechartype);
  650. loadtype('shortstring',cshortstringtype);
  651. loadtype('longstring',clongstringtype);
  652. loadtype('ansistring',cansistringtype);
  653. loadtype('widestring',cwidestringtype);
  654. loadtype('unicodestring',cunicodestringtype);
  655. loadtype('openshortstring',openshortstringtype);
  656. loadtype('openchararray',openchararraytype);
  657. if init_settings.fputype <> fpu_none then
  658. begin
  659. loadtype('s32real',s32floattype);
  660. loadtype('s64real',s64floattype);
  661. loadtype('s80real',s80floattype);
  662. loadtype('sc80real',sc80floattype);
  663. end;
  664. loadtype('s64currency',s64currencytype);
  665. loadtype('boolean',pasbool1type);
  666. loadtype('boolean8',pasbool8type);
  667. loadtype('boolean16',pasbool16type);
  668. loadtype('boolean32',pasbool32type);
  669. loadtype('boolean64',pasbool64type);
  670. loadtype('bytebool',bool8type);
  671. loadtype('wordbool',bool16type);
  672. loadtype('longbool',bool32type);
  673. loadtype('qwordbool',bool64type);
  674. loadtype('char_pointer',charpointertype);
  675. loadtype('widechar_pointer',widecharpointertype);
  676. loadtype('parentfp_void_pointer',parentfpvoidpointertype);
  677. {$ifdef x86}
  678. loadtype('void_nearpointer',voidnearpointertype);
  679. loadtype('void_nearcspointer',voidnearcspointertype);
  680. loadtype('void_neardspointer',voidneardspointertype);
  681. loadtype('void_nearsspointer',voidnearsspointertype);
  682. loadtype('void_nearespointer',voidnearespointertype);
  683. loadtype('void_nearfspointer',voidnearfspointertype);
  684. loadtype('void_neargspointer',voidneargspointertype);
  685. {$ifdef i8086}
  686. loadtype('void_farpointer',voidfarpointertype);
  687. loadtype('void_hugepointer',voidhugepointertype);
  688. loadtype('char_nearpointer',charnearpointertype);
  689. loadtype('char_farpointer',charfarpointertype);
  690. loadtype('char_hugepointer',charhugepointertype);
  691. loadtype('byte_farpointer',bytefarpointertype);
  692. loadtype('word_farpointer',wordfarpointertype);
  693. loadtype('longint_farpointer',longintfarpointertype);
  694. {$endif i8086}
  695. {$endif x86}
  696. {$ifdef llvm}
  697. loadtype('llvmbool1',llvmbool1type);
  698. {$endif llvm}
  699. loadtype('file',cfiletype);
  700. if not(target_info.system in systems_managed_vm) then
  701. begin
  702. loadtype('pvmt',pvmttype);
  703. loadtype('vtblarray',vmtarraytype);
  704. loadtype('__vtbl_ptr_type',vmttype);
  705. end;
  706. if f_variants in features then
  707. begin
  708. loadtype('variant',cvarianttype);
  709. loadtype('olevariant',colevarianttype);
  710. end;
  711. loadtype('methodpointer',methodpointertype);
  712. loadtype('nestedprocpointer',nestedprocpointertype);
  713. {$ifdef llvm}
  714. loadtype('metadata',llvm_metadatatype);
  715. {$endif}
  716. loadtype('HRESULT',hresultdef);
  717. loadtype('TTYPEKIND',typekindtype);
  718. set_default_int_types;
  719. set_default_ptr_types;
  720. set_current_module(oldcurrentmodule);
  721. end;
  722. procedure registernodes;
  723. {
  724. Register all possible nodes in the nodeclass array that
  725. will be used for loading the nodes from a ppu
  726. }
  727. begin
  728. nodeclass[addn]:=caddnode;
  729. nodeclass[muln]:=caddnode;
  730. nodeclass[subn]:=caddnode;
  731. nodeclass[divn]:=cmoddivnode;
  732. nodeclass[symdifn]:=caddnode;
  733. nodeclass[modn]:=cmoddivnode;
  734. nodeclass[assignn]:=cassignmentnode;
  735. nodeclass[loadn]:=cloadnode;
  736. nodeclass[rangen]:=crangenode;
  737. nodeclass[ltn]:=caddnode;
  738. nodeclass[lten]:=caddnode;
  739. nodeclass[gtn]:=caddnode;
  740. nodeclass[gten]:=caddnode;
  741. nodeclass[equaln]:=caddnode;
  742. nodeclass[unequaln]:=caddnode;
  743. nodeclass[inn]:=cinnode;
  744. nodeclass[orn]:=caddnode;
  745. nodeclass[xorn]:=caddnode;
  746. nodeclass[shrn]:=cshlshrnode;
  747. nodeclass[shln]:=cshlshrnode;
  748. nodeclass[slashn]:=caddnode;
  749. nodeclass[andn]:=caddnode;
  750. nodeclass[subscriptn]:=csubscriptnode;
  751. nodeclass[derefn]:=cderefnode;
  752. nodeclass[addrn]:=caddrnode;
  753. nodeclass[ordconstn]:=cordconstnode;
  754. nodeclass[typeconvn]:=ctypeconvnode;
  755. nodeclass[calln]:=ccallnode;
  756. nodeclass[callparan]:=ccallparanode;
  757. nodeclass[realconstn]:=crealconstnode;
  758. nodeclass[unaryminusn]:=cunaryminusnode;
  759. nodeclass[unaryplusn]:=cunaryplusnode;
  760. nodeclass[asmn]:=casmnode;
  761. nodeclass[vecn]:=cvecnode;
  762. nodeclass[pointerconstn]:=cpointerconstnode;
  763. nodeclass[stringconstn]:=cstringconstnode;
  764. nodeclass[notn]:=cnotnode;
  765. nodeclass[inlinen]:=cinlinenode;
  766. nodeclass[niln]:=cnilnode;
  767. nodeclass[errorn]:=cerrornode;
  768. nodeclass[typen]:=ctypenode;
  769. nodeclass[setelementn]:=csetelementnode;
  770. nodeclass[setconstn]:=csetconstnode;
  771. nodeclass[blockn]:=cblocknode;
  772. nodeclass[statementn]:=cstatementnode;
  773. nodeclass[ifn]:=cifnode;
  774. nodeclass[breakn]:=cbreaknode;
  775. nodeclass[continuen]:=ccontinuenode;
  776. nodeclass[whilerepeatn]:=cwhilerepeatnode;
  777. nodeclass[forn]:=cfornode;
  778. nodeclass[exitn]:=cexitnode;
  779. nodeclass[casen]:=ccasenode;
  780. nodeclass[labeln]:=clabelnode;
  781. nodeclass[goton]:=cgotonode;
  782. nodeclass[tryexceptn]:=ctryexceptnode;
  783. nodeclass[raisen]:=craisenode;
  784. nodeclass[tryfinallyn]:=ctryfinallynode;
  785. nodeclass[onn]:=connode;
  786. nodeclass[isn]:=cisnode;
  787. nodeclass[asn]:=casnode;
  788. nodeclass[starstarn]:=caddnode;
  789. nodeclass[arrayconstructorn]:=carrayconstructornode;
  790. nodeclass[arrayconstructorrangen]:=carrayconstructorrangenode;
  791. nodeclass[tempcreaten]:=ctempcreatenode;
  792. nodeclass[temprefn]:=ctemprefnode;
  793. nodeclass[tempdeleten]:=ctempdeletenode;
  794. nodeclass[addoptn]:=caddnode;
  795. nodeclass[nothingn]:=cnothingnode;
  796. nodeclass[loadvmtaddrn]:=cloadvmtaddrnode;
  797. nodeclass[guidconstn]:=cguidconstnode;
  798. nodeclass[rttin]:=crttinode;
  799. nodeclass[loadparentfpn]:=cloadparentfpnode;
  800. end;
  801. procedure registertais;
  802. {
  803. Register all possible tais in the taiclass array that
  804. will be used for loading the tais from a ppu
  805. }
  806. begin
  807. aiclass[ait_none]:=nil;
  808. aiclass[ait_align]:=tai_align;
  809. aiclass[ait_section]:=tai_section;
  810. aiclass[ait_comment]:=tai_comment;
  811. aiclass[ait_string]:=tai_string;
  812. aiclass[ait_instruction]:=taicpu;
  813. aiclass[ait_datablock]:=tai_datablock;
  814. aiclass[ait_symbol]:=tai_symbol;
  815. aiclass[ait_symbol_end]:=tai_symbol_end;
  816. aiclass[ait_directive]:=tai_directive;
  817. aiclass[ait_label]:=tai_label;
  818. aiclass[ait_const]:=tai_const;
  819. aiclass[ait_realconst]:=tai_realconst;
  820. aiclass[ait_stab]:=tai_stab;
  821. aiclass[ait_force_line]:=tai_force_line;
  822. aiclass[ait_function_name]:=tai_function_name;
  823. aiclass[ait_symbolpair]:=tai_symbolpair;
  824. aiclass[ait_cutobject]:=tai_cutobject;
  825. aiclass[ait_regalloc]:=tai_regalloc;
  826. aiclass[ait_tempalloc]:=tai_tempalloc;
  827. aiclass[ait_marker]:=tai_marker;
  828. aiclass[ait_seh_directive]:=tai_seh_directive;
  829. {$ifdef JVM}
  830. aiclass[ait_jvar]:=tai_jvar;
  831. aiclass[ait_jcatch]:=tai_jcatch;
  832. {$endif JVM}
  833. end;
  834. end.