globals.pas 44 KB

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