globals.pas 44 KB

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