globals.pas 45 KB

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