psystem.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Load the system unit, create required defs for systemunit
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit psystem;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. symbase;
  23. procedure insertinternsyms(p : tsymtable);
  24. procedure insert_intern_types(p : tsymtable);
  25. procedure readconstdefs;
  26. procedure createconstdefs;
  27. implementation
  28. uses
  29. globals,
  30. symconst,symtype,symsym,symdef,symtable,
  31. ninl,globtype;
  32. procedure insertinternsyms(p : tsymtable);
  33. {
  34. all intern procedures for the system unit
  35. }
  36. begin
  37. p.insert(tsyssym.create('Concat',in_concat_x));
  38. p.insert(tsyssym.create('Write',in_write_x));
  39. p.insert(tsyssym.create('WriteLn',in_writeln_x));
  40. p.insert(tsyssym.create('Assigned',in_assigned_x));
  41. p.insert(tsyssym.create('Read',in_read_x));
  42. p.insert(tsyssym.create('ReadLn',in_readln_x));
  43. p.insert(tsyssym.create('Ofs',in_ofs_x));
  44. p.insert(tsyssym.create('SizeOf',in_sizeof_x));
  45. p.insert(tsyssym.create('TypeOf',in_typeof_x));
  46. p.insert(tsyssym.create('Low',in_low_x));
  47. p.insert(tsyssym.create('High',in_high_x));
  48. p.insert(tsyssym.create('Seg',in_seg_x));
  49. p.insert(tsyssym.create('Ord',in_ord_x));
  50. p.insert(tsyssym.create('Pred',in_pred_x));
  51. p.insert(tsyssym.create('Succ',in_succ_x));
  52. p.insert(tsyssym.create('Exclude',in_exclude_x_y));
  53. p.insert(tsyssym.create('Include',in_include_x_y));
  54. p.insert(tsyssym.create('Break',in_break));
  55. p.insert(tsyssym.create('Exit',in_exit));
  56. p.insert(tsyssym.create('Continue',in_continue));
  57. p.insert(tsyssym.create('Dec',in_dec_x));
  58. p.insert(tsyssym.create('Inc',in_inc_x));
  59. p.insert(tsyssym.create('Str',in_str_x_string));
  60. p.insert(tsyssym.create('Assert',in_assert_x_y));
  61. p.insert(tsyssym.create('Val',in_val_x));
  62. p.insert(tsyssym.create('Addr',in_addr_x));
  63. p.insert(tsyssym.create('TypeInfo',in_typeinfo_x));
  64. p.insert(tsyssym.create('SetLength',in_setlength_x));
  65. p.insert(tsyssym.create('Finalize',in_finalize_x));
  66. p.insert(tsyssym.create('Length',in_length_x));
  67. p.insert(tsyssym.create('New',in_new_x));
  68. p.insert(tsyssym.create('Dispose',in_dispose_x));
  69. end;
  70. procedure insert_intern_types(p : tsymtable);
  71. {
  72. all the types inserted into the system unit
  73. }
  74. function addtype(const s:string;const t:ttype):ttypesym;
  75. begin
  76. result:=ttypesym.create(s,t);
  77. p.insert(result);
  78. { add init/final table if required }
  79. if t.def.needs_inittable then
  80. generate_inittable(result);
  81. end;
  82. procedure adddef(const s:string;def:tdef);
  83. var
  84. t : ttype;
  85. begin
  86. t.setdef(def);
  87. p.insert(ttypesym.create(s,t));
  88. end;
  89. var
  90. { several defs to simulate more or less C++ objects for GDB }
  91. vmttype,
  92. vmtarraytype : ttype;
  93. vmtsymtable : tsymtable;
  94. begin
  95. { Normal types }
  96. if (cs_fp_emulation in aktmoduleswitches) then
  97. begin
  98. addtype('Single',s32floattype);
  99. { extended size is the best real type for the target }
  100. addtype('Real',s32floattype);
  101. pbestrealtype:=@s32floattype;
  102. end
  103. else
  104. begin
  105. addtype('Single',s32floattype);
  106. addtype('Double',s64floattype);
  107. { extended size is the best real type for the target }
  108. addtype('Extended',pbestrealtype^);
  109. addtype('Real',s64floattype);
  110. end;
  111. {$ifdef x86}
  112. adddef('Comp',tfloatdef.create(s64comp));
  113. {$endif x86}
  114. addtype('Currency',s64currencytype);
  115. addtype('Pointer',voidpointertype);
  116. addtype('FarPointer',voidfarpointertype);
  117. addtype('ShortString',cshortstringtype);
  118. addtype('LongString',clongstringtype);
  119. addtype('AnsiString',cansistringtype);
  120. addtype('WideString',cwidestringtype);
  121. addtype('Boolean',booltype);
  122. addtype('ByteBool',booltype);
  123. adddef('WordBool',torddef.create(bool16bit,0,1));
  124. adddef('LongBool',torddef.create(bool32bit,0,1));
  125. addtype('Char',cchartype);
  126. addtype('WideChar',cwidechartype);
  127. adddef('Text',tfiledef.createtext);
  128. addtype('Cardinal',u32bittype);
  129. addtype('QWord',cu64bittype);
  130. addtype('Int64',cs64bittype);
  131. adddef('TypedFile',tfiledef.createtyped(voidtype));
  132. addtype('Variant',cvarianttype);
  133. { Internal types }
  134. addtype('$formal',cformaltype);
  135. addtype('$void',voidtype);
  136. addtype('$byte',u8bittype);
  137. addtype('$word',u16bittype);
  138. addtype('$ulong',u32bittype);
  139. addtype('$longint',s32bittype);
  140. addtype('$qword',cu64bittype);
  141. addtype('$int64',cs64bittype);
  142. addtype('$char',cchartype);
  143. addtype('$widechar',cwidechartype);
  144. addtype('$shortstring',cshortstringtype);
  145. addtype('$longstring',clongstringtype);
  146. addtype('$ansistring',cansistringtype);
  147. addtype('$widestring',cwidestringtype);
  148. addtype('$openshortstring',openshortstringtype);
  149. addtype('$boolean',booltype);
  150. addtype('$void_pointer',voidpointertype);
  151. addtype('$char_pointer',charpointertype);
  152. addtype('$void_farpointer',voidfarpointertype);
  153. addtype('$openchararray',openchararraytype);
  154. addtype('$file',cfiletype);
  155. addtype('$variant',cvarianttype);
  156. addtype('$s32real',s32floattype);
  157. addtype('$s64real',s64floattype);
  158. addtype('$s80real',s80floattype);
  159. addtype('$s64currency',s64currencytype);
  160. { Add a type for virtual method tables }
  161. vmtsymtable:=trecordsymtable.create;
  162. vmttype.setdef(trecorddef.create(vmtsymtable));
  163. pvmttype.setdef(tpointerdef.create(vmttype));
  164. vmtsymtable.insert(tvarsym.create('$parent',pvmttype));
  165. vmtsymtable.insert(tvarsym.create('$length',s32bittype));
  166. vmtsymtable.insert(tvarsym.create('$mlength',s32bittype));
  167. vmtarraytype.setdef(tarraydef.create(0,1,s32bittype));
  168. tarraydef(vmtarraytype.def).elementtype:=voidpointertype;
  169. vmtsymtable.insert(tvarsym.create('$__pfn',vmtarraytype));
  170. addtype('$__vtbl_ptr_type',vmttype);
  171. addtype('$pvmt',pvmttype);
  172. vmtarraytype.setdef(tarraydef.create(0,1,s32bittype));
  173. tarraydef(vmtarraytype.def).elementtype:=pvmttype;
  174. addtype('$vtblarray',vmtarraytype);
  175. { Add functions that require compiler magic }
  176. insertinternsyms(p);
  177. end;
  178. procedure readconstdefs;
  179. {
  180. Load all default definitions for consts from the system unit
  181. }
  182. begin
  183. globaldef('byte',u8bittype);
  184. globaldef('word',u16bittype);
  185. globaldef('ulong',u32bittype);
  186. globaldef('longint',s32bittype);
  187. globaldef('qword',cu64bittype);
  188. globaldef('int64',cs64bittype);
  189. globaldef('formal',cformaltype);
  190. globaldef('void',voidtype);
  191. globaldef('char',cchartype);
  192. globaldef('widechar',cwidechartype);
  193. globaldef('shortstring',cshortstringtype);
  194. globaldef('longstring',clongstringtype);
  195. globaldef('ansistring',cansistringtype);
  196. globaldef('widestring',cwidestringtype);
  197. globaldef('openshortstring',openshortstringtype);
  198. globaldef('openchararray',openchararraytype);
  199. globaldef('s32real',s32floattype);
  200. globaldef('s64real',s64floattype);
  201. globaldef('s80real',s80floattype);
  202. globaldef('s64currency',s64currencytype);
  203. globaldef('boolean',booltype);
  204. globaldef('void_pointer',voidpointertype);
  205. globaldef('char_pointer',charpointertype);
  206. globaldef('void_farpointer',voidfarpointertype);
  207. globaldef('file',cfiletype);
  208. globaldef('pvmt',pvmttype);
  209. globaldef('variant',cvarianttype);
  210. {$ifdef i386}
  211. ordpointertype:=u32bittype;
  212. {$endif i386}
  213. {$ifdef x86_64}
  214. ordpointertype:=cu64bittype;
  215. {$endif x86_64}
  216. {$ifdef powerpc}
  217. ordpointertype:=u32bittype;
  218. {$endif powerpc}
  219. {$ifdef sparc}
  220. ordpointertype:=u32bittype;
  221. {$endif sparc}
  222. {$ifdef m68k}
  223. ordpointertype:=u32bittype;
  224. {$endif}
  225. end;
  226. procedure createconstdefs;
  227. {
  228. Create all default definitions for consts for the system unit
  229. }
  230. var
  231. oldregisterdef : boolean;
  232. begin
  233. { create definitions for constants }
  234. oldregisterdef:=registerdef;
  235. registerdef:=false;
  236. cformaltype.setdef(tformaldef.create);
  237. voidtype.setdef(torddef.create(uvoid,0,0));
  238. u8bittype.setdef(torddef.create(u8bit,0,255));
  239. u16bittype.setdef(torddef.create(u16bit,0,65535));
  240. u32bittype.setdef(torddef.create(u32bit,0,high(cardinal)));
  241. s32bittype.setdef(torddef.create(s32bit,low(longint),high(longint)));
  242. cu64bittype.setdef(torddef.create(u64bit,low(qword),TConstExprInt(high(qword))));
  243. cs64bittype.setdef(torddef.create(s64bit,low(int64),high(int64)));
  244. booltype.setdef(torddef.create(bool8bit,0,1));
  245. cchartype.setdef(torddef.create(uchar,0,255));
  246. cwidechartype.setdef(torddef.create(uwidechar,0,65535));
  247. cshortstringtype.setdef(tstringdef.createshort(255));
  248. { should we give a length to the default long and ansi string definition ?? }
  249. clongstringtype.setdef(tstringdef.createlong(-1));
  250. cansistringtype.setdef(tstringdef.createansi(-1));
  251. cwidestringtype.setdef(tstringdef.createwide(-1));
  252. { length=0 for shortstring is open string (needed for readln(string) }
  253. openshortstringtype.setdef(tstringdef.createshort(0));
  254. openchararraytype.setdef(tarraydef.create(0,-1,s32bittype));
  255. tarraydef(openchararraytype.def).elementtype:=cchartype;
  256. {$ifdef x86}
  257. {$ifdef i386}
  258. ordpointertype:=u32bittype;
  259. {$endif i386}
  260. {$ifdef x86_64}
  261. ordpointertype:=cu64bittype;
  262. {$endif x86_64}
  263. s32floattype.setdef(tfloatdef.create(s32real));
  264. s64floattype.setdef(tfloatdef.create(s64real));
  265. s80floattype.setdef(tfloatdef.create(s80real));
  266. {$endif x86}
  267. {$ifdef powerpc}
  268. ordpointertype:=u32bittype;
  269. s32floattype.setdef(tfloatdef.create(s32real));
  270. s64floattype.setdef(tfloatdef.create(s64real));
  271. s80floattype.setdef(tfloatdef.create(s80real));
  272. {$endif powerpc}
  273. {$ifdef sparc}
  274. ordpointertype:=u32bittype;
  275. s32floattype.setdef(tfloatdef.create(s32real));
  276. s64floattype.setdef(tfloatdef.create(s64real));
  277. s80floattype.setdef(tfloatdef.create(s80real));
  278. {$endif sparc}
  279. {$ifdef m68k}
  280. ordpointertype:=u32bittype;
  281. s32floattype.setdef(tfloatdef.create(s32real));
  282. s64floattype.setdef(tfloatdef.create(s64real));
  283. s80floattype.setdef(tfloatdef.create(s80real));
  284. {$endif}
  285. s64currencytype.setdef(tfloatdef.create(s64currency));
  286. { some other definitions }
  287. voidpointertype.setdef(tpointerdef.create(voidtype));
  288. charpointertype.setdef(tpointerdef.create(cchartype));
  289. voidfarpointertype.setdef(tpointerdef.createfar(voidtype));
  290. cfiletype.setdef(tfiledef.createuntyped);
  291. cvarianttype.setdef(tvariantdef.create);
  292. registerdef:=oldregisterdef;
  293. end;
  294. end.
  295. {
  296. $Log$
  297. Revision 1.35 2002-08-14 19:14:39 carl
  298. + fpu emulation support (generic and untested)
  299. Revision 1.34 2002/08/13 18:01:52 carl
  300. * rename swatoperands to swapoperands
  301. + m68k first compilable version (still needs a lot of testing):
  302. assembler generator, system information , inline
  303. assembler reader.
  304. Revision 1.33 2002/08/11 15:28:00 florian
  305. + support of explicit type case <any ordinal type>->pointer
  306. (delphi mode only)
  307. Revision 1.32 2002/07/25 17:54:24 carl
  308. + Extended is now CPU dependant (equal to bestrealtype)
  309. Revision 1.30 2002/07/07 09:52:32 florian
  310. * powerpc target fixed, very simple units can be compiled
  311. * some basic stuff for better callparanode handling, far from being finished
  312. Revision 1.29 2002/07/06 20:18:47 carl
  313. + more SPARC patches from Mazen
  314. Revision 1.28 2002/07/04 20:43:02 florian
  315. * first x86-64 patches
  316. Revision 1.27 2002/07/01 16:23:54 peter
  317. * cg64 patch
  318. * basics for currency
  319. * asnode updates for class and interface (not finished)
  320. Revision 1.26 2002/05/18 13:34:16 peter
  321. * readded missing revisions
  322. Revision 1.25 2002/05/16 19:46:44 carl
  323. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  324. + try to fix temp allocation (still in ifdef)
  325. + generic constructor calls
  326. + start of tassembler / tmodulebase class cleanup
  327. Revision 1.23 2002/05/12 16:53:09 peter
  328. * moved entry and exitcode to ncgutil and cgobj
  329. * foreach gets extra argument for passing local data to the
  330. iterator function
  331. * -CR checks also class typecasts at runtime by changing them
  332. into as
  333. * fixed compiler to cycle with the -CR option
  334. * fixed stabs with elf writer, finally the global variables can
  335. be watched
  336. * removed a lot of routines from cga unit and replaced them by
  337. calls to cgobj
  338. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  339. u32bit then the other is typecasted also to u32bit without giving
  340. a rangecheck warning/error.
  341. * fixed pascal calling method with reversing also the high tree in
  342. the parast, detected by tcalcst3 test
  343. Revision 1.22 2002/01/24 12:33:53 jonas
  344. * adapted ranges of native types to int64 (e.g. high cardinal is no
  345. longer longint($ffffffff), but just $fffffff in psystem)
  346. * small additional fix in 64bit rangecheck code generation for 32 bit
  347. processors
  348. * adaption of ranges required the matching talgorithm used for selecting
  349. which overloaded procedure to call to be adapted. It should now always
  350. select the closest match for ordinal parameters.
  351. + inttostr(qword) in sysstr.inc/sysstrh.inc
  352. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  353. fixes were required to be able to add them)
  354. * is_in_limit() moved from ncal to types unit, should always be used
  355. instead of direct comparisons of low/high values of orddefs because
  356. qword is a special case
  357. }