psystem.pas 33 KB

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