globals.pas 44 KB

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