globals.pas 44 KB

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