psystem.pas 32 KB

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