globals.pas 44 KB

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