globtype.pas 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  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 = AnsiString;
  28. {$ifdef symansistr}
  29. TSymStr = AnsiString;
  30. {$else symansistr}
  31. TSymStr = ShortString;
  32. {$endif symansistr}
  33. PSymStr = ^TSymStr;
  34. TByteDynArray = array of byte;
  35. TAnsiCharDynArray = array of ansichar;
  36. Int32 = Longint;
  37. { Integer type corresponding to pointer size }
  38. {$ifdef cpu64bitaddr}
  39. PUint = qword;
  40. PInt = int64;
  41. {$endif cpu64bitaddr}
  42. {$ifdef cpu32bitaddr}
  43. PUint = cardinal;
  44. PInt = longint;
  45. {$endif cpu32bitaddr}
  46. {$ifdef cpu16bitaddr}
  47. PUint = word;
  48. PInt = Smallint;
  49. {$endif cpu16bitaddr}
  50. { Natural integer register type and size for the target machine }
  51. {$ifdef cpu64bitalu}
  52. AWord = qword;
  53. AInt = Int64;
  54. Const
  55. AIntBits = 64;
  56. {$endif cpu64bitalu}
  57. {$ifdef cpu32bitalu}
  58. AWord = longword;
  59. AInt = longint;
  60. Const
  61. AIntBits = 32;
  62. {$endif cpu32bitalu}
  63. {$ifdef cpu16bitalu}
  64. AWord = Word;
  65. AInt = Smallint;
  66. Const
  67. AIntBits = 16;
  68. {$endif cpu16bitalu}
  69. {$ifdef cpu8bitalu}
  70. AWord = Byte;
  71. AInt = Shortint;
  72. Const
  73. AIntBits = 8;
  74. {$endif cpu8bitalu}
  75. { Maximum possible size of locals space (stack frame) }
  76. Const
  77. {$if defined(cpu16bitaddr)}
  78. MaxLocalsSize = High(PUint);
  79. {$else}
  80. MaxLocalsSize = High(longint) - 15;
  81. {$endif}
  82. Type
  83. PAWord = ^AWord;
  84. PAInt = ^AInt;
  85. { target cpu specific type used to store data sizes }
  86. {$ifdef cpu16bitaddr}
  87. { on small CPUs such as i8086, we use LongInt to support data structures
  88. larger than 32767 bytes and up to 65535 bytes in size. Since asizeint
  89. must be signed, we use LongInt/LongWord. }
  90. ASizeInt = LongInt;
  91. ASizeUInt = LongWord;
  92. {$else cpu16bitaddr}
  93. ASizeInt = PInt;
  94. ASizeUInt = PUInt;
  95. {$endif cpu16bitaddr}
  96. { type used for handling constants etc. in the code generator }
  97. TCGInt = Int64;
  98. { This must be an ordinal type with the same size as a pointer
  99. Note: Must be unsigned! Otherwise, ugly code like
  100. pointer(-1) will result in a pointer with the value
  101. $fffffffffffffff on a 32bit machine if the compiler uses
  102. int64 constants internally (JM) }
  103. {$ifdef i8086}
  104. TConstPtrUInt = LongWord; { 32-bit for far pointers support }
  105. {$else i8086}
  106. TConstPtrUInt = PUint;
  107. {$endif i8086}
  108. { Use a variant record to be sure that the array if aligned correctly }
  109. tcompdoublerec=record
  110. case byte of
  111. 0 : (bytes:array[0..7] of byte);
  112. 1 : (value:double);
  113. end;
  114. { Use a variant record to be sure that the array if aligned correctly }
  115. tcompsinglerec=record
  116. case byte of
  117. 0 : (bytes:array[0..3] of byte);
  118. 1 : (value:single);
  119. end;
  120. tcompextendedrec=record
  121. case byte of
  122. 0 : (bytes:array[0..9] of byte);
  123. 1 : (value:extended);
  124. end;
  125. pconstset = ^tconstset;
  126. tconstset = set of 0..255;
  127. { Switches which can be changed locally }
  128. tlocalswitch = (cs_localnone,
  129. { codegen }
  130. cs_check_overflow,cs_check_range,cs_check_object,
  131. cs_check_io,cs_check_stack,
  132. cs_checkpointer,cs_check_ordinal_size,
  133. cs_generate_stackframes,cs_do_assertion,cs_generate_rtti,
  134. cs_full_boolean_eval,cs_typed_const_writable,cs_allow_enum_calc,
  135. cs_do_inline,cs_fpu_fwait,cs_ieee_errors,
  136. cs_check_low_addr_load,cs_imported_data,
  137. cs_excessprecision,cs_check_fpu_exceptions,
  138. cs_check_all_case_coverage,
  139. { mmx }
  140. cs_mmx,cs_mmx_saturation,
  141. { parser }
  142. cs_typed_addresses,cs_strict_var_strings,cs_refcountedstrings,
  143. cs_bitpacking,cs_varpropsetter,cs_scopedenums,cs_pointermath,
  144. cs_openstring,
  145. { macpas specific}
  146. cs_external_var, cs_externally_visible,
  147. { jvm specific }
  148. cs_check_var_copyout,
  149. cs_zerobasedstrings,
  150. { i8086 specific }
  151. cs_force_far_calls,
  152. cs_hugeptr_arithmetic_normalization,
  153. cs_hugeptr_comparison_normalization,
  154. cs_legacyifend
  155. );
  156. tlocalswitches = set of tlocalswitch;
  157. { Switches which can be changed only at the beginning of a new module }
  158. tmoduleswitch = (cs_modulenone,
  159. { parser }
  160. cs_fp_emulation,cs_extsyntax,
  161. { support }
  162. cs_support_goto,cs_support_macro,
  163. cs_support_c_operators,
  164. { generation }
  165. cs_profile,cs_debuginfo,cs_compilesystem,
  166. cs_lineinfo,cs_implicit_exceptions,
  167. cs_explicit_codepage,cs_system_codepage,
  168. { linking }
  169. cs_create_smart,cs_create_dynamic,cs_create_pic,
  170. { browser switches are back }
  171. cs_browser,cs_local_browser,
  172. { target specific }
  173. cs_executable_stack,
  174. { i8086 specific }
  175. cs_huge_code,
  176. cs_win16_smartcallbacks,
  177. { Record usage of checkpointer experimental feature }
  178. cs_checkpointer_called,
  179. { enable link time optimisation (both unit code generation and optimising the whole program/library) }
  180. cs_lto,
  181. { LLVM sanitizers }
  182. cs_sanitize_address
  183. );
  184. tmoduleswitches = set of tmoduleswitch;
  185. { Switches which can be changed only for a whole program/compilation,
  186. mostly set with commandline }
  187. tglobalswitch = (cs_globalnone,
  188. { parameter switches }
  189. cs_check_unit_name,cs_constructor_name,cs_support_exceptions,
  190. cs_support_c_objectivepas,
  191. cs_transparent_file_names,
  192. { units }
  193. cs_load_objpas_unit,
  194. cs_load_gpc_unit,
  195. cs_load_fpcylix_unit,
  196. cs_support_vectors,
  197. { debuginfo }
  198. cs_use_heaptrc,cs_use_lineinfo,
  199. cs_gdb_valgrind,cs_no_regalloc,cs_stabs_preservecase,
  200. { assembling }
  201. cs_asm_leave,cs_asm_extern,cs_asm_pipe,cs_asm_source,cs_asm_rtti_source,
  202. cs_asm_regalloc,cs_asm_tempalloc,cs_asm_nodes,cs_asm_pre_binutils_2_25,
  203. { linking }
  204. cs_link_nolink,cs_link_static,cs_link_smart,cs_link_shared,cs_link_deffile,
  205. cs_link_strip,cs_link_staticflag,cs_link_on_target,cs_link_extern,cs_link_opt_vtable,
  206. cs_link_opt_used_sections,cs_link_separate_dbg_file,
  207. cs_link_map,cs_link_pthread,cs_link_no_default_lib_order,
  208. cs_link_native,
  209. cs_link_pre_binutils_2_19,
  210. cs_link_vlink,
  211. cs_link_discard_start,cs_link_discard_zeroreg_sp,cs_link_discard_copydata,cs_link_discard_jmp_main,
  212. { disable LTO for the system unit (needed to work around linker bugs on macOS) }
  213. cs_lto_nosystem,
  214. cs_assemble_on_target,
  215. { use a memory model which allows large data structures, e.g. > 2 GB static data on x86-64 targets
  216. this not supported on all OSes }
  217. cs_large,
  218. { if applicable, the compiler generates an executable in uf2 format }
  219. cs_generate_uf2,
  220. { Use ld.lld linker }
  221. cs_link_lld
  222. );
  223. tglobalswitches = set of tglobalswitch;
  224. { global switches specific to debug information }
  225. tdebugswitch = (ds_none,
  226. { enable set support in dwarf debug info, breaks gdb versions }
  227. { without support for that tag (they refuse to parse the rest }
  228. { of the debug information) }
  229. ds_dwarf_sets,
  230. { use absolute paths for include files in stabs. Pro: gdb }
  231. { always knows full path to file. Con: doesn't work anymore }
  232. { if the include file is moved (otherwise, things still work }
  233. { if your source hierarchy is the same, but has a different }
  234. { base path) }
  235. ds_stabs_abs_include_files,
  236. { prefix method names by "classname__" in DWARF (like is done }
  237. { for Stabs); not enabled by default, because otherwise once }
  238. { support for calling methods has been added to gdb, you'd }
  239. { always have to type classinstance.classname__methodname() }
  240. ds_dwarf_method_class_prefix,
  241. { Simulate C++ debug information in DWARF. It can be used for }
  242. { debuggers, which do not support Pascal. }
  243. ds_dwarf_cpp,
  244. { emit line number information in LINNUM/LINNUM32 records, }
  245. { using the MS LINK format, for targets that use the OMF }
  246. { object format. This option is useful for compatibility with }
  247. { the Open Watcom Debugger and the Open Watcom Linker. Even }
  248. { though, they support and use dwarf debug information in the }
  249. { final executable file, they expect LINNUM records in the }
  250. { object modules for the line number information. }
  251. ds_dwarf_omf_linnum
  252. );
  253. tdebugswitches = set of tdebugswitch;
  254. { global target-specific switches }
  255. ttargetswitch = (ts_none,
  256. { generate code that results in smaller TOCs than normal (AIX) }
  257. ts_small_toc,
  258. { for the JVM target: generate integer array initializations via string
  259. constants in order to reduce the generated code size (Java routines
  260. are limited to 64kb of bytecode) }
  261. ts_compact_int_array_init,
  262. { for the JVM target: intialize enum fields in constructors with the
  263. enum class instance corresponding to ordinal value 0 (not done by
  264. default because this initialization can only be performed after the
  265. inherited constructors have run, and if they call a virtual method
  266. of the current class, then this virtual method may already have
  267. initialized that field with another value and the constructor
  268. initialization will result in data loss }
  269. ts_jvm_enum_field_init,
  270. { when automatically generating getters/setters for properties, use
  271. these strings as prefixes for the generated getters/setter names }
  272. ts_auto_getter_prefix,
  273. ts_auto_setter_predix,
  274. ts_thumb_interworking,
  275. { lowercase the first character of routine names, used to generate
  276. names that are compliant with Java coding standards from code
  277. written according to Delphi coding standards }
  278. ts_lowercase_proc_start,
  279. { initialise local variables on the JVM target so you won't get
  280. accidental uses of uninitialised values }
  281. ts_init_locals,
  282. { emit a CLD instruction before using the x86 string instructions }
  283. ts_cld,
  284. { increment BP before pushing it in the function prologue and decrement
  285. it after popping it in the function epilogue, iff the function is
  286. going to terminate with a far ret. Thus, the BP value pushed on the
  287. stack becomes odd if the function is far and even if the function is
  288. near. This allows walking the BP chain on the stack and e.g.
  289. obtaining a stack trace even if the program uses a mixture of near
  290. and far calls. This is also required for Win16 real mode, because it
  291. allows Windows to move code segments around (in order to defragment
  292. memory) and then walk through the stacks of all running programs and
  293. update the segment values of the segment that has moved. }
  294. ts_x86_far_procs_push_odd_bp,
  295. { no exception support. Raising an exception will abort the program. }
  296. ts_wasm_no_exceptions,
  297. { Branchful exceptions support. A global threadvar is checked after each function call. }
  298. ts_wasm_bf_exceptions,
  299. { JavaScript-based exception support }
  300. ts_wasm_js_exceptions,
  301. { native WebAssembly exceptions support:
  302. https://github.com/WebAssembly/exception-handling/blob/master/proposals/exception-handling/Exceptions.md }
  303. ts_wasm_native_exceptions,
  304. { support multithreading via the WebAssembly threading proposal:
  305. https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md }
  306. ts_wasm_threads,
  307. { use saturating (nontrapping) float to int conversion instructions:
  308. https://github.com/WebAssembly/spec/blob/main/proposals/nontrapping-float-to-int-conversion/Overview.md }
  309. ts_wasm_saturating_float_to_int
  310. );
  311. ttargetswitches = set of ttargetswitch;
  312. { adding a new entry here requires also adding the appropriate define in
  313. systemh.inc (FK)
  314. }
  315. tfeature = (
  316. f_heap,f_init_final,f_rtti,f_classes,f_exceptions,f_exitcode,
  317. f_ansistrings,f_widestrings,f_textio,f_consoleio,f_fileio,
  318. f_random,f_variants,f_objects,f_dynarrays,f_threading,f_commandargs,
  319. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources,
  320. f_unicodestring
  321. );
  322. tfeatures = set of tfeature;
  323. type
  324. { optimizer }
  325. toptimizerswitch = (
  326. cs_opt_level1,cs_opt_level2,cs_opt_level3,cs_opt_level4,
  327. cs_opt_regvar,cs_opt_uncertain,cs_opt_size,cs_opt_stackframe,
  328. cs_opt_peephole,cs_opt_loopunroll,cs_opt_tailrecursion,cs_opt_nodecse,
  329. cs_opt_nodedfa,cs_opt_loopstrength,cs_opt_scheduler,cs_opt_autoinline,cs_useebp,cs_userbp,
  330. cs_opt_reorder_fields,cs_opt_fastmath,
  331. { Allow removing expressions whose result is not used, even when this
  332. can change program behaviour (range check errors disappear,
  333. access violations due to invalid pointer derefences disappear, ...).
  334. Note: it does not (and must not) remove expressions that have
  335. explicit side-effects, only implicit side-effects (like the ones
  336. mentioned before) can disappear.
  337. }
  338. cs_opt_dead_values,
  339. { compiler checks for empty procedures/methods and removes calls to them if possible }
  340. cs_opt_remove_empty_proc,
  341. cs_opt_constant_propagate,
  342. cs_opt_dead_store_eliminate,
  343. cs_opt_forcenostackframe,
  344. cs_opt_use_load_modify_store,
  345. cs_opt_unused_para,
  346. cs_opt_consts,
  347. cs_opt_forloop
  348. );
  349. toptimizerswitches = set of toptimizerswitch;
  350. { whole program optimizer }
  351. twpoptimizerswitch = (
  352. cs_wpo_devirtualize_calls,cs_wpo_optimize_vmts,
  353. cs_wpo_symbol_liveness
  354. );
  355. twpoptimizerswitches = set of twpoptimizerswitch;
  356. { platform triplet style }
  357. ttripletstyle = (
  358. { llvm toolchain parameters }
  359. triplet_llvm,
  360. { llvm run time library file names }
  361. triplet_llvmrt
  362. { , triple_gnu }
  363. );
  364. { module flags (extra unit flags not in ppu header) }
  365. tmoduleflag = (
  366. mf_init, { unit has initialization section }
  367. mf_finalize, { unit has finalization section }
  368. mf_checkpointer_called, { Unit uses experimental checkpointer test code }
  369. mf_has_resourcestrings, { unit has resource string section }
  370. mf_release, { unit was compiled with -Ur option }
  371. mf_threadvars, { unit has threadvars }
  372. mf_has_stabs_debuginfo, { this unit has stabs debuginfo generated }
  373. mf_local_symtable, { this unit has a local symtable stored }
  374. mf_uses_variants, { this unit uses variants }
  375. mf_has_resourcefiles, { this unit has external resources (using $R directive)}
  376. mf_has_exports, { this module or a used unit has exports }
  377. mf_has_dwarf_debuginfo, { this unit has dwarf debuginfo generated }
  378. mf_wideinits, { this unit has winlike widestring typed constants }
  379. mf_classinits, { this unit has class constructors/destructors }
  380. mf_resstrinits, { this unit has string consts referencing resourcestrings }
  381. mf_i8086_far_code, { this unit uses an i8086 memory model with far code (i.e. medium, large or huge) }
  382. mf_i8086_far_data, { this unit uses an i8086 memory model with far data (i.e. compact or large) }
  383. mf_i8086_huge_data, { this unit uses an i8086 memory model with huge data (i.e. huge) }
  384. mf_i8086_cs_equals_ds, { this unit uses an i8086 memory model with CS=DS (i.e. tiny) }
  385. mf_i8086_ss_equals_ds, { this unit uses an i8086 memory model with SS=DS (i.e. tiny, small or medium) }
  386. mf_package_deny, { this unit must not be part of a package }
  387. mf_package_weak, { this unit may be completely contained in a package }
  388. mf_llvm, { compiled for LLVM code generator, not compatible with regular compiler because of different nodes in inline functions }
  389. mf_symansistr, { symbols are ansistrings (for ppudump) }
  390. mf_wasm_no_exceptions, { unit was compiled in WebAssembly 'no exceptions' mode }
  391. mf_wasm_bf_exceptions, { unit was compiled in WebAssembly 'branchful' exceptions mode }
  392. mf_wasm_js_exceptions, { unit was compiled in WebAssembly JavaScript-based exceptions mode }
  393. mf_wasm_native_exceptions, { unit was compiled in WebAssembly native exceptions mode }
  394. mf_wasm_threads, { unit was compiled with WebAssembly multithreading support turned on }
  395. mf_system_unit { unit was compiled as a System unit }
  396. );
  397. tmoduleflags = set of tmoduleflag;
  398. type
  399. ttargetswitchinfo = record
  400. name: string[22];
  401. { target switch can have an arbitratry value, not only on/off }
  402. hasvalue: boolean;
  403. { target switch can be used only globally }
  404. isglobal: boolean;
  405. define: string[32];
  406. end;
  407. const
  408. OptimizerSwitchStr : array[toptimizerswitch] of string[18] = (
  409. 'LEVEL1','LEVEL2','LEVEL3','LEVEL4',
  410. 'REGVAR','UNCERTAIN','SIZE','STACKFRAME',
  411. 'PEEPHOLE','LOOPUNROLL','TAILREC','CSE',
  412. 'DFA','STRENGTH','SCHEDULE','AUTOINLINE','USEEBP','USERBP',
  413. 'ORDERFIELDS','FASTMATH','DEADVALUES','REMOVEEMPTYPROCS',
  414. 'CONSTPROP',
  415. 'DEADSTORE','FORCENOSTACKFRAME','USELOADMODIFYSTORE',
  416. 'UNUSEDPARA','CONSTS','FORLOOP'
  417. );
  418. WPOptimizerSwitchStr : array [twpoptimizerswitch] of string[14] = (
  419. 'DEVIRTCALLS','OPTVMTS','SYMBOLLIVENESS'
  420. );
  421. DebugSwitchStr : array[tdebugswitch] of string[22] = ('',
  422. 'DWARFSETS','STABSABSINCLUDES','DWARFMETHODCLASSPREFIX','DWARFCPP','DWARFOMFLINNUM');
  423. TargetSwitchStr : array[ttargetswitch] of ttargetswitchinfo = (
  424. (name: ''; hasvalue: false; isglobal: true ; define: ''),
  425. (name: 'SMALLTOC'; hasvalue: false; isglobal: true ; define: ''),
  426. (name: 'COMPACTINTARRAYINIT'; hasvalue: false; isglobal: true ; define: ''),
  427. (name: 'ENUMFIELDINIT'; hasvalue: false; isglobal: true ; define: ''),
  428. (name: 'AUTOGETTERPREFIX'; hasvalue: true ; isglobal: false; define: ''),
  429. (name: 'AUTOSETTERPREFIX'; hasvalue: true ; isglobal: false; define: ''),
  430. (name: 'THUMBINTERWORKING'; hasvalue: false; isglobal: true ; define: ''),
  431. (name: 'LOWERCASEPROCSTART'; hasvalue: false; isglobal: true ; define: ''),
  432. (name: 'INITLOCALS'; hasvalue: false; isglobal: true ; define: ''),
  433. (name: 'CLD'; hasvalue: false; isglobal: true ; define: 'FPC_ENABLED_CLD'),
  434. (name: 'FARPROCSPUSHODDBP'; hasvalue: false; isglobal: false; define: 'FPC_FAR_PROCS_PUSH_ODD_BP'),
  435. (name: 'NOEXCEPTIONS'; hasvalue: false; isglobal: true ; define: 'FPC_WASM_NO_EXCEPTIONS'),
  436. (name: 'BFEXCEPTIONS'; hasvalue: false; isglobal: true ; define: 'FPC_WASM_BRANCHFUL_EXCEPTIONS'),
  437. (name: 'JSEXCEPTIONS'; hasvalue: false; isglobal: true ; define: 'FPC_WASM_JS_EXCEPTIONS'),
  438. (name: 'WASMEXCEPTIONS'; hasvalue: false; isglobal: true ; define: 'FPC_WASM_NATIVE_EXCEPTIONS'),
  439. (name: 'WASMTHREADS'; hasvalue: false; isglobal: true ; define: 'FPC_WASM_THREADS'),
  440. (name: 'SATURATINGFLOATTOINT';hasvalue: false; isglobal: false; define: 'FPC_WASM_SATURATING_FLOAT_TO_INT')
  441. );
  442. { switches being applied to all CPUs at the given level }
  443. genericlevel1optimizerswitches = [cs_opt_level1,cs_opt_peephole];
  444. genericlevel2optimizerswitches = [cs_opt_level2,cs_opt_remove_empty_proc,cs_opt_unused_para];
  445. genericlevel3optimizerswitches = [cs_opt_level3,cs_opt_constant_propagate,cs_opt_nodedfa,cs_opt_loopstrength
  446. {$ifndef llvm},cs_opt_use_load_modify_store{$endif},
  447. cs_opt_loopunroll,cs_opt_forloop];
  448. genericlevel4optimizerswitches = [cs_opt_level4,cs_opt_reorder_fields,cs_opt_dead_values,cs_opt_fastmath];
  449. { whole program optimizations whose information generation requires
  450. information from all loaded units
  451. }
  452. WPOptimizationsNeedingAllUnitInfo = [cs_wpo_devirtualize_calls,cs_wpo_optimize_vmts];
  453. featurestr : array[tfeature] of string[14] = (
  454. 'HEAP','INITFINAL','RTTI','CLASSES','EXCEPTIONS','EXITCODE',
  455. 'ANSISTRINGS','WIDESTRINGS','TEXTIO','CONSOLEIO','FILEIO',
  456. 'RANDOM','VARIANTS','OBJECTS','DYNARRAYS','THREADING','COMMANDARGS',
  457. 'PROCESSES','STACKCHECK','DYNLIBS','SOFTFPU','OBJECTIVEC1','RESOURCES',
  458. 'UNICODESTRINGS'
  459. );
  460. type
  461. { Switches which can be changed by a mode (fpc,tp7,delphi) }
  462. tmodeswitch = (m_none,
  463. { generic }
  464. m_fpc,m_objfpc,m_delphi,m_tp7,m_mac,m_iso,m_extpas,
  465. {$ifdef gpc_mode}m_gpc,{$endif}
  466. { more specific }
  467. m_class, { delphi class model }
  468. m_objpas, { load objpas unit }
  469. m_result, { result in functions }
  470. m_string_pchar, { pchar 2 string conversion }
  471. m_cvar_support, { cvar variable directive }
  472. m_nested_comment, { nested comments }
  473. m_tp_procvar, { tp style procvars (no @ needed) }
  474. m_mac_procvar, { macpas style procvars }
  475. m_repeat_forward, { repeating forward declarations is needed }
  476. m_pointer_2_procedure, { allows the assignement of pointers to
  477. procedure variables }
  478. m_autoderef, { does auto dereferencing of struct. vars }
  479. m_initfinal, { initialization/finalization for units }
  480. m_default_ansistring, { ansistring turned on by default }
  481. m_out, { support the calling convention OUT }
  482. m_default_para, { support default parameters }
  483. m_hintdirective, { support hint directives }
  484. m_duplicate_names, { allow locals/paras to have duplicate names of globals }
  485. m_property, { allow properties }
  486. m_default_inline, { allow inline proc directive }
  487. m_except, { allow exception-related keywords }
  488. m_objectivec1, { support interfacing with Objective-C (1.0) }
  489. m_objectivec2, { support interfacing with Objective-C (2.0) }
  490. m_nested_procvars, { support nested procedural variables }
  491. m_non_local_goto, { support non local gotos (like iso pascal) }
  492. m_advanced_records, { advanced record syntax with visibility sections, methods and properties }
  493. m_isolike_unary_minus, { unary minus like in iso pascal: same precedence level as binary minus/plus }
  494. m_systemcodepage, { use system codepage as compiler codepage by default, emit ansistrings with system codepage }
  495. m_final_fields, { allows declaring fields as "final", which means they must be initialised
  496. in the (class) constructor and are constant from then on (same as final
  497. fields in Java) }
  498. m_default_unicodestring, { makes the default string type in $h+ mode unicodestring rather than
  499. ansistring; similarly, char becomes unicodechar rather than ansichar }
  500. m_type_helpers, { allows the declaration of "type helper" for all supported types
  501. (primitive types, records, classes, interfaces) }
  502. m_blocks, { support for http://en.wikipedia.org/wiki/Blocks_(C_language_extension) }
  503. m_isolike_io, { I/O as it required by an ISO compatible compiler }
  504. m_isolike_program_para, { program parameters as it required by an ISO compatible compiler }
  505. m_isolike_mod, { mod operation as it is required by an iso compatible compiler }
  506. m_array_operators, { use Delphi compatible array operators instead of custom ones ("+") }
  507. m_multi_helpers, { helpers can appear in multiple scopes simultaneously }
  508. m_array2dynarray, { regular arrays can be implicitly converted to dynamic arrays }
  509. m_prefixed_attributes, { enable attributes that are defined before the type they belong to }
  510. m_underscoreisseparator,{ _ can be used as separator to group digits in numbers }
  511. m_implicit_function_specialization, { attempt to specialize generic function by inferring types from parameters }
  512. m_function_references, { enable Delphi-style function references }
  513. m_anonymous_functions { enable Delphi-style anonymous functions }
  514. );
  515. tmodeswitches = set of tmodeswitch;
  516. const
  517. alllanguagemodes = [m_fpc,m_objfpc,m_delphi,m_tp7,m_mac,m_iso,m_extpas];
  518. type
  519. { Application types (platform specific) }
  520. tapptype = (
  521. app_none,
  522. app_native, { native for Windows and NativeNT targets }
  523. app_gui, { graphic user-interface application }
  524. app_cui, { console application }
  525. app_fs, { full-screen type application (OS/2 and EMX only) }
  526. app_tool, { tool application, (MPW tool for MacOS, MacOS only) }
  527. app_arm7, { for Nintendo DS target }
  528. app_arm9, { for Nintendo DS target }
  529. app_bundle, { dynamically loadable bundle, Darwin only }
  530. app_com { DOS .COM file }
  531. );
  532. { interface types }
  533. tinterfacetypes = (
  534. it_interfacecom,
  535. it_interfacecorba,
  536. it_interfacejava
  537. );
  538. { currently parsed block type }
  539. tblock_type = (
  540. bt_none, { not assigned }
  541. bt_general, { default }
  542. bt_type, { type section }
  543. bt_const, { const section }
  544. bt_const_type, { const part of type. e.g.: ": Integer = 1" }
  545. bt_var, { variable declaration }
  546. bt_var_type, { type of variable }
  547. bt_except, { except section }
  548. bt_body { procedure body }
  549. );
  550. { Temp types }
  551. ttemptype = (tt_none,
  552. { free temp location, can be reused for something else }
  553. tt_free,
  554. { temp location that will be freed when ttgobj.UnGetTemp/
  555. ttgobj.UnGetIfTemp is called on it }
  556. tt_normal,
  557. { temp location that will not be freed; if it has to be
  558. freed, first ttgobj.changetemptype() it to tt_normal,
  559. or call ttgobj.UnGetLocal() instead (for local variables,
  560. since they are also persistent temps) }
  561. tt_persistent,
  562. { temp location that can never be reused anymore, even
  563. after it has been freed }
  564. tt_noreuse,
  565. { freed version of the above }
  566. tt_freenoreuse,
  567. { temp location that has been allocated by the register
  568. allocator and that can be reallocated only by the
  569. register allocator }
  570. tt_regallocator,
  571. { freed version of the above }
  572. tt_freeregallocator);
  573. ttemptypeset = set of ttemptype;
  574. { calling convention for tprocdef and tprocvardef }
  575. tproccalloption=(pocall_none,
  576. { procedure uses C styled calling }
  577. pocall_cdecl,
  578. { C++ calling conventions }
  579. pocall_cppdecl,
  580. { Far16 for OS/2 }
  581. pocall_far16,
  582. { Old style FPC default calling }
  583. pocall_oldfpccall,
  584. { Procedure has compiler magic}
  585. pocall_internproc,
  586. { procedure is a system call, applies e.g. to MorphOS and PalmOS }
  587. pocall_syscall,
  588. { pascal standard left to right }
  589. pocall_pascal,
  590. { procedure uses register (fastcall) calling }
  591. pocall_register,
  592. { safe call calling conventions }
  593. pocall_safecall,
  594. { procedure uses stdcall call }
  595. pocall_stdcall,
  596. { Special calling convention for cpus without a floating point
  597. unit. Floating point numbers are passed in integer registers
  598. instead of floating point registers. Depending on the other
  599. available calling conventions available for the cpu
  600. this replaces either pocall_fastcall or pocall_stdcall.
  601. }
  602. pocall_softfloat,
  603. { Metrowerks Pascal. Special case on Mac OS (X): passes all }
  604. { constant records by reference. }
  605. pocall_mwpascal,
  606. { Special interrupt handler for embedded systems }
  607. pocall_interrupt,
  608. { Directive for arm: pass floating point values in (v)float registers
  609. regardless of the actual calling conventions }
  610. pocall_hardfloat,
  611. { for x86-64: force sysv ABI (Pascal resp. C) }
  612. pocall_sysv_abi_default,
  613. pocall_sysv_abi_cdecl,
  614. { for x86-64: forces Microsoft ABI (Pascal resp. C) }
  615. pocall_ms_abi_default,
  616. pocall_ms_abi_cdecl,
  617. { for x86-64: Microsoft's "vectorcall" ABI }
  618. pocall_vectorcall
  619. );
  620. tproccalloptions = set of tproccalloption;
  621. const
  622. proccalloptionStr : array[tproccalloption] of string[16]=('',
  623. 'CDecl',
  624. 'CPPDecl',
  625. 'Far16',
  626. 'OldFPCCall',
  627. 'InternProc',
  628. 'SysCall',
  629. 'Pascal',
  630. 'Register',
  631. 'SafeCall',
  632. 'StdCall',
  633. 'SoftFloat',
  634. 'MWPascal',
  635. 'Interrupt',
  636. 'HardFloat',
  637. 'SysV_ABI_Default',
  638. 'SysV_ABI_CDecl',
  639. 'MS_ABI_Default',
  640. 'MS_ABI_CDecl',
  641. 'VectorCall'
  642. );
  643. { Default calling convention }
  644. {$if defined(i8086)}
  645. pocall_default = pocall_pascal;
  646. {$elseif defined(i386) or defined(x86_64)}
  647. pocall_default = pocall_register;
  648. {$elseif defined(m68k)}
  649. pocall_default = pocall_register;
  650. {$else}
  651. pocall_default = pocall_stdcall;
  652. {$endif}
  653. cstylearrayofconst = [pocall_cdecl,pocall_cppdecl,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl];
  654. modeswitchstr : array[tmodeswitch] of string[30] = ('',
  655. '','','','','','','',
  656. {$ifdef gpc_mode}'',{$endif}
  657. { more specific }
  658. 'CLASS',
  659. 'OBJPAS',
  660. 'RESULT',
  661. 'PCHARTOSTRING',
  662. 'CVAR',
  663. 'NESTEDCOMMENTS',
  664. 'CLASSICPROCVARS',
  665. 'MACPROCVARS',
  666. 'REPEATFORWARD',
  667. 'POINTERTOPROCVAR',
  668. 'AUTODEREF',
  669. 'INITFINAL',
  670. 'ANSISTRINGS',
  671. 'OUT',
  672. 'DEFAULTPARAMETERS',
  673. 'HINTDIRECTIVE',
  674. 'DUPLICATELOCALS',
  675. 'PROPERTIES',
  676. 'ALLOWINLINE',
  677. 'EXCEPTIONS',
  678. 'OBJECTIVEC1',
  679. 'OBJECTIVEC2',
  680. 'NESTEDPROCVARS',
  681. 'NONLOCALGOTO',
  682. 'ADVANCEDRECORDS',
  683. 'ISOUNARYMINUS',
  684. 'SYSTEMCODEPAGE',
  685. 'FINALFIELDS',
  686. 'UNICODESTRINGS',
  687. 'TYPEHELPERS',
  688. 'CBLOCKS',
  689. 'ISOIO',
  690. 'ISOPROGRAMPARAS',
  691. 'ISOMOD',
  692. 'ARRAYOPERATORS',
  693. 'MULTIHELPERS',
  694. 'ARRAYTODYNARRAY',
  695. 'PREFIXEDATTRIBUTES',
  696. 'UNDERSCOREISSEPARATOR',
  697. 'IMPLICITFUNCTIONSPECIALIZATION',
  698. 'FUNCTIONREFERENCES',
  699. 'ANONYMOUSFUNCTIONS'
  700. );
  701. type
  702. tprocinfoflag=(
  703. { procedure has at least one assembler block }
  704. pi_has_assembler_block,
  705. { procedure does a call }
  706. pi_do_call,
  707. { procedure has a try statement = no register optimization }
  708. pi_uses_exceptions,
  709. { procedure is declared as @var(assembler), don't optimize}
  710. pi_is_assembler,
  711. { procedure contains data which needs to be finalized }
  712. pi_needs_implicit_finally,
  713. { procedure has the implicit try..finally generated }
  714. pi_has_implicit_finally,
  715. { procedure uses fpu}
  716. pi_uses_fpu,
  717. { procedure uses GOT for PIC code }
  718. pi_needs_got,
  719. { references var/proc/type/const in static symtable,
  720. i.e. not allowed for inlining from other units }
  721. pi_uses_static_symtable,
  722. { set if the procedure has to push parameters onto the stack }
  723. pi_has_stackparameter,
  724. { set if the procedure has at least one label }
  725. pi_has_label,
  726. { calls itself recursive }
  727. pi_is_recursive,
  728. { stack frame optimization not possible (only on x86 probably) }
  729. pi_needs_stackframe,
  730. { set if the procedure has at least one register saved on the stack }
  731. pi_has_saved_regs,
  732. { dfa was generated for this proc }
  733. pi_dfaavailable,
  734. { subroutine contains interprocedural used labels }
  735. pi_has_interproclabel,
  736. { subroutine has unwind info (win64) }
  737. pi_has_unwind_info,
  738. { subroutine contains interprocedural gotos }
  739. pi_has_global_goto,
  740. { subroutine contains inherited call }
  741. pi_has_inherited,
  742. { subroutine has nested exit }
  743. pi_has_nested_exit,
  744. { allocates memory on stack, so stack is unbalanced on exit }
  745. pi_has_stack_allocs,
  746. { set if the stack frame of the procedure is estimated }
  747. pi_estimatestacksize,
  748. { the routine calls a C-style varargs function }
  749. pi_calls_c_varargs,
  750. { the routine has an open array parameter,
  751. for i8086 cpu huge memory model,
  752. as this changes SP register it requires special handling
  753. to restore DS segment register }
  754. pi_has_open_array_parameter,
  755. { subroutine uses threadvars }
  756. pi_uses_threadvar,
  757. { set if the procedure has generated data which shall go in an except table }
  758. pi_has_except_table_data,
  759. { subroutine needs to load and maintain a tls register }
  760. pi_needs_tls,
  761. { subroutine uses get_frame }
  762. pi_uses_get_frame,
  763. { x86 only: subroutine uses ymm registers, requires vzeroupper call }
  764. pi_uses_ymm,
  765. { set if no frame pointer is needed, the rules when this applies is target specific }
  766. pi_no_framepointer_needed
  767. );
  768. tprocinfoflags=set of tprocinfoflag;
  769. ttlsmodel = (tlsm_none,
  770. { elf tls model: works for all kind of code and thread vars }
  771. tlsm_global_dynamic,
  772. { elf tls model: works only if the thread vars are declared and used in the same module,
  773. regardless when the module is loaded }
  774. tlsm_local_dynamic,
  775. { elf tls model: works only if the thread vars are declared and used in modules and executables loaded at startup }
  776. tlsm_initial_exec,
  777. { elf tls model: works only if the thread vars are declared and used in the same executable }
  778. tlsm_local_exec
  779. );
  780. type
  781. { float types -- warning, this enum/order is used internally by the RTL
  782. as well in rtl/inc/real2str.inc }
  783. tfloattype = (
  784. s32real,s64real,s80real,sc80real { the C "long double" type on x86 },
  785. s64comp,s64currency,s128real
  786. );
  787. type
  788. { register allocator live range extension direction }
  789. TRADirection = (rad_forward, rad_backwards, rad_backwards_reinit);
  790. type
  791. {$ifndef symansistr}
  792. TIDString = string[maxidlen];
  793. {$else}
  794. TIDString = TSymStr;
  795. {$endif}
  796. tnormalset = set of byte; { 256 elements set }
  797. pnormalset = ^tnormalset;
  798. pboolean = ^boolean;
  799. pdouble = ^double;
  800. pbyte = ^byte;
  801. pword = ^word;
  802. plongint = ^longint;
  803. plongintarray = plongint;
  804. tfileposline = longint;
  805. tfileposcolumn = word;
  806. tfileposfileindex = word;
  807. tfileposmoduleindex = word;
  808. pfileposinfo = ^tfileposinfo;
  809. tfileposinfo = record
  810. { if types of column or fileindex are changed, modify tcompilerppufile.putposinfo }
  811. line : tfileposline;
  812. column : tfileposcolumn;
  813. fileindex : tfileposfileindex;
  814. moduleindex : tfileposmoduleindex;
  815. end;
  816. {$ifndef xFPC}
  817. type
  818. pguid = ^tguid;
  819. tguid = packed record
  820. D1: LongWord;
  821. D2: Word;
  822. D3: Word;
  823. D4: array[0..7] of Byte;
  824. end;
  825. {$endif}
  826. tstringencoding = Word;
  827. tcodepagestring = string[20];
  828. const
  829. { link options }
  830. link_none = $0;
  831. link_always = $1;
  832. link_static = $2;
  833. link_smart = $4;
  834. link_shared = $8;
  835. link_lto = $10;
  836. type
  837. { a message state }
  838. tmsgstate = (
  839. ms_on := 1,
  840. ms_off := 2,
  841. ms_error := 3,
  842. ms_on_global := $11, // turn on output
  843. ms_off_global := $22, // turn off output
  844. ms_error_global := $33 // cast to error
  845. );
  846. const
  847. { Mask for current value of message state }
  848. ms_local_mask = $0f;
  849. { Mask for global value of message state
  850. that needs to be restored when changing units }
  851. ms_global_mask = $f0;
  852. { Shift used to convert global to local message state }
  853. ms_shift = 4;
  854. type
  855. pmessagestaterecord = ^tmessagestaterecord;
  856. tmessagestaterecord = record
  857. next : pmessagestaterecord;
  858. value : longint;
  859. state : tmsgstate;
  860. end;
  861. type
  862. tx86memorymodel = (mm_tiny,mm_small,mm_medium,mm_compact,mm_large,mm_huge);
  863. const
  864. x86memorymodelstr : array[tx86memorymodel] of string[7]=(
  865. 'TINY',
  866. 'SMALL',
  867. 'MEDIUM',
  868. 'COMPACT',
  869. 'LARGE',
  870. 'HUGE');
  871. { hide Sysutils.ExecuteProcess in units using this one after SysUtils}
  872. const
  873. ExecuteProcess = 'Do not use' deprecated 'Use cfileutil.RequotedExecuteProcess instead, ExecuteProcess cannot deal with single quotes as used by Unix command lines';
  874. Type
  875. tfilenametransformation = (ftNone,ftLowerCase,ftUpperCase,ft83);
  876. tfilenametransformations = set of tfilenametransformation;
  877. Const AllTransformations = [Low(tfilenametransformation)..high(tfilenametransformation)];
  878. { extended rtti directive }
  879. type
  880. trtti_clause = (
  881. rtc_none,
  882. rtc_inherit,
  883. rtc_explicit
  884. );
  885. trtti_visibility = (
  886. rv_private,
  887. rv_protected,
  888. rv_public,
  889. rv_published
  890. );
  891. trtti_visibilities = set of trtti_visibility;
  892. prtti_visibilities = ^trtti_visibilities;
  893. trtti_option = (
  894. ro_methods,
  895. ro_fields,
  896. ro_properties
  897. );
  898. trtti_directive = record
  899. clause: trtti_clause;
  900. options: array[trtti_option] of trtti_visibilities;
  901. end;
  902. implementation
  903. end.