globals.pas 47 KB

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