globals.pas 44 KB

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