globals.pas 44 KB

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