globals.pas 51 KB

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