globals.pas 50 KB

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