psystem.pas 37 KB

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