globals.pas 45 KB

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