psystem.pas 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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 wasm}
  358. create_fpu_types;
  359. s64currencytype:=corddef.create(scurrency,low(int64),high(int64),true);
  360. {$endif wasm}
  361. {$ifdef xtensa}
  362. create_fpu_types;
  363. s64currencytype:=corddef.create(scurrency,low(int64),high(int64),true);
  364. {$endif xtensa}
  365. set_default_int_types;
  366. { some other definitions }
  367. charpointertype:=cpointerdef.create(cansichartype);
  368. widecharpointertype:=cpointerdef.create(cwidechartype);
  369. {$ifdef i8086}
  370. parentfpvoidpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ss);
  371. {$else i8086}
  372. parentfpvoidpointertype:=cpointerdef.create(voidtype);
  373. {$endif i8086}
  374. {$ifdef x86}
  375. voidnearpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near);
  376. voidnearcspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_cs);
  377. voidneardspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ds);
  378. voidnearsspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ss);
  379. voidnearespointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_es);
  380. voidnearfspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_fs);
  381. voidneargspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_gs);
  382. {$ifdef i8086}
  383. voidfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_far);
  384. voidhugepointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_huge);
  385. charnearpointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_near);
  386. charfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_far);
  387. charhugepointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_huge);
  388. bytefarpointertype:=tcpupointerdefclass(cpointerdef).createx86(u8inttype,x86pt_far);
  389. wordfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(u16inttype,x86pt_far);
  390. longintfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(s32inttype,x86pt_far);
  391. {$endif i8086}
  392. x86_m64type:=carraydef.create(0,1,s32inttype);
  393. x86_m128type:=carraydef.create(0,3,s32inttype);
  394. x86_m128dtype:=carraydef.create(0,1,s32inttype);
  395. x86_m128itype:=carraydef.create(0,3,s32inttype);
  396. x86_m256type:=carraydef.create(0,7,s32inttype);
  397. x86_m256dtype:=carraydef.create(0,3,s32inttype);
  398. x86_m256itype:=carraydef.create(0,7,s32inttype);
  399. tarraydef(x86_m64type).elementdef:=s32floattype;
  400. tarraydef(x86_m128type).elementdef:=s32floattype;
  401. tarraydef(x86_m128dtype).elementdef:=s64floattype;
  402. tarraydef(x86_m128itype).elementdef:=s32floattype;
  403. tarraydef(x86_m256type).elementdef:=s32floattype;
  404. tarraydef(x86_m256dtype).elementdef:=s64floattype;
  405. tarraydef(x86_m256itype).elementdef:=s32floattype;
  406. {$endif x86}
  407. set_default_ptr_types;
  408. openchararraytype:=carraydef.create_openarray;
  409. tarraydef(openchararraytype).elementdef:=cansichartype;
  410. cfiletype:=cfiledef.createuntyped;
  411. if f_variants in features then
  412. begin
  413. cvarianttype:=cvariantdef.create(vt_normalvariant);
  414. colevarianttype:=cvariantdef.create(vt_olevariant);
  415. end;
  416. {$ifdef cpufpemu}
  417. { Normal types }
  418. (* we use the same types as without emulator, the only
  419. difference is that direct calls to the emulator are generated
  420. if (cs_fp_emulation in current_settings.moduleswitches) then
  421. begin
  422. addtype('Single',s32floattype);
  423. { extended size is the best real type for the target }
  424. addtype('Real',s32floattype);
  425. pbestrealtype:=@s32floattype;
  426. { extended size is the best real type for the target }
  427. addtype('Extended',pbestrealtype^);
  428. end
  429. else
  430. *)
  431. {$endif cpufpemu}
  432. if init_settings.fputype<>fpu_none then
  433. begin
  434. addtype('Single',s32floattype);
  435. addtype('Double',s64floattype);
  436. { extended size is the best real type for the target }
  437. addtype('Extended',pbestrealtype^);
  438. { CExtended corresponds to the C version of the Extended type
  439. (either "long double" or "double") }
  440. if target_info.system in systems_android then
  441. { Android has "long double"="double" even for x86 }
  442. addtype('CExtended',s64floattype)
  443. else
  444. if tfloatdef(pbestrealtype^).floattype=s80real then
  445. addtype('CExtended',sc80floattype)
  446. else
  447. addtype('CExtended',pbestrealtype^);
  448. end;
  449. {$ifdef x86}
  450. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  451. if target_info.system<>system_x86_64_win64 then
  452. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  453. addtype('Comp',cfloatdef.create(s64comp,true));
  454. {$endif x86}
  455. addtype('Currency',s64currencytype);
  456. addtype('Pointer',voidpointertype);
  457. {$ifdef x86}
  458. addtype('NearPointer',voidnearpointertype);
  459. addtype('NearCsPointer',voidnearcspointertype);
  460. addtype('NearDsPointer',voidneardspointertype);
  461. addtype('NearSsPointer',voidnearsspointertype);
  462. addtype('NearEsPointer',voidnearespointertype);
  463. addtype('NearFsPointer',voidnearfspointertype);
  464. addtype('NearGsPointer',voidneargspointertype);
  465. {$ifdef i8086}
  466. addtype('FarPointer',voidfarpointertype);
  467. addtype('HugePointer',voidhugepointertype);
  468. {$endif i8086}
  469. addtype('__m64',x86_m64type);
  470. addtype('__m128', x86_m128type);
  471. addtype('__m128d',x86_m128dtype);
  472. addtype('__m128i',x86_m128itype);
  473. addtype('__m256', x86_m256type);
  474. addtype('__m256d',x86_m256dtype);
  475. addtype('__m256i',x86_m256itype);
  476. {$endif x86}
  477. addtype('ShortString',cshortstringtype);
  478. {$ifdef support_longstring}
  479. addtype('LongString',clongstringtype);
  480. {$endif support_longstring}
  481. addtype('AnsiString',cansistringtype);
  482. addtype('WideString',cwidestringtype);
  483. addtype('UnicodeString',cunicodestringtype);
  484. addtype('OpenString',openshortstringtype);
  485. addtype('Boolean',pasbool1type);
  486. addtype('Boolean8',pasbool8type);
  487. addtype('Boolean16',pasbool16type);
  488. addtype('Boolean32',pasbool32type);
  489. addtype('Boolean64',pasbool64type);
  490. addtype('ByteBool',bool8type);
  491. addtype('WordBool',bool16type);
  492. addtype('LongBool',bool32type);
  493. addtype('QWordBool',bool64type);
  494. {$ifdef llvm}
  495. addtype('LLVMBool1',llvmbool1type);
  496. {$endif llvm}
  497. addtype('Byte',u8inttype);
  498. addtype('ShortInt',s8inttype);
  499. addtype('Word',u16inttype);
  500. addtype('SmallInt',s16inttype);
  501. addtype('LongWord',u32inttype);
  502. addtype('LongInt',s32inttype);
  503. addtype('QWord',u64inttype);
  504. addtype('Int64',s64inttype);
  505. addtype('Char',cansichartype);
  506. addtype('WideChar',cwidechartype);
  507. addtype('Text',cfiledef.createtext);
  508. addtype('TypedFile',cfiledef.createtyped(voidtype));
  509. if f_variants in features then
  510. begin
  511. addtype('Variant',cvarianttype);
  512. addtype('OleVariant',colevarianttype);
  513. end;
  514. { Internal types }
  515. addtype('$undefined',cundefinedtype);
  516. addtype('$formal',cformaltype);
  517. addtype('$typedformal',ctypedformaltype);
  518. addtype('$void',voidtype);
  519. addtype('$void_pointer',voidpointertype);
  520. addtype('$byte',u8inttype);
  521. addtype('$shortint',s8inttype);
  522. addtype('$word',u16inttype);
  523. addtype('$smallint',s16inttype);
  524. addtype('$sint24',s24inttype);
  525. addtype('$uint24',u24inttype);
  526. addtype('$ulong',u32inttype);
  527. addtype('$longint',s32inttype);
  528. addtype('$sint40',s40inttype);
  529. addtype('$uint40',u40inttype);
  530. addtype('$sint48',s48inttype);
  531. addtype('$uint48',u48inttype);
  532. addtype('$sint56',s56inttype);
  533. addtype('$uint56',u56inttype);
  534. addtype('$qword',u64inttype);
  535. addtype('$int64',s64inttype);
  536. addtype('$uint128',u128inttype);
  537. addtype('$int128',s128inttype);
  538. addtype('$char',cansichartype);
  539. addtype('$widechar',cwidechartype);
  540. addtype('$shortstring',cshortstringtype);
  541. addtype('$longstring',clongstringtype);
  542. addtype('$ansistring',cansistringtype);
  543. addtype('$widestring',cwidestringtype);
  544. addtype('$unicodestring',cunicodestringtype);
  545. addtype('$openshortstring',openshortstringtype);
  546. addtype('$boolean',pasbool1type);
  547. addtype('$boolean8',pasbool8type);
  548. addtype('$boolean16',pasbool16type);
  549. addtype('$boolean32',pasbool32type);
  550. addtype('$boolean64',pasbool64type);
  551. addtype('$bytebool',bool8type);
  552. addtype('$wordbool',bool16type);
  553. addtype('$longbool',bool32type);
  554. addtype('$qwordbool',bool64type);
  555. {$ifdef llvm}
  556. addtype('$llvmbool1',llvmbool1type);
  557. llvm_metadatatype:=cpointerdef.create(voidtype);
  558. { if this gets renamed, also adjust agllvm so it still writes the identifier of this type as "metadata" }
  559. addtype('$metadata',llvm_metadatatype);
  560. addtype('LLVMMetadata',llvm_metadatatype);
  561. {$endif llvm}
  562. addtype('$char_pointer',charpointertype);
  563. addtype('$widechar_pointer',widecharpointertype);
  564. addtype('$parentfp_void_pointer',parentfpvoidpointertype);
  565. {$ifdef x86}
  566. addtype('$void_nearpointer',voidnearpointertype);
  567. addtype('$void_nearcspointer',voidnearcspointertype);
  568. addtype('$void_neardspointer',voidneardspointertype);
  569. addtype('$void_nearsspointer',voidnearsspointertype);
  570. addtype('$void_nearespointer',voidnearespointertype);
  571. addtype('$void_nearfspointer',voidnearfspointertype);
  572. addtype('$void_neargspointer',voidneargspointertype);
  573. {$ifdef i8086}
  574. addtype('$void_farpointer',voidfarpointertype);
  575. addtype('$void_hugepointer',voidhugepointertype);
  576. addtype('$char_nearpointer',charnearpointertype);
  577. addtype('$char_farpointer',charfarpointertype);
  578. addtype('$char_hugepointer',charhugepointertype);
  579. addtype('$byte_farpointer',bytefarpointertype);
  580. addtype('$word_farpointer',wordfarpointertype);
  581. addtype('$longint_farpointer',longintfarpointertype);
  582. {$endif i8086}
  583. addtype('$__m64', x86_m64type);
  584. addtype('$__m128', x86_m128type);
  585. addtype('$__m128d',x86_m128dtype);
  586. addtype('$__m128i',x86_m128itype);
  587. addtype('$__m256', x86_m256type);
  588. addtype('$__m256d',x86_m256dtype);
  589. addtype('$__m256i',x86_m256itype);
  590. {$endif x86}
  591. addtype('$openchararray',openchararraytype);
  592. addtype('$file',cfiletype);
  593. if f_variants in features then
  594. begin
  595. addtype('$variant',cvarianttype);
  596. addtype('$olevariant',colevarianttype);
  597. end;
  598. if init_settings.fputype<>fpu_none then
  599. begin
  600. addtype('$s32real',s32floattype);
  601. addtype('$s64real',s64floattype);
  602. addtype('$s80real',s80floattype);
  603. addtype('$sc80real',sc80floattype);
  604. end;
  605. addtype('$s64currency',s64currencytype);
  606. if not(target_info.system in systems_managed_vm) then
  607. begin
  608. { Add a type for virtual method tables }
  609. hrecst:=trecordsymtable.create('',current_settings.packrecords,current_settings.alignment.recordalignmin);
  610. vmttype:=crecorddef.create('',hrecst);
  611. pvmttype:=cpointerdef.create(vmttype);
  612. { can't use addtype for pvmt because the rtti of the pointed
  613. type is not available. The rtti for pvmt will be written implicitly
  614. by thev tblarray below }
  615. systemunit.insert(ctypesym.create('$pvmt',pvmttype));
  616. addfield(hrecst,cfieldvarsym.create('$length',vs_value,sizesinttype,[]));
  617. addfield(hrecst,cfieldvarsym.create('$mlength',vs_value,sizesinttype,[]));
  618. addfield(hrecst,cfieldvarsym.create('$parent',vs_value,pvmttype,[]));
  619. { it seems vmttype is used both for TP objects and Delphi classes,
  620. so the next entry could either be the first virtual method (vm1)
  621. (object) or the class name (class). We can't easily create separate
  622. vtable formats for both, as gdb is hard coded to search for
  623. __vtbl_ptr_type in all cases (JM) }
  624. addfield(hrecst,cfieldvarsym.create('$vm1_or_classname',vs_value,cpointerdef.create(cshortstringtype),[]));
  625. vmtarraytype:=carraydef.create(0,0,s32inttype);
  626. tarraydef(vmtarraytype).elementdef:=voidpointertype;
  627. addfield(hrecst,cfieldvarsym.create('$__pfn',vs_value,vmtarraytype,[]));
  628. addtype('$__vtbl_ptr_type',vmttype);
  629. vmtarraytype:=carraydef.create(0,1,s32inttype);
  630. tarraydef(vmtarraytype).elementdef:=pvmttype;
  631. addtype('$vtblarray',vmtarraytype);
  632. end;
  633. { Add a type for methodpointers }
  634. hrecst:=trecordsymtable.create('',1,current_settings.alignment.recordalignmin);
  635. addfield(hrecst,cfieldvarsym.create('$proc',vs_value,voidcodepointertype,[]));
  636. addfield(hrecst,cfieldvarsym.create('$self',vs_value,voidpointertype,[]));
  637. methodpointertype:=crecorddef.create('',hrecst);
  638. addtype('$methodpointer',methodpointertype);
  639. { Add a type for nested proc pointers }
  640. hrecst:=trecordsymtable.create('',1,current_settings.alignment.recordalignmin);
  641. addfield(hrecst,cfieldvarsym.create('$proc',vs_value,voidcodepointertype,[]));
  642. addfield(hrecst,cfieldvarsym.create('$parentfp',vs_value,parentfpvoidpointertype,[]));
  643. nestedprocpointertype:=crecorddef.create('',hrecst);
  644. addtype('$nestedprocpointer',nestedprocpointertype);
  645. symtablestack.pop(systemunit);
  646. end;
  647. procedure load_intern_types;
  648. {
  649. Load all default definitions for consts from the system unit
  650. }
  651. procedure loadtype(const s:string;var def:tdef);
  652. var
  653. srsym : ttypesym;
  654. begin
  655. srsym:=search_system_type(s);
  656. def:=srsym.typedef;
  657. end;
  658. var
  659. oldcurrentmodule : tmodule;
  660. begin
  661. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  662. if target_info.system=system_x86_64_win64 then
  663. pbestrealtype:=@s64floattype;
  664. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  665. oldcurrentmodule:=current_module;
  666. set_current_module(nil);
  667. loadtype('byte',u8inttype);
  668. loadtype('shortint',s8inttype);
  669. loadtype('word',u16inttype);
  670. loadtype('smallint',s16inttype);
  671. loadtype('uint24',u24inttype);
  672. loadtype('sint24',s24inttype);
  673. loadtype('ulong',u32inttype);
  674. loadtype('longint',s32inttype);
  675. loadtype('uint40',u40inttype);
  676. loadtype('sint40',s40inttype);
  677. loadtype('uint48',u48inttype);
  678. loadtype('sint48',s48inttype);
  679. loadtype('uint56',u56inttype);
  680. loadtype('sint56',s56inttype);
  681. loadtype('qword',u64inttype);
  682. loadtype('int64',s64inttype);
  683. loadtype('uint128',u128inttype);
  684. loadtype('int128',s128inttype);
  685. loadtype('undefined',cundefinedtype);
  686. loadtype('formal',cformaltype);
  687. loadtype('typedformal',ctypedformaltype);
  688. loadtype('void',voidtype);
  689. loadtype('void_pointer',voidpointertype);
  690. loadtype('char',cansichartype);
  691. loadtype('widechar',cwidechartype);
  692. loadtype('shortstring',cshortstringtype);
  693. loadtype('longstring',clongstringtype);
  694. loadtype('ansistring',cansistringtype);
  695. loadtype('widestring',cwidestringtype);
  696. loadtype('unicodestring',cunicodestringtype);
  697. loadtype('openshortstring',openshortstringtype);
  698. loadtype('openchararray',openchararraytype);
  699. if init_settings.fputype <> fpu_none then
  700. begin
  701. loadtype('s32real',s32floattype);
  702. loadtype('s64real',s64floattype);
  703. loadtype('s80real',s80floattype);
  704. loadtype('sc80real',sc80floattype);
  705. end;
  706. loadtype('s64currency',s64currencytype);
  707. loadtype('boolean',pasbool1type);
  708. loadtype('boolean8',pasbool8type);
  709. loadtype('boolean16',pasbool16type);
  710. loadtype('boolean32',pasbool32type);
  711. loadtype('boolean64',pasbool64type);
  712. loadtype('bytebool',bool8type);
  713. loadtype('wordbool',bool16type);
  714. loadtype('longbool',bool32type);
  715. loadtype('qwordbool',bool64type);
  716. loadtype('char_pointer',charpointertype);
  717. loadtype('widechar_pointer',widecharpointertype);
  718. loadtype('parentfp_void_pointer',parentfpvoidpointertype);
  719. {$ifdef x86}
  720. loadtype('void_nearpointer',voidnearpointertype);
  721. loadtype('void_nearcspointer',voidnearcspointertype);
  722. loadtype('void_neardspointer',voidneardspointertype);
  723. loadtype('void_nearsspointer',voidnearsspointertype);
  724. loadtype('void_nearespointer',voidnearespointertype);
  725. loadtype('void_nearfspointer',voidnearfspointertype);
  726. loadtype('void_neargspointer',voidneargspointertype);
  727. {$ifdef i8086}
  728. loadtype('void_farpointer',voidfarpointertype);
  729. loadtype('void_hugepointer',voidhugepointertype);
  730. loadtype('char_nearpointer',charnearpointertype);
  731. loadtype('char_farpointer',charfarpointertype);
  732. loadtype('char_hugepointer',charhugepointertype);
  733. loadtype('byte_farpointer',bytefarpointertype);
  734. loadtype('word_farpointer',wordfarpointertype);
  735. loadtype('longint_farpointer',longintfarpointertype);
  736. {$endif i8086}
  737. loadtype('__m64', x86_m64type);
  738. loadtype('__m128', x86_m128type);
  739. loadtype('__m128d',x86_m128dtype);
  740. loadtype('__m128i',x86_m128itype);
  741. loadtype('__m256', x86_m256type);
  742. loadtype('__m256d',x86_m256dtype);
  743. loadtype('__m256i',x86_m256itype);
  744. {$endif x86}
  745. {$ifdef llvm}
  746. loadtype('llvmbool1',llvmbool1type);
  747. loadtype('metadata',llvm_metadatatype);
  748. {$endif llvm}
  749. loadtype('file',cfiletype);
  750. if not(target_info.system in systems_managed_vm) then
  751. begin
  752. loadtype('pvmt',pvmttype);
  753. loadtype('vtblarray',vmtarraytype);
  754. loadtype('__vtbl_ptr_type',vmttype);
  755. end;
  756. if f_variants in features then
  757. begin
  758. loadtype('variant',cvarianttype);
  759. loadtype('olevariant',colevarianttype);
  760. end;
  761. loadtype('methodpointer',methodpointertype);
  762. loadtype('nestedprocpointer',nestedprocpointertype);
  763. loadtype('HRESULT',hresultdef);
  764. loadtype('TTYPEKIND',typekindtype);
  765. set_default_int_types;
  766. set_default_ptr_types;
  767. set_current_module(oldcurrentmodule);
  768. end;
  769. procedure registernodes;
  770. {
  771. Register all possible nodes in the nodeclass array that
  772. will be used for loading the nodes from a ppu
  773. }
  774. begin
  775. nodeclass[addn]:=caddnode;
  776. nodeclass[muln]:=caddnode;
  777. nodeclass[subn]:=caddnode;
  778. nodeclass[divn]:=cmoddivnode;
  779. nodeclass[symdifn]:=caddnode;
  780. nodeclass[modn]:=cmoddivnode;
  781. nodeclass[assignn]:=cassignmentnode;
  782. nodeclass[loadn]:=cloadnode;
  783. nodeclass[rangen]:=crangenode;
  784. nodeclass[ltn]:=caddnode;
  785. nodeclass[lten]:=caddnode;
  786. nodeclass[gtn]:=caddnode;
  787. nodeclass[gten]:=caddnode;
  788. nodeclass[equaln]:=caddnode;
  789. nodeclass[unequaln]:=caddnode;
  790. nodeclass[inn]:=cinnode;
  791. nodeclass[orn]:=caddnode;
  792. nodeclass[xorn]:=caddnode;
  793. nodeclass[shrn]:=cshlshrnode;
  794. nodeclass[shln]:=cshlshrnode;
  795. nodeclass[slashn]:=caddnode;
  796. nodeclass[andn]:=caddnode;
  797. nodeclass[subscriptn]:=csubscriptnode;
  798. nodeclass[derefn]:=cderefnode;
  799. nodeclass[addrn]:=caddrnode;
  800. nodeclass[ordconstn]:=cordconstnode;
  801. nodeclass[typeconvn]:=ctypeconvnode;
  802. nodeclass[calln]:=ccallnode;
  803. nodeclass[callparan]:=ccallparanode;
  804. nodeclass[realconstn]:=crealconstnode;
  805. nodeclass[unaryminusn]:=cunaryminusnode;
  806. nodeclass[unaryplusn]:=cunaryplusnode;
  807. nodeclass[asmn]:=casmnode;
  808. nodeclass[vecn]:=cvecnode;
  809. nodeclass[pointerconstn]:=cpointerconstnode;
  810. nodeclass[stringconstn]:=cstringconstnode;
  811. nodeclass[notn]:=cnotnode;
  812. nodeclass[inlinen]:=cinlinenode;
  813. nodeclass[niln]:=cnilnode;
  814. nodeclass[errorn]:=cerrornode;
  815. nodeclass[typen]:=ctypenode;
  816. nodeclass[setelementn]:=csetelementnode;
  817. nodeclass[setconstn]:=csetconstnode;
  818. nodeclass[blockn]:=cblocknode;
  819. nodeclass[statementn]:=cstatementnode;
  820. nodeclass[ifn]:=cifnode;
  821. nodeclass[breakn]:=cbreaknode;
  822. nodeclass[continuen]:=ccontinuenode;
  823. nodeclass[whilerepeatn]:=cwhilerepeatnode;
  824. nodeclass[forn]:=cfornode;
  825. nodeclass[exitn]:=cexitnode;
  826. nodeclass[casen]:=ccasenode;
  827. nodeclass[labeln]:=clabelnode;
  828. nodeclass[goton]:=cgotonode;
  829. nodeclass[tryexceptn]:=ctryexceptnode;
  830. nodeclass[raisen]:=craisenode;
  831. nodeclass[tryfinallyn]:=ctryfinallynode;
  832. nodeclass[onn]:=connode;
  833. nodeclass[isn]:=cisnode;
  834. nodeclass[asn]:=casnode;
  835. nodeclass[starstarn]:=caddnode;
  836. nodeclass[arrayconstructorn]:=carrayconstructornode;
  837. nodeclass[arrayconstructorrangen]:=carrayconstructorrangenode;
  838. nodeclass[tempcreaten]:=ctempcreatenode;
  839. nodeclass[temprefn]:=ctemprefnode;
  840. nodeclass[tempdeleten]:=ctempdeletenode;
  841. nodeclass[addoptn]:=caddnode;
  842. nodeclass[nothingn]:=cnothingnode;
  843. nodeclass[loadvmtaddrn]:=cloadvmtaddrnode;
  844. nodeclass[guidconstn]:=cguidconstnode;
  845. nodeclass[rttin]:=crttinode;
  846. nodeclass[loadparentfpn]:=cloadparentfpnode;
  847. end;
  848. procedure registertais;
  849. {
  850. Register all possible tais in the taiclass array that
  851. will be used for loading the tais from a ppu
  852. }
  853. begin
  854. aiclass[ait_none]:=nil;
  855. aiclass[ait_align]:=tai_align;
  856. aiclass[ait_section]:=tai_section;
  857. aiclass[ait_comment]:=tai_comment;
  858. aiclass[ait_string]:=tai_string;
  859. aiclass[ait_instruction]:=taicpu;
  860. aiclass[ait_datablock]:=tai_datablock;
  861. aiclass[ait_symbol]:=tai_symbol;
  862. aiclass[ait_symbol_end]:=tai_symbol_end;
  863. aiclass[ait_directive]:=tai_directive;
  864. aiclass[ait_label]:=tai_label;
  865. aiclass[ait_const]:=tai_const;
  866. aiclass[ait_realconst]:=tai_realconst;
  867. aiclass[ait_stab]:=tai_stab;
  868. aiclass[ait_force_line]:=tai_force_line;
  869. aiclass[ait_function_name]:=tai_function_name;
  870. aiclass[ait_symbolpair]:=tai_symbolpair;
  871. aiclass[ait_cutobject]:=tai_cutobject;
  872. aiclass[ait_regalloc]:=tai_regalloc;
  873. aiclass[ait_tempalloc]:=tai_tempalloc;
  874. aiclass[ait_marker]:=tai_marker;
  875. aiclass[ait_seh_directive]:=tai_seh_directive;
  876. {$ifdef JVM}
  877. aiclass[ait_jvar]:=tai_jvar;
  878. aiclass[ait_jcatch]:=tai_jcatch;
  879. {$endif JVM}
  880. end;
  881. end.