psystem.pas 29 KB

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