2
0

globtype.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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. { Integer type corresponding to pointer size }
  29. {$ifdef cpu64bitaddr}
  30. PUint = qword;
  31. PInt = int64;
  32. {$endif cpu64bitaddr}
  33. {$ifdef cpu32bitaddr}
  34. PUint = cardinal;
  35. PInt = longint;
  36. {$endif cpu32bitaddr}
  37. {$ifdef cpu16bitaddr}
  38. PUint = word;
  39. PInt = Smallint;
  40. {$endif cpu16bitaddr}
  41. { Natural integer register type and size for the target machine }
  42. {$ifdef cpu64bitalu}
  43. AWord = qword;
  44. AInt = Int64;
  45. Const
  46. AIntBits = 64;
  47. {$endif cpu64bitalu}
  48. {$ifdef cpu32bitalu}
  49. AWord = longword;
  50. AInt = longint;
  51. Const
  52. AIntBits = 32;
  53. {$endif cpu32bitalu}
  54. {$ifdef cpu16bitalu}
  55. AWord = Word;
  56. AInt = Smallint;
  57. Const
  58. AIntBits = 16;
  59. {$endif cpu16bitalu}
  60. Type
  61. PAWord = ^AWord;
  62. PAInt = ^AInt;
  63. { This must be an ordinal type with the same size as a pointer
  64. Note: Must be unsigned! Otherwise, ugly code like
  65. pointer(-1) will result in a pointer with the value
  66. $fffffffffffffff on a 32bit machine if the compiler uses
  67. int64 constants internally (JM) }
  68. TConstPtrUInt = AWord;
  69. { Use a variant record to be sure that the array if aligned correctly }
  70. tdoublerec=record
  71. case byte of
  72. 0 : (bytes:array[0..7] of byte);
  73. 1 : (value:double);
  74. end;
  75. textendedrec=record
  76. case byte of
  77. 0 : (bytes:array[0..9] of byte);
  78. 1 : (value:extended);
  79. end;
  80. pconstset = ^tconstset;
  81. tconstset = set of 0..255;
  82. { Switches which can be changed locally }
  83. tlocalswitch = (cs_localnone,
  84. { codegen }
  85. cs_check_overflow,cs_check_range,cs_check_object,
  86. cs_check_io,cs_check_stack,
  87. cs_checkpointer,cs_check_ordinal_size,
  88. cs_generate_stackframes,cs_do_assertion,cs_generate_rtti,
  89. cs_full_boolean_eval,cs_typed_const_writable,cs_allow_enum_calc,
  90. cs_do_inline,cs_fpu_fwait,
  91. { mmx }
  92. cs_mmx,cs_mmx_saturation,
  93. { parser }
  94. cs_typed_addresses,cs_strict_var_strings,cs_ansistrings,cs_bitpacking,
  95. { macpas specific}
  96. cs_external_var, cs_externally_visible
  97. );
  98. tlocalswitches = set of tlocalswitch;
  99. { Switches which can be changed only at the beginning of a new module }
  100. tmoduleswitch = (cs_modulenone,
  101. { parser }
  102. cs_fp_emulation,cs_extsyntax,cs_openstring,
  103. { support }
  104. cs_support_goto,cs_support_macro,
  105. cs_support_c_operators,cs_static_keyword,
  106. { generation }
  107. cs_profile,cs_debuginfo,cs_compilesystem,
  108. cs_lineinfo,cs_implicit_exceptions,
  109. { linking }
  110. cs_create_smart,cs_create_dynamic,cs_create_pic,
  111. { browser switches are back }
  112. cs_browser,cs_local_browser,
  113. { target specific }
  114. cs_executable_stack
  115. );
  116. tmoduleswitches = set of tmoduleswitch;
  117. { Switches which can be changed only for a whole program/compilation,
  118. mostly set with commandline }
  119. tglobalswitch = (cs_globalnone,
  120. { parameter switches }
  121. cs_check_unit_name,cs_constructor_name,cs_support_exceptions,
  122. cs_support_c_objectivepas,
  123. { units }
  124. cs_load_objpas_unit,
  125. cs_load_gpc_unit,
  126. cs_load_fpcylix_unit,
  127. cs_support_vectors,
  128. { debuginfo }
  129. cs_use_heaptrc,cs_use_lineinfo,
  130. cs_gdb_valgrind,cs_no_regalloc,cs_stabs_preservecase,
  131. { assembling }
  132. cs_asm_leave,cs_asm_extern,cs_asm_pipe,cs_asm_source,
  133. cs_asm_regalloc,cs_asm_tempalloc,cs_asm_nodes,
  134. { linking }
  135. cs_link_nolink,cs_link_static,cs_link_smart,cs_link_shared,cs_link_deffile,
  136. cs_link_strip,cs_link_staticflag,cs_link_on_target,cs_link_extern,cs_link_opt_vtable,
  137. cs_link_opt_used_sections,cs_link_separate_dbg_file,
  138. cs_link_map,cs_link_pthread,cs_link_no_default_lib_order
  139. );
  140. tglobalswitches = set of tglobalswitch;
  141. { global switches specific to debug information }
  142. tdebugswitch = (ds_none,
  143. { enable set support in dwarf debug info, breaks gdb versions }
  144. { without support for that tag (they refuse to parse the rest }
  145. { of the debug information) }
  146. ds_dwarf_sets,
  147. { use absolute paths for include files in stabs. Pro: gdb }
  148. { always knows full path to file. Con: doesn't work anymore }
  149. { if the include file is moved (otherwise, things still work }
  150. { if your source hierarchy is the same, but has a different }
  151. { base path) }
  152. ds_stabs_abs_include_files
  153. );
  154. tdebugswitches = set of tdebugswitch;
  155. { adding a new entry here requires also adding the appropriate define in
  156. systemh.inc (FK)
  157. }
  158. tfeature = (
  159. f_heap,f_init_final,f_rtti,f_classes,f_exceptions,f_exitcode,
  160. f_ansistrings,f_widestrings,f_textio,f_consoleio,f_fileio,
  161. f_random,f_variants,f_objects,f_dynarrays,f_threading,f_commandargs,
  162. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1
  163. );
  164. tfeatures = set of tfeature;
  165. type
  166. { optimizer }
  167. toptimizerswitch = (cs_opt_none,
  168. cs_opt_level1,cs_opt_level2,cs_opt_level3,
  169. cs_opt_regvar,cs_opt_uncertain,cs_opt_size,cs_opt_stackframe,
  170. cs_opt_peephole,cs_opt_asmcse,cs_opt_loopunroll,cs_opt_tailrecursion,cs_opt_nodecse,
  171. cs_opt_nodedfa,cs_opt_loopstrength
  172. );
  173. toptimizerswitches = set of toptimizerswitch;
  174. { whole program optimizer }
  175. twpoptimizerswitch = (
  176. cs_wpo_devirtualize_calls,cs_wpo_optimize_vmts,
  177. cs_wpo_symbol_liveness
  178. );
  179. twpoptimizerswitches = set of twpoptimizerswitch;
  180. const
  181. OptimizerSwitchStr : array[toptimizerswitch] of string[10] = ('',
  182. 'LEVEL1','LEVEL2','LEVEL3',
  183. 'REGVAR','UNCERTAIN','SIZE','STACKFRAME',
  184. 'PEEPHOLE','ASMCSE','LOOPUNROLL','TAILREC','CSE','DFA','STRENGTH'
  185. );
  186. WPOptimizerSwitchStr : array [twpoptimizerswitch] of string[14] = (
  187. 'DEVIRTCALLS','OPTVMTS','SYMBOLLIVENESS'
  188. );
  189. DebugSwitchStr : array[tdebugswitch] of string[16] = ('',
  190. 'DWARFSETS','STABSABSINCLUDES');
  191. { switches being applied to all CPUs at the given level }
  192. genericlevel1optimizerswitches = [cs_opt_level1];
  193. genericlevel2optimizerswitches = [cs_opt_level2];
  194. genericlevel3optimizerswitches = [cs_opt_level3];
  195. { whole program optimizations whose information generation requires
  196. information from all loaded units
  197. }
  198. WPOptimizationsNeedingAllUnitInfo = [cs_wpo_devirtualize_calls];
  199. featurestr : array[tfeature] of string[12] = (
  200. 'HEAP','INITFINAL','RTTI','CLASSES','EXCEPTIONS','EXITCODE',
  201. 'ANSISTRINGS','WIDESTRINGS','TEXTIO','CONSOLEIO','FILEIO',
  202. 'RANDOM','VARIANTS','OBJECTS','DYNARRAYS','THREADING','COMMANDARGS',
  203. 'PROCESSES','STACKCHECK','DYNLIBS','SOFTFPU','OBJECTIVEC1'
  204. );
  205. type
  206. { Switches which can be changed by a mode (fpc,tp7,delphi) }
  207. tmodeswitch = (m_none,m_all, { needed for keyword }
  208. { generic }
  209. m_fpc,m_objfpc,m_delphi,m_tp7,m_mac,
  210. {$ifdef fpc_mode}m_gpc,{$endif}
  211. { more specific }
  212. m_class, { delphi class model }
  213. m_objpas, { load objpas unit }
  214. m_result, { result in functions }
  215. m_string_pchar, { pchar 2 string conversion }
  216. m_cvar_support, { cvar variable directive }
  217. m_nested_comment, { nested comments }
  218. m_tp_procvar, { tp style procvars (no @ needed) }
  219. m_mac_procvar, { macpas style procvars }
  220. m_repeat_forward, { repeating forward declarations is needed }
  221. m_pointer_2_procedure, { allows the assignement of pointers to
  222. procedure variables }
  223. m_autoderef, { does auto dereferencing of struct. vars }
  224. m_initfinal, { initialization/finalization for units }
  225. m_add_pointer, { allow pointer add/sub operations }
  226. m_default_ansistring, { ansistring turned on by default }
  227. m_out, { support the calling convention OUT }
  228. m_default_para, { support default parameters }
  229. m_hintdirective, { support hint directives }
  230. m_duplicate_names, { allow locals/paras to have duplicate names of globals }
  231. m_property, { allow properties }
  232. m_default_inline, { allow inline proc directive }
  233. m_except, { allow exception-related keywords }
  234. m_objectivec1 { support interfacing with Objective-C (1.0) }
  235. );
  236. tmodeswitches = set of tmodeswitch;
  237. { Win32, OS/2 & MacOS application types }
  238. tapptype = (
  239. app_none,
  240. app_native,
  241. app_gui, { graphic user-interface application}
  242. app_cui, { console application}
  243. app_fs, { full-screen type application (OS/2 and EMX only) }
  244. app_tool, { tool application, (MPW tool for MacOS, MacOS only)}
  245. app_arm7,
  246. app_arm9,
  247. app_bundle { dynamically loadable bundle, Darwin only }
  248. );
  249. { interface types }
  250. tinterfacetypes = (
  251. it_interfacecom,
  252. it_interfacecorba
  253. );
  254. { currently parsed block type }
  255. tblock_type = (bt_none,
  256. bt_general,bt_type,bt_const,bt_const_type,bt_var,bt_var_type,bt_except,bt_body
  257. );
  258. { Temp types }
  259. ttemptype = (tt_none,
  260. tt_free,tt_normal,tt_persistent,
  261. tt_noreuse,tt_freenoreuse);
  262. ttemptypeset = set of ttemptype;
  263. { calling convention for tprocdef and tprocvardef }
  264. tproccalloption=(pocall_none,
  265. { procedure uses C styled calling }
  266. pocall_cdecl,
  267. { C++ calling conventions }
  268. pocall_cppdecl,
  269. { Far16 for OS/2 }
  270. pocall_far16,
  271. { Old style FPC default calling }
  272. pocall_oldfpccall,
  273. { Procedure has compiler magic}
  274. pocall_internproc,
  275. { procedure is a system call, applies e.g. to MorphOS and PalmOS }
  276. pocall_syscall,
  277. { pascal standard left to right }
  278. pocall_pascal,
  279. { procedure uses register (fastcall) calling }
  280. pocall_register,
  281. { safe call calling conventions }
  282. pocall_safecall,
  283. { procedure uses stdcall call }
  284. pocall_stdcall,
  285. { Special calling convention for cpus without a floating point
  286. unit. Floating point numbers are passed in integer registers
  287. instead of floating point registers. Depending on the other
  288. available calling conventions available for the cpu
  289. this replaces either pocall_fastcall or pocall_stdcall.
  290. }
  291. pocall_softfloat,
  292. { Metrowerks Pascal. Special case on Mac OS (X): passes all }
  293. { constant records by reference. }
  294. pocall_mwpascal
  295. );
  296. tproccalloptions = set of tproccalloption;
  297. const
  298. proccalloptionStr : array[tproccalloption] of string[14]=('',
  299. 'CDecl',
  300. 'CPPDecl',
  301. 'Far16',
  302. 'OldFPCCall',
  303. 'InternProc',
  304. 'SysCall',
  305. 'Pascal',
  306. 'Register',
  307. 'SafeCall',
  308. 'StdCall',
  309. 'SoftFloat',
  310. 'MWPascal'
  311. );
  312. { Default calling convention }
  313. {$ifdef x86}
  314. pocall_default = pocall_register;
  315. {$else}
  316. pocall_default = pocall_stdcall;
  317. {$endif}
  318. modeswitchstr : array[tmodeswitch] of string[18] = ('','',
  319. '','','','','',
  320. {$ifdef fpc_mode}'',{$endif}
  321. { more specific }
  322. 'CLASS',
  323. 'OBJPAS',
  324. 'RESULT',
  325. 'PCHARTOSTRING',
  326. 'CVAR',
  327. 'NESTEDCOMMENTS',
  328. 'CLASSICPROCVARS',
  329. 'MACPROCVARS',
  330. 'REPEATFORWARD',
  331. 'POINTERTOPROCVAR',
  332. 'AUTODEREF',
  333. 'INITFINAL',
  334. 'POINTERARITHMETICS',
  335. 'ANSISTRINGS',
  336. 'OUT',
  337. 'DEFAULTPARAMETERS',
  338. 'HINTDIRECTIVE',
  339. 'DUPLICATELOCALS',
  340. 'PROPERTIES',
  341. 'ALLOWINLINE',
  342. 'EXCEPTIONS',
  343. 'OBJECTIVEC1');
  344. type
  345. tprocinfoflag=(
  346. { procedure has at least one assembler block }
  347. pi_has_assembler_block,
  348. { procedure does a call }
  349. pi_do_call,
  350. { procedure has a try statement = no register optimization }
  351. pi_uses_exceptions,
  352. { procedure is declared as @var(assembler), don't optimize}
  353. pi_is_assembler,
  354. { procedure contains data which needs to be finalized }
  355. pi_needs_implicit_finally,
  356. { procedure has the implicit try..finally generated }
  357. pi_has_implicit_finally,
  358. { procedure uses fpu}
  359. pi_uses_fpu,
  360. { procedure uses GOT for PIC code }
  361. pi_needs_got,
  362. { references var/proc/type/const in static symtable,
  363. i.e. not allowed for inlining from other units }
  364. pi_uses_static_symtable,
  365. { set if the procedure has to push parameters onto the stack }
  366. pi_has_stackparameter,
  367. { set if the procedure has at least one got }
  368. pi_has_goto,
  369. { calls itself recursive }
  370. pi_is_recursive,
  371. { stack frame optimization not possible (only on x86 probably) }
  372. pi_needs_stackframe,
  373. { set if the procedure has at least one register saved on the stack }
  374. pi_has_saved_regs,
  375. { dfa was generated for this proc }
  376. pi_dfaavailable
  377. );
  378. tprocinfoflags=set of tprocinfoflag;
  379. type
  380. { float types }
  381. tfloattype = (
  382. s32real,s64real,s80real,
  383. s64comp,s64currency,s128real
  384. );
  385. type
  386. { register allocator live range extension direction }
  387. TRADirection = (rad_forward, rad_backwards, rad_backwards_reinit);
  388. type
  389. TIDString = string[maxidlen];
  390. tnormalset = set of byte; { 256 elements set }
  391. pnormalset = ^tnormalset;
  392. pboolean = ^boolean;
  393. pdouble = ^double;
  394. pbyte = ^byte;
  395. pword = ^word;
  396. plongint = ^longint;
  397. plongintarray = plongint;
  398. pfileposinfo = ^tfileposinfo;
  399. tfileposinfo = record
  400. { if types of column or fileindex are changed, modify tcompilerppufile.putposinfo }
  401. line : longint;
  402. column : word;
  403. fileindex : word;
  404. moduleindex : word;
  405. end;
  406. {$ifndef xFPC}
  407. type
  408. pguid = ^tguid;
  409. tguid = packed record
  410. D1: LongWord;
  411. D2: Word;
  412. D3: Word;
  413. D4: array[0..7] of Byte;
  414. end;
  415. {$endif}
  416. const
  417. { link options }
  418. link_none = $0;
  419. link_always = $1;
  420. link_static = $2;
  421. link_smart = $4;
  422. link_shared = $8;
  423. implementation
  424. end.