globals.pas 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements some support functions and global variables
  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 globals;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. {$ifdef windows}
  22. windows,
  23. {$endif}
  24. {$ifdef os2}
  25. dos,
  26. {$endif os2}
  27. {$ifdef hasunix}
  28. Baseunix,unix,
  29. {$endif}
  30. {$IFNDEF USE_FAKE_SYSUTILS}
  31. sysutils,
  32. {$ELSE}
  33. fksysutl,
  34. {$ENDIF}
  35. { comphook pulls in sysutils anyways }
  36. cutils,cclasses,cfileutl,
  37. cpuinfo,
  38. {$if defined(LLVM) and not defined(GENERIC_CPU)}
  39. llvminfo,
  40. {$endif LLVM and not GENERIC_CPU}
  41. globtype,version,systems;
  42. const
  43. delphimodeswitches =
  44. [m_delphi,m_class,m_objpas,m_result,m_string_pchar,
  45. m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
  46. m_out,m_default_para,m_duplicate_names,m_hintdirective,
  47. m_property,m_default_inline,m_except,m_advanced_records];
  48. delphiunicodemodeswitches = delphimodeswitches + [m_systemcodepage,m_default_unicodestring];
  49. fpcmodeswitches =
  50. [m_fpc,m_string_pchar,m_nested_comment,m_repeat_forward,
  51. m_cvar_support,m_initfinal,m_hintdirective,
  52. m_property,m_default_inline];
  53. objfpcmodeswitches =
  54. [m_objfpc,m_fpc,m_class,m_objpas,m_result,m_string_pchar,m_nested_comment,
  55. m_repeat_forward,m_cvar_support,m_initfinal,m_out,m_default_para,m_hintdirective,
  56. m_property,m_default_inline,m_except];
  57. tpmodeswitches =
  58. [m_tp7,m_tp_procvar,m_duplicate_names];
  59. {$ifdef gpc_mode}
  60. gpcmodeswitches =
  61. [m_gpc,m_tp_procvar];
  62. {$endif}
  63. macmodeswitches =
  64. [m_mac,m_cvar_support,m_mac_procvar,m_nested_procvars,m_non_local_goto,m_isolike_unary_minus,m_default_inline];
  65. isomodeswitches =
  66. [m_iso,m_tp_procvar,m_duplicate_names,m_nested_procvars,m_non_local_goto,m_isolike_unary_minus,m_isolike_io,
  67. m_isolike_program_para,
  68. m_isolike_mod];
  69. extpasmodeswitches =
  70. [m_extpas,m_tp_procvar,m_duplicate_names,m_nested_procvars,m_non_local_goto,m_isolike_unary_minus,m_isolike_io,
  71. m_isolike_program_para,
  72. m_isolike_mod];
  73. { maximum nesting of routines }
  74. maxnesting = 32;
  75. { Filenames and extensions }
  76. sourceext = '.pp';
  77. pasext = '.pas';
  78. pext = '.p';
  79. treelogfilename = 'tree.log';
  80. {$if defined(CPUARM) and defined(FPUFPA)}
  81. MathQNaN : tcompdoublerec = (bytes : (0,0,252,255,0,0,0,0));
  82. MathInf : tcompdoublerec = (bytes : (0,0,240,127,0,0,0,0));
  83. MathNegInf : tcompdoublerec = (bytes : (0,0,240,255,0,0,0,0));
  84. MathPi : tcompdoublerec = (bytes : (251,33,9,64,24,45,68,84));
  85. {$else}
  86. {$ifdef FPC_LITTLE_ENDIAN}
  87. MathQNaN : tcompdoublerec = (bytes : (0,0,0,0,0,0,252,255));
  88. MathInf : tcompdoublerec = (bytes : (0,0,0,0,0,0,240,127));
  89. MathNegInf : tcompdoublerec = (bytes : (0,0,0,0,0,0,240,255));
  90. MathPi : tcompdoublerec = (bytes : (24,45,68,84,251,33,9,64));
  91. MathPiExtended : tcompextendedrec = (bytes : (53,194,104,33,162,218,15,201,0,64));
  92. {$else FPC_LITTLE_ENDIAN}
  93. MathQNaN : tcompdoublerec = (bytes : (255,252,0,0,0,0,0,0));
  94. MathInf : tcompdoublerec = (bytes : (127,240,0,0,0,0,0,0));
  95. MathNegInf : tcompdoublerec = (bytes : (255,240,0,0,0,0,0,0));
  96. MathPi : tcompdoublerec = (bytes : (64,9,33,251,84,68,45,24));
  97. MathPiExtended : tcompextendedrec = (bytes : (64,0,201,15,218,162,33,104,194,53));
  98. {$endif FPC_LITTLE_ENDIAN}
  99. {$endif}
  100. CP_UTF8 = 65001;
  101. CP_UTF16LE = 1200;
  102. CP_UTF16BE = 1201;
  103. CP_NONE = 65535;
  104. { by default no local variable trashing }
  105. localvartrashing: longint = -1;
  106. nroftrashvalues = 4;
  107. trashintvalues: array[0..nroftrashvalues-1] of int64 = ($5555555555555555,$AAAAAAAAAAAAAAAA,$EFEFEFEFEFEFEFEF,0);
  108. type
  109. { this is written to ppus during token recording for generics,
  110. it used to required to be packed,
  111. but this requirement is now obsolete,
  112. as the fields are written one by one. PM 2012-06-13 }
  113. tsettings = record
  114. alignment : talignmentinfo;
  115. globalswitches : tglobalswitches;
  116. targetswitches : ttargetswitches;
  117. moduleswitches : tmoduleswitches;
  118. localswitches : tlocalswitches;
  119. modeswitches : tmodeswitches;
  120. optimizerswitches : toptimizerswitches;
  121. { generate information necessary to perform these wpo's during a subsequent compilation }
  122. genwpoptimizerswitches: twpoptimizerswitches;
  123. { perform these wpo's using information generated during a previous compilation }
  124. dowpoptimizerswitches: twpoptimizerswitches;
  125. debugswitches : tdebugswitches;
  126. { 0: old behaviour for sets <=256 elements
  127. >0: round to this size }
  128. setalloc,
  129. packenum : shortint;
  130. packrecords : shortint;
  131. maxfpuregisters : shortint;
  132. cputype,
  133. optimizecputype,
  134. asmcputype : tcputype;
  135. fputype : tfputype;
  136. asmmode : tasmmode;
  137. interfacetype : tinterfacetypes;
  138. defproccall : tproccalloption;
  139. sourcecodepage : tstringencoding;
  140. minfpconstprec : tfloattype;
  141. disabledircache : boolean;
  142. {$if defined(i8086)}
  143. x86memorymodel : tx86memorymodel;
  144. {$endif defined(i8086)}
  145. {$if defined(ARM)}
  146. instructionset : tinstructionset;
  147. {$endif defined(ARM)}
  148. {$if defined(LLVM) and not defined(GENERIC_CPU)}
  149. llvmversion: tllvmversion;
  150. {$endif defined(LLVM) and not defined(GENERIC_CPU)}
  151. { CPU targets with microcontroller support can add a controller specific unit }
  152. controllertype : tcontrollertype;
  153. { WARNING: this pointer cannot be written as such in record token }
  154. pmessage : pmessagestaterecord;
  155. end;
  156. const
  157. LinkMapWeightDefault = 1000;
  158. type
  159. TLinkRec = record
  160. Key : AnsiString;
  161. Value : AnsiString; // key expands to valuelist "value"
  162. Weight: longint;
  163. end;
  164. TLinkStrMap = class
  165. private
  166. itemcnt : longint;
  167. fmap : Array Of TLinkRec;
  168. function Lookup(key:Ansistring):longint;
  169. function getlinkrec(i:longint):TLinkRec;
  170. public
  171. procedure Add(key:ansistring;value:AnsiString='';weight:longint=LinkMapWeightDefault);
  172. procedure addseries(keys:AnsiString;weight:longint=LinkMapWeightDefault);
  173. function AddDep(keyvalue:String):boolean;
  174. function AddWeight(keyvalue:String):boolean;
  175. procedure SetValue(key:AnsiString;Weight:Integer);
  176. procedure SortonWeight;
  177. function Find(key:AnsiString):AnsiString;
  178. procedure Expand(src:TCmdStrList;dest: TLinkStrMap);
  179. procedure UpdateWeights(Weightmap:TLinkStrMap);
  180. constructor Create;
  181. property count : longint read itemcnt;
  182. property items[I:longint]:TLinkRec read getlinkrec; default;
  183. end;
  184. tpendingstate = record
  185. nextverbositystr : shortstring;
  186. nextlocalswitches : tlocalswitches;
  187. nextverbosityfullswitch: longint;
  188. nextcallingstr : shortstring;
  189. nextmessagerecord : pmessagestaterecord;
  190. nextalignment : talignmentinfo;
  191. alignmentchanged,
  192. verbosityfullswitched,
  193. localswitcheschanged : boolean;
  194. end;
  195. var
  196. { specified inputfile }
  197. inputfilepath : string;
  198. inputfilename : string;
  199. { specified outputfile with -o parameter }
  200. outputfilename : string;
  201. outputprefix : pshortstring;
  202. outputsuffix : pshortstring;
  203. { specified with -FE or -FU }
  204. outputexedir : TPathStr;
  205. outputunitdir : TPathStr;
  206. { specified with -FW and -Fw }
  207. wpofeedbackinput,
  208. wpofeedbackoutput : TPathStr;
  209. { external assembler extra option }
  210. asmextraopt : string;
  211. { things specified with parameters }
  212. paralinkoptions : TCmdStr;
  213. paradynamiclinker : string;
  214. paraprintnodetree : byte;
  215. {$ifdef PREPROCWRITE}
  216. parapreprocess : boolean;
  217. {$endif PREPROCWRITE}
  218. printnodefile : text;
  219. { typical cross compiling params}
  220. { directory where the utils can be found (options -FD) }
  221. utilsdirectory : TPathStr;
  222. { targetname specific prefix used by these utils (options -XP<path>) }
  223. utilsprefix : TCmdStr;
  224. cshared : boolean; { pass --shared to ld to link C libs shared}
  225. Dontlinkstdlibpath: Boolean; { Don't add std paths to linkpath}
  226. rlinkpath : TCmdStr; { rpath-link linkdir override}
  227. sysrootpath : TCmdStr; { target system root to search dyn linker }
  228. { some flags for global compiler switches }
  229. do_build,
  230. do_release,
  231. do_make : boolean;
  232. { Path to ppc }
  233. exepath : TPathStr;
  234. { Path to unicode charmap/collation binaries }
  235. unicodepath : TPathStr;
  236. { path for searching units, different paths can be seperated by ; }
  237. librarysearchpath,
  238. unitsearchpath,
  239. objectsearchpath,
  240. includesearchpath,
  241. frameworksearchpath : TSearchPathList;
  242. packagesearchpath : TSearchPathList;
  243. { list of default namespaces }
  244. namespacelist : TCmdStrList;
  245. { contains tpackageentry entries }
  246. packagelist : TFPHashList;
  247. autoloadunits : string;
  248. { linking }
  249. usewindowapi : boolean;
  250. description : string;
  251. SetPEFlagsSetExplicity,
  252. SetPEOptFlagsSetExplicity,
  253. SetPEOSVersionSetExplicitely,
  254. SetPESubSysVersionSetExplicitely,
  255. SetPEUserVersionSetExplicitely,
  256. ImageBaseSetExplicity,
  257. MinStackSizeSetExplicity,
  258. MaxStackSizeSetExplicity,
  259. DescriptionSetExplicity : boolean;
  260. dllversion : string;
  261. dllmajor,
  262. dllminor,
  263. dllrevision : word; { revision only for netware }
  264. { win pe }
  265. peosversionminor,
  266. peosversionmajor,
  267. pesubsysversionminor,
  268. pesubsysversionmajor,
  269. peuserversionminor,
  270. peuserversionmajor : word;
  271. peoptflags,
  272. peflags : longint;
  273. minstacksize,
  274. maxstacksize,
  275. imagebase : puint;
  276. UseDeffileForExports : boolean;
  277. UseDeffileForExportsSetExplicitly : boolean;
  278. GenerateImportSection,
  279. GenerateImportSectionSetExplicitly,
  280. RelocSection : boolean;
  281. MacOSXVersionMin,
  282. iPhoneOSVersionMin: string[15];
  283. RelocSectionSetExplicitly : boolean;
  284. current_tokenpos, { position of the last token }
  285. current_filepos : tfileposinfo; { current position }
  286. nwscreenname : string;
  287. nwthreadname : string;
  288. nwcopyright : string;
  289. codegenerror : boolean; { true if there is an error reported }
  290. exception_raised : boolean; { true if there is an exception reported }
  291. block_type : tblock_type; { type of currently parsed block }
  292. compile_level : word;
  293. exceptblockcounter : integer; { each except block gets a unique number check gotos }
  294. current_exceptblock : integer; { the exceptblock number of the current block (0 if none) }
  295. LinkLibraryAliases : TLinkStrMap;
  296. LinkLibraryOrder : TLinkStrMap;
  297. init_settings,
  298. current_settings : tsettings;
  299. pendingstate : tpendingstate;
  300. { Memory sizes }
  301. heapsize,
  302. maxheapsize,
  303. stacksize : longint;
  304. {$Ifdef EXTDEBUG}
  305. { parameter switches }
  306. debugstop : boolean;
  307. {$EndIf EXTDEBUG}
  308. { Application type (platform specific)
  309. see globtype.pas for description }
  310. apptype : tapptype;
  311. features : tfeatures;
  312. { prefix added to automatically generated setters/getters. If empty,
  313. no getters/setters will be automatically generated except if required
  314. for visibility reasons (but in that case the names will be mangled so
  315. they are unique) }
  316. prop_auto_getter_prefix,
  317. prop_auto_setter_prefix : string;
  318. const
  319. Inside_asm_statement : boolean = false;
  320. global_unit_count : word = 0;
  321. { for error info in pp.pas }
  322. parser_current_file : string = '';
  323. {$if defined(m68k) or defined(arm)}
  324. { PalmOS resources }
  325. palmos_applicationname : string = 'FPC Application';
  326. palmos_applicationid : string[4] = 'FPCA';
  327. {$endif defined(m68k) or defined(arm)}
  328. { default name of the C-style "main" procedure of the library/program }
  329. { (this will be prefixed with the target_info.cprefix) }
  330. defaultmainaliasname = 'main';
  331. mainaliasname : string = defaultmainaliasname;
  332. const
  333. default_settings : TSettings = (
  334. alignment : (
  335. procalign : 0;
  336. loopalign : 0;
  337. jumpalign : 0;
  338. constalignmin : 0;
  339. constalignmax : 0;
  340. varalignmin : 0;
  341. varalignmax : 0;
  342. localalignmin : 0;
  343. localalignmax : 0;
  344. recordalignmin : 0;
  345. recordalignmax : 0;
  346. maxCrecordalign : 0;
  347. );
  348. globalswitches : [cs_check_unit_name,cs_link_static];
  349. targetswitches : [];
  350. moduleswitches : [cs_extsyntax,cs_implicit_exceptions];
  351. localswitches : [cs_check_io,cs_typed_const_writable,cs_pointermath,cs_imported_data{$ifdef i8086},cs_force_far_calls{$endif}];
  352. modeswitches : fpcmodeswitches;
  353. optimizerswitches : [];
  354. genwpoptimizerswitches : [];
  355. dowpoptimizerswitches : [];
  356. {$ifdef i8086}
  357. debugswitches : [ds_dwarf_sets,ds_dwarf_omf_linnum];
  358. {$else i8086}
  359. debugswitches : [ds_dwarf_sets];
  360. {$endif i8086}
  361. setalloc : 0;
  362. packenum : 4;
  363. {$ifdef i8086}
  364. packrecords : 1;
  365. {$else i8086}
  366. packrecords : 0;
  367. {$endif i8086}
  368. maxfpuregisters : 0;
  369. { Note: GENERIC_CPU is used together with generic subdirectory to
  370. be able to compile some of the units without any real CPU.
  371. This is used to generate a CPU independant PPUDUMP utility. PM }
  372. {$ifdef GENERIC_CPU}
  373. cputype : cpu_none;
  374. optimizecputype : cpu_none;
  375. asmcputype : cpu_none;
  376. fputype : fpu_none;
  377. {$else not GENERIC_CPU}
  378. {$ifdef i386}
  379. cputype : cpu_Pentium;
  380. optimizecputype : cpu_Pentium3;
  381. asmcputype : cpu_none;
  382. fputype : fpu_x87;
  383. {$endif i386}
  384. {$ifdef m68k}
  385. cputype : cpu_MC68020;
  386. optimizecputype : cpu_MC68020;
  387. asmcputype : cpu_none;
  388. fputype : fpu_soft;
  389. {$endif m68k}
  390. {$ifdef powerpc}
  391. cputype : cpu_PPC604;
  392. optimizecputype : cpu_ppc7400;
  393. asmcputype : cpu_none;
  394. fputype : fpu_standard;
  395. {$endif powerpc}
  396. {$ifdef POWERPC64}
  397. cputype : cpu_PPC970;
  398. optimizecputype : cpu_ppc970;
  399. asmcputype : cpu_none;
  400. fputype : fpu_standard;
  401. {$endif POWERPC64}
  402. {$ifdef sparc}
  403. cputype : cpu_SPARC_V9;
  404. optimizecputype : cpu_SPARC_V9;
  405. asmcputype : cpu_none;
  406. fputype : fpu_hard;
  407. {$endif sparc}
  408. {$ifdef sparc64}
  409. cputype : cpu_SPARC_V9;
  410. optimizecputype : cpu_SPARC_V9;
  411. asmcputype : cpu_none;
  412. fputype : fpu_hard;
  413. {$endif sparc64}
  414. {$ifdef arm}
  415. cputype : cpu_armv4;
  416. optimizecputype : cpu_armv4;
  417. asmcputype : cpu_none;
  418. fputype : fpu_fpa;
  419. {$endif arm}
  420. {$ifdef x86_64}
  421. cputype : cpu_athlon64;
  422. optimizecputype : cpu_athlon64;
  423. asmcputype : cpu_none;
  424. fputype : fpu_sse64;
  425. {$endif x86_64}
  426. {$ifdef avr}
  427. cputype : cpuinfo.cpu_avr5;
  428. optimizecputype : cpuinfo.cpu_avr5;
  429. asmcputype : cpu_none;
  430. fputype : fpu_none;
  431. {$endif avr}
  432. {$ifdef mips}
  433. cputype : cpu_mips2;
  434. optimizecputype : cpu_mips2;
  435. asmcputype : cpu_none;
  436. fputype : fpu_mips2;
  437. {$endif mips}
  438. {$ifdef jvm}
  439. cputype : cpu_none;
  440. optimizecputype : cpu_none;
  441. asmcputype : cpu_none;
  442. fputype : fpu_standard;
  443. {$endif jvm}
  444. {$ifdef aarch64}
  445. cputype : cpu_armv8;
  446. optimizecputype : cpu_armv8;
  447. asmcputype : cpu_none;
  448. fputype : fpu_vfp;
  449. {$endif aarch64}
  450. {$ifdef i8086}
  451. cputype : cpu_8086;
  452. optimizecputype : cpu_8086;
  453. { Use cpu_none by default,
  454. because using cpu_8086 by default means
  455. that we reject any instruction above bare 8086 instruction set
  456. for all assembler code PM }
  457. asmcputype : cpu_none;
  458. fputype : fpu_x87;
  459. {$endif i8086}
  460. {$endif not GENERIC_CPU}
  461. asmmode : asmmode_standard;
  462. {$ifndef jvm}
  463. interfacetype : it_interfacecom;
  464. {$else jvm}
  465. interfacetype : it_interfacejava;
  466. {$endif jvm}
  467. defproccall : pocall_default;
  468. sourcecodepage : 28591;
  469. minfpconstprec : s32real;
  470. disabledircache : false;
  471. {$if defined(i8086)}
  472. x86memorymodel : mm_small;
  473. {$endif defined(i8086)}
  474. {$if defined(ARM)}
  475. instructionset : is_arm;
  476. {$endif defined(ARM)}
  477. {$if defined(LLVM) and not defined(GENERIC_CPU)}
  478. llvmversion : llvmver_3_9_0;
  479. {$endif defined(LLVM) and not defined(GENERIC_CPU)}
  480. controllertype : ct_none;
  481. pmessage : nil;
  482. );
  483. var
  484. starttime : real;
  485. startsystime : TSystemTime;
  486. function getdatestr:string;
  487. function gettimestr:string;
  488. function filetimestring( t : longint) : string;
  489. function getrealtime(const st: TSystemTime) : real;
  490. function getrealtime : real;
  491. procedure DefaultReplacements(var s:ansistring);
  492. function GetEnvPChar(const envname:ansistring):pchar;
  493. procedure FreeEnvPChar(p:pchar);
  494. function is_number_float(d : double) : boolean;
  495. { discern +0.0 and -0.0 }
  496. function get_real_sign(r: bestreal): longint;
  497. procedure InitGlobals;
  498. procedure DoneGlobals;
  499. procedure register_initdone_proc(init,done:tprocedure);
  500. function string2guid(const s: string; var GUID: TGUID): boolean;
  501. function guid2string(const GUID: TGUID): string;
  502. function SetAktProcCall(const s:string; var a:tproccalloption):boolean;
  503. function Setabitype(const s:string;var a:tabi):boolean;
  504. function Setoptimizecputype(const s:string;var a:tcputype):boolean;
  505. function Setcputype(const s:string;var a:tsettings):boolean;
  506. function SetFpuType(const s:string;var a:tfputype):boolean;
  507. function SetControllerType(const s:string;var a:tcontrollertype):boolean;
  508. function HandleFeature(const s : string) : boolean;
  509. function SetMinFPConstPrec(const s: string; var a: tfloattype) : boolean;
  510. {# Routine to get the required alignment for size of data, which will
  511. be placed in bss segment, according to the current alignment requirements }
  512. function var_align(want_align: longint): shortint;
  513. function var_align_size(siz: longint): shortint;
  514. {# Routine to get the required alignment for size of data, which will
  515. be placed in data/const segment, according to the current alignment requirements }
  516. function const_align(want_align: longint): shortint;
  517. function const_align_size(siz: longint): shortint;
  518. {$ifdef ARM}
  519. function is_double_hilo_swapped: boolean;{$ifdef USEINLINE}inline;{$endif}
  520. {$endif ARM}
  521. function floating_point_range_check_error : boolean;
  522. function use_dotted_functions: boolean;
  523. { hide Sysutils.ExecuteProcess in units using this one after SysUtils}
  524. const
  525. ExecuteProcess = 'Do not use' deprecated 'Use cfileutil.RequotedExecuteProcess instead, ExecuteProcess cannot deal with single quotes as used by Unix command lines';
  526. implementation
  527. {$if defined(macos)}
  528. uses
  529. macutils;
  530. {$elseif defined(mswindows)}
  531. uses
  532. windirs;
  533. {$endif}
  534. {****************************************************************************
  535. TLinkStrMap
  536. ****************************************************************************}
  537. Constructor TLinkStrMap.create;
  538. begin
  539. inherited;
  540. itemcnt:=0;
  541. end;
  542. procedure TLinkStrMap.Add(key:ansistring;value:AnsiString='';weight:longint=LinkMapWeightDefault);
  543. begin
  544. if lookup(key)<>-1 Then
  545. exit;
  546. if itemcnt<=length(fmap) Then
  547. setlength(fmap,itemcnt+10);
  548. fmap[itemcnt].key:=key;
  549. fmap[itemcnt].value:=value;
  550. fmap[itemcnt].weight:=weight;
  551. inc(itemcnt);
  552. end;
  553. function TLinkStrMap.AddDep(keyvalue:String):boolean;
  554. var
  555. i : Longint;
  556. begin
  557. AddDep:=false;
  558. i:=pos('=',keyvalue);
  559. if i=0 then
  560. exit;
  561. Add(Copy(KeyValue,1,i-1),Copy(KeyValue,i+1,length(KeyValue)-i));
  562. AddDep:=True;
  563. end;
  564. function TLinkStrMap.AddWeight(keyvalue:String):boolean;
  565. var
  566. i,j : Longint;
  567. Code : Word;
  568. s : AnsiString;
  569. begin
  570. AddWeight:=false;
  571. i:=pos('=',keyvalue);
  572. if i=0 then
  573. exit;
  574. s:=Copy(KeyValue,i+1,length(KeyValue)-i);
  575. val(s,j,code);
  576. if code=0 Then
  577. begin
  578. Add(Copy(KeyValue,1,i-1),'',j);
  579. AddWeight:=True;
  580. end;
  581. end;
  582. procedure TLinkStrMap.addseries(keys:AnsiString;weight:longint);
  583. var
  584. i,j,k : longint;
  585. begin
  586. k:=length(keys);
  587. i:=1;
  588. while i<=k do
  589. begin
  590. j:=i;
  591. while (i<=k) and (keys[i]<>',') do
  592. inc(i);
  593. add(copy(keys,j,i-j),'',weight);
  594. inc(i);
  595. end;
  596. end;
  597. procedure TLinkStrMap.SetValue(Key:Ansistring;weight:Integer);
  598. var
  599. j : longint;
  600. begin
  601. j:=lookup(key);
  602. if j<>-1 then
  603. fmap[j].weight:=weight;
  604. end;
  605. function TLinkStrMap.find(key:Ansistring):Ansistring;
  606. var
  607. j : longint;
  608. begin
  609. find:='';
  610. j:=lookup(key);
  611. if j<>-1 then
  612. find:=fmap[j].value;
  613. end;
  614. function TLinkStrMap.lookup(key:Ansistring):longint;
  615. var
  616. i : longint;
  617. begin
  618. lookup:=-1;
  619. i:=0;
  620. while (i<itemcnt) and (fmap[i].key<>key) do
  621. inc(i);
  622. if i<>itemcnt then
  623. lookup:=i;
  624. end;
  625. procedure TLinkStrMap.SortOnWeight;
  626. var
  627. i, j : longint;
  628. m : TLinkRec;
  629. begin
  630. if itemcnt <2 then exit;
  631. for i:=0 to itemcnt-1 do
  632. for j:=i+1 to itemcnt-1 do
  633. begin
  634. if fmap[i].weight>fmap[j].weight Then
  635. begin
  636. m:=fmap[i];
  637. fmap[i]:=fmap[j];
  638. fmap[j]:=m;
  639. end;
  640. end;
  641. end;
  642. function TLinkStrMap.getlinkrec(i:longint):TLinkRec;
  643. begin
  644. result:=fmap[i];
  645. end;
  646. procedure TLinkStrMap.Expand(Src:TCmdStrList;Dest:TLinkStrMap);
  647. // expands every thing in Src to Dest for linkorder purposes.
  648. var
  649. r : longint;
  650. LibN : TCmdStr;
  651. begin
  652. while not src.empty do
  653. begin
  654. LibN:=src.getfirst;
  655. r:=lookup (LibN);
  656. if r=-1 then
  657. dest.add(LibN)
  658. else
  659. dest.addseries(fmap[r].value);
  660. end;
  661. end;
  662. procedure TLinkStrMap.UpdateWeights(Weightmap:TLinkStrMap);
  663. var
  664. l,r : longint;
  665. begin
  666. for l := 0 to itemcnt-1 do
  667. begin
  668. r:=weightmap.lookup (fmap[l].key);
  669. if r<>-1 then
  670. fmap[l].weight:=weightmap[r].weight;
  671. end;
  672. end;
  673. {****************************************************************************
  674. Time Handling
  675. ****************************************************************************}
  676. Function L0(l:longint):string;
  677. {
  678. return the string of value l, if l<10 then insert a zero, so
  679. the string is always at least 2 chars '01','02',etc
  680. }
  681. var
  682. s : string;
  683. begin
  684. Str(l,s);
  685. if l<10 then
  686. s:='0'+s;
  687. L0:=s;
  688. end;
  689. function gettimestr:string;
  690. {
  691. get the current time in a string HH:MM:SS
  692. }
  693. var
  694. st: TSystemTime;
  695. begin
  696. GetLocalTime(st);
  697. gettimestr:=L0(st.Hour)+':'+L0(st.Minute)+':'+L0(st.Second);
  698. end;
  699. function getdatestr:string;
  700. {
  701. get the current date in a string YY/MM/DD
  702. }
  703. var
  704. st: TSystemTime;
  705. begin
  706. GetLocalTime(st);
  707. getdatestr:=L0(st.Year)+'/'+L0(st.Month)+'/'+L0(st.Day);
  708. end;
  709. function filetimestring( t : longint) : string;
  710. {
  711. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  712. }
  713. var
  714. DT : TDateTime;
  715. hsec : word;
  716. Year,Month,Day: Word;
  717. hour,min,sec : word;
  718. begin
  719. if t=-1 then
  720. begin
  721. Result := 'Not Found';
  722. exit;
  723. end;
  724. DT := FileDateToDateTime(t);
  725. DecodeTime(DT,hour,min,sec,hsec);
  726. DecodeDate(DT,year,month,day);
  727. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  728. end;
  729. function getrealtime(const st: TSystemTime) : real;
  730. begin
  731. result := st.Hour*3600.0 + st.Minute*60.0 + st.Second + st.MilliSecond/1000.0;
  732. end;
  733. function getrealtime : real;
  734. var
  735. st:TSystemTime;
  736. begin
  737. GetLocalTime(st);
  738. result:=getrealtime(st);
  739. end;
  740. {****************************************************************************
  741. Default Macro Handling
  742. ****************************************************************************}
  743. procedure DefaultReplacements(var s:ansistring);
  744. {$ifdef mswindows}
  745. procedure ReplaceSpecialFolder(const MacroName: string; const ID: integer);
  746. begin
  747. // Only try to receive the special folders (and thus dynamically
  748. // load shfolder.dll) when that's needed.
  749. if pos(MacroName,s)>0 then
  750. Replace(s,MacroName,GetWindowsSpecialDir(ID));
  751. end;
  752. {$endif mswindows}
  753. var
  754. envstr: string;
  755. envvalue: pchar;
  756. i: integer;
  757. begin
  758. { Replace some macros }
  759. Replace(s,'$FPCVERSION',version_string);
  760. Replace(s,'$FPCFULLVERSION',full_version_string);
  761. Replace(s,'$FPCDATE',date_string);
  762. Replace(s,'$FPCCPU',target_cpu_string);
  763. Replace(s,'$FPCOS',target_os_string);
  764. if (tf_use_8_3 in Source_Info.Flags) or
  765. (tf_use_8_3 in Target_Info.Flags) then
  766. Replace(s,'$FPCTARGET',target_os_string)
  767. else
  768. Replace(s,'$FPCTARGET',target_full_string);
  769. Replace(s,'$FPCSUBARCH',lower(cputypestr[init_settings.cputype]));
  770. Replace(s,'$FPCABI',lower(abiinfo[target_info.abi].name));
  771. {$ifdef i8086}
  772. Replace(s,'$FPCMEMORYMODEL',lower(x86memorymodelstr[init_settings.x86memorymodel]));
  773. {$else i8086}
  774. Replace(s,'$FPCMEMORYMODEL','flat');
  775. {$endif i8086}
  776. {$ifdef mswindows}
  777. ReplaceSpecialFolder('$LOCAL_APPDATA',CSIDL_LOCAL_APPDATA);
  778. ReplaceSpecialFolder('$APPDATA',CSIDL_APPDATA);
  779. ReplaceSpecialFolder('$COMMON_APPDATA',CSIDL_COMMON_APPDATA);
  780. ReplaceSpecialFolder('$PERSONAL',CSIDL_PERSONAL);
  781. ReplaceSpecialFolder('$PROGRAM_FILES',CSIDL_PROGRAM_FILES);
  782. ReplaceSpecialFolder('$PROGRAM_FILES_COMMON',CSIDL_PROGRAM_FILES_COMMON);
  783. ReplaceSpecialFolder('$PROFILE',CSIDL_PROFILE);
  784. {$endif mswindows}
  785. { Replace environment variables between dollar signs }
  786. i := pos('$',s);
  787. while i>0 do
  788. begin
  789. envstr:=copy(s,i+1,length(s)-i);
  790. i:=pos('$',envstr);
  791. if i>0 then
  792. begin
  793. envstr := copy(envstr,1,i-1);
  794. envvalue := GetEnvPChar(envstr);
  795. if assigned(envvalue) then
  796. begin
  797. Replace(s,'$'+envstr+'$',envvalue);
  798. // Look if there is another env.var in the string
  799. i:=pos('$',s);
  800. end
  801. else
  802. // if the env.var is not set, do not replace the env.variable
  803. // and stop looking for more env.var within the string
  804. i := 0;
  805. FreeEnvPChar(envvalue);
  806. end;
  807. end;
  808. end;
  809. {****************************************************************************
  810. OS Dependent things
  811. ****************************************************************************}
  812. function GetEnvPChar(const envname:ansistring):pchar;
  813. {$ifdef mswindows}
  814. var
  815. s : string;
  816. i,len : longint;
  817. hp,p,p2 : pchar;
  818. {$endif}
  819. begin
  820. {$ifdef hasunix}
  821. GetEnvPchar:=BaseUnix.fpGetEnv(pansichar(envname));
  822. {$define GETENVOK}
  823. {$endif}
  824. {$ifdef mswindows}
  825. GetEnvPchar:=nil;
  826. p:=GetEnvironmentStringsA;
  827. hp:=p;
  828. while hp^<>#0 do
  829. begin
  830. s:=strpas(hp);
  831. i:=pos('=',s);
  832. len:=strlen(hp);
  833. if upper(copy(s,1,i-1))=upper(envname) then
  834. begin
  835. GetMem(p2,len-length(envname));
  836. Move(hp[i],p2^,len-length(envname));
  837. GetEnvPchar:=p2;
  838. break;
  839. end;
  840. { next string entry}
  841. hp:=hp+len+1;
  842. end;
  843. FreeEnvironmentStrings(p);
  844. {$define GETENVOK}
  845. {$endif}
  846. {$ifdef os2}
  847. GetEnvPChar := Dos.GetEnvPChar (EnvName);
  848. {$define GETENVOK}
  849. {$endif}
  850. {$ifdef GETENVOK}
  851. {$undef GETENVOK}
  852. {$else}
  853. GetEnvPchar:=StrPNew(GetEnvironmentVariable(envname));
  854. if (length(GetEnvPChar)=0) then
  855. begin
  856. FreeEnvPChar(GetEnvPChar);
  857. GetEnvPChar:=nil;
  858. end;
  859. {$endif}
  860. end;
  861. procedure FreeEnvPChar(p:pchar);
  862. begin
  863. {$ifndef hasunix}
  864. {$ifndef os2}
  865. freemem(p);
  866. {$endif}
  867. {$endif}
  868. end;
  869. function is_number_float(d : double) : boolean;
  870. var
  871. bytearray : array[0..7] of byte;
  872. begin
  873. move(d,bytearray,8);
  874. { only 1.1 save, 1.0.x will use always little endian }
  875. {$ifdef FPC_BIG_ENDIAN}
  876. result:=((bytearray[0] and $7f)<>$7f) or ((bytearray[1] and $f0)<>$f0);
  877. {$else FPC_BIG_ENDIAN}
  878. result:=((bytearray[7] and $7f)<>$7f) or ((bytearray[6] and $f0)<>$f0);
  879. {$endif FPC_BIG_ENDIAN}
  880. end;
  881. function get_real_sign(r: bestreal): longint;
  882. var
  883. p: pbyte;
  884. begin
  885. p := pbyte(@r);
  886. {$ifdef CPU_ARM}
  887. inc(p,4);
  888. {$else}
  889. {$ifdef FPC_LITTLE_ENDIAN}
  890. inc(p,sizeof(r)-1);
  891. {$endif}
  892. {$endif}
  893. if (p^ and $80) = 0 then
  894. result := 1
  895. else
  896. result := -1;
  897. end;
  898. function convertdoublerec(d : tcompdoublerec) : tcompdoublerec;{$ifdef USEINLINE}inline;{$endif}
  899. {$ifdef CPUARM}
  900. var
  901. i : longint;
  902. begin
  903. for i:=0 to 3 do
  904. begin
  905. result.bytes[i+4]:=d.bytes[i];
  906. result.bytes[i]:=d.bytes[i+4];
  907. end;
  908. {$else CPUARM}
  909. begin
  910. result:=d;
  911. {$endif CPUARM}
  912. end;
  913. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  914. function string2guid(const s: string; var GUID: TGUID): boolean;
  915. function ishexstr(const hs: string): boolean;
  916. var
  917. i: integer;
  918. begin
  919. ishexstr:=false;
  920. for i:=1 to Length(hs) do begin
  921. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  922. exit;
  923. end;
  924. ishexstr:=true;
  925. end;
  926. function hexstr2longint(const hexs: string): longint;
  927. var
  928. i: integer;
  929. rl: longint;
  930. begin
  931. rl:=0;
  932. for i:=1 to length(hexs) do begin
  933. rl:=rl shl 4;
  934. case hexs[i] of
  935. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  936. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  937. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  938. end
  939. end;
  940. hexstr2longint:=rl;
  941. end;
  942. var
  943. i: integer;
  944. begin
  945. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  946. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  947. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  948. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  949. ishexstr(copy(s,26,12)) then begin
  950. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  951. { these values are arealdy in the correct range (4 chars = word) }
  952. GUID.D2:=word(hexstr2longint(copy(s,11,4)));
  953. GUID.D3:=word(hexstr2longint(copy(s,16,4)));
  954. for i:=0 to 1 do
  955. GUID.D4[i]:=byte(hexstr2longint(copy(s,21+i*2,2)));
  956. for i:=2 to 7 do
  957. GUID.D4[i]:=byte(hexstr2longint(copy(s,22+i*2,2)));
  958. string2guid:=true;
  959. end
  960. else if (length(s)=0) then
  961. begin
  962. FillChar(GUID,SizeOf(GUID),0);
  963. string2guid:=true;
  964. end
  965. else
  966. string2guid:=false;
  967. end;
  968. function guid2string(const GUID: TGUID): string;
  969. begin
  970. guid2string:=
  971. '{'+hexstr(GUID.D1,8)+
  972. '-'+hexstr(GUID.D2,4)+
  973. '-'+hexstr(GUID.D3,4)+
  974. '-'+hexstr(GUID.D4[0],2)+hexstr(GUID.D4[1],2)+
  975. '-'+hexstr(GUID.D4[2],2)+hexstr(GUID.D4[3],2)+
  976. hexstr(GUID.D4[4],2)+hexstr(GUID.D4[5],2)+
  977. hexstr(GUID.D4[6],2)+hexstr(GUID.D4[7],2)+
  978. '}';
  979. end;
  980. function SetAktProcCall(const s:string; var a:tproccalloption):boolean;
  981. const
  982. DefProcCallName : array[tproccalloption] of string[16] = ('',
  983. 'CDECL',
  984. 'CPPDECL',
  985. 'FAR16',
  986. 'OLDFPCCALL',
  987. '', { internproc }
  988. '', { syscall }
  989. 'PASCAL',
  990. 'REGISTER',
  991. 'SAFECALL',
  992. 'STDCALL',
  993. 'SOFTFLOAT',
  994. 'MWPASCAL',
  995. 'INTERRUPT',
  996. 'HARDFLOAT',
  997. 'SYSV_ABI_DEFAULT',
  998. 'SYSV_ABI_CDECL',
  999. 'MS_ABI_DEFAULT',
  1000. 'MS_ABI_CDECL',
  1001. 'VECTORCALL'
  1002. );
  1003. var
  1004. t : tproccalloption;
  1005. hs : string;
  1006. begin
  1007. result:=false;
  1008. if (s = '') then
  1009. exit;
  1010. hs:=upper(s);
  1011. if (hs = 'DEFAULT') then
  1012. begin
  1013. a := pocall_default;
  1014. result := true;
  1015. exit;
  1016. end;
  1017. for t:=low(tproccalloption) to high(tproccalloption) do
  1018. if DefProcCallName[t]=hs then
  1019. begin
  1020. a:=t;
  1021. result:=true;
  1022. break;
  1023. end;
  1024. end;
  1025. function Setabitype(const s:string;var a:tabi):boolean;
  1026. var
  1027. t : tabi;
  1028. hs : string;
  1029. begin
  1030. result:=false;
  1031. hs:=Upper(s);
  1032. for t:=low(t) to high(t) do
  1033. if abiinfo[t].supported and
  1034. (abiinfo[t].name=hs) then
  1035. begin
  1036. a:=t;
  1037. { abi_old_win32_gnu is a win32 i386 specific "feature" }
  1038. if (t<>abi_old_win32_gnu) or (target_info.system=system_i386_win32) then
  1039. result:=true;
  1040. break;
  1041. end;
  1042. end;
  1043. function Setoptimizecputype(const s:string;var a:tcputype):boolean;
  1044. var
  1045. t : tcputype;
  1046. hs : string;
  1047. begin
  1048. result:=false;
  1049. hs:=Upper(s);
  1050. for t:=low(tcputype) to high(tcputype) do
  1051. if cputypestr[t]=hs then
  1052. begin
  1053. a:=t;
  1054. result:=true;
  1055. break;
  1056. end;
  1057. end;
  1058. function Setcputype(const s:string;var a:tsettings):boolean;
  1059. var
  1060. t : tcputype;
  1061. hs : string;
  1062. begin
  1063. result:=false;
  1064. hs:=Upper(s);
  1065. for t:=low(tcputype) to high(tcputype) do
  1066. if cputypestr[t]=hs then
  1067. begin
  1068. a.cputype:=t;
  1069. result:=true;
  1070. break;
  1071. end;
  1072. {$ifdef arm}
  1073. { set default instruction set for arm }
  1074. if result then
  1075. begin
  1076. if a.cputype in [cpu_armv6m,cpu_armv6t2,cpu_armv7m,cpu_armv7em] then
  1077. a.instructionset:=is_thumb
  1078. else
  1079. a.instructionset:=is_arm;
  1080. end;
  1081. {$endif arm}
  1082. end;
  1083. function SetFpuType(const s:string;var a:tfputype):boolean;
  1084. var
  1085. t : tfputype;
  1086. begin
  1087. result:=false;
  1088. for t:=low(tfputype) to high(tfputype) do
  1089. if fputypestr[t]=s then
  1090. begin
  1091. a:=t;
  1092. result:=true;
  1093. break;
  1094. end;
  1095. end;
  1096. function SetControllerType(const s:string;var a:tcontrollertype):boolean;
  1097. var
  1098. t : tcontrollertype;
  1099. hs : string;
  1100. begin
  1101. { The following check allows to reduce amount of code for platforms }
  1102. { not supporting microcontrollers due to evaluation at compile time. }
  1103. {$PUSH}
  1104. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  1105. if ControllerSupport then
  1106. begin
  1107. result:=false;
  1108. hs:=Upper(s);
  1109. for t:=low(tcontrollertype) to high(tcontrollertype) do
  1110. if embedded_controllers[t].controllertypestr=hs then
  1111. begin
  1112. a:=t;
  1113. result:=true;
  1114. break;
  1115. end;
  1116. end
  1117. else
  1118. begin
  1119. a := ct_none;
  1120. Result := true;
  1121. end;
  1122. {$POP}
  1123. end;
  1124. function HandleFeature(const s : string) : boolean;
  1125. var
  1126. i : tfeature;
  1127. begin
  1128. result:=true;
  1129. for i:=low(tfeature) to high(tfeature) do
  1130. if s=featurestr[i] then
  1131. begin
  1132. include(features,i);
  1133. exit;
  1134. end;
  1135. { Also support -Sfnoheap to exclude heap }
  1136. if Copy(S,1,2)='NO' then
  1137. for i:=low(tfeature) to high(tfeature) do
  1138. if s='NO'+featurestr[i] then
  1139. begin
  1140. exclude(features,i);
  1141. exit;
  1142. end;
  1143. result:=false;
  1144. end;
  1145. function SetMinFPConstPrec(const s: string; var a: tfloattype) : boolean;
  1146. var
  1147. value, error: longint;
  1148. begin
  1149. if (upper(s)='DEFAULT') then
  1150. begin
  1151. a:=s32real;
  1152. result:=true;
  1153. exit;
  1154. end;
  1155. result:=false;
  1156. val(s,value,error);
  1157. if (error<>0) then
  1158. exit;
  1159. case value of
  1160. 32: a:=s32real;
  1161. 64: a:=s64real;
  1162. { adding support for 80 bit here is tricky, since we can't really }
  1163. { check whether the target cpu+OS actually supports it }
  1164. else
  1165. exit;
  1166. end;
  1167. result:=true;
  1168. end;
  1169. function var_align(want_align: longint): shortint;
  1170. begin
  1171. var_align := used_align(want_align,current_settings.alignment.varalignmin,current_settings.alignment.varalignmax);
  1172. end;
  1173. function var_align_size(siz: longint): shortint;
  1174. begin
  1175. siz := size_2_align(siz);
  1176. var_align_size := var_align(siz);
  1177. end;
  1178. function const_align(want_align: longint): shortint;
  1179. begin
  1180. const_align := used_align(want_align,current_settings.alignment.constalignmin,current_settings.alignment.constalignmax);
  1181. end;
  1182. function const_align_size(siz: longint): shortint;
  1183. begin
  1184. siz := size_2_align(siz);
  1185. const_align_size := const_align(siz);
  1186. end;
  1187. {$ifdef ARM}
  1188. function is_double_hilo_swapped: boolean;{$ifdef USEINLINE}inline;{$endif}
  1189. begin
  1190. result := (current_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  1191. not(cs_fp_emulation in current_settings.moduleswitches);
  1192. {$ifdef FPC_DOUBLE_HILO_SWAPPED}
  1193. { inverse result if compiler was compiled with swapped hilo already }
  1194. result := not result;
  1195. {$endif FPC_DOUBLE_HILO_SWAPPED}
  1196. end;
  1197. {$endif ARM}
  1198. function floating_point_range_check_error : boolean;
  1199. begin
  1200. result:=cs_ieee_errors in current_settings.localswitches;
  1201. end;
  1202. function use_dotted_functions: boolean;
  1203. begin
  1204. result:=
  1205. (target_info.system in systems_dotted_function_names) and
  1206. (target_info.abi<>abi_powerpc_elfv2);
  1207. end;
  1208. {****************************************************************************
  1209. Init
  1210. ****************************************************************************}
  1211. {$ifdef unix}
  1212. {$define need_path_search}
  1213. {$endif unix}
  1214. {$ifdef os2}
  1215. {$define need_path_search}
  1216. {$endif os2}
  1217. {$ifdef macos}
  1218. {$define need_path_search}
  1219. {$endif macos}
  1220. procedure get_exepath;
  1221. var
  1222. localExepath : TCmdStr;
  1223. exeName:TCmdStr;
  1224. {$ifdef need_path_search}
  1225. hs1 : TPathStr;
  1226. {$endif need_path_search}
  1227. begin
  1228. localexepath:=GetEnvironmentVariable('PPC_EXEC_PATH');
  1229. exeName := '';
  1230. if localexepath='' then
  1231. begin
  1232. exeName := FixFileName(system.paramstr(0));
  1233. localexepath := ExtractFilePath(exeName);
  1234. end;
  1235. {$ifdef need_path_search}
  1236. if localexepath='' then
  1237. begin
  1238. hs1 := ExtractFileName(exeName);
  1239. ChangeFileExt(hs1,source_info.exeext);
  1240. {$ifdef macos}
  1241. FindFile(hs1,GetEnvironmentVariable('Commands'),false,localExepath);
  1242. {$else macos}
  1243. FindFile(hs1,GetEnvironmentVariable('PATH'),false,localExepath);
  1244. {$endif macos}
  1245. localExepath:=ExtractFilePath(localExepath);
  1246. end;
  1247. {$endif need_path_search}
  1248. exepath:=FixPath(localExepath,false);
  1249. end;
  1250. type
  1251. tinitdoneentry=record
  1252. init:tprocedure;
  1253. done:tprocedure;
  1254. end;
  1255. pinitdoneentry=^tinitdoneentry;
  1256. const
  1257. initdoneprocs : TFPList = nil;
  1258. procedure allocinitdoneprocs;
  1259. begin
  1260. { Avoid double initialization }
  1261. if assigned(initdoneprocs) then
  1262. exit;
  1263. initdoneprocs:=tfplist.create;
  1264. end;
  1265. procedure register_initdone_proc(init,done:tprocedure);
  1266. var
  1267. entry : pinitdoneentry;
  1268. begin
  1269. new(entry);
  1270. entry^.init:=init;
  1271. entry^.done:=done;
  1272. { Do not rely on the fact that
  1273. globals unit initialization code
  1274. has already been executed.
  1275. Unit initialization order is too
  1276. uncertian for that. PM }
  1277. if not assigned(initdoneprocs) then
  1278. allocinitdoneprocs;
  1279. initdoneprocs.add(entry);
  1280. end;
  1281. procedure callinitprocs;
  1282. var
  1283. i : longint;
  1284. begin
  1285. if not assigned(initdoneprocs) then
  1286. exit;
  1287. for i:=0 to initdoneprocs.count-1 do
  1288. with pinitdoneentry(initdoneprocs[i])^ do
  1289. if assigned(init) then
  1290. init();
  1291. end;
  1292. procedure calldoneprocs;
  1293. var
  1294. i : longint;
  1295. begin
  1296. if not assigned(initdoneprocs) then
  1297. exit;
  1298. for i:=0 to initdoneprocs.count-1 do
  1299. with pinitdoneentry(initdoneprocs[i])^ do
  1300. if assigned(done) then
  1301. done();
  1302. end;
  1303. procedure freeinitdoneprocs;
  1304. var
  1305. i : longint;
  1306. begin
  1307. if not assigned(initdoneprocs) then
  1308. exit;
  1309. for i:=0 to initdoneprocs.count-1 do
  1310. dispose(pinitdoneentry(initdoneprocs[i]));
  1311. initdoneprocs.free;
  1312. { Reset variable, to be on the safe side }
  1313. initdoneprocs:=nil;
  1314. end;
  1315. procedure DoneGlobals;
  1316. begin
  1317. calldoneprocs;
  1318. librarysearchpath.Free;
  1319. unitsearchpath.Free;
  1320. objectsearchpath.Free;
  1321. includesearchpath.Free;
  1322. frameworksearchpath.Free;
  1323. LinkLibraryAliases.Free;
  1324. LinkLibraryOrder.Free;
  1325. packagesearchpath.Free;
  1326. namespacelist.Free;
  1327. end;
  1328. procedure InitGlobals;
  1329. begin
  1330. get_exepath;
  1331. { reset globals }
  1332. do_build:=false;
  1333. do_release:=false;
  1334. do_make:=true;
  1335. compile_level:=0;
  1336. codegenerror:=false;
  1337. { Output }
  1338. OutputFileName:='';
  1339. OutputPrefix:=Nil;
  1340. OutputSuffix:=Nil;
  1341. OutputExeDir:='';
  1342. OutputUnitDir:='';
  1343. { Utils directory }
  1344. utilsdirectory:='';
  1345. utilsprefix:='';
  1346. cshared:=false;
  1347. rlinkpath:='';
  1348. sysrootpath:='';
  1349. { Search Paths }
  1350. unicodepath:='';
  1351. librarysearchpath:=TSearchPathList.Create;
  1352. unitsearchpath:=TSearchPathList.Create;
  1353. includesearchpath:=TSearchPathList.Create;
  1354. objectsearchpath:=TSearchPathList.Create;
  1355. frameworksearchpath:=TSearchPathList.Create;
  1356. packagesearchpath:=TSearchPathList.Create;
  1357. namespacelist:=TCmdStrList.Create;
  1358. { Def file }
  1359. usewindowapi:=false;
  1360. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1361. DescriptionSetExplicity:=false;
  1362. SetPEFlagsSetExplicity:=false;
  1363. SetPEOptFlagsSetExplicity:=false;
  1364. SetPEOSVersionSetExplicitely:=false;
  1365. SetPESubSysVersionSetExplicitely:=false;
  1366. SetPEUserVersionSetExplicitely:=false;
  1367. ImageBaseSetExplicity:=false;
  1368. MinStackSizeSetExplicity:=false;
  1369. MaxStackSizeSetExplicity:=false;
  1370. dllversion:='';
  1371. dllmajor:=1;
  1372. dllminor:=0;
  1373. dllrevision:=0;
  1374. nwscreenname := '';
  1375. nwthreadname := '';
  1376. nwcopyright := '';
  1377. UseDeffileForExports:=false;
  1378. UseDeffileForExportsSetExplicitly:=false;
  1379. GenerateImportSection:=false;
  1380. RelocSection:=false;
  1381. RelocSectionSetExplicitly:=false;
  1382. MacOSXVersionMin:='';
  1383. iPhoneOSVersionMin:='';
  1384. { memory sizes, will be overridden by parameter or default for target
  1385. in options or init_parser }
  1386. stacksize:=0;
  1387. { not initialized yet }
  1388. apptype:=app_cui;
  1389. { Init values }
  1390. init_settings:=default_settings;
  1391. if init_settings.optimizecputype=cpu_none then
  1392. init_settings.optimizecputype:=init_settings.cputype;
  1393. LinkLibraryAliases :=TLinkStrMap.Create;
  1394. LinkLibraryOrder :=TLinkStrMap.Create;
  1395. { enable all features by default }
  1396. features:=[low(Tfeature)..high(Tfeature)];
  1397. callinitprocs;
  1398. end;
  1399. initialization
  1400. allocinitdoneprocs;
  1401. finalization
  1402. freeinitdoneprocs;
  1403. end.