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