globals.pas 46 KB

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