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