globtype.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. Global types
  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 globtype;
  19. {$i fpcdefs.inc}
  20. interface
  21. const
  22. maxidlen = 64;
  23. type
  24. {$ifndef fpc}
  25. qword = int64;
  26. {$endif fpc}
  27. {$ifdef ver1_0}
  28. { Bootstrapping }
  29. PtrInt = DWord;
  30. SizeInt = Longint;
  31. {$endif ver1_0}
  32. { Natural integer register type and size for the target machine }
  33. {$ifdef cpu64bit}
  34. AWord = qword;
  35. AInt = Int64;
  36. {$else cpu64bit}
  37. AWord = longword;
  38. AInt = longint;
  39. {$endif cpu64bit}
  40. PAWord = ^AWord;
  41. PAInt = ^AInt;
  42. { the ordinal type used when evaluating constant integer expressions }
  43. TConstExprInt = int64;
  44. { ... the same unsigned }
  45. TConstExprUInt = qword;
  46. { This must be an ordinal type with the same size as a pointer
  47. Note: Must be unsigned! Otherwise, ugly code like
  48. pointer(-1) will result in a pointer with the value
  49. $fffffffffffffff on a 32bit machine if the compiler uses
  50. int64 constants internally (JM) }
  51. TConstPtrUInt = AWord;
  52. { Switches which can be changed locally }
  53. tlocalswitch = (cs_localnone,
  54. { codegen }
  55. cs_check_overflow,cs_check_range,cs_check_object,
  56. cs_check_io,cs_check_stack,
  57. cs_omitstackframe,cs_do_assertion,cs_generate_rtti,
  58. cs_full_boolean_eval,cs_typed_const_writable,
  59. { mmx }
  60. cs_mmx,cs_mmx_saturation,
  61. { parser }
  62. cs_typed_addresses,cs_strict_var_strings,cs_ansistrings
  63. );
  64. tlocalswitches = set of tlocalswitch;
  65. { Switches which can be changed only at the beginning of a new module }
  66. tmoduleswitch = (cs_modulenone,
  67. { parser }
  68. cs_fp_emulation,cs_extsyntax,cs_openstring,
  69. { support }
  70. cs_support_inline,cs_support_goto,cs_support_macro,
  71. cs_support_c_operators,cs_static_keyword,
  72. { generation }
  73. cs_profile,cs_debuginfo,cs_browser,cs_local_browser,cs_compilesystem,
  74. cs_lineinfo,cs_threading,cs_implicit_exceptions,
  75. { linking }
  76. cs_create_smart,cs_create_dynamic,cs_create_pic
  77. );
  78. tmoduleswitches = set of tmoduleswitch;
  79. { Switches which can be changed only for a whole program/compilation,
  80. mostly set with commandline }
  81. tglobalswitch = (cs_globalnone,
  82. { parameter switches }
  83. cs_check_unit_name,cs_constructor_name,
  84. { units }
  85. cs_load_objpas_unit,
  86. cs_load_gpc_unit,
  87. { optimizer }
  88. cs_regvars,cs_no_regalloc,cs_uncertainopts,cs_littlesize,
  89. cs_optimize,cs_fastoptimize,cs_slowoptimize,cs_align,
  90. { browser }
  91. cs_browser_log,
  92. { debugger }
  93. cs_gdb_dbx,cs_gdb_gsym,cs_gdb_heaptrc,cs_gdb_lineinfo,
  94. cs_checkpointer,cs_gdb_valgrind,cs_gdb_dwarf,
  95. { assembling }
  96. cs_asm_leave,cs_asm_extern,cs_asm_pipe,cs_asm_source,
  97. cs_asm_regalloc,cs_asm_tempalloc,cs_asm_nodes,
  98. { linking }
  99. cs_link_extern,cs_link_static,cs_link_smart,cs_link_shared,cs_link_deffile,
  100. cs_link_strip,cs_link_staticflag,cs_link_on_target,cs_link_internal,
  101. cs_link_map,cs_link_pthread
  102. );
  103. tglobalswitches = set of tglobalswitch;
  104. { Switches which can be changed by a mode (fpc,tp7,delphi) }
  105. tmodeswitch = (m_none,m_all, { needed for keyword }
  106. { generic }
  107. m_fpc,m_objfpc,m_delphi,m_tp7,m_gpc,m_mac,
  108. { more specific }
  109. m_class, { delphi class model }
  110. m_objpas, { load objpas unit }
  111. m_result, { result in functions }
  112. m_string_pchar, { pchar 2 string conversion }
  113. m_cvar_support, { cvar variable directive }
  114. m_nested_comment, { nested comments }
  115. m_tp_procvar, { tp style procvars (no @ needed) }
  116. m_repeat_forward, { repeating forward declarations is needed }
  117. m_pointer_2_procedure, { allows the assignement of pointers to
  118. procedure variables }
  119. m_autoderef, { does auto dereferencing of struct. vars }
  120. m_initfinal, { initialization/finalization for units }
  121. m_add_pointer, { allow pointer add/sub operations }
  122. m_default_ansistring, { ansistring turned on by default }
  123. m_out, { support the calling convention OUT }
  124. m_default_para, { support default parameters }
  125. m_hintdirective, { support hint directives }
  126. m_duplicate_names { allow locals/paras to have duplicate names of globals }
  127. );
  128. tmodeswitches = set of tmodeswitch;
  129. { Win32, OS/2 & MacOS application types }
  130. tapptype = (
  131. app_none,
  132. app_gui, { graphic user-interface application}
  133. app_cui, { console application}
  134. app_fs, { full-screen type application (OS/2 and EMX only) }
  135. app_tool { tool application, (MPW tool for MacOS, MacOS only)}
  136. );
  137. { interface types }
  138. tinterfacetypes = (
  139. it_interfacecom,
  140. it_interfacecorba
  141. );
  142. { currently parsed block type }
  143. tblock_type = (bt_none,
  144. bt_general,bt_type,bt_const,bt_except,bt_body
  145. );
  146. { calling convention for tprocdef and tprocvardef }
  147. tproccalloption=(pocall_none,
  148. { procedure uses C styled calling }
  149. pocall_cdecl,
  150. { C++ calling conventions }
  151. pocall_cppdecl,
  152. { Procedure is used for internal compiler calls }
  153. pocall_compilerproc,
  154. { Far16 for OS/2 }
  155. pocall_far16,
  156. { Old style FPC default calling }
  157. pocall_oldfpccall,
  158. { Procedure is an assembler macro }
  159. pocall_inline,
  160. { Procedure has compiler magic}
  161. pocall_internproc,
  162. { procedure is a system call, applies e.g. to MorphOS and PalmOS }
  163. pocall_syscall,
  164. { pascal standard left to right }
  165. pocall_pascal,
  166. { procedure uses register (fastcall) calling }
  167. pocall_register,
  168. { safe call calling conventions }
  169. pocall_safecall,
  170. { procedure uses stdcall call }
  171. pocall_stdcall,
  172. { Special calling convention for cpus without a floating point
  173. unit. Floating point numbers are passed in integer registers
  174. instead of floating point registers. Depending on the other
  175. available calling conventions available for the cpu
  176. this replaces either pocall_fastcall or pocall_stdcall.
  177. }
  178. pocall_softfloat
  179. );
  180. tproccalloptions = set of tproccalloption;
  181. tprocinfoflag=(
  182. { procedure uses asm }
  183. pi_uses_asm,
  184. { procedure does a call }
  185. pi_do_call,
  186. { procedure has a try statement = no register optimization }
  187. pi_uses_exceptions,
  188. { procedure is declared as @var(assembler), don't optimize}
  189. pi_is_assembler,
  190. { procedure contains data which needs to be finalized }
  191. pi_needs_implicit_finally,
  192. { procedure has the implicit try..finally generated }
  193. pi_has_implicit_finally,
  194. { procedure uses fpu}
  195. pi_uses_fpu,
  196. { procedure uses GOT for PIC code }
  197. pi_needs_got
  198. );
  199. tprocinfoflags=set of tprocinfoflag;
  200. {$ifdef ansistring_bits}
  201. Tstringbits=(sb_16,sb_32,sb_64);
  202. {$endif}
  203. const
  204. proccalloptionStr : array[tproccalloption] of string[14]=('',
  205. 'CDecl',
  206. 'CPPDecl',
  207. 'CompilerProc',
  208. 'Far16',
  209. 'OldFPCCall',
  210. 'Inline',
  211. 'InternProc',
  212. 'SysCall',
  213. 'Pascal',
  214. 'Register',
  215. 'SafeCall',
  216. 'StdCall',
  217. 'SoftFloat'
  218. );
  219. { Default calling convention }
  220. {$ifdef x86}
  221. pocall_default = pocall_register;
  222. {$else}
  223. pocall_default = pocall_stdcall;
  224. {$endif}
  225. type
  226. stringid = string[maxidlen];
  227. tnormalset = set of byte; { 256 elements set }
  228. pnormalset = ^tnormalset;
  229. pboolean = ^boolean;
  230. pdouble = ^double;
  231. pbyte = ^byte;
  232. pword = ^word;
  233. plongint = ^longint;
  234. plongintarray = plongint;
  235. Tconstant=record
  236. case signed:boolean of
  237. false:
  238. (valueu:cardinal);
  239. true:
  240. (values:longint);
  241. end;
  242. {$ifndef Delphi}
  243. {$ifndef xFPC}
  244. type
  245. pguid = ^tguid;
  246. tguid = packed record
  247. D1: LongWord;
  248. D2: Word;
  249. D3: Word;
  250. D4: array[0..7] of Byte;
  251. end;
  252. {$endif}
  253. {$endif}
  254. const
  255. { link options }
  256. link_none = $0;
  257. link_allways = $1;
  258. link_static = $2;
  259. link_smart = $4;
  260. link_shared = $8;
  261. implementation
  262. end.
  263. {
  264. $Log$
  265. Revision 1.57 2004-06-16 20:07:07 florian
  266. * dwarf branch merged
  267. Revision 1.56 2004/05/23 15:06:20 peter
  268. * implicit_finally flag must be set in pass1
  269. * add check whether the implicit frame is generated when expected
  270. Revision 1.55 2004/05/23 14:32:17 peter
  271. * tprocinfoflag moved to globtype
  272. Revision 1.54 2004/05/02 11:48:46 peter
  273. * strlenint is replaced with sizeint
  274. Revision 1.53 2004/04/29 19:56:36 daniel
  275. * Prepare compiler infrastructure for multiple ansistring types
  276. Revision 1.52 2004/04/28 15:19:03 florian
  277. + syscall directive support for MorphOS added
  278. Revision 1.51.2.3 2004/05/02 00:45:51 peter
  279. * define sizeint for 1.0.x
  280. Revision 1.51.2.2 2004/05/01 16:02:09 peter
  281. * POINTER_SIZE replaced with sizeof(aint)
  282. * aint,aword,tconst*int moved to globtype
  283. Revision 1.51.2.1 2004/04/10 22:08:52 florian
  284. + more dwarf infrastructure
  285. Revision 1.51 2004/04/04 18:46:09 olle
  286. + added $APPTYPE TOOL for MPW tools on MacOS
  287. Revision 1.50 2004/03/10 22:52:57 peter
  288. * more stabs fixes
  289. * special mode -gv for valgrind compatible stabs
  290. Revision 1.49 2004/02/15 16:34:18 marco
  291. * pthread on -CURRENT related fixes.
  292. Revision 1.48 2003/12/23 23:22:35 peter
  293. * register calling is now default for i386
  294. Revision 1.47 2003/12/14 20:51:17 daniel
  295. * Register calling disabled again
  296. Revision 1.46 2003/12/14 20:24:28 daniel
  297. * Register allocator speed optimizations
  298. - Worklist no longer a ringbuffer
  299. - No find operations are left
  300. - Simplify now done in constant time
  301. - unusedregs is now a Tsuperregisterworklist
  302. - Microoptimizations
  303. Revision 1.45 2003/12/04 23:27:32 peter
  304. * remove redundant calls to add_edge_used
  305. Revision 1.44 2003/11/07 15:58:32 florian
  306. * Florian's culmutative nr. 1; contains:
  307. - invalid calling conventions for a certain cpu are rejected
  308. - arm softfloat calling conventions
  309. - -Sp for cpu dependend code generation
  310. - several arm fixes
  311. - remaining code for value open array paras on heap
  312. Revision 1.43 2003/09/28 13:39:58 peter
  313. * default calling convention changed to stdcall
  314. Revision 1.42 2003/09/07 22:09:35 peter
  315. * preparations for different default calling conventions
  316. * various RA fixes
  317. Revision 1.41 2003/09/04 21:37:29 olle
  318. + added new lagnuage mode: MAC
  319. Revision 1.40 2003/09/03 15:55:00 peter
  320. * NEWRA branch merged
  321. Revision 1.39 2003/08/09 18:56:54 daniel
  322. * cs_regalloc renamed to cs_regvars to avoid confusion with register
  323. allocator
  324. * Some preventive changes to i386 spillinh code
  325. Revision 1.38 2003/04/27 11:21:32 peter
  326. * aktprocdef renamed to current_procdef
  327. * procinfo renamed to current_procinfo
  328. * procinfo will now be stored in current_module so it can be
  329. cleaned up properly
  330. * gen_main_procsym changed to create_main_proc and release_main_proc
  331. to also generate a tprocinfo structure
  332. * fixed unit implicit initfinal
  333. Revision 1.37 2003/04/27 07:29:50 peter
  334. * current_procdef cleanup, current_procdef is now always nil when parsing
  335. a new procdef declaration
  336. * aktprocsym removed
  337. * lexlevel removed, use symtable.symtablelevel instead
  338. * implicit init/final code uses the normal genentry/genexit
  339. * funcret state checking updated for new funcret handling
  340. Revision 1.36 2003/04/22 23:50:22 peter
  341. * firstpass uses expectloc
  342. * checks if there are differences between the expectloc and
  343. location.loc from secondpass in EXTDEBUG
  344. Revision 1.35 2003/03/08 08:59:07 daniel
  345. + $define newra will enable new register allocator
  346. + getregisterint will return imaginary registers with $newra
  347. + -sr switch added, will skip register allocation so you can see
  348. the direct output of the code generator before register allocation
  349. Revision 1.34 2002/10/16 19:01:43 peter
  350. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  351. implicit exception frames for procedures with initialized variables
  352. and for constructors. The default is on for compatibility
  353. Revision 1.33 2002/10/14 19:43:41 peter
  354. * threading switch, defines the symbol FPC_THREADING
  355. Revision 1.32 2002/10/05 12:43:24 carl
  356. * fixes for Delphi 6 compilation
  357. (warning : Some features do not work under Delphi)
  358. Revision 1.31 2002/08/19 19:36:42 peter
  359. * More fixes for cross unit inlining, all tnodes are now implemented
  360. * Moved pocall_internconst to po_internconst because it is not a
  361. calling type at all and it conflicted when inlining of these small
  362. functions was requested
  363. Revision 1.30 2002/08/12 15:08:39 carl
  364. + stab register indexes for powerpc (moved from gdb to cpubase)
  365. + tprocessor enumeration moved to cpuinfo
  366. + linker in target_info is now a class
  367. * many many updates for m68k (will soon start to compile)
  368. - removed some ifdef or correct them for correct cpu
  369. Revision 1.29 2002/08/06 20:55:20 florian
  370. * first part of ppc calling conventions fix
  371. Revision 1.28 2002/07/04 20:43:00 florian
  372. * first x86-64 patches
  373. Revision 1.27 2002/07/01 18:46:22 peter
  374. * internal linker
  375. * reorganized aasm layer
  376. Revision 1.26 2002/05/18 13:34:08 peter
  377. * readded missing revisions
  378. Revision 1.25 2002/05/16 19:46:36 carl
  379. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  380. + try to fix temp allocation (still in ifdef)
  381. + generic constructor calls
  382. + start of tassembler / tmodulebase class cleanup
  383. Revision 1.23 2002/05/12 16:53:05 peter
  384. * moved entry and exitcode to ncgutil and cgobj
  385. * foreach gets extra argument for passing local data to the
  386. iterator function
  387. * -CR checks also class typecasts at runtime by changing them
  388. into as
  389. * fixed compiler to cycle with the -CR option
  390. * fixed stabs with elf writer, finally the global variables can
  391. be watched
  392. * removed a lot of routines from cga unit and replaced them by
  393. calls to cgobj
  394. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  395. u32bit then the other is typecasted also to u32bit without giving
  396. a rangecheck warning/error.
  397. * fixed pascal calling method with reversing also the high tree in
  398. the parast, detected by tcalcst3 test
  399. Revision 1.22 2002/04/21 19:02:03 peter
  400. * removed newn and disposen nodes, the code is now directly
  401. inlined from pexpr
  402. * -an option that will write the secondpass nodes to the .s file, this
  403. requires EXTDEBUG define to actually write the info
  404. * fixed various internal errors and crashes due recent code changes
  405. Revision 1.21 2002/03/24 19:05:59 carl
  406. + patch for SPARC from Mazen NEIFER
  407. Revision 1.20 2002/01/24 18:25:48 peter
  408. * implicit result variable generation for assembler routines
  409. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  410. }