psystem.pas 30 KB

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