globals.pas 43 KB

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