psystem.pas 32 KB

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