psystem.pas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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. charnearpointertype:=tpointerdef.createx86(cansichartype,x86pt_near);
  269. charfarpointertype:=tpointerdef.createx86(cansichartype,x86pt_far);
  270. bytefarpointertype:=tpointerdef.createx86(u8inttype,x86pt_far);
  271. wordfarpointertype:=tpointerdef.createx86(u16inttype,x86pt_far);
  272. longintfarpointertype:=tpointerdef.createx86(s32inttype,x86pt_far);
  273. {$endif i8086}
  274. {$endif x86}
  275. cfiletype:=tfiledef.createuntyped;
  276. cvarianttype:=tvariantdef.create(vt_normalvariant);
  277. colevarianttype:=tvariantdef.create(vt_olevariant);
  278. {$ifdef cpufpemu}
  279. { Normal types }
  280. (* we use the same types as without emulator, the only
  281. difference is that direct calls to the emulator are generated
  282. if (cs_fp_emulation in current_settings.moduleswitches) then
  283. begin
  284. addtype('Single',s32floattype);
  285. { extended size is the best real type for the target }
  286. addtype('Real',s32floattype);
  287. pbestrealtype:=@s32floattype;
  288. { extended size is the best real type for the target }
  289. addtype('Extended',pbestrealtype^);
  290. end
  291. else
  292. *)
  293. {$endif cpufpemu}
  294. if init_settings.fputype <> fpu_none then
  295. begin
  296. addtype('Single',s32floattype);
  297. addtype('Double',s64floattype);
  298. { extended size is the best real type for the target }
  299. addtype('Extended',pbestrealtype^);
  300. { CExtended corresponds to the C version of the Extended type
  301. (either "long double" or "double") }
  302. if target_info.system in systems_android then
  303. { Android has "long double"="double" even for x86 }
  304. addtype('CExtended',s64floattype)
  305. else
  306. if tfloatdef(pbestrealtype^).floattype=s80real then
  307. addtype('CExtended',sc80floattype)
  308. else
  309. addtype('CExtended',pbestrealtype^);
  310. end;
  311. {$ifdef x86}
  312. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  313. if target_info.system<>system_x86_64_win64 then
  314. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  315. addtype('Comp',tfloatdef.create(s64comp));
  316. {$endif x86}
  317. addtype('Currency',s64currencytype);
  318. addtype('Pointer',voidpointertype);
  319. {$ifdef x86}
  320. addtype('NearPointer',voidnearpointertype);
  321. addtype('NearCsPointer',voidnearcspointertype);
  322. addtype('NearDsPointer',voidneardspointertype);
  323. addtype('NearSsPointer',voidnearsspointertype);
  324. addtype('NearEsPointer',voidnearespointertype);
  325. addtype('NearFsPointer',voidnearfspointertype);
  326. addtype('NearGsPointer',voidneargspointertype);
  327. {$ifdef i8086}
  328. addtype('FarPointer',voidfarpointertype);
  329. addtype('HugePointer',voidhugepointertype);
  330. {$endif i8086}
  331. {$endif x86}
  332. addtype('ShortString',cshortstringtype);
  333. {$ifdef support_longstring}
  334. addtype('LongString',clongstringtype);
  335. {$endif support_longstring}
  336. addtype('AnsiString',cansistringtype);
  337. addtype('WideString',cwidestringtype);
  338. addtype('UnicodeString',cunicodestringtype);
  339. addtype('OpenString',openshortstringtype);
  340. addtype('Boolean',pasbool8type);
  341. addtype('Boolean16',pasbool16type);
  342. addtype('Boolean32',pasbool32type);
  343. addtype('Boolean64',pasbool64type);
  344. addtype('ByteBool',bool8type);
  345. addtype('WordBool',bool16type);
  346. addtype('LongBool',bool32type);
  347. addtype('QWordBool',bool64type);
  348. addtype('Byte',u8inttype);
  349. addtype('ShortInt',s8inttype);
  350. addtype('Word',u16inttype);
  351. addtype('SmallInt',s16inttype);
  352. addtype('LongWord',u32inttype);
  353. addtype('LongInt',s32inttype);
  354. addtype('QWord',u64inttype);
  355. addtype('Int64',s64inttype);
  356. addtype('Char',cansichartype);
  357. addtype('WideChar',cwidechartype);
  358. addtype('Text',tfiledef.createtext);
  359. addtype('TypedFile',tfiledef.createtyped(voidtype));
  360. addtype('Variant',cvarianttype);
  361. addtype('OleVariant',colevarianttype);
  362. { Internal types }
  363. addtype('$undefined',cundefinedtype);
  364. addtype('$formal',cformaltype);
  365. addtype('$typedformal',ctypedformaltype);
  366. addtype('$void',voidtype);
  367. addtype('$void_pointer',voidpointertype);
  368. addtype('$byte',u8inttype);
  369. addtype('$shortint',s8inttype);
  370. addtype('$word',u16inttype);
  371. addtype('$smallint',s16inttype);
  372. addtype('$ulong',u32inttype);
  373. addtype('$longint',s32inttype);
  374. addtype('$qword',u64inttype);
  375. addtype('$int64',s64inttype);
  376. addtype('$char',cansichartype);
  377. addtype('$widechar',cwidechartype);
  378. addtype('$shortstring',cshortstringtype);
  379. addtype('$longstring',clongstringtype);
  380. addtype('$ansistring',cansistringtype);
  381. addtype('$widestring',cwidestringtype);
  382. addtype('$unicodestring',cunicodestringtype);
  383. addtype('$openshortstring',openshortstringtype);
  384. addtype('$boolean',pasbool8type);
  385. addtype('$boolean16',pasbool16type);
  386. addtype('$boolean32',pasbool32type);
  387. addtype('$boolean64',pasbool64type);
  388. addtype('$bytebool',bool8type);
  389. addtype('$wordbool',bool16type);
  390. addtype('$longbool',bool32type);
  391. addtype('$qwordbool',bool64type);
  392. addtype('$char_pointer',charpointertype);
  393. addtype('$widechar_pointer',widecharpointertype);
  394. addtype('$parentfp_void_pointer',parentfpvoidpointertype);
  395. {$ifdef x86}
  396. addtype('$void_nearpointer',voidnearpointertype);
  397. addtype('$void_nearcspointer',voidnearcspointertype);
  398. addtype('$void_neardspointer',voidneardspointertype);
  399. addtype('$void_nearsspointer',voidnearsspointertype);
  400. addtype('$void_nearespointer',voidnearespointertype);
  401. addtype('$void_nearfspointer',voidnearfspointertype);
  402. addtype('$void_neargspointer',voidneargspointertype);
  403. {$ifdef i8086}
  404. addtype('$void_farpointer',voidfarpointertype);
  405. addtype('$void_hugepointer',voidhugepointertype);
  406. addtype('$char_nearpointer',charnearpointertype);
  407. addtype('$char_farpointer',charfarpointertype);
  408. addtype('$byte_farpointer',bytefarpointertype);
  409. addtype('$word_farpointer',wordfarpointertype);
  410. addtype('$longint_farpointer',longintfarpointertype);
  411. {$endif i8086}
  412. {$endif x86}
  413. addtype('$openchararray',openchararraytype);
  414. addtype('$file',cfiletype);
  415. addtype('$variant',cvarianttype);
  416. addtype('$olevariant',colevarianttype);
  417. if init_settings.fputype<>fpu_none then
  418. begin
  419. addtype('$s32real',s32floattype);
  420. addtype('$s64real',s64floattype);
  421. addtype('$s80real',s80floattype);
  422. addtype('$sc80real',sc80floattype);
  423. end;
  424. addtype('$s64currency',s64currencytype);
  425. if not(target_info.system in systems_managed_vm) then
  426. begin
  427. { Add a type for virtual method tables }
  428. hrecst:=trecordsymtable.create('',current_settings.packrecords);
  429. vmttype:=trecorddef.create('',hrecst);
  430. pvmttype:=tpointerdef.create(vmttype);
  431. { can't use addtype for pvmt because the rtti of the pointed
  432. type is not available. The rtti for pvmt will be written implicitly
  433. by thev tblarray below }
  434. systemunit.insert(ttypesym.create('$pvmt',pvmttype));
  435. addfield(hrecst,tfieldvarsym.create('$length',vs_value,ptrsinttype,[]));
  436. addfield(hrecst,tfieldvarsym.create('$mlength',vs_value,ptrsinttype,[]));
  437. addfield(hrecst,tfieldvarsym.create('$parent',vs_value,pvmttype,[]));
  438. { it seems vmttype is used both for TP objects and Delphi classes,
  439. so the next entry could either be the first virtual method (vm1)
  440. (object) or the class name (class). We can't easily create separate
  441. vtable formats for both, as gdb is hard coded to search for
  442. __vtbl_ptr_type in all cases (JM) }
  443. addfield(hrecst,tfieldvarsym.create('$vm1_or_classname',vs_value,tpointerdef.create(cshortstringtype),[]));
  444. vmtarraytype:=tarraydef.create(0,0,s32inttype);
  445. tarraydef(vmtarraytype).elementdef:=voidpointertype;
  446. addfield(hrecst,tfieldvarsym.create('$__pfn',vs_value,vmtarraytype,[]));
  447. addtype('$__vtbl_ptr_type',vmttype);
  448. vmtarraytype:=tarraydef.create(0,1,s32inttype);
  449. tarraydef(vmtarraytype).elementdef:=pvmttype;
  450. addtype('$vtblarray',vmtarraytype);
  451. { Add a type for methodpointers }
  452. hrecst:=trecordsymtable.create('',1);
  453. {$ifdef i8086}
  454. if current_settings.x86memorymodel in x86_far_code_models then
  455. addfield(hrecst,tfieldvarsym.create('$proc',vs_value,voidfarpointertype,[]))
  456. else
  457. addfield(hrecst,tfieldvarsym.create('$proc',vs_value,voidnearpointertype,[]));
  458. {$else i8086}
  459. addfield(hrecst,tfieldvarsym.create('$proc',vs_value,voidpointertype,[]));
  460. {$endif i8086}
  461. addfield(hrecst,tfieldvarsym.create('$self',vs_value,voidpointertype,[]));
  462. methodpointertype:=trecorddef.create('',hrecst);
  463. addtype('$methodpointer',methodpointertype);
  464. end;
  465. symtablestack.pop(systemunit);
  466. end;
  467. procedure load_intern_types;
  468. {
  469. Load all default definitions for consts from the system unit
  470. }
  471. procedure loadtype(const s:string;var def:tdef);
  472. var
  473. srsym : ttypesym;
  474. begin
  475. srsym:=search_system_type(s);
  476. def:=srsym.typedef;
  477. end;
  478. var
  479. oldcurrentmodule : tmodule;
  480. begin
  481. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  482. if target_info.system=system_x86_64_win64 then
  483. pbestrealtype:=@s64floattype;
  484. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  485. oldcurrentmodule:=current_module;
  486. set_current_module(nil);
  487. loadtype('byte',u8inttype);
  488. loadtype('shortint',s8inttype);
  489. loadtype('word',u16inttype);
  490. loadtype('smallint',s16inttype);
  491. loadtype('ulong',u32inttype);
  492. loadtype('longint',s32inttype);
  493. loadtype('qword',u64inttype);
  494. loadtype('int64',s64inttype);
  495. loadtype('undefined',cundefinedtype);
  496. loadtype('formal',cformaltype);
  497. loadtype('typedformal',ctypedformaltype);
  498. loadtype('void',voidtype);
  499. loadtype('void_pointer',voidpointertype);
  500. loadtype('char',cansichartype);
  501. loadtype('widechar',cwidechartype);
  502. loadtype('shortstring',cshortstringtype);
  503. loadtype('longstring',clongstringtype);
  504. loadtype('ansistring',cansistringtype);
  505. loadtype('widestring',cwidestringtype);
  506. loadtype('unicodestring',cunicodestringtype);
  507. loadtype('openshortstring',openshortstringtype);
  508. loadtype('openchararray',openchararraytype);
  509. if init_settings.fputype <> fpu_none then
  510. begin
  511. loadtype('s32real',s32floattype);
  512. loadtype('s64real',s64floattype);
  513. loadtype('s80real',s80floattype);
  514. loadtype('sc80real',sc80floattype);
  515. end;
  516. loadtype('s64currency',s64currencytype);
  517. loadtype('boolean',pasbool8type);
  518. loadtype('boolean16',pasbool16type);
  519. loadtype('boolean32',pasbool32type);
  520. loadtype('boolean64',pasbool64type);
  521. loadtype('bytebool',bool8type);
  522. loadtype('wordbool',bool16type);
  523. loadtype('longbool',bool32type);
  524. loadtype('qwordbool',bool64type);
  525. loadtype('char_pointer',charpointertype);
  526. loadtype('widechar_pointer',widecharpointertype);
  527. loadtype('parentfp_void_pointer',parentfpvoidpointertype);
  528. {$ifdef x86}
  529. loadtype('void_nearpointer',voidnearpointertype);
  530. loadtype('void_nearcspointer',voidnearcspointertype);
  531. loadtype('void_neardspointer',voidneardspointertype);
  532. loadtype('void_nearsspointer',voidnearsspointertype);
  533. loadtype('void_nearespointer',voidnearespointertype);
  534. loadtype('void_nearfspointer',voidnearfspointertype);
  535. loadtype('void_neargspointer',voidneargspointertype);
  536. {$ifdef i8086}
  537. loadtype('void_farpointer',voidfarpointertype);
  538. loadtype('void_hugepointer',voidhugepointertype);
  539. loadtype('char_nearpointer',charnearpointertype);
  540. loadtype('char_farpointer',charfarpointertype);
  541. loadtype('byte_farpointer',bytefarpointertype);
  542. loadtype('word_farpointer',wordfarpointertype);
  543. loadtype('longint_farpointer',longintfarpointertype);
  544. {$endif i8086}
  545. {$endif x86}
  546. loadtype('file',cfiletype);
  547. if not(target_info.system in systems_managed_vm) then
  548. begin
  549. loadtype('pvmt',pvmttype);
  550. loadtype('vtblarray',vmtarraytype);
  551. loadtype('__vtbl_ptr_type',vmttype);
  552. end;
  553. loadtype('variant',cvarianttype);
  554. loadtype('olevariant',colevarianttype);
  555. loadtype('methodpointer',methodpointertype);
  556. loadtype('HRESULT',hresultdef);
  557. set_default_int_types;
  558. set_current_module(oldcurrentmodule);
  559. end;
  560. procedure registernodes;
  561. {
  562. Register all possible nodes in the nodeclass array that
  563. will be used for loading the nodes from a ppu
  564. }
  565. begin
  566. nodeclass[addn]:=caddnode;
  567. nodeclass[muln]:=caddnode;
  568. nodeclass[subn]:=caddnode;
  569. nodeclass[divn]:=cmoddivnode;
  570. nodeclass[symdifn]:=caddnode;
  571. nodeclass[modn]:=cmoddivnode;
  572. nodeclass[assignn]:=cassignmentnode;
  573. nodeclass[loadn]:=cloadnode;
  574. nodeclass[rangen]:=crangenode;
  575. nodeclass[ltn]:=caddnode;
  576. nodeclass[lten]:=caddnode;
  577. nodeclass[gtn]:=caddnode;
  578. nodeclass[gten]:=caddnode;
  579. nodeclass[equaln]:=caddnode;
  580. nodeclass[unequaln]:=caddnode;
  581. nodeclass[inn]:=cinnode;
  582. nodeclass[orn]:=caddnode;
  583. nodeclass[xorn]:=caddnode;
  584. nodeclass[shrn]:=cshlshrnode;
  585. nodeclass[shln]:=cshlshrnode;
  586. nodeclass[slashn]:=caddnode;
  587. nodeclass[andn]:=caddnode;
  588. nodeclass[subscriptn]:=csubscriptnode;
  589. nodeclass[derefn]:=cderefnode;
  590. nodeclass[addrn]:=caddrnode;
  591. nodeclass[ordconstn]:=cordconstnode;
  592. nodeclass[typeconvn]:=ctypeconvnode;
  593. nodeclass[calln]:=ccallnode;
  594. nodeclass[callparan]:=ccallparanode;
  595. nodeclass[realconstn]:=crealconstnode;
  596. nodeclass[unaryminusn]:=cunaryminusnode;
  597. nodeclass[unaryplusn]:=cunaryplusnode;
  598. nodeclass[asmn]:=casmnode;
  599. nodeclass[vecn]:=cvecnode;
  600. nodeclass[pointerconstn]:=cpointerconstnode;
  601. nodeclass[stringconstn]:=cstringconstnode;
  602. nodeclass[notn]:=cnotnode;
  603. nodeclass[inlinen]:=cinlinenode;
  604. nodeclass[niln]:=cnilnode;
  605. nodeclass[errorn]:=cerrornode;
  606. nodeclass[typen]:=ctypenode;
  607. nodeclass[setelementn]:=csetelementnode;
  608. nodeclass[setconstn]:=csetconstnode;
  609. nodeclass[blockn]:=cblocknode;
  610. nodeclass[statementn]:=cstatementnode;
  611. nodeclass[ifn]:=cifnode;
  612. nodeclass[breakn]:=cbreaknode;
  613. nodeclass[continuen]:=ccontinuenode;
  614. nodeclass[whilerepeatn]:=cwhilerepeatnode;
  615. nodeclass[forn]:=cfornode;
  616. nodeclass[exitn]:=cexitnode;
  617. nodeclass[withn]:=cwithnode;
  618. nodeclass[casen]:=ccasenode;
  619. nodeclass[labeln]:=clabelnode;
  620. nodeclass[goton]:=cgotonode;
  621. nodeclass[tryexceptn]:=ctryexceptnode;
  622. nodeclass[raisen]:=craisenode;
  623. nodeclass[tryfinallyn]:=ctryfinallynode;
  624. nodeclass[onn]:=connode;
  625. nodeclass[isn]:=cisnode;
  626. nodeclass[asn]:=casnode;
  627. nodeclass[starstarn]:=caddnode;
  628. nodeclass[arrayconstructorn]:=carrayconstructornode;
  629. nodeclass[arrayconstructorrangen]:=carrayconstructorrangenode;
  630. nodeclass[tempcreaten]:=ctempcreatenode;
  631. nodeclass[temprefn]:=ctemprefnode;
  632. nodeclass[tempdeleten]:=ctempdeletenode;
  633. nodeclass[addoptn]:=caddnode;
  634. nodeclass[nothingn]:=cnothingnode;
  635. nodeclass[loadvmtaddrn]:=cloadvmtaddrnode;
  636. nodeclass[guidconstn]:=cguidconstnode;
  637. nodeclass[rttin]:=crttinode;
  638. nodeclass[loadparentfpn]:=cloadparentfpnode;
  639. end;
  640. procedure registertais;
  641. {
  642. Register all possible tais in the taiclass array that
  643. will be used for loading the tais from a ppu
  644. }
  645. begin
  646. aiclass[ait_none]:=nil;
  647. aiclass[ait_align]:=tai_align;
  648. aiclass[ait_section]:=tai_section;
  649. aiclass[ait_comment]:=tai_comment;
  650. aiclass[ait_string]:=tai_string;
  651. aiclass[ait_instruction]:=taicpu;
  652. aiclass[ait_datablock]:=tai_datablock;
  653. aiclass[ait_symbol]:=tai_symbol;
  654. aiclass[ait_symbol_end]:=tai_symbol_end;
  655. aiclass[ait_directive]:=tai_directive;
  656. aiclass[ait_label]:=tai_label;
  657. aiclass[ait_const]:=tai_const;
  658. aiclass[ait_real_32bit]:=tai_real_32bit;
  659. aiclass[ait_real_64bit]:=tai_real_64bit;
  660. aiclass[ait_real_80bit]:=tai_real_80bit;
  661. aiclass[ait_comp_64bit]:=tai_comp_64bit;
  662. aiclass[ait_stab]:=tai_stab;
  663. aiclass[ait_force_line]:=tai_force_line;
  664. aiclass[ait_function_name]:=tai_function_name;
  665. {$ifdef alpha}
  666. { the follow is for the DEC Alpha }
  667. aiclass[ait_frame]:=tai_frame;
  668. {$endif alpha}
  669. {$ifdef m68k}
  670. { TODO: FIXME: tai_labeled_instruction doesn't exists}
  671. // aiclass[ait_labeled_instruction]:=tai_labeled_instruction;
  672. {$endif m68k}
  673. {$ifdef ia64}
  674. aiclass[ait_bundle]:=tai_bundle;
  675. aiclass[ait_stop]:=tai_stop;
  676. {$endif ia64}
  677. {$ifdef SPARC}
  678. // aiclass[ait_labeled_instruction]:=tai_labeled_instruction;
  679. {$endif SPARC}
  680. {$ifdef arm}
  681. aiclass[ait_thumb_func]:=tai_thumb_func;
  682. aiclass[ait_thumb_set]:=tai_thumb_set;
  683. {$endif arm}
  684. aiclass[ait_set]:=tai_set;
  685. aiclass[ait_weak]:=tai_weak;
  686. aiclass[ait_cutobject]:=tai_cutobject;
  687. aiclass[ait_regalloc]:=tai_regalloc;
  688. aiclass[ait_tempalloc]:=tai_tempalloc;
  689. aiclass[ait_marker]:=tai_marker;
  690. aiclass[ait_seh_directive]:=tai_seh_directive;
  691. {$ifdef JVM}
  692. aiclass[ait_jvar]:=tai_jvar;
  693. aiclass[ait_jcatch]:=tai_jcatch;
  694. {$endif JVM}
  695. end;
  696. end.