psystem.pas 33 KB

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