globtype.pas 15 KB

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