globtype.pas 18 KB

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