psystem.pas 35 KB

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