globals.pas 45 KB

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