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