2
0

psystem.pas 34 KB

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