psystem.pas 38 KB

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