globals.pas 50 KB

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