psystem.pas 38 KB

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