psystem.pas 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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,
  30. systems,
  31. symconst,symtype,symsym,symdef,symcpu,symtable,
  32. aasmtai,aasmdata,aasmcpu,
  33. ncgutil,ncgrtti,fmodule,
  34. node,nbas,nflw,nset,ncon,ncnv,nld,nmem,ncal,nmat,nadd,ninl,nopt
  35. ;
  36. procedure create_intern_symbols;
  37. {
  38. all intern procedures for the system unit
  39. }
  40. begin
  41. systemunit.insert(csyssym.create('Concat',in_concat_x));
  42. systemunit.insert(csyssym.create('Write',in_write_x));
  43. systemunit.insert(csyssym.create('WriteLn',in_writeln_x));
  44. systemunit.insert(csyssym.create('WriteStr',in_writestr_x));
  45. systemunit.insert(csyssym.create('Assigned',in_assigned_x));
  46. systemunit.insert(csyssym.create('Read',in_read_x));
  47. systemunit.insert(csyssym.create('ReadLn',in_readln_x));
  48. systemunit.insert(csyssym.create('ReadStr',in_readstr_x));
  49. systemunit.insert(csyssym.create('Ofs',in_ofs_x));
  50. systemunit.insert(csyssym.create('SizeOf',in_sizeof_x));
  51. systemunit.insert(csyssym.create('BitSizeOf',in_bitsizeof_x));
  52. systemunit.insert(csyssym.create('TypeOf',in_typeof_x));
  53. systemunit.insert(csyssym.create('Low',in_low_x));
  54. systemunit.insert(csyssym.create('High',in_high_x));
  55. systemunit.insert(csyssym.create('Slice',in_slice_x));
  56. systemunit.insert(csyssym.create('Seg',in_seg_x));
  57. systemunit.insert(csyssym.create('Ord',in_ord_x));
  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. systemunit.insert(csyssym.create('TypeInfo',in_typeinfo_x));
  76. systemunit.insert(csyssym.create('SetLength',in_setlength_x));
  77. systemunit.insert(csyssym.create('Copy',in_copy_x));
  78. systemunit.insert(csyssym.create('Initialize',in_initialize_x));
  79. systemunit.insert(csyssym.create('Finalize',in_finalize_x));
  80. systemunit.insert(csyssym.create('Length',in_length_x));
  81. systemunit.insert(csyssym.create('New',in_new_x));
  82. systemunit.insert(csyssym.create('Dispose',in_dispose_x));
  83. {$ifdef SUPPORT_GET_FRAME}
  84. systemunit.insert(csyssym.create('Get_Frame',in_get_frame));
  85. {$endif SUPPORT_GET_FRAME}
  86. systemunit.insert(csyssym.create('Unaligned',in_unaligned_x));
  87. systemunit.insert(csyssym.create('Aligned',in_aligned_x));
  88. systemunit.insert(csyssym.create('ObjCSelector',in_objc_selector_x)); { objc only }
  89. systemunit.insert(csyssym.create('ObjCEncode',in_objc_encode_x)); { objc only }
  90. systemunit.insert(csyssym.create('Default',in_default_x));
  91. systemunit.insert(csyssym.create('SetString',in_setstring_x_y_z));
  92. systemunit.insert(cconstsym.create_ord('False',constord,0,pasbool8type));
  93. systemunit.insert(cconstsym.create_ord('True',constord,1,pasbool8type));
  94. end;
  95. procedure set_default_int_types;
  96. begin
  97. {$ifdef cpu64bitaddr}
  98. uinttype:=u64inttype;
  99. sinttype:=s64inttype;
  100. ptruinttype:=u64inttype;
  101. ptrsinttype:=s64inttype;
  102. {$endif cpu64bitaddr}
  103. {$ifdef cpu32bitaddr}
  104. uinttype:=u32inttype;
  105. sinttype:=s32inttype;
  106. ptruinttype:=u32inttype;
  107. ptrsinttype:=s32inttype;
  108. {$endif cpu32bitaddr}
  109. {$ifdef cpu32bitalu}
  110. uinttype:=u32inttype;
  111. sinttype:=s32inttype;
  112. {$endif cpu32bitalu}
  113. {$ifdef cpu16bitaddr}
  114. ptruinttype:=u16inttype;
  115. ptrsinttype:=s16inttype;
  116. {$endif cpu16bitaddr}
  117. {$ifdef cpu16bitalu}
  118. uinttype:=u16inttype;
  119. sinttype:=s16inttype;
  120. {$endif cpu16bitalu}
  121. {$ifdef cpu8bitalu}
  122. uinttype:=u8inttype;
  123. sinttype:=s8inttype;
  124. {$endif cpu8bitalu}
  125. {$ifndef avr}
  126. osuinttype:=uinttype;
  127. ossinttype:=sinttype;
  128. {$else avr}
  129. osuinttype:=u16inttype;
  130. ossinttype:=s16inttype;
  131. {$endif avr}
  132. end;
  133. procedure set_default_ptr_types;
  134. begin
  135. {$ifdef i8086}
  136. if current_settings.x86memorymodel in x86_far_code_models then
  137. voidcodepointertype:=voidfarpointertype
  138. else
  139. voidcodepointertype:=voidnearpointertype;
  140. voidstackpointertype:=voidnearsspointertype;
  141. {$else i8086}
  142. voidcodepointertype:=voidpointertype;
  143. voidstackpointertype:=voidpointertype;
  144. {$endif i8086}
  145. end;
  146. procedure create_intern_types;
  147. {
  148. all the types inserted into the system unit
  149. }
  150. function addtype(const s:string;def:tdef):ttypesym;
  151. begin
  152. result:=ctypesym.create(s,def);
  153. systemunit.insert(result);
  154. end;
  155. procedure addfield(recst:tabstractrecordsymtable;sym:tfieldvarsym);
  156. begin
  157. recst.insert(sym);
  158. recst.addfield(sym,vis_hidden);
  159. end;
  160. procedure create_fpu_types;
  161. begin
  162. if init_settings.fputype<>fpu_none then
  163. begin
  164. s32floattype:=cfloatdef.create(s32real);
  165. s64floattype:=cfloatdef.create(s64real);
  166. s80floattype:=cfloatdef.create(s80real);
  167. sc80floattype:=cfloatdef.create(sc80real);
  168. end else begin
  169. s32floattype:=nil;
  170. s64floattype:=nil;
  171. s80floattype:=nil;
  172. sc80floattype:=nil;
  173. end;
  174. end;
  175. var
  176. hrecst : trecordsymtable;
  177. begin
  178. symtablestack.push(systemunit);
  179. cundefinedtype:=cundefineddef.create;
  180. cformaltype:=cformaldef.create(false);
  181. ctypedformaltype:=cformaldef.create(true);
  182. voidtype:=corddef.create(uvoid,0,0);
  183. voidpointertype:=cpointerdef.create(voidtype);
  184. u8inttype:=corddef.create(u8bit,0,255);
  185. s8inttype:=corddef.create(s8bit,int64(-128),127);
  186. u16inttype:=corddef.create(u16bit,0,65535);
  187. s16inttype:=corddef.create(s16bit,int64(-32768),32767);
  188. u32inttype:=corddef.create(u32bit,0,high(longword));
  189. s32inttype:=corddef.create(s32bit,int64(low(longint)),int64(high(longint)));
  190. u64inttype:=corddef.create(u64bit,low(qword),high(qword));
  191. s64inttype:=corddef.create(s64bit,low(int64),high(int64));
  192. pasbool8type:=corddef.create(pasbool8,0,1);
  193. pasbool16type:=corddef.create(pasbool16,0,1);
  194. pasbool32type:=corddef.create(pasbool32,0,1);
  195. pasbool64type:=corddef.create(pasbool64,0,1);
  196. bool8type:=corddef.create(bool8bit,low(int64),high(int64));
  197. bool16type:=corddef.create(bool16bit,low(int64),high(int64));
  198. bool32type:=corddef.create(bool32bit,low(int64),high(int64));
  199. bool64type:=corddef.create(bool64bit,low(int64),high(int64));
  200. cansichartype:=corddef.create(uchar,0,255);
  201. cwidechartype:=corddef.create(uwidechar,0,65535);
  202. cshortstringtype:=cstringdef.createshort(255);
  203. { should we give a length to the default long and ansi string definition ?? }
  204. clongstringtype:=cstringdef.createlong(-1);
  205. cansistringtype:=cstringdef.createansi(0);
  206. if target_info.system in systems_windows then
  207. cwidestringtype:=cstringdef.createwide
  208. else
  209. cwidestringtype:=cstringdef.createunicode;
  210. cunicodestringtype:=cstringdef.createunicode;
  211. { length=0 for shortstring is open string (needed for readln(string) }
  212. openshortstringtype:=cstringdef.createshort(0);
  213. {$ifdef x86}
  214. create_fpu_types;
  215. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  216. if target_info.system=system_x86_64_win64 then
  217. begin
  218. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  219. pbestrealtype:=@s64floattype;
  220. end
  221. else
  222. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  223. s64currencytype:=cfloatdef.create(s64currency);
  224. {$endif x86}
  225. {$ifdef powerpc}
  226. create_fpu_types;
  227. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  228. {$endif powerpc}
  229. {$ifdef POWERPC64}
  230. create_fpu_types;
  231. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  232. {$endif POWERPC64}
  233. {$ifdef sparc}
  234. create_fpu_types;
  235. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  236. {$endif sparc}
  237. {$ifdef m68k}
  238. create_fpu_types;
  239. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  240. {$endif}
  241. {$ifdef arm}
  242. create_fpu_types;
  243. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  244. {$endif arm}
  245. {$ifdef aarch64}
  246. create_fpu_types;
  247. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  248. {$endif aarch64}
  249. {$ifdef avr}
  250. s32floattype:=cfloatdef.create(s32real);
  251. s64floattype:=cfloatdef.create(s64real);
  252. s80floattype:=cfloatdef.create(s80real);
  253. sc80floattype:=cfloatdef.create(sc80real);
  254. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  255. {$endif avr}
  256. {$ifdef mips}
  257. create_fpu_types;
  258. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  259. {$endif mips}
  260. {$ifdef jvm}
  261. create_fpu_types;
  262. s64currencytype:=corddef.create(scurrency,low(int64),high(int64));
  263. {$endif jvm}
  264. set_default_int_types;
  265. { some other definitions }
  266. openchararraytype:=carraydef.create(0,-1,ptrsinttype);
  267. tarraydef(openchararraytype).elementdef:=cansichartype;
  268. charpointertype:=cpointerdef.create(cansichartype);
  269. widecharpointertype:=cpointerdef.create(cwidechartype);
  270. {$ifdef i8086}
  271. parentfpvoidpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ss);
  272. {$else i8086}
  273. parentfpvoidpointertype:=cpointerdef.create(voidtype);
  274. {$endif i8086}
  275. {$ifdef x86}
  276. voidnearpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near);
  277. voidnearcspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_cs);
  278. voidneardspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ds);
  279. voidnearsspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_ss);
  280. voidnearespointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_es);
  281. voidnearfspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_fs);
  282. voidneargspointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_near_gs);
  283. {$ifdef i8086}
  284. voidfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_far);
  285. voidhugepointertype:=tcpupointerdefclass(cpointerdef).createx86(voidtype,x86pt_huge);
  286. charnearpointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_near);
  287. charfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_far);
  288. charhugepointertype:=tcpupointerdefclass(cpointerdef).createx86(cansichartype,x86pt_huge);
  289. bytefarpointertype:=tcpupointerdefclass(cpointerdef).createx86(u8inttype,x86pt_far);
  290. wordfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(u16inttype,x86pt_far);
  291. longintfarpointertype:=tcpupointerdefclass(cpointerdef).createx86(s32inttype,x86pt_far);
  292. {$endif i8086}
  293. x86_m64type:=carraydef.create(0,1,s32inttype);
  294. x86_m128type:=carraydef.create(0,3,s32inttype);
  295. x86_m128dtype:=carraydef.create(0,1,s32inttype);
  296. x86_m128itype:=carraydef.create(0,3,s32inttype);
  297. x86_m256type:=carraydef.create(0,7,s32inttype);
  298. x86_m256dtype:=carraydef.create(0,3,s32inttype);
  299. x86_m256itype:=carraydef.create(0,7,s32inttype);
  300. tarraydef(x86_m64type).elementdef:=s32floattype;
  301. tarraydef(x86_m128type).elementdef:=s32floattype;
  302. tarraydef(x86_m128dtype).elementdef:=s64floattype;
  303. tarraydef(x86_m128itype).elementdef:=s32floattype;
  304. tarraydef(x86_m256type).elementdef:=s32floattype;
  305. tarraydef(x86_m256dtype).elementdef:=s64floattype;
  306. tarraydef(x86_m256itype).elementdef:=s32floattype;
  307. {$endif x86}
  308. set_default_ptr_types;
  309. cfiletype:=cfiledef.createuntyped;
  310. cvarianttype:=cvariantdef.create(vt_normalvariant);
  311. colevarianttype:=cvariantdef.create(vt_olevariant);
  312. {$ifdef cpufpemu}
  313. { Normal types }
  314. (* we use the same types as without emulator, the only
  315. difference is that direct calls to the emulator are generated
  316. if (cs_fp_emulation in current_settings.moduleswitches) then
  317. begin
  318. addtype('Single',s32floattype);
  319. { extended size is the best real type for the target }
  320. addtype('Real',s32floattype);
  321. pbestrealtype:=@s32floattype;
  322. { extended size is the best real type for the target }
  323. addtype('Extended',pbestrealtype^);
  324. end
  325. else
  326. *)
  327. {$endif cpufpemu}
  328. if init_settings.fputype <> fpu_none then
  329. begin
  330. addtype('Single',s32floattype);
  331. addtype('Double',s64floattype);
  332. { extended size is the best real type for the target }
  333. addtype('Extended',pbestrealtype^);
  334. { CExtended corresponds to the C version of the Extended type
  335. (either "long double" or "double") }
  336. if target_info.system in systems_android then
  337. { Android has "long double"="double" even for x86 }
  338. addtype('CExtended',s64floattype)
  339. else
  340. if tfloatdef(pbestrealtype^).floattype=s80real then
  341. addtype('CExtended',sc80floattype)
  342. else
  343. addtype('CExtended',pbestrealtype^);
  344. end;
  345. {$ifdef x86}
  346. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  347. if target_info.system<>system_x86_64_win64 then
  348. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  349. addtype('Comp',cfloatdef.create(s64comp));
  350. {$endif x86}
  351. addtype('Currency',s64currencytype);
  352. addtype('Pointer',voidpointertype);
  353. {$ifdef x86}
  354. addtype('NearPointer',voidnearpointertype);
  355. addtype('NearCsPointer',voidnearcspointertype);
  356. addtype('NearDsPointer',voidneardspointertype);
  357. addtype('NearSsPointer',voidnearsspointertype);
  358. addtype('NearEsPointer',voidnearespointertype);
  359. addtype('NearFsPointer',voidnearfspointertype);
  360. addtype('NearGsPointer',voidneargspointertype);
  361. {$ifdef i8086}
  362. addtype('FarPointer',voidfarpointertype);
  363. addtype('HugePointer',voidhugepointertype);
  364. {$endif i8086}
  365. addtype('__m64',x86_m64type);
  366. addtype('__m128', x86_m128type);
  367. addtype('__m128d',x86_m128dtype);
  368. addtype('__m128i',x86_m128itype);
  369. addtype('__m256', x86_m256type);
  370. addtype('__m256d',x86_m256dtype);
  371. addtype('__m256i',x86_m256itype);
  372. {$endif x86}
  373. addtype('ShortString',cshortstringtype);
  374. {$ifdef support_longstring}
  375. addtype('LongString',clongstringtype);
  376. {$endif support_longstring}
  377. addtype('AnsiString',cansistringtype);
  378. addtype('WideString',cwidestringtype);
  379. addtype('UnicodeString',cunicodestringtype);
  380. addtype('OpenString',openshortstringtype);
  381. addtype('Boolean',pasbool8type);
  382. addtype('Boolean16',pasbool16type);
  383. addtype('Boolean32',pasbool32type);
  384. addtype('Boolean64',pasbool64type);
  385. addtype('ByteBool',bool8type);
  386. addtype('WordBool',bool16type);
  387. addtype('LongBool',bool32type);
  388. addtype('QWordBool',bool64type);
  389. addtype('Byte',u8inttype);
  390. addtype('ShortInt',s8inttype);
  391. addtype('Word',u16inttype);
  392. addtype('SmallInt',s16inttype);
  393. addtype('LongWord',u32inttype);
  394. addtype('LongInt',s32inttype);
  395. addtype('QWord',u64inttype);
  396. addtype('Int64',s64inttype);
  397. addtype('Char',cansichartype);
  398. addtype('WideChar',cwidechartype);
  399. addtype('Text',cfiledef.createtext);
  400. addtype('TypedFile',cfiledef.createtyped(voidtype));
  401. addtype('Variant',cvarianttype);
  402. addtype('OleVariant',colevarianttype);
  403. { Internal types }
  404. addtype('$undefined',cundefinedtype);
  405. addtype('$formal',cformaltype);
  406. addtype('$typedformal',ctypedformaltype);
  407. addtype('$void',voidtype);
  408. addtype('$void_pointer',voidpointertype);
  409. addtype('$byte',u8inttype);
  410. addtype('$shortint',s8inttype);
  411. addtype('$word',u16inttype);
  412. addtype('$smallint',s16inttype);
  413. addtype('$ulong',u32inttype);
  414. addtype('$longint',s32inttype);
  415. addtype('$qword',u64inttype);
  416. addtype('$int64',s64inttype);
  417. addtype('$char',cansichartype);
  418. addtype('$widechar',cwidechartype);
  419. addtype('$shortstring',cshortstringtype);
  420. addtype('$longstring',clongstringtype);
  421. addtype('$ansistring',cansistringtype);
  422. addtype('$widestring',cwidestringtype);
  423. addtype('$unicodestring',cunicodestringtype);
  424. addtype('$openshortstring',openshortstringtype);
  425. addtype('$boolean',pasbool8type);
  426. addtype('$boolean16',pasbool16type);
  427. addtype('$boolean32',pasbool32type);
  428. addtype('$boolean64',pasbool64type);
  429. addtype('$bytebool',bool8type);
  430. addtype('$wordbool',bool16type);
  431. addtype('$longbool',bool32type);
  432. addtype('$qwordbool',bool64type);
  433. addtype('$char_pointer',charpointertype);
  434. addtype('$widechar_pointer',widecharpointertype);
  435. addtype('$parentfp_void_pointer',parentfpvoidpointertype);
  436. {$ifdef x86}
  437. addtype('$void_nearpointer',voidnearpointertype);
  438. addtype('$void_nearcspointer',voidnearcspointertype);
  439. addtype('$void_neardspointer',voidneardspointertype);
  440. addtype('$void_nearsspointer',voidnearsspointertype);
  441. addtype('$void_nearespointer',voidnearespointertype);
  442. addtype('$void_nearfspointer',voidnearfspointertype);
  443. addtype('$void_neargspointer',voidneargspointertype);
  444. {$ifdef i8086}
  445. addtype('$void_farpointer',voidfarpointertype);
  446. addtype('$void_hugepointer',voidhugepointertype);
  447. addtype('$char_nearpointer',charnearpointertype);
  448. addtype('$char_farpointer',charfarpointertype);
  449. addtype('$char_hugepointer',charhugepointertype);
  450. addtype('$byte_farpointer',bytefarpointertype);
  451. addtype('$word_farpointer',wordfarpointertype);
  452. addtype('$longint_farpointer',longintfarpointertype);
  453. {$endif i8086}
  454. addtype('$__m64', x86_m64type);
  455. addtype('$__m128', x86_m128type);
  456. addtype('$__m128d',x86_m128dtype);
  457. addtype('$__m128i',x86_m128itype);
  458. addtype('$__m256', x86_m256type);
  459. addtype('$__m256d',x86_m256dtype);
  460. addtype('$__m256i',x86_m256itype);
  461. {$endif x86}
  462. addtype('$openchararray',openchararraytype);
  463. addtype('$file',cfiletype);
  464. addtype('$variant',cvarianttype);
  465. addtype('$olevariant',colevarianttype);
  466. if init_settings.fputype<>fpu_none then
  467. begin
  468. addtype('$s32real',s32floattype);
  469. addtype('$s64real',s64floattype);
  470. addtype('$s80real',s80floattype);
  471. addtype('$sc80real',sc80floattype);
  472. end;
  473. addtype('$s64currency',s64currencytype);
  474. if not(target_info.system in systems_managed_vm) then
  475. begin
  476. { Add a type for virtual method tables }
  477. hrecst:=trecordsymtable.create('',current_settings.packrecords,current_settings.alignment.recordalignmin,current_settings.alignment.maxCrecordalign);
  478. vmttype:=crecorddef.create('',hrecst);
  479. pvmttype:=cpointerdef.create(vmttype);
  480. { can't use addtype for pvmt because the rtti of the pointed
  481. type is not available. The rtti for pvmt will be written implicitly
  482. by thev tblarray below }
  483. systemunit.insert(ctypesym.create('$pvmt',pvmttype));
  484. addfield(hrecst,cfieldvarsym.create('$length',vs_value,ptrsinttype,[]));
  485. addfield(hrecst,cfieldvarsym.create('$mlength',vs_value,ptrsinttype,[]));
  486. addfield(hrecst,cfieldvarsym.create('$parent',vs_value,pvmttype,[]));
  487. { it seems vmttype is used both for TP objects and Delphi classes,
  488. so the next entry could either be the first virtual method (vm1)
  489. (object) or the class name (class). We can't easily create separate
  490. vtable formats for both, as gdb is hard coded to search for
  491. __vtbl_ptr_type in all cases (JM) }
  492. addfield(hrecst,cfieldvarsym.create('$vm1_or_classname',vs_value,cpointerdef.create(cshortstringtype),[]));
  493. vmtarraytype:=carraydef.create(0,0,s32inttype);
  494. tarraydef(vmtarraytype).elementdef:=voidpointertype;
  495. addfield(hrecst,cfieldvarsym.create('$__pfn',vs_value,vmtarraytype,[]));
  496. addtype('$__vtbl_ptr_type',vmttype);
  497. vmtarraytype:=carraydef.create(0,1,s32inttype);
  498. tarraydef(vmtarraytype).elementdef:=pvmttype;
  499. addtype('$vtblarray',vmtarraytype);
  500. end;
  501. { Add a type for methodpointers }
  502. hrecst:=trecordsymtable.create('',1,current_settings.alignment.recordalignmin,current_settings.alignment.maxCrecordalign);
  503. addfield(hrecst,cfieldvarsym.create('$proc',vs_value,voidcodepointertype,[]));
  504. addfield(hrecst,cfieldvarsym.create('$self',vs_value,voidpointertype,[]));
  505. methodpointertype:=crecorddef.create('',hrecst);
  506. addtype('$methodpointer',methodpointertype);
  507. { Add a type for nested proc pointers }
  508. hrecst:=trecordsymtable.create('',1,current_settings.alignment.recordalignmin,current_settings.alignment.maxCrecordalign);
  509. addfield(hrecst,cfieldvarsym.create('$proc',vs_value,voidcodepointertype,[]));
  510. addfield(hrecst,cfieldvarsym.create('$parentfp',vs_value,parentfpvoidpointertype,[]));
  511. nestedprocpointertype:=crecorddef.create('',hrecst);
  512. addtype('$nestedprocpointer',nestedprocpointertype);
  513. symtablestack.pop(systemunit);
  514. end;
  515. procedure load_intern_types;
  516. {
  517. Load all default definitions for consts from the system unit
  518. }
  519. procedure loadtype(const s:string;var def:tdef);
  520. var
  521. srsym : ttypesym;
  522. begin
  523. srsym:=search_system_type(s);
  524. def:=srsym.typedef;
  525. end;
  526. var
  527. oldcurrentmodule : tmodule;
  528. begin
  529. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  530. if target_info.system=system_x86_64_win64 then
  531. pbestrealtype:=@s64floattype;
  532. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  533. oldcurrentmodule:=current_module;
  534. set_current_module(nil);
  535. loadtype('byte',u8inttype);
  536. loadtype('shortint',s8inttype);
  537. loadtype('word',u16inttype);
  538. loadtype('smallint',s16inttype);
  539. loadtype('ulong',u32inttype);
  540. loadtype('longint',s32inttype);
  541. loadtype('qword',u64inttype);
  542. loadtype('int64',s64inttype);
  543. loadtype('undefined',cundefinedtype);
  544. loadtype('formal',cformaltype);
  545. loadtype('typedformal',ctypedformaltype);
  546. loadtype('void',voidtype);
  547. loadtype('void_pointer',voidpointertype);
  548. loadtype('char',cansichartype);
  549. loadtype('widechar',cwidechartype);
  550. loadtype('shortstring',cshortstringtype);
  551. loadtype('longstring',clongstringtype);
  552. loadtype('ansistring',cansistringtype);
  553. loadtype('widestring',cwidestringtype);
  554. loadtype('unicodestring',cunicodestringtype);
  555. loadtype('openshortstring',openshortstringtype);
  556. loadtype('openchararray',openchararraytype);
  557. if init_settings.fputype <> fpu_none then
  558. begin
  559. loadtype('s32real',s32floattype);
  560. loadtype('s64real',s64floattype);
  561. loadtype('s80real',s80floattype);
  562. loadtype('sc80real',sc80floattype);
  563. end;
  564. loadtype('s64currency',s64currencytype);
  565. loadtype('boolean',pasbool8type);
  566. loadtype('boolean16',pasbool16type);
  567. loadtype('boolean32',pasbool32type);
  568. loadtype('boolean64',pasbool64type);
  569. loadtype('bytebool',bool8type);
  570. loadtype('wordbool',bool16type);
  571. loadtype('longbool',bool32type);
  572. loadtype('qwordbool',bool64type);
  573. loadtype('char_pointer',charpointertype);
  574. loadtype('widechar_pointer',widecharpointertype);
  575. loadtype('parentfp_void_pointer',parentfpvoidpointertype);
  576. {$ifdef x86}
  577. loadtype('void_nearpointer',voidnearpointertype);
  578. loadtype('void_nearcspointer',voidnearcspointertype);
  579. loadtype('void_neardspointer',voidneardspointertype);
  580. loadtype('void_nearsspointer',voidnearsspointertype);
  581. loadtype('void_nearespointer',voidnearespointertype);
  582. loadtype('void_nearfspointer',voidnearfspointertype);
  583. loadtype('void_neargspointer',voidneargspointertype);
  584. {$ifdef i8086}
  585. loadtype('void_farpointer',voidfarpointertype);
  586. loadtype('void_hugepointer',voidhugepointertype);
  587. loadtype('char_nearpointer',charnearpointertype);
  588. loadtype('char_farpointer',charfarpointertype);
  589. loadtype('char_hugepointer',charhugepointertype);
  590. loadtype('byte_farpointer',bytefarpointertype);
  591. loadtype('word_farpointer',wordfarpointertype);
  592. loadtype('longint_farpointer',longintfarpointertype);
  593. {$endif i8086}
  594. loadtype('__m64', x86_m64type);
  595. loadtype('__m128', x86_m128type);
  596. loadtype('__m128d',x86_m128dtype);
  597. loadtype('__m128i',x86_m128itype);
  598. loadtype('__m256', x86_m256type);
  599. loadtype('__m256d',x86_m256dtype);
  600. loadtype('__m256i',x86_m256itype);
  601. {$endif x86}
  602. loadtype('file',cfiletype);
  603. if not(target_info.system in systems_managed_vm) then
  604. begin
  605. loadtype('pvmt',pvmttype);
  606. loadtype('vtblarray',vmtarraytype);
  607. loadtype('__vtbl_ptr_type',vmttype);
  608. end;
  609. loadtype('variant',cvarianttype);
  610. loadtype('olevariant',colevarianttype);
  611. loadtype('methodpointer',methodpointertype);
  612. loadtype('nestedprocpointer',nestedprocpointertype);
  613. loadtype('HRESULT',hresultdef);
  614. set_default_int_types;
  615. set_default_ptr_types;
  616. set_current_module(oldcurrentmodule);
  617. end;
  618. procedure registernodes;
  619. {
  620. Register all possible nodes in the nodeclass array that
  621. will be used for loading the nodes from a ppu
  622. }
  623. begin
  624. nodeclass[addn]:=caddnode;
  625. nodeclass[muln]:=caddnode;
  626. nodeclass[subn]:=caddnode;
  627. nodeclass[divn]:=cmoddivnode;
  628. nodeclass[symdifn]:=caddnode;
  629. nodeclass[modn]:=cmoddivnode;
  630. nodeclass[assignn]:=cassignmentnode;
  631. nodeclass[loadn]:=cloadnode;
  632. nodeclass[rangen]:=crangenode;
  633. nodeclass[ltn]:=caddnode;
  634. nodeclass[lten]:=caddnode;
  635. nodeclass[gtn]:=caddnode;
  636. nodeclass[gten]:=caddnode;
  637. nodeclass[equaln]:=caddnode;
  638. nodeclass[unequaln]:=caddnode;
  639. nodeclass[inn]:=cinnode;
  640. nodeclass[orn]:=caddnode;
  641. nodeclass[xorn]:=caddnode;
  642. nodeclass[shrn]:=cshlshrnode;
  643. nodeclass[shln]:=cshlshrnode;
  644. nodeclass[slashn]:=caddnode;
  645. nodeclass[andn]:=caddnode;
  646. nodeclass[subscriptn]:=csubscriptnode;
  647. nodeclass[derefn]:=cderefnode;
  648. nodeclass[addrn]:=caddrnode;
  649. nodeclass[ordconstn]:=cordconstnode;
  650. nodeclass[typeconvn]:=ctypeconvnode;
  651. nodeclass[calln]:=ccallnode;
  652. nodeclass[callparan]:=ccallparanode;
  653. nodeclass[realconstn]:=crealconstnode;
  654. nodeclass[unaryminusn]:=cunaryminusnode;
  655. nodeclass[unaryplusn]:=cunaryplusnode;
  656. nodeclass[asmn]:=casmnode;
  657. nodeclass[vecn]:=cvecnode;
  658. nodeclass[pointerconstn]:=cpointerconstnode;
  659. nodeclass[stringconstn]:=cstringconstnode;
  660. nodeclass[notn]:=cnotnode;
  661. nodeclass[inlinen]:=cinlinenode;
  662. nodeclass[niln]:=cnilnode;
  663. nodeclass[errorn]:=cerrornode;
  664. nodeclass[typen]:=ctypenode;
  665. nodeclass[setelementn]:=csetelementnode;
  666. nodeclass[setconstn]:=csetconstnode;
  667. nodeclass[blockn]:=cblocknode;
  668. nodeclass[statementn]:=cstatementnode;
  669. nodeclass[ifn]:=cifnode;
  670. nodeclass[breakn]:=cbreaknode;
  671. nodeclass[continuen]:=ccontinuenode;
  672. nodeclass[whilerepeatn]:=cwhilerepeatnode;
  673. nodeclass[forn]:=cfornode;
  674. nodeclass[exitn]:=cexitnode;
  675. nodeclass[withn]:=cwithnode;
  676. nodeclass[casen]:=ccasenode;
  677. nodeclass[labeln]:=clabelnode;
  678. nodeclass[goton]:=cgotonode;
  679. nodeclass[tryexceptn]:=ctryexceptnode;
  680. nodeclass[raisen]:=craisenode;
  681. nodeclass[tryfinallyn]:=ctryfinallynode;
  682. nodeclass[onn]:=connode;
  683. nodeclass[isn]:=cisnode;
  684. nodeclass[asn]:=casnode;
  685. nodeclass[starstarn]:=caddnode;
  686. nodeclass[arrayconstructorn]:=carrayconstructornode;
  687. nodeclass[arrayconstructorrangen]:=carrayconstructorrangenode;
  688. nodeclass[tempcreaten]:=ctempcreatenode;
  689. nodeclass[temprefn]:=ctemprefnode;
  690. nodeclass[tempdeleten]:=ctempdeletenode;
  691. nodeclass[addoptn]:=caddnode;
  692. nodeclass[nothingn]:=cnothingnode;
  693. nodeclass[loadvmtaddrn]:=cloadvmtaddrnode;
  694. nodeclass[guidconstn]:=cguidconstnode;
  695. nodeclass[rttin]:=crttinode;
  696. nodeclass[loadparentfpn]:=cloadparentfpnode;
  697. end;
  698. procedure registertais;
  699. {
  700. Register all possible tais in the taiclass array that
  701. will be used for loading the tais from a ppu
  702. }
  703. begin
  704. aiclass[ait_none]:=nil;
  705. aiclass[ait_align]:=tai_align;
  706. aiclass[ait_section]:=tai_section;
  707. aiclass[ait_comment]:=tai_comment;
  708. aiclass[ait_string]:=tai_string;
  709. aiclass[ait_instruction]:=taicpu;
  710. aiclass[ait_datablock]:=tai_datablock;
  711. aiclass[ait_symbol]:=tai_symbol;
  712. aiclass[ait_symbol_end]:=tai_symbol_end;
  713. aiclass[ait_directive]:=tai_directive;
  714. aiclass[ait_label]:=tai_label;
  715. aiclass[ait_const]:=tai_const;
  716. aiclass[ait_realconst]:=tai_realconst;
  717. aiclass[ait_stab]:=tai_stab;
  718. aiclass[ait_force_line]:=tai_force_line;
  719. aiclass[ait_function_name]:=tai_function_name;
  720. {$ifdef alpha}
  721. { the follow is for the DEC Alpha }
  722. aiclass[ait_frame]:=tai_frame;
  723. {$endif alpha}
  724. {$ifdef m68k}
  725. { TODO: FIXME: tai_labeled_instruction doesn't exists}
  726. // aiclass[ait_labeled_instruction]:=tai_labeled_instruction;
  727. {$endif m68k}
  728. {$ifdef ia64}
  729. aiclass[ait_bundle]:=tai_bundle;
  730. aiclass[ait_stop]:=tai_stop;
  731. {$endif ia64}
  732. {$ifdef SPARC}
  733. // aiclass[ait_labeled_instruction]:=tai_labeled_instruction;
  734. {$endif SPARC}
  735. aiclass[ait_symbolpair]:=tai_symbolpair;
  736. aiclass[ait_weak]:=tai_weak;
  737. aiclass[ait_cutobject]:=tai_cutobject;
  738. aiclass[ait_regalloc]:=tai_regalloc;
  739. aiclass[ait_tempalloc]:=tai_tempalloc;
  740. aiclass[ait_marker]:=tai_marker;
  741. aiclass[ait_seh_directive]:=tai_seh_directive;
  742. {$ifdef JVM}
  743. aiclass[ait_jvar]:=tai_jvar;
  744. aiclass[ait_jcatch]:=tai_jcatch;
  745. {$endif JVM}
  746. end;
  747. end.