globals.pas 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  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. {$ifdef VER2_4}
  415. cwindirs,
  416. {$else VER2_4}
  417. windirs,
  418. {$endif VER2_4}
  419. {$endif}
  420. comphook;
  421. {****************************************************************************
  422. TLinkStrMap
  423. ****************************************************************************}
  424. Constructor TLinkStrMap.create;
  425. begin
  426. inherited;
  427. itemcnt:=0;
  428. end;
  429. procedure TLinkStrMap.Add(key:ansistring;value:AnsiString='';weight:longint=LinkMapWeightDefault);
  430. begin
  431. if lookup(key)<>-1 Then
  432. exit;
  433. if itemcnt<=length(fmap) Then
  434. setlength(fmap,itemcnt+10);
  435. fmap[itemcnt].key:=key;
  436. fmap[itemcnt].value:=value;
  437. fmap[itemcnt].weight:=weight;
  438. inc(itemcnt);
  439. end;
  440. function TLinkStrMap.AddDep(keyvalue:String):boolean;
  441. var
  442. i : Longint;
  443. begin
  444. AddDep:=false;
  445. i:=pos('=',keyvalue);
  446. if i=0 then
  447. exit;
  448. Add(Copy(KeyValue,1,i-1),Copy(KeyValue,i+1,length(KeyValue)-i));
  449. AddDep:=True;
  450. end;
  451. function TLinkStrMap.AddWeight(keyvalue:String):boolean;
  452. var
  453. i,j : Longint;
  454. Code : Word;
  455. s : AnsiString;
  456. begin
  457. AddWeight:=false;
  458. i:=pos('=',keyvalue);
  459. if i=0 then
  460. exit;
  461. s:=Copy(KeyValue,i+1,length(KeyValue)-i);
  462. val(s,j,code);
  463. if code=0 Then
  464. begin
  465. Add(Copy(KeyValue,1,i-1),'',j);
  466. AddWeight:=True;
  467. end;
  468. end;
  469. procedure TLinkStrMap.addseries(keys:AnsiString;weight:longint);
  470. var
  471. i,j,k : longint;
  472. begin
  473. k:=length(keys);
  474. i:=1;
  475. while i<=k do
  476. begin
  477. j:=i;
  478. while (i<=k) and (keys[i]<>',') do
  479. inc(i);
  480. add(copy(keys,j,i-j),'',weight);
  481. inc(i);
  482. end;
  483. end;
  484. procedure TLinkStrMap.SetValue(Key:Ansistring;weight:Integer);
  485. var
  486. j : longint;
  487. begin
  488. j:=lookup(key);
  489. if j<>-1 then
  490. fmap[j].weight:=weight;
  491. end;
  492. function TLinkStrMap.find(key:Ansistring):Ansistring;
  493. var
  494. j : longint;
  495. begin
  496. find:='';
  497. j:=lookup(key);
  498. if j<>-1 then
  499. find:=fmap[j].value;
  500. end;
  501. function TLinkStrMap.lookup(key:Ansistring):longint;
  502. var
  503. i : longint;
  504. begin
  505. lookup:=-1;
  506. i:=0;
  507. while (i<itemcnt) and (fmap[i].key<>key) do
  508. inc(i);
  509. if i<>itemcnt then
  510. lookup:=i;
  511. end;
  512. procedure TLinkStrMap.SortOnWeight;
  513. var
  514. i, j : longint;
  515. m : TLinkRec;
  516. begin
  517. if itemcnt <2 then exit;
  518. for i:=0 to itemcnt-1 do
  519. for j:=i+1 to itemcnt-1 do
  520. begin
  521. if fmap[i].weight>fmap[j].weight Then
  522. begin
  523. m:=fmap[i];
  524. fmap[i]:=fmap[j];
  525. fmap[j]:=m;
  526. end;
  527. end;
  528. end;
  529. function TLinkStrMap.getlinkrec(i:longint):TLinkRec;
  530. begin
  531. result:=fmap[i];
  532. end;
  533. procedure TLinkStrMap.Expand(Src:TCmdStrList;Dest:TLinkStrMap);
  534. // expands every thing in Src to Dest for linkorder purposes.
  535. var
  536. r : longint;
  537. LibN : TCmdStr;
  538. begin
  539. while not src.empty do
  540. begin
  541. LibN:=src.getfirst;
  542. r:=lookup (LibN);
  543. if r=-1 then
  544. dest.add(LibN)
  545. else
  546. dest.addseries(fmap[r].value);
  547. end;
  548. end;
  549. procedure TLinkStrMap.UpdateWeights(Weightmap:TLinkStrMap);
  550. var
  551. l,r : longint;
  552. begin
  553. for l := 0 to itemcnt-1 do
  554. begin
  555. r:=weightmap.lookup (fmap[l].key);
  556. if r<>-1 then
  557. fmap[l].weight:=weightmap[r].weight;
  558. end;
  559. end;
  560. {****************************************************************************
  561. Time Handling
  562. ****************************************************************************}
  563. Function L0(l:longint):string;
  564. {
  565. return the string of value l, if l<10 then insert a zero, so
  566. the string is always at least 2 chars '01','02',etc
  567. }
  568. var
  569. s : string;
  570. begin
  571. Str(l,s);
  572. if l<10 then
  573. s:='0'+s;
  574. L0:=s;
  575. end;
  576. function gettimestr:string;
  577. {
  578. get the current time in a string HH:MM:SS
  579. }
  580. var
  581. hour,min,sec,hsec : word;
  582. begin
  583. DecodeTime(Time,hour,min,sec,hsec);
  584. gettimestr:=L0(Hour)+':'+L0(min)+':'+L0(sec);
  585. end;
  586. function getdatestr:string;
  587. {
  588. get the current date in a string YY/MM/DD
  589. }
  590. var
  591. Year,Month,Day: Word;
  592. begin
  593. DecodeDate(Date,year,month,day);
  594. getdatestr:=L0(Year)+'/'+L0(Month)+'/'+L0(Day);
  595. end;
  596. function filetimestring( t : longint) : string;
  597. {
  598. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  599. }
  600. var
  601. DT : TDateTime;
  602. hsec : word;
  603. Year,Month,Day: Word;
  604. hour,min,sec : word;
  605. begin
  606. if t=-1 then
  607. begin
  608. Result := 'Not Found';
  609. exit;
  610. end;
  611. DT := FileDateToDateTime(t);
  612. DecodeTime(DT,hour,min,sec,hsec);
  613. DecodeDate(DT,year,month,day);
  614. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  615. end;
  616. function getrealtime : real;
  617. var
  618. h,m,s,s1000 : word;
  619. begin
  620. DecodeTime(Time,h,m,s,s1000);
  621. result:=h*3600.0+m*60.0+s+s1000/1000.0;
  622. end;
  623. {****************************************************************************
  624. Default Macro Handling
  625. ****************************************************************************}
  626. procedure DefaultReplacements(var s:ansistring);
  627. {$ifdef mswindows}
  628. procedure ReplaceSpecialFolder(const MacroName: string; const ID: integer);
  629. begin
  630. // Only try to receive the special folders (and thus dynamically
  631. // load shfolder.dll) when that's needed.
  632. if pos(MacroName,s)>0 then
  633. Replace(s,MacroName,GetWindowsSpecialDir(ID));
  634. end;
  635. {$endif mswindows}
  636. var
  637. envstr: string;
  638. envvalue: pchar;
  639. i: integer;
  640. begin
  641. { Replace some macros }
  642. Replace(s,'$FPCVERSION',version_string);
  643. Replace(s,'$FPCFULLVERSION',full_version_string);
  644. Replace(s,'$FPCDATE',date_string);
  645. Replace(s,'$FPCCPU',target_cpu_string);
  646. Replace(s,'$FPCOS',target_os_string);
  647. if tf_use_8_3 in Source_Info.Flags then
  648. Replace(s,'$FPCTARGET',target_os_string)
  649. else
  650. Replace(s,'$FPCTARGET',target_full_string);
  651. {$ifdef mswindows}
  652. ReplaceSpecialFolder('$LOCAL_APPDATA',CSIDL_LOCAL_APPDATA);
  653. ReplaceSpecialFolder('$APPDATA',CSIDL_APPDATA);
  654. ReplaceSpecialFolder('$COMMON_APPDATA',CSIDL_COMMON_APPDATA);
  655. ReplaceSpecialFolder('$PERSONAL',CSIDL_PERSONAL);
  656. ReplaceSpecialFolder('$PROGRAM_FILES',CSIDL_PROGRAM_FILES);
  657. ReplaceSpecialFolder('$PROGRAM_FILES_COMMON',CSIDL_PROGRAM_FILES_COMMON);
  658. ReplaceSpecialFolder('$PROFILE',CSIDL_PROFILE);
  659. {$endif mswindows}
  660. { Replace environment variables between dollar signs }
  661. i := pos('$',s);
  662. while i>0 do
  663. begin
  664. envstr:=copy(s,i+1,length(s)-i);
  665. i:=pos('$',envstr);
  666. if i>0 then
  667. begin
  668. envstr := copy(envstr,1,i-1);
  669. envvalue := GetEnvPChar(envstr);
  670. if assigned(envvalue) then
  671. begin
  672. Replace(s,'$'+envstr+'$',envvalue);
  673. // Look if there is another env.var in the string
  674. i:=pos('$',s);
  675. end
  676. else
  677. // if the env.var is not set, do not replace the env.variable
  678. // and stop looking for more env.var within the string
  679. i := 0;
  680. FreeEnvPChar(envvalue);
  681. end;
  682. end;
  683. end;
  684. {****************************************************************************
  685. OS Dependent things
  686. ****************************************************************************}
  687. function GetEnvPChar(const envname:string):pchar;
  688. {$ifdef win32}
  689. var
  690. s : string;
  691. i,len : longint;
  692. hp,p,p2 : pchar;
  693. {$endif}
  694. begin
  695. {$ifdef hasunix}
  696. GetEnvPchar:=BaseUnix.fpGetEnv(envname);
  697. {$define GETENVOK}
  698. {$endif}
  699. {$ifdef win32}
  700. GetEnvPchar:=nil;
  701. p:=GetEnvironmentStrings;
  702. hp:=p;
  703. while hp^<>#0 do
  704. begin
  705. s:=strpas(hp);
  706. i:=pos('=',s);
  707. len:=strlen(hp);
  708. if upper(copy(s,1,i-1))=upper(envname) then
  709. begin
  710. GetMem(p2,len-length(envname));
  711. Move(hp[i],p2^,len-length(envname));
  712. GetEnvPchar:=p2;
  713. break;
  714. end;
  715. { next string entry}
  716. hp:=hp+len+1;
  717. end;
  718. FreeEnvironmentStrings(p);
  719. {$define GETENVOK}
  720. {$endif}
  721. {$ifdef os2}
  722. GetEnvPChar := Dos.GetEnvPChar (EnvName);
  723. {$define GETENVOK}
  724. {$endif}
  725. {$ifdef GETENVOK}
  726. {$undef GETENVOK}
  727. {$else}
  728. GetEnvPchar:=StrPNew(GetEnvironmentVariable(envname));
  729. {$endif}
  730. end;
  731. procedure FreeEnvPChar(p:pchar);
  732. begin
  733. {$ifndef hasunix}
  734. {$ifndef os2}
  735. freemem(p);
  736. {$endif}
  737. {$endif}
  738. end;
  739. {$if defined(MORPHOS) or defined(AMIGA)}
  740. {$define AMIGASHELL}
  741. {$endif}
  742. function Shell(const command:ansistring): longint;
  743. { This is already defined in the linux.ppu for linux, need for the *
  744. expansion under linux }
  745. {$ifdef hasunix}
  746. begin
  747. result := Unix.fpsystem(command);
  748. end;
  749. {$else hasunix}
  750. {$ifdef amigashell}
  751. begin
  752. result := ExecuteProcess('',command);
  753. end;
  754. {$else amigashell}
  755. var
  756. comspec : string;
  757. begin
  758. comspec:=GetEnvironmentVariable('COMSPEC');
  759. result := ExecuteProcess(comspec,' /C '+command);
  760. end;
  761. {$endif amigashell}
  762. {$endif hasunix}
  763. {$UNDEF AMIGASHELL}
  764. function is_number_float(d : double) : boolean;
  765. var
  766. bytearray : array[0..7] of byte;
  767. begin
  768. move(d,bytearray,8);
  769. { only 1.1 save, 1.0.x will use always little endian }
  770. {$ifdef FPC_BIG_ENDIAN}
  771. result:=((bytearray[0] and $7f)<>$7f) or ((bytearray[1] and $f0)<>$f0);
  772. {$else FPC_BIG_ENDIAN}
  773. result:=((bytearray[7] and $7f)<>$7f) or ((bytearray[6] and $f0)<>$f0);
  774. {$endif FPC_BIG_ENDIAN}
  775. end;
  776. function get_real_sign(r: bestreal): longint;
  777. var
  778. p: pbyte;
  779. begin
  780. p := pbyte(@r);
  781. {$ifdef CPU_ARM}
  782. inc(p,4);
  783. {$else}
  784. {$ifdef FPC_LITTLE_ENDIAN}
  785. inc(p,sizeof(r)-1);
  786. {$endif}
  787. {$endif}
  788. if (p^ and $80) = 0 then
  789. result := 1
  790. else
  791. result := -1;
  792. end;
  793. function convertdoublerec(d : tdoublerec) : tdoublerec;{$ifdef USEINLINE}inline;{$endif}
  794. {$ifdef CPUARM}
  795. var
  796. i : longint;
  797. begin
  798. for i:=0 to 3 do
  799. begin
  800. result.bytes[i+4]:=d.bytes[i];
  801. result.bytes[i]:=d.bytes[i+4];
  802. end;
  803. {$else CPUARM}
  804. begin
  805. result:=d;
  806. {$endif CPUARM}
  807. end;
  808. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  809. function string2guid(const s: string; var GUID: TGUID): boolean;
  810. function ishexstr(const hs: string): boolean;
  811. var
  812. i: integer;
  813. begin
  814. ishexstr:=false;
  815. for i:=1 to Length(hs) do begin
  816. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  817. exit;
  818. end;
  819. ishexstr:=true;
  820. end;
  821. function hexstr2longint(const hexs: string): longint;
  822. var
  823. i: integer;
  824. rl: longint;
  825. begin
  826. rl:=0;
  827. for i:=1 to length(hexs) do begin
  828. rl:=rl shl 4;
  829. case hexs[i] of
  830. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  831. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  832. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  833. end
  834. end;
  835. hexstr2longint:=rl;
  836. end;
  837. var
  838. i: integer;
  839. begin
  840. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  841. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  842. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  843. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  844. ishexstr(copy(s,26,12)) then begin
  845. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  846. { these values are arealdy in the correct range (4 chars = word) }
  847. GUID.D2:=word(hexstr2longint(copy(s,11,4)));
  848. GUID.D3:=word(hexstr2longint(copy(s,16,4)));
  849. for i:=0 to 1 do
  850. GUID.D4[i]:=byte(hexstr2longint(copy(s,21+i*2,2)));
  851. for i:=2 to 7 do
  852. GUID.D4[i]:=byte(hexstr2longint(copy(s,22+i*2,2)));
  853. string2guid:=true;
  854. end
  855. else if (length(s)=0) then
  856. begin
  857. FillChar(GUID,SizeOf(GUID),0);
  858. string2guid:=true;
  859. end
  860. else
  861. string2guid:=false;
  862. end;
  863. function guid2string(const GUID: TGUID): string;
  864. begin
  865. guid2string:=
  866. '{'+hexstr(GUID.D1,8)+
  867. '-'+hexstr(GUID.D2,4)+
  868. '-'+hexstr(GUID.D3,4)+
  869. '-'+hexstr(GUID.D4[0],2)+hexstr(GUID.D4[1],2)+
  870. '-'+hexstr(GUID.D4[2],2)+hexstr(GUID.D4[3],2)+
  871. hexstr(GUID.D4[4],2)+hexstr(GUID.D4[5],2)+
  872. hexstr(GUID.D4[6],2)+hexstr(GUID.D4[7],2)+
  873. '}';
  874. end;
  875. function SetAktProcCall(const s:string; var a:tproccalloption):boolean;
  876. const
  877. DefProcCallName : array[tproccalloption] of string[12] = ('',
  878. 'CDECL',
  879. 'CPPDECL',
  880. 'FAR16',
  881. 'OLDFPCCALL',
  882. '', { internproc }
  883. '', { syscall }
  884. 'PASCAL',
  885. 'REGISTER',
  886. 'SAFECALL',
  887. 'STDCALL',
  888. 'SOFTFLOAT',
  889. 'MWPASCAL'
  890. );
  891. var
  892. t : tproccalloption;
  893. hs : string;
  894. begin
  895. result:=false;
  896. if (s = '') then
  897. exit;
  898. hs:=upper(s);
  899. if (hs = 'DEFAULT') then
  900. begin
  901. a := pocall_default;
  902. result := true;
  903. exit;
  904. end;
  905. for t:=low(tproccalloption) to high(tproccalloption) do
  906. if DefProcCallName[t]=hs then
  907. begin
  908. a:=t;
  909. result:=true;
  910. break;
  911. end;
  912. end;
  913. function Setabitype(const s:string;var a:tabi):boolean;
  914. var
  915. t : tabi;
  916. hs : string;
  917. begin
  918. result:=false;
  919. hs:=Upper(s);
  920. for t:=low(t) to high(t) do
  921. if abi2str[t]=hs then
  922. begin
  923. a:=t;
  924. result:=true;
  925. break;
  926. end;
  927. end;
  928. function Setcputype(const s:string;var a:tcputype):boolean;
  929. var
  930. t : tcputype;
  931. hs : string;
  932. begin
  933. result:=false;
  934. hs:=Upper(s);
  935. for t:=low(tcputype) to high(tcputype) do
  936. if cputypestr[t]=hs then
  937. begin
  938. a:=t;
  939. result:=true;
  940. break;
  941. end;
  942. end;
  943. function SetFpuType(const s:string;var a:tfputype):boolean;
  944. var
  945. t : tfputype;
  946. begin
  947. result:=false;
  948. for t:=low(tfputype) to high(tfputype) do
  949. if fputypestr[t]=s then
  950. begin
  951. a:=t;
  952. result:=true;
  953. break;
  954. end;
  955. end;
  956. {$if defined(arm) or defined(avr)}
  957. function SetControllerType(const s:string;var a:tcontrollertype):boolean;
  958. var
  959. t : tcontrollertype;
  960. hs : string;
  961. begin
  962. result:=false;
  963. hs:=Upper(s);
  964. for t:=low(tcontrollertype) to high(tcontrollertype) do
  965. if controllertypestr[t]=hs then
  966. begin
  967. a:=t;
  968. result:=true;
  969. break;
  970. end;
  971. end;
  972. {$endif defined(arm) or defined(avr)}
  973. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  974. var
  975. tok : string;
  976. vstr : string;
  977. l : longint;
  978. code : integer;
  979. b : talignmentinfo;
  980. begin
  981. UpdateAlignmentStr:=true;
  982. uppervar(s);
  983. fillchar(b,sizeof(b),0);
  984. repeat
  985. tok:=GetToken(s,'=');
  986. if tok='' then
  987. break;
  988. vstr:=GetToken(s,',');
  989. val(vstr,l,code);
  990. if tok='PROC' then
  991. b.procalign:=l
  992. else if tok='JUMP' then
  993. b.jumpalign:=l
  994. else if tok='LOOP' then
  995. b.loopalign:=l
  996. else if tok='CONSTMIN' then
  997. begin
  998. b.constalignmin:=l;
  999. if l>b.constalignmax then
  1000. b.constalignmax:=l;
  1001. end
  1002. else if tok='CONSTMAX' then
  1003. b.constalignmax:=l
  1004. else if tok='VARMIN' then
  1005. begin
  1006. b.varalignmin:=l;
  1007. if l>b.varalignmax then
  1008. b.varalignmax:=l;
  1009. end
  1010. else if tok='VARMAX' then
  1011. b.varalignmax:=l
  1012. else if tok='LOCALMIN' then
  1013. begin
  1014. b.localalignmin:=l;
  1015. if l>b.localalignmax then
  1016. b.localalignmax:=l;
  1017. end
  1018. else if tok='LOCALMAX' then
  1019. b.localalignmax:=l
  1020. else if tok='RECORDMIN' then
  1021. begin
  1022. b.recordalignmin:=l;
  1023. if l>b.recordalignmax then
  1024. b.recordalignmax:=l;
  1025. end
  1026. else if tok='RECORDMAX' then
  1027. b.recordalignmax:=l
  1028. else { Error }
  1029. UpdateAlignmentStr:=false;
  1030. until false;
  1031. UpdateAlignment(a,b);
  1032. end;
  1033. function UpdateOptimizerStr(s:string;var a:toptimizerswitches):boolean;
  1034. var
  1035. tok : string;
  1036. doset,
  1037. found : boolean;
  1038. opt : toptimizerswitch;
  1039. begin
  1040. result:=true;
  1041. uppervar(s);
  1042. repeat
  1043. tok:=GetToken(s,',');
  1044. if tok='' then
  1045. break;
  1046. if Copy(tok,1,2)='NO' then
  1047. begin
  1048. delete(tok,1,2);
  1049. doset:=false;
  1050. end
  1051. else
  1052. doset:=true;
  1053. found:=false;
  1054. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  1055. begin
  1056. if OptimizerSwitchStr[opt]=tok then
  1057. begin
  1058. found:=true;
  1059. break;
  1060. end;
  1061. end;
  1062. if found then
  1063. begin
  1064. if doset then
  1065. include(a,opt)
  1066. else
  1067. exclude(a,opt);
  1068. end
  1069. else
  1070. result:=false;
  1071. until false;
  1072. end;
  1073. function UpdateWpoStr(s: string; var a: twpoptimizerswitches): boolean;
  1074. var
  1075. tok : string;
  1076. doset,
  1077. found : boolean;
  1078. opt : twpoptimizerswitch;
  1079. begin
  1080. result:=true;
  1081. uppervar(s);
  1082. repeat
  1083. tok:=GetToken(s,',');
  1084. if tok='' then
  1085. break;
  1086. if Copy(tok,1,2)='NO' then
  1087. begin
  1088. delete(tok,1,2);
  1089. doset:=false;
  1090. end
  1091. else
  1092. doset:=true;
  1093. found:=false;
  1094. if (tok = 'ALL') then
  1095. begin
  1096. for opt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  1097. if doset then
  1098. include(a,opt)
  1099. else
  1100. exclude(a,opt);
  1101. end
  1102. else
  1103. begin
  1104. for opt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  1105. begin
  1106. if WPOptimizerSwitchStr[opt]=tok then
  1107. begin
  1108. found:=true;
  1109. break;
  1110. end;
  1111. end;
  1112. if found then
  1113. begin
  1114. if doset then
  1115. include(a,opt)
  1116. else
  1117. exclude(a,opt);
  1118. end
  1119. else
  1120. result:=false;
  1121. end;
  1122. until false;
  1123. end;
  1124. function UpdateDebugStr(s:string;var a:tdebugswitches):boolean;
  1125. var
  1126. tok : string;
  1127. doset,
  1128. found : boolean;
  1129. opt : tdebugswitch;
  1130. begin
  1131. result:=true;
  1132. uppervar(s);
  1133. repeat
  1134. tok:=GetToken(s,',');
  1135. if tok='' then
  1136. break;
  1137. if Copy(tok,1,2)='NO' then
  1138. begin
  1139. delete(tok,1,2);
  1140. doset:=false;
  1141. end
  1142. else
  1143. doset:=true;
  1144. found:=false;
  1145. for opt:=low(tdebugswitch) to high(tdebugswitch) do
  1146. begin
  1147. if DebugSwitchStr[opt]=tok then
  1148. begin
  1149. found:=true;
  1150. break;
  1151. end;
  1152. end;
  1153. if found then
  1154. begin
  1155. if doset then
  1156. include(a,opt)
  1157. else
  1158. exclude(a,opt);
  1159. end
  1160. else
  1161. result:=false;
  1162. until false;
  1163. end;
  1164. function IncludeFeature(const s : string) : boolean;
  1165. var
  1166. i : tfeature;
  1167. begin
  1168. result:=true;
  1169. for i:=low(tfeature) to high(tfeature) do
  1170. if s=featurestr[i] then
  1171. begin
  1172. include(features,i);
  1173. exit;
  1174. end;
  1175. result:=false;
  1176. end;
  1177. function SetMinFPConstPrec(const s: string; var a: tfloattype) : boolean;
  1178. var
  1179. value, error: longint;
  1180. begin
  1181. if (upper(s)='DEFAULT') then
  1182. begin
  1183. a:=s32real;
  1184. result:=true;
  1185. exit;
  1186. end;
  1187. result:=false;
  1188. val(s,value,error);
  1189. if (error<>0) then
  1190. exit;
  1191. case value of
  1192. 32: a:=s32real;
  1193. 64: a:=s64real;
  1194. { adding support for 80 bit here is tricky, since we can't really }
  1195. { check whether the target cpu+OS actually supports it }
  1196. else
  1197. exit;
  1198. end;
  1199. result:=true;
  1200. end;
  1201. function var_align(want_align: longint): shortint;
  1202. begin
  1203. var_align := used_align(want_align,current_settings.alignment.varalignmin,current_settings.alignment.varalignmax);
  1204. end;
  1205. function var_align_size(siz: longint): shortint;
  1206. begin
  1207. siz := size_2_align(siz);
  1208. var_align_size := var_align(siz);
  1209. end;
  1210. function const_align(want_align: longint): shortint;
  1211. begin
  1212. const_align := used_align(want_align,current_settings.alignment.constalignmin,current_settings.alignment.constalignmax);
  1213. end;
  1214. function const_align_size(siz: longint): shortint;
  1215. begin
  1216. siz := size_2_align(siz);
  1217. const_align_size := const_align(siz);
  1218. end;
  1219. {$ifdef ARM}
  1220. function is_double_hilo_swapped: boolean;{$ifdef USEINLINE}inline;{$endif}
  1221. begin
  1222. result := (current_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  1223. not(cs_fp_emulation in current_settings.moduleswitches);
  1224. {$ifdef FPC_DOUBLE_HILO_SWAPPED}
  1225. { inverse result if compiler was compiled with swapped hilo already }
  1226. result := not result;
  1227. {$endif FPC_DOUBLE_HILO_SWAPPED}
  1228. end;
  1229. {$endif ARM}
  1230. function floating_point_range_check_error : boolean;
  1231. begin
  1232. result:=cs_ieee_errors in current_settings.localswitches;
  1233. end;
  1234. {****************************************************************************
  1235. Init
  1236. ****************************************************************************}
  1237. {$ifdef unix}
  1238. {$define need_path_search}
  1239. {$endif unix}
  1240. {$ifdef os2}
  1241. {$define need_path_search}
  1242. {$endif os2}
  1243. {$ifdef macos}
  1244. {$define need_path_search}
  1245. {$endif macos}
  1246. procedure get_exepath;
  1247. var
  1248. localExepath : TCmdStr;
  1249. exeName:TCmdStr;
  1250. {$ifdef need_path_search}
  1251. hs1 : TPathStr;
  1252. {$endif need_path_search}
  1253. begin
  1254. localexepath:=GetEnvironmentVariable('PPC_EXEC_PATH');
  1255. if localexepath='' then
  1256. begin
  1257. exeName := FixFileName(system.paramstr(0));
  1258. localexepath := ExtractFilePath(exeName);
  1259. end;
  1260. {$ifdef need_path_search}
  1261. if localexepath='' then
  1262. begin
  1263. hs1 := ExtractFileName(exeName);
  1264. ChangeFileExt(hs1,source_info.exeext);
  1265. {$ifdef macos}
  1266. FindFile(hs1,GetEnvironmentVariable('Commands'),false,localExepath);
  1267. {$else macos}
  1268. FindFile(hs1,GetEnvironmentVariable('PATH'),false,localExepath);
  1269. {$endif macos}
  1270. localExepath:=ExtractFilePath(localExepath);
  1271. end;
  1272. {$endif need_path_search}
  1273. exepath:=FixPath(localExepath,false);
  1274. end;
  1275. procedure DoneGlobals;
  1276. begin
  1277. librarysearchpath.Free;
  1278. unitsearchpath.Free;
  1279. objectsearchpath.Free;
  1280. includesearchpath.Free;
  1281. frameworksearchpath.Free;
  1282. LinkLibraryAliases.Free;
  1283. LinkLibraryOrder.Free;
  1284. end;
  1285. procedure InitGlobals;
  1286. begin
  1287. get_exepath;
  1288. { reset globals }
  1289. do_build:=false;
  1290. do_release:=false;
  1291. do_make:=true;
  1292. compile_level:=0;
  1293. codegenerror:=false;
  1294. DLLsource:=false;
  1295. paratarget:=system_none;
  1296. paratargetasm:=as_none;
  1297. paratargetdbg:=dbg_none;
  1298. { Output }
  1299. OutputFileName:='';
  1300. OutputPrefix:=Nil;
  1301. OutputSuffix:=Nil;
  1302. OutputExeDir:='';
  1303. OutputUnitDir:='';
  1304. { Utils directory }
  1305. utilsdirectory:='';
  1306. utilsprefix:='';
  1307. cshared:=false;
  1308. rlinkpath:='';
  1309. sysrootpath:='';
  1310. { Search Paths }
  1311. librarysearchpath:=TSearchPathList.Create;
  1312. unitsearchpath:=TSearchPathList.Create;
  1313. includesearchpath:=TSearchPathList.Create;
  1314. objectsearchpath:=TSearchPathList.Create;
  1315. frameworksearchpath:=TSearchPathList.Create;
  1316. { Def file }
  1317. usewindowapi:=false;
  1318. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1319. DescriptionSetExplicity:=false;
  1320. SetPEFlagsSetExplicity:=false;
  1321. ImageBaseSetExplicity:=false;
  1322. MinStackSizeSetExplicity:=false;
  1323. MaxStackSizeSetExplicity:=false;
  1324. dllversion:='';
  1325. dllmajor:=1;
  1326. dllminor:=0;
  1327. dllrevision:=0;
  1328. nwscreenname := '';
  1329. nwthreadname := '';
  1330. nwcopyright := '';
  1331. UseDeffileForExports:=false;
  1332. UseDeffileForExportsSetExplicitly:=false;
  1333. GenerateImportSection:=false;
  1334. RelocSection:=false;
  1335. RelocSectionSetExplicitly:=false;
  1336. LinkTypeSetExplicitly:=false;
  1337. { memory sizes, will be overridden by parameter or default for target
  1338. in options or init_parser }
  1339. stacksize:=0;
  1340. { not initialized yet }
  1341. jmp_buf_size:=-1;
  1342. apptype:=app_cui;
  1343. { Init values }
  1344. init_settings:=default_settings;
  1345. if init_settings.optimizecputype=cpu_none then
  1346. init_settings.optimizecputype:=init_settings.cputype;
  1347. LinkLibraryAliases :=TLinkStrMap.Create;
  1348. LinkLibraryOrder :=TLinkStrMap.Create;
  1349. { enable all features by default }
  1350. features:=[low(Tfeature)..high(Tfeature)];
  1351. end;
  1352. end.