psystem.pas 32 KB

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