globals.pas 44 KB

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