globals.pas 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  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_avr5;
  348. optimizecputype : cpuinfo.cpu_avr5;
  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. 'INTERRUPT'
  891. );
  892. var
  893. t : tproccalloption;
  894. hs : string;
  895. begin
  896. result:=false;
  897. if (s = '') then
  898. exit;
  899. hs:=upper(s);
  900. if (hs = 'DEFAULT') then
  901. begin
  902. a := pocall_default;
  903. result := true;
  904. exit;
  905. end;
  906. for t:=low(tproccalloption) to high(tproccalloption) do
  907. if DefProcCallName[t]=hs then
  908. begin
  909. a:=t;
  910. result:=true;
  911. break;
  912. end;
  913. end;
  914. function Setabitype(const s:string;var a:tabi):boolean;
  915. var
  916. t : tabi;
  917. hs : string;
  918. begin
  919. result:=false;
  920. hs:=Upper(s);
  921. for t:=low(t) to high(t) do
  922. if abi2str[t]=hs then
  923. begin
  924. a:=t;
  925. result:=true;
  926. break;
  927. end;
  928. end;
  929. function Setcputype(const s:string;var a:tcputype):boolean;
  930. var
  931. t : tcputype;
  932. hs : string;
  933. begin
  934. result:=false;
  935. hs:=Upper(s);
  936. for t:=low(tcputype) to high(tcputype) do
  937. if cputypestr[t]=hs then
  938. begin
  939. a:=t;
  940. result:=true;
  941. break;
  942. end;
  943. end;
  944. function SetFpuType(const s:string;var a:tfputype):boolean;
  945. var
  946. t : tfputype;
  947. begin
  948. result:=false;
  949. for t:=low(tfputype) to high(tfputype) do
  950. if fputypestr[t]=s then
  951. begin
  952. a:=t;
  953. result:=true;
  954. break;
  955. end;
  956. end;
  957. {$if defined(arm) or defined(avr)}
  958. function SetControllerType(const s:string;var a:tcontrollertype):boolean;
  959. var
  960. t : tcontrollertype;
  961. hs : string;
  962. begin
  963. result:=false;
  964. hs:=Upper(s);
  965. for t:=low(tcontrollertype) to high(tcontrollertype) do
  966. if controllertypestr[t]=hs then
  967. begin
  968. a:=t;
  969. result:=true;
  970. break;
  971. end;
  972. end;
  973. {$endif defined(arm) or defined(avr)}
  974. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  975. var
  976. tok : string;
  977. vstr : string;
  978. l : longint;
  979. code : integer;
  980. b : talignmentinfo;
  981. begin
  982. UpdateAlignmentStr:=true;
  983. uppervar(s);
  984. fillchar(b,sizeof(b),0);
  985. repeat
  986. tok:=GetToken(s,'=');
  987. if tok='' then
  988. break;
  989. vstr:=GetToken(s,',');
  990. val(vstr,l,code);
  991. if tok='PROC' then
  992. b.procalign:=l
  993. else if tok='JUMP' then
  994. b.jumpalign:=l
  995. else if tok='LOOP' then
  996. b.loopalign:=l
  997. else if tok='CONSTMIN' then
  998. begin
  999. b.constalignmin:=l;
  1000. if l>b.constalignmax then
  1001. b.constalignmax:=l;
  1002. end
  1003. else if tok='CONSTMAX' then
  1004. b.constalignmax:=l
  1005. else if tok='VARMIN' then
  1006. begin
  1007. b.varalignmin:=l;
  1008. if l>b.varalignmax then
  1009. b.varalignmax:=l;
  1010. end
  1011. else if tok='VARMAX' then
  1012. b.varalignmax:=l
  1013. else if tok='LOCALMIN' then
  1014. begin
  1015. b.localalignmin:=l;
  1016. if l>b.localalignmax then
  1017. b.localalignmax:=l;
  1018. end
  1019. else if tok='LOCALMAX' then
  1020. b.localalignmax:=l
  1021. else if tok='RECORDMIN' then
  1022. begin
  1023. b.recordalignmin:=l;
  1024. if l>b.recordalignmax then
  1025. b.recordalignmax:=l;
  1026. end
  1027. else if tok='RECORDMAX' then
  1028. b.recordalignmax:=l
  1029. else { Error }
  1030. UpdateAlignmentStr:=false;
  1031. until false;
  1032. UpdateAlignment(a,b);
  1033. end;
  1034. function UpdateOptimizerStr(s:string;var a:toptimizerswitches):boolean;
  1035. var
  1036. tok : string;
  1037. doset,
  1038. found : boolean;
  1039. opt : toptimizerswitch;
  1040. begin
  1041. result:=true;
  1042. uppervar(s);
  1043. repeat
  1044. tok:=GetToken(s,',');
  1045. if tok='' then
  1046. break;
  1047. if Copy(tok,1,2)='NO' then
  1048. begin
  1049. delete(tok,1,2);
  1050. doset:=false;
  1051. end
  1052. else
  1053. doset:=true;
  1054. found:=false;
  1055. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  1056. begin
  1057. if OptimizerSwitchStr[opt]=tok then
  1058. begin
  1059. found:=true;
  1060. break;
  1061. end;
  1062. end;
  1063. if found then
  1064. begin
  1065. if doset then
  1066. include(a,opt)
  1067. else
  1068. exclude(a,opt);
  1069. end
  1070. else
  1071. result:=false;
  1072. until false;
  1073. end;
  1074. function UpdateWpoStr(s: string; var a: twpoptimizerswitches): boolean;
  1075. var
  1076. tok : string;
  1077. doset,
  1078. found : boolean;
  1079. opt : twpoptimizerswitch;
  1080. begin
  1081. result:=true;
  1082. uppervar(s);
  1083. repeat
  1084. tok:=GetToken(s,',');
  1085. if tok='' then
  1086. break;
  1087. if Copy(tok,1,2)='NO' then
  1088. begin
  1089. delete(tok,1,2);
  1090. doset:=false;
  1091. end
  1092. else
  1093. doset:=true;
  1094. found:=false;
  1095. if (tok = 'ALL') then
  1096. begin
  1097. for opt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  1098. if doset then
  1099. include(a,opt)
  1100. else
  1101. exclude(a,opt);
  1102. end
  1103. else
  1104. begin
  1105. for opt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  1106. begin
  1107. if WPOptimizerSwitchStr[opt]=tok then
  1108. begin
  1109. found:=true;
  1110. break;
  1111. end;
  1112. end;
  1113. if found then
  1114. begin
  1115. if doset then
  1116. include(a,opt)
  1117. else
  1118. exclude(a,opt);
  1119. end
  1120. else
  1121. result:=false;
  1122. end;
  1123. until false;
  1124. end;
  1125. function UpdateDebugStr(s:string;var a:tdebugswitches):boolean;
  1126. var
  1127. tok : string;
  1128. doset,
  1129. found : boolean;
  1130. opt : tdebugswitch;
  1131. begin
  1132. result:=true;
  1133. uppervar(s);
  1134. repeat
  1135. tok:=GetToken(s,',');
  1136. if tok='' then
  1137. break;
  1138. if Copy(tok,1,2)='NO' then
  1139. begin
  1140. delete(tok,1,2);
  1141. doset:=false;
  1142. end
  1143. else
  1144. doset:=true;
  1145. found:=false;
  1146. for opt:=low(tdebugswitch) to high(tdebugswitch) do
  1147. begin
  1148. if DebugSwitchStr[opt]=tok then
  1149. begin
  1150. found:=true;
  1151. break;
  1152. end;
  1153. end;
  1154. if found then
  1155. begin
  1156. if doset then
  1157. include(a,opt)
  1158. else
  1159. exclude(a,opt);
  1160. end
  1161. else
  1162. result:=false;
  1163. until false;
  1164. end;
  1165. function IncludeFeature(const s : string) : boolean;
  1166. var
  1167. i : tfeature;
  1168. begin
  1169. result:=true;
  1170. for i:=low(tfeature) to high(tfeature) do
  1171. if s=featurestr[i] then
  1172. begin
  1173. include(features,i);
  1174. exit;
  1175. end;
  1176. result:=false;
  1177. end;
  1178. function SetMinFPConstPrec(const s: string; var a: tfloattype) : boolean;
  1179. var
  1180. value, error: longint;
  1181. begin
  1182. if (upper(s)='DEFAULT') then
  1183. begin
  1184. a:=s32real;
  1185. result:=true;
  1186. exit;
  1187. end;
  1188. result:=false;
  1189. val(s,value,error);
  1190. if (error<>0) then
  1191. exit;
  1192. case value of
  1193. 32: a:=s32real;
  1194. 64: a:=s64real;
  1195. { adding support for 80 bit here is tricky, since we can't really }
  1196. { check whether the target cpu+OS actually supports it }
  1197. else
  1198. exit;
  1199. end;
  1200. result:=true;
  1201. end;
  1202. function var_align(want_align: longint): shortint;
  1203. begin
  1204. var_align := used_align(want_align,current_settings.alignment.varalignmin,current_settings.alignment.varalignmax);
  1205. end;
  1206. function var_align_size(siz: longint): shortint;
  1207. begin
  1208. siz := size_2_align(siz);
  1209. var_align_size := var_align(siz);
  1210. end;
  1211. function const_align(want_align: longint): shortint;
  1212. begin
  1213. const_align := used_align(want_align,current_settings.alignment.constalignmin,current_settings.alignment.constalignmax);
  1214. end;
  1215. function const_align_size(siz: longint): shortint;
  1216. begin
  1217. siz := size_2_align(siz);
  1218. const_align_size := const_align(siz);
  1219. end;
  1220. {$ifdef ARM}
  1221. function is_double_hilo_swapped: boolean;{$ifdef USEINLINE}inline;{$endif}
  1222. begin
  1223. result := (current_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  1224. not(cs_fp_emulation in current_settings.moduleswitches);
  1225. {$ifdef FPC_DOUBLE_HILO_SWAPPED}
  1226. { inverse result if compiler was compiled with swapped hilo already }
  1227. result := not result;
  1228. {$endif FPC_DOUBLE_HILO_SWAPPED}
  1229. end;
  1230. {$endif ARM}
  1231. function floating_point_range_check_error : boolean;
  1232. begin
  1233. result:=cs_ieee_errors in current_settings.localswitches;
  1234. end;
  1235. {****************************************************************************
  1236. Init
  1237. ****************************************************************************}
  1238. {$ifdef unix}
  1239. {$define need_path_search}
  1240. {$endif unix}
  1241. {$ifdef os2}
  1242. {$define need_path_search}
  1243. {$endif os2}
  1244. {$ifdef macos}
  1245. {$define need_path_search}
  1246. {$endif macos}
  1247. procedure get_exepath;
  1248. var
  1249. localExepath : TCmdStr;
  1250. exeName:TCmdStr;
  1251. {$ifdef need_path_search}
  1252. hs1 : TPathStr;
  1253. {$endif need_path_search}
  1254. begin
  1255. localexepath:=GetEnvironmentVariable('PPC_EXEC_PATH');
  1256. if localexepath='' then
  1257. begin
  1258. exeName := FixFileName(system.paramstr(0));
  1259. localexepath := ExtractFilePath(exeName);
  1260. end;
  1261. {$ifdef need_path_search}
  1262. if localexepath='' then
  1263. begin
  1264. hs1 := ExtractFileName(exeName);
  1265. ChangeFileExt(hs1,source_info.exeext);
  1266. {$ifdef macos}
  1267. FindFile(hs1,GetEnvironmentVariable('Commands'),false,localExepath);
  1268. {$else macos}
  1269. FindFile(hs1,GetEnvironmentVariable('PATH'),false,localExepath);
  1270. {$endif macos}
  1271. localExepath:=ExtractFilePath(localExepath);
  1272. end;
  1273. {$endif need_path_search}
  1274. exepath:=FixPath(localExepath,false);
  1275. end;
  1276. procedure DoneGlobals;
  1277. begin
  1278. librarysearchpath.Free;
  1279. unitsearchpath.Free;
  1280. objectsearchpath.Free;
  1281. includesearchpath.Free;
  1282. frameworksearchpath.Free;
  1283. LinkLibraryAliases.Free;
  1284. LinkLibraryOrder.Free;
  1285. end;
  1286. procedure InitGlobals;
  1287. begin
  1288. get_exepath;
  1289. { reset globals }
  1290. do_build:=false;
  1291. do_release:=false;
  1292. do_make:=true;
  1293. compile_level:=0;
  1294. codegenerror:=false;
  1295. DLLsource:=false;
  1296. paratarget:=system_none;
  1297. paratargetasm:=as_none;
  1298. paratargetdbg:=dbg_none;
  1299. { Output }
  1300. OutputFileName:='';
  1301. OutputPrefix:=Nil;
  1302. OutputSuffix:=Nil;
  1303. OutputExeDir:='';
  1304. OutputUnitDir:='';
  1305. { Utils directory }
  1306. utilsdirectory:='';
  1307. utilsprefix:='';
  1308. cshared:=false;
  1309. rlinkpath:='';
  1310. sysrootpath:='';
  1311. { Search Paths }
  1312. librarysearchpath:=TSearchPathList.Create;
  1313. unitsearchpath:=TSearchPathList.Create;
  1314. includesearchpath:=TSearchPathList.Create;
  1315. objectsearchpath:=TSearchPathList.Create;
  1316. frameworksearchpath:=TSearchPathList.Create;
  1317. { Def file }
  1318. usewindowapi:=false;
  1319. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1320. DescriptionSetExplicity:=false;
  1321. SetPEFlagsSetExplicity:=false;
  1322. ImageBaseSetExplicity:=false;
  1323. MinStackSizeSetExplicity:=false;
  1324. MaxStackSizeSetExplicity:=false;
  1325. dllversion:='';
  1326. dllmajor:=1;
  1327. dllminor:=0;
  1328. dllrevision:=0;
  1329. nwscreenname := '';
  1330. nwthreadname := '';
  1331. nwcopyright := '';
  1332. UseDeffileForExports:=false;
  1333. UseDeffileForExportsSetExplicitly:=false;
  1334. GenerateImportSection:=false;
  1335. RelocSection:=false;
  1336. RelocSectionSetExplicitly:=false;
  1337. LinkTypeSetExplicitly:=false;
  1338. { memory sizes, will be overridden by parameter or default for target
  1339. in options or init_parser }
  1340. stacksize:=0;
  1341. { not initialized yet }
  1342. jmp_buf_size:=-1;
  1343. apptype:=app_cui;
  1344. { Init values }
  1345. init_settings:=default_settings;
  1346. if init_settings.optimizecputype=cpu_none then
  1347. init_settings.optimizecputype:=init_settings.cputype;
  1348. LinkLibraryAliases :=TLinkStrMap.Create;
  1349. LinkLibraryOrder :=TLinkStrMap.Create;
  1350. { enable all features by default }
  1351. features:=[low(Tfeature)..high(Tfeature)];
  1352. end;
  1353. end.