globtype.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  3. Global types
  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 globtype;
  18. {$i fpcdefs.inc}
  19. interface
  20. const
  21. maxidlen = 127;
  22. type
  23. { TCmdStr is used to pass command line parameters to an external program to be
  24. executed from the FPC application. In some circomstances, this can be more
  25. than 255 characters. That's why using Ansi Strings}
  26. TCmdStr = AnsiString;
  27. TPathStr = String;
  28. { Natural integer register type and size for the target machine }
  29. {$ifdef cpu64bit}
  30. AWord = qword;
  31. AInt = Int64;
  32. Const
  33. AIntBits = 64;
  34. {$else cpu64bit}
  35. AWord = longword;
  36. AInt = longint;
  37. Const
  38. AIntBits = 32;
  39. {$endif cpu64bit}
  40. Type
  41. PAWord = ^AWord;
  42. PAInt = ^AInt;
  43. { This must be an ordinal type with the same size as a pointer
  44. Note: Must be unsigned! Otherwise, ugly code like
  45. pointer(-1) will result in a pointer with the value
  46. $fffffffffffffff on a 32bit machine if the compiler uses
  47. int64 constants internally (JM) }
  48. TConstPtrUInt = AWord;
  49. { Use a variant record to be sure that the array if aligned correctly }
  50. tdoublerec=record
  51. case byte of
  52. 0 : (bytes:array[0..7] of byte);
  53. 1 : (value:double);
  54. end;
  55. textendedrec=record
  56. case byte of
  57. 0 : (bytes:array[0..9] of byte);
  58. 1 : (value:extended);
  59. end;
  60. pconstset = ^tconstset;
  61. tconstset = set of 0..255;
  62. { Switches which can be changed locally }
  63. tlocalswitch = (cs_localnone,
  64. { codegen }
  65. cs_check_overflow,cs_check_range,cs_check_object,
  66. cs_check_io,cs_check_stack,
  67. cs_checkpointer,
  68. cs_generate_stackframes,cs_do_assertion,cs_generate_rtti,
  69. cs_full_boolean_eval,cs_typed_const_writable,cs_allow_enum_calc,
  70. cs_do_inline,cs_fpu_fwait,
  71. { mmx }
  72. cs_mmx,cs_mmx_saturation,
  73. { parser }
  74. cs_typed_addresses,cs_strict_var_strings,cs_ansistrings,cs_bitpacking,
  75. { macpas specific}
  76. cs_external_var, cs_externally_visible
  77. );
  78. tlocalswitches = set of tlocalswitch;
  79. { Switches which can be changed only at the beginning of a new module }
  80. tmoduleswitch = (cs_modulenone,
  81. { parser }
  82. cs_fp_emulation,cs_extsyntax,cs_openstring,
  83. { support }
  84. cs_support_goto,cs_support_macro,
  85. cs_support_c_operators,cs_static_keyword,
  86. { generation }
  87. cs_profile,cs_debuginfo,cs_compilesystem,
  88. cs_lineinfo,cs_implicit_exceptions,
  89. { linking }
  90. cs_create_smart,cs_create_dynamic,cs_create_pic,
  91. { browser switches are back }
  92. cs_browser,cs_local_browser
  93. );
  94. tmoduleswitches = set of tmoduleswitch;
  95. { Switches which can be changed only for a whole program/compilation,
  96. mostly set with commandline }
  97. tglobalswitch = (cs_globalnone,
  98. { parameter switches }
  99. cs_check_unit_name,cs_constructor_name,cs_support_exceptions,
  100. { units }
  101. cs_load_objpas_unit,
  102. cs_load_gpc_unit,
  103. cs_load_fpcylix_unit,
  104. cs_support_vectors,
  105. { debuginfo }
  106. cs_use_heaptrc,cs_use_lineinfo,
  107. cs_gdb_valgrind,cs_no_regalloc,cs_stabs_preservecase,
  108. { assembling }
  109. cs_asm_leave,cs_asm_extern,cs_asm_pipe,cs_asm_source,
  110. cs_asm_regalloc,cs_asm_tempalloc,cs_asm_nodes,
  111. { linking }
  112. cs_link_nolink,cs_link_static,cs_link_smart,cs_link_shared,cs_link_deffile,
  113. cs_link_strip,cs_link_staticflag,cs_link_on_target,cs_link_extern,cs_link_opt_vtable,
  114. cs_link_opt_used_sections,cs_link_separate_dbg_file,
  115. cs_link_map,cs_link_pthread,cs_link_no_default_lib_order
  116. );
  117. tglobalswitches = set of tglobalswitch;
  118. { adding a new entry here requires also adding the appropriate define in
  119. systemh.inc (FK)
  120. }
  121. tfeature = (
  122. f_heap,f_init_final,f_rtti,f_classes,f_exceptions,f_exitcode,
  123. f_ansistrings,f_widestrings,f_textio,f_consoleio,f_fileio,
  124. f_random,f_variants,f_objects,f_dynarrays,f_threading,f_commandargs,
  125. f_processes,f_stackcheck
  126. );
  127. tfeatures = set of tfeature;
  128. type
  129. { optimizer }
  130. toptimizerswitch = (cs_opt_none,
  131. cs_opt_level1,cs_opt_level2,cs_opt_level3,
  132. cs_opt_regvar,cs_opt_uncertain,cs_opt_size,cs_opt_stackframe,
  133. cs_opt_peephole,cs_opt_asmcse,cs_opt_loopunroll,cs_opt_tailrecursion,cs_opt_nodecse,
  134. cs_opt_nodedfa
  135. );
  136. toptimizerswitches = set of toptimizerswitch;
  137. const
  138. OptimizerSwitchStr : array[toptimizerswitch] of string[10] = ('',
  139. 'LEVEL1','LEVEL2','LEVEL3',
  140. 'REGVAR','UNCERTAIN','SIZE','STACKFRAME',
  141. 'PEEPHOLE','ASMCSE','LOOPUNROLL','TAILREC','CSE','DFA'
  142. );
  143. { switches being applied to all CPUs at the given level }
  144. genericlevel1optimizerswitches = [cs_opt_level1];
  145. genericlevel2optimizerswitches = [cs_opt_level2];
  146. genericlevel3optimizerswitches = [cs_opt_level3];
  147. featurestr : array[tfeature] of string[12] = (
  148. 'HEAP','INITFINAL','RTTI','CLASSES','EXCEPTIONS','EXITCODE',
  149. 'ANSISTRINGS','WIDESTRINGS','TEXTIO','CONSOLEIO','FILEIO',
  150. 'RANDOM','VARIANTS','OBJECTS','DYNARRAYS','THREADING','COMMANDARGS',
  151. 'PROCESSES','STACKCHECK'
  152. );
  153. type
  154. { Switches which can be changed by a mode (fpc,tp7,delphi) }
  155. tmodeswitch = (m_none,m_all, { needed for keyword }
  156. { generic }
  157. m_fpc,m_objfpc,m_delphi,m_tp7,m_mac,
  158. {$ifdef fpc_mode}m_gpc,{$endif}
  159. { more specific }
  160. m_class, { delphi class model }
  161. m_objpas, { load objpas unit }
  162. m_result, { result in functions }
  163. m_string_pchar, { pchar 2 string conversion }
  164. m_cvar_support, { cvar variable directive }
  165. m_nested_comment, { nested comments }
  166. m_tp_procvar, { tp style procvars (no @ needed) }
  167. m_mac_procvar, { macpas style procvars }
  168. m_repeat_forward, { repeating forward declarations is needed }
  169. m_pointer_2_procedure, { allows the assignement of pointers to
  170. procedure variables }
  171. m_autoderef, { does auto dereferencing of struct. vars }
  172. m_initfinal, { initialization/finalization for units }
  173. m_add_pointer, { allow pointer add/sub operations }
  174. m_default_ansistring, { ansistring turned on by default }
  175. m_out, { support the calling convention OUT }
  176. m_default_para, { support default parameters }
  177. m_hintdirective, { support hint directives }
  178. m_duplicate_names, { allow locals/paras to have duplicate names of globals }
  179. m_property, { allow properties }
  180. m_default_inline, { allow inline proc directive }
  181. m_except { allow exception-related keywords }
  182. );
  183. tmodeswitches = set of tmodeswitch;
  184. { Win32, OS/2 & MacOS application types }
  185. tapptype = (
  186. app_none,
  187. app_native,
  188. app_gui, { graphic user-interface application}
  189. app_cui, { console application}
  190. app_fs, { full-screen type application (OS/2 and EMX only) }
  191. app_tool, { tool application, (MPW tool for MacOS, MacOS only)}
  192. app_arm7,
  193. app_arm9
  194. );
  195. { interface types }
  196. tinterfacetypes = (
  197. it_interfacecom,
  198. it_interfacecorba
  199. );
  200. { currently parsed block type }
  201. tblock_type = (bt_none,
  202. bt_general,bt_type,bt_const,bt_except,bt_body,bt_specialize
  203. );
  204. { Temp types }
  205. ttemptype = (tt_none,
  206. tt_free,tt_normal,tt_persistent,
  207. tt_noreuse,tt_freenoreuse);
  208. ttemptypeset = set of ttemptype;
  209. { calling convention for tprocdef and tprocvardef }
  210. tproccalloption=(pocall_none,
  211. { procedure uses C styled calling }
  212. pocall_cdecl,
  213. { C++ calling conventions }
  214. pocall_cppdecl,
  215. { Far16 for OS/2 }
  216. pocall_far16,
  217. { Old style FPC default calling }
  218. pocall_oldfpccall,
  219. { Procedure has compiler magic}
  220. pocall_internproc,
  221. { procedure is a system call, applies e.g. to MorphOS and PalmOS }
  222. pocall_syscall,
  223. { pascal standard left to right }
  224. pocall_pascal,
  225. { procedure uses register (fastcall) calling }
  226. pocall_register,
  227. { safe call calling conventions }
  228. pocall_safecall,
  229. { procedure uses stdcall call }
  230. pocall_stdcall,
  231. { Special calling convention for cpus without a floating point
  232. unit. Floating point numbers are passed in integer registers
  233. instead of floating point registers. Depending on the other
  234. available calling conventions available for the cpu
  235. this replaces either pocall_fastcall or pocall_stdcall.
  236. }
  237. pocall_softfloat,
  238. { Metrowerks Pascal. Special case on Mac OS (X): passes all }
  239. { constant records by reference. }
  240. pocall_mwpascal
  241. );
  242. tproccalloptions = set of tproccalloption;
  243. const
  244. proccalloptionStr : array[tproccalloption] of string[14]=('',
  245. 'CDecl',
  246. 'CPPDecl',
  247. 'Far16',
  248. 'OldFPCCall',
  249. 'InternProc',
  250. 'SysCall',
  251. 'Pascal',
  252. 'Register',
  253. 'SafeCall',
  254. 'StdCall',
  255. 'SoftFloat',
  256. 'MWPascal'
  257. );
  258. { Default calling convention }
  259. {$ifdef x86}
  260. pocall_default = pocall_register;
  261. {$else}
  262. pocall_default = pocall_stdcall;
  263. {$endif}
  264. type
  265. tprocinfoflag=(
  266. { procedure has at least one assembler block }
  267. pi_has_assembler_block,
  268. { procedure does a call }
  269. pi_do_call,
  270. { procedure has a try statement = no register optimization }
  271. pi_uses_exceptions,
  272. { procedure is declared as @var(assembler), don't optimize}
  273. pi_is_assembler,
  274. { procedure contains data which needs to be finalized }
  275. pi_needs_implicit_finally,
  276. { procedure has the implicit try..finally generated }
  277. pi_has_implicit_finally,
  278. { procedure uses fpu}
  279. pi_uses_fpu,
  280. { procedure uses GOT for PIC code }
  281. pi_needs_got,
  282. { references var/proc/type/const in static symtable,
  283. i.e. not allowed for inlining from other units }
  284. pi_uses_static_symtable,
  285. { set if the procedure has to push parameters onto the stack }
  286. pi_has_stackparameter,
  287. { set if the procedure has at least one got }
  288. pi_has_goto,
  289. { calls itself recursive }
  290. pi_is_recursive,
  291. { stack frame optimization not possible (only on x86 probably) }
  292. pi_needs_stackframe
  293. );
  294. tprocinfoflags=set of tprocinfoflag;
  295. type
  296. TIDString = string[maxidlen];
  297. tnormalset = set of byte; { 256 elements set }
  298. pnormalset = ^tnormalset;
  299. pboolean = ^boolean;
  300. pdouble = ^double;
  301. pbyte = ^byte;
  302. pword = ^word;
  303. plongint = ^longint;
  304. plongintarray = plongint;
  305. pfileposinfo = ^tfileposinfo;
  306. tfileposinfo = record
  307. line : longint;
  308. column : word;
  309. fileindex : word;
  310. moduleindex : word;
  311. end;
  312. {$ifndef xFPC}
  313. type
  314. pguid = ^tguid;
  315. tguid = packed record
  316. D1: LongWord;
  317. D2: Word;
  318. D3: Word;
  319. D4: array[0..7] of Byte;
  320. end;
  321. {$endif}
  322. const
  323. { link options }
  324. link_none = $0;
  325. link_always = $1;
  326. link_static = $2;
  327. link_smart = $4;
  328. link_shared = $8;
  329. implementation
  330. end.