globals.pas 47 KB

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