psystem.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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;
  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. addtype('Single',s32floattype);
  97. addtype('Double',s64floattype);
  98. { extended size is the best real type for the target }
  99. addtype('Extended',pbestrealtype^);
  100. addtype('Real',s64floattype);
  101. {$ifdef x86}
  102. adddef('Comp',tfloatdef.create(s64comp));
  103. {$endif x86}
  104. addtype('Currency',s64currencytype);
  105. addtype('Pointer',voidpointertype);
  106. addtype('FarPointer',voidfarpointertype);
  107. addtype('ShortString',cshortstringtype);
  108. addtype('LongString',clongstringtype);
  109. addtype('AnsiString',cansistringtype);
  110. addtype('WideString',cwidestringtype);
  111. addtype('Boolean',booltype);
  112. addtype('ByteBool',booltype);
  113. adddef('WordBool',torddef.create(bool16bit,0,1));
  114. adddef('LongBool',torddef.create(bool32bit,0,1));
  115. addtype('Char',cchartype);
  116. addtype('WideChar',cwidechartype);
  117. adddef('Text',tfiledef.createtext);
  118. addtype('Cardinal',u32bittype);
  119. addtype('QWord',cu64bittype);
  120. addtype('Int64',cs64bittype);
  121. adddef('TypedFile',tfiledef.createtyped(voidtype));
  122. addtype('Variant',cvarianttype);
  123. { Internal types }
  124. addtype('$formal',cformaltype);
  125. addtype('$void',voidtype);
  126. addtype('$byte',u8bittype);
  127. addtype('$word',u16bittype);
  128. addtype('$ulong',u32bittype);
  129. addtype('$longint',s32bittype);
  130. addtype('$qword',cu64bittype);
  131. addtype('$int64',cs64bittype);
  132. addtype('$char',cchartype);
  133. addtype('$widechar',cwidechartype);
  134. addtype('$shortstring',cshortstringtype);
  135. addtype('$longstring',clongstringtype);
  136. addtype('$ansistring',cansistringtype);
  137. addtype('$widestring',cwidestringtype);
  138. addtype('$openshortstring',openshortstringtype);
  139. addtype('$boolean',booltype);
  140. addtype('$void_pointer',voidpointertype);
  141. addtype('$char_pointer',charpointertype);
  142. addtype('$void_farpointer',voidfarpointertype);
  143. addtype('$openchararray',openchararraytype);
  144. addtype('$file',cfiletype);
  145. addtype('$variant',cvarianttype);
  146. addtype('$s32real',s32floattype);
  147. addtype('$s64real',s64floattype);
  148. addtype('$s80real',s80floattype);
  149. addtype('$s64currency',s64currencytype);
  150. { Add a type for virtual method tables }
  151. vmtsymtable:=trecordsymtable.create;
  152. vmttype.setdef(trecorddef.create(vmtsymtable));
  153. pvmttype.setdef(tpointerdef.create(vmttype));
  154. vmtsymtable.insert(tvarsym.create('$parent',pvmttype));
  155. vmtsymtable.insert(tvarsym.create('$length',s32bittype));
  156. vmtsymtable.insert(tvarsym.create('$mlength',s32bittype));
  157. vmtarraytype.setdef(tarraydef.create(0,1,s32bittype));
  158. tarraydef(vmtarraytype.def).elementtype:=voidpointertype;
  159. vmtsymtable.insert(tvarsym.create('$__pfn',vmtarraytype));
  160. addtype('$__vtbl_ptr_type',vmttype);
  161. addtype('$pvmt',pvmttype);
  162. vmtarraytype.setdef(tarraydef.create(0,1,s32bittype));
  163. tarraydef(vmtarraytype.def).elementtype:=pvmttype;
  164. addtype('$vtblarray',vmtarraytype);
  165. { Add functions that require compiler magic }
  166. insertinternsyms(p);
  167. end;
  168. procedure readconstdefs;
  169. {
  170. Load all default definitions for consts from the system unit
  171. }
  172. begin
  173. globaldef('byte',u8bittype);
  174. globaldef('word',u16bittype);
  175. globaldef('ulong',u32bittype);
  176. globaldef('longint',s32bittype);
  177. globaldef('qword',cu64bittype);
  178. globaldef('int64',cs64bittype);
  179. globaldef('formal',cformaltype);
  180. globaldef('void',voidtype);
  181. globaldef('char',cchartype);
  182. globaldef('widechar',cwidechartype);
  183. globaldef('shortstring',cshortstringtype);
  184. globaldef('longstring',clongstringtype);
  185. globaldef('ansistring',cansistringtype);
  186. globaldef('widestring',cwidestringtype);
  187. globaldef('openshortstring',openshortstringtype);
  188. globaldef('openchararray',openchararraytype);
  189. globaldef('s32real',s32floattype);
  190. globaldef('s64real',s64floattype);
  191. globaldef('s80real',s80floattype);
  192. globaldef('s64currency',s64currencytype);
  193. globaldef('boolean',booltype);
  194. globaldef('void_pointer',voidpointertype);
  195. globaldef('char_pointer',charpointertype);
  196. globaldef('void_farpointer',voidfarpointertype);
  197. globaldef('file',cfiletype);
  198. globaldef('pvmt',pvmttype);
  199. globaldef('variant',cvarianttype);
  200. end;
  201. procedure createconstdefs;
  202. {
  203. Create all default definitions for consts for the system unit
  204. }
  205. var
  206. oldregisterdef : boolean;
  207. begin
  208. { create definitions for constants }
  209. oldregisterdef:=registerdef;
  210. registerdef:=false;
  211. cformaltype.setdef(tformaldef.create);
  212. voidtype.setdef(torddef.create(uvoid,0,0));
  213. u8bittype.setdef(torddef.create(u8bit,0,255));
  214. u16bittype.setdef(torddef.create(u16bit,0,65535));
  215. u32bittype.setdef(torddef.create(u32bit,0,high(cardinal)));
  216. s32bittype.setdef(torddef.create(s32bit,low(longint),high(longint)));
  217. cu64bittype.setdef(torddef.create(u64bit,low(qword),TConstExprInt(high(qword))));
  218. cs64bittype.setdef(torddef.create(s64bit,low(int64),high(int64)));
  219. booltype.setdef(torddef.create(bool8bit,0,1));
  220. cchartype.setdef(torddef.create(uchar,0,255));
  221. cwidechartype.setdef(torddef.create(uwidechar,0,65535));
  222. cshortstringtype.setdef(tstringdef.createshort(255));
  223. { should we give a length to the default long and ansi string definition ?? }
  224. clongstringtype.setdef(tstringdef.createlong(-1));
  225. cansistringtype.setdef(tstringdef.createansi(-1));
  226. cwidestringtype.setdef(tstringdef.createwide(-1));
  227. { length=0 for shortstring is open string (needed for readln(string) }
  228. openshortstringtype.setdef(tstringdef.createshort(0));
  229. openchararraytype.setdef(tarraydef.create(0,-1,s32bittype));
  230. tarraydef(openchararraytype.def).elementtype:=cchartype;
  231. {$ifdef x86}
  232. s32floattype.setdef(tfloatdef.create(s32real));
  233. s64floattype.setdef(tfloatdef.create(s64real));
  234. s80floattype.setdef(tfloatdef.create(s80real));
  235. {$endif x86}
  236. {$ifdef powerpc}
  237. s32floattype.setdef(tfloatdef.create(s32real));
  238. s64floattype.setdef(tfloatdef.create(s64real));
  239. s80floattype.setdef(tfloatdef.create(s80real));
  240. {$endif powerpc}
  241. {$ifdef sparc}
  242. s32floattype.setdef(tfloatdef.create(s32real));
  243. s64floattype.setdef(tfloatdef.create(s64real));
  244. {$endif sparc}
  245. s64currencytype.setdef(tfloatdef.create(s64currency));
  246. {$ifdef m68k}
  247. s32floattype.setdef(tfloatdef.create(s32real));
  248. if (cs_fp_emulation in aktmoduleswitches) then
  249. begin
  250. s64floattype.setdef(tfloatdef.create(s32real));
  251. s80floattype.setdef(tfloatdef.create(s32real)))
  252. end
  253. else
  254. begin
  255. s64floattype.setdef(tfloatdef.create(s64real));
  256. s80floattype.setdef(tfloatdef.create(s80real));
  257. end;
  258. {$endif}
  259. { some other definitions }
  260. voidpointertype.setdef(tpointerdef.create(voidtype));
  261. charpointertype.setdef(tpointerdef.create(cchartype));
  262. voidfarpointertype.setdef(tpointerdef.createfar(voidtype));
  263. cfiletype.setdef(tfiledef.createuntyped);
  264. cvarianttype.setdef(tvariantdef.create);
  265. registerdef:=oldregisterdef;
  266. end;
  267. end.
  268. {
  269. $Log$
  270. Revision 1.32 2002-07-25 17:54:24 carl
  271. + Extended is now CPU dependant (equal to bestrealtype)
  272. Revision 1.30 2002/07/07 09:52:32 florian
  273. * powerpc target fixed, very simple units can be compiled
  274. * some basic stuff for better callparanode handling, far from being finished
  275. Revision 1.29 2002/07/06 20:18:47 carl
  276. + more SPARC patches from Mazen
  277. Revision 1.28 2002/07/04 20:43:02 florian
  278. * first x86-64 patches
  279. Revision 1.27 2002/07/01 16:23:54 peter
  280. * cg64 patch
  281. * basics for currency
  282. * asnode updates for class and interface (not finished)
  283. Revision 1.26 2002/05/18 13:34:16 peter
  284. * readded missing revisions
  285. Revision 1.25 2002/05/16 19:46:44 carl
  286. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  287. + try to fix temp allocation (still in ifdef)
  288. + generic constructor calls
  289. + start of tassembler / tmodulebase class cleanup
  290. Revision 1.23 2002/05/12 16:53:09 peter
  291. * moved entry and exitcode to ncgutil and cgobj
  292. * foreach gets extra argument for passing local data to the
  293. iterator function
  294. * -CR checks also class typecasts at runtime by changing them
  295. into as
  296. * fixed compiler to cycle with the -CR option
  297. * fixed stabs with elf writer, finally the global variables can
  298. be watched
  299. * removed a lot of routines from cga unit and replaced them by
  300. calls to cgobj
  301. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  302. u32bit then the other is typecasted also to u32bit without giving
  303. a rangecheck warning/error.
  304. * fixed pascal calling method with reversing also the high tree in
  305. the parast, detected by tcalcst3 test
  306. Revision 1.22 2002/01/24 12:33:53 jonas
  307. * adapted ranges of native types to int64 (e.g. high cardinal is no
  308. longer longint($ffffffff), but just $fffffff in psystem)
  309. * small additional fix in 64bit rangecheck code generation for 32 bit
  310. processors
  311. * adaption of ranges required the matching talgorithm used for selecting
  312. which overloaded procedure to call to be adapted. It should now always
  313. select the closest match for ordinal parameters.
  314. + inttostr(qword) in sysstr.inc/sysstrh.inc
  315. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  316. fixes were required to be able to add them)
  317. * is_in_limit() moved from ncal to types unit, should always be used
  318. instead of direct comparisons of low/high values of orddefs because
  319. qword is a special case
  320. }