globtype.pas 18 KB

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