aasmdata.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. {
  2. Copyright (c) 1998-2006 by Florian Klaempfl
  3. This unit implements an abstract asmoutput class for all processor types
  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. { @abstract(This unit implements an abstract asm output class for all processor types)
  18. This unit implements an abstract assembler output class for all processors, these
  19. are then overridden for each assembler writer to actually write the data in these
  20. classes to an assembler file.
  21. }
  22. unit aasmdata;
  23. {$i fpcdefs.inc}
  24. interface
  25. uses
  26. cutils,cclasses,
  27. globtype,systems,
  28. cgbase,
  29. symtype,
  30. aasmbase;
  31. type
  32. { Type of AsmLists. The order is important for the layout of the
  33. information in the .o file. The stabs for the types must be defined
  34. before they can be referenced and therefor they need to be written
  35. first (PFV) }
  36. TAsmListType=(
  37. al_start,
  38. al_stabs,
  39. { pure assembler routines }
  40. al_pure_assembler,
  41. al_procedures,
  42. al_globals,
  43. al_const,
  44. al_typedconsts,
  45. al_rotypedconsts,
  46. al_threadvars,
  47. al_imports,
  48. al_exports,
  49. al_resources,
  50. al_rtti,
  51. { all symbols with indirect suffix }
  52. al_indirectglobals,
  53. al_dwarf_frame,
  54. al_dwarf_info,
  55. al_dwarf_abbrev,
  56. al_dwarf_line,
  57. al_dwarf_aranges,
  58. al_dwarf_ranges,
  59. al_dwarf_loc,
  60. al_dwarf_loclists,
  61. al_picdata,
  62. al_indirectpicdata,
  63. al_resourcestrings,
  64. { Objective-C related sections }
  65. al_objc_data,
  66. { keep pool data separate, so we can generate new pool entries
  67. while emitting other data }
  68. al_objc_pools,
  69. al_end
  70. );
  71. {$push}{$j-}
  72. const
  73. globaldataasmlisttypes: array[1..5] of TAsmListType = (
  74. al_globals,
  75. al_const,
  76. al_typedconsts,
  77. al_rotypedconsts,
  78. al_threadvars
  79. );
  80. {$pop}
  81. { Type of constant 'pools'. Mostly for string types, but usable for
  82. floating point and large set constants, too. }
  83. type
  84. TConstPoolType = (
  85. sp_invalid,
  86. sp_conststr,
  87. sp_shortstr,
  88. sp_longstr,
  89. sp_ansistr,
  90. sp_widestr,
  91. sp_unicodestr,
  92. sp_objcclassnamerefs,
  93. sp_varnamerefs,
  94. sp_objcclassnames,
  95. sp_objcvarnames,
  96. sp_objcvartypes,
  97. sp_objcprotocolrefs,
  98. sp_varsets,
  99. sp_floats,
  100. sp_guids,
  101. sp_paraloc
  102. );
  103. const
  104. AsmListTypeStr : array[TAsmListType] of string[24] =(
  105. 'al_begin',
  106. 'al_stabs',
  107. 'al_pure_assembler',
  108. 'al_procedures',
  109. 'al_globals',
  110. 'al_const',
  111. 'al_typedconsts',
  112. 'al_rotypedconsts',
  113. 'al_threadvars',
  114. 'al_imports',
  115. 'al_exports',
  116. 'al_resources',
  117. 'al_rtti',
  118. 'al_indirectglobals',
  119. 'al_dwarf_frame',
  120. 'al_dwarf_info',
  121. 'al_dwarf_abbrev',
  122. 'al_dwarf_line',
  123. 'al_dwarf_aranges',
  124. 'al_dwarf_ranges',
  125. 'al_dwarf_loc',
  126. 'al_dwarf_loclists',
  127. 'al_picdata',
  128. 'al_indirectpicdata',
  129. 'al_resourcestrings',
  130. 'al_objc_data',
  131. 'al_objc_pools',
  132. 'al_end'
  133. );
  134. type
  135. TAsmList = class(tlinkedlist)
  136. section_count : longint;
  137. constructor create;
  138. function getlasttaifilepos : pfileposinfo;
  139. { inserts another List at the begin and make this List empty }
  140. procedure insertList(p : TLinkedList); override;
  141. { inserts another List before the provided item and make this List empty }
  142. procedure insertListBefore(Item:TLinkedListItem;p : TLinkedList); override;
  143. { inserts another List after the provided item and make this List empty }
  144. procedure insertListAfter(Item:TLinkedListItem;p : TLinkedList); override;
  145. { concats another List at the end and make this List empty }
  146. procedure concatList(p : TLinkedList); override;
  147. { concats another List at the start and makes a copy
  148. the list is ordered in reverse.
  149. }
  150. procedure insertListcopy(p : TLinkedList); override;
  151. { concats another List at the end and makes a copy }
  152. procedure concatListcopy(p : TLinkedList); override;
  153. { removes all items from the list, the items are not freed }
  154. procedure RemoveAll; override;
  155. end;
  156. TAsmCFI=class
  157. public
  158. constructor create;virtual;
  159. destructor destroy;override;
  160. procedure generate_code(list:TAsmList);virtual;
  161. procedure start_frame(list:TAsmList);virtual;
  162. procedure end_frame(list:TAsmList);virtual;
  163. procedure outmost_frame(list:TAsmList);virtual;
  164. procedure cfa_offset(list:TAsmList;reg:tregister;ofs:longint);virtual;
  165. procedure cfa_restore(list:TAsmList;reg:tregister);virtual;
  166. procedure cfa_def_cfa(list:TAsmList;reg:tregister;ofs:longint);virtual;
  167. procedure cfa_def_cfa_register(list:TAsmList;reg:tregister);virtual;
  168. procedure cfa_def_cfa_offset(list:TAsmList;ofs:longint);virtual;
  169. function get_frame_start: TAsmLabel;virtual;
  170. function get_cfa_list : TAsmList;virtual;
  171. end;
  172. TAsmCFIClass=class of TAsmCFI;
  173. { TAsmData }
  174. TAsmData = class
  175. private
  176. { Symbols }
  177. FAsmSymbolDict : TFPHashObjectList;
  178. FAltSymbolList : TFPObjectList;
  179. FNextAltNr : longint;
  180. FNextLabelNr : array[TAsmLabeltype] of longint;
  181. { Call Frame Information for stack unwinding}
  182. FAsmCFI : TAsmCFI;
  183. FConstPools : array[TConstPoolType] of THashSet;
  184. function GetConstPools(APoolType: TConstPoolType): THashSet;
  185. protected
  186. function DefineAsmSymbolByClassBase(symclass: TAsmSymbolClass; const s : TSymStr;_bind:TAsmSymBind;_typ:Tasmsymtype; def: tdef; out wasdefined: boolean) : TAsmSymbol;
  187. public
  188. name : pshortstring; { owned by tmodule }
  189. NextVTEntryNr : longint;
  190. { Assembler lists }
  191. AsmLists : array[TAsmListType] of TAsmList;
  192. CurrAsmList : TAsmList;
  193. WideInits : TLinkedList;
  194. ResStrInits : TLinkedList;
  195. constructor create(n: pshortstring);
  196. destructor destroy;override;
  197. { asmsymbol }
  198. function DefineAsmSymbolByClass(symclass: TAsmSymbolClass; const s : TSymStr;_bind:TAsmSymBind;_typ:Tasmsymtype; def: tdef) : TAsmSymbol; virtual;
  199. function DefineAsmSymbol(const s : TSymStr;_bind:TAsmSymBind;_typ:Tasmsymtype; def: tdef) : TAsmSymbol;
  200. function DefineProcAsmSymbol(pd: tdef; const s: TSymStr; global: boolean): TAsmSymbol;
  201. function WeakRefAsmSymbol(const s : TSymStr;_typ:Tasmsymtype) : TAsmSymbol;
  202. function RefAsmSymbol(const s : TSymStr;_typ:Tasmsymtype;indirect:boolean=false) : TAsmSymbol;
  203. function GetAsmSymbol(const s : TSymStr) : TAsmSymbol;
  204. { create new assembler label }
  205. procedure getlabel(out l : TAsmLabel;alt:TAsmLabeltype);
  206. procedure getjumplabel(out l : TAsmLabel);
  207. procedure getglobaljumplabel(out l : TAsmLabel);
  208. procedure getaddrlabel(out l : TAsmLabel);
  209. { visible from outside current object }
  210. procedure getglobaldatalabel(out l : TAsmLabel);
  211. { visible only inside current object, but doesn't start with
  212. target_asm.label_prefix (treated the Darwin linker as the start of a
  213. dead-strippable data block) }
  214. procedure getstaticdatalabel(out l : TAsmLabel);
  215. { visible only inside the current object and does start with
  216. target_asm.label_prefix (not treated by the Darwin linker as the start
  217. of a dead-strippable data block, and references to such labels are
  218. also ignored to determine whether a data block should be live) }
  219. procedure getlocaldatalabel(out l : TAsmLabel);
  220. { generate an alternative (duplicate) symbol }
  221. procedure GenerateAltSymbol(p:TAsmSymbol);
  222. procedure ResetAltSymbols;
  223. property AsmSymbolDict:TFPHashObjectList read FAsmSymbolDict;
  224. property AsmCFI:TAsmCFI read FAsmCFI;
  225. { hash tables for reusing constant storage }
  226. property ConstPools[APoolType:TConstPoolType]: THashSet read GetConstPools;
  227. end;
  228. TAsmDataClass = class of TAsmData;
  229. TTCInitItem = class(TLinkedListItem)
  230. sym: tsym;
  231. offset: aint;
  232. datalabel: TAsmSymbol;
  233. datadef: TDef;
  234. constructor Create(asym: tsym; aoffset: aint; alabel: TAsmSymbol; alabeldef: tdef);
  235. end;
  236. var
  237. casmdata: TAsmDataClass;
  238. var
  239. CAsmCFI : TAsmCFIClass;
  240. current_asmdata : TAsmData;
  241. implementation
  242. uses
  243. verbose,
  244. globals,
  245. symconst,
  246. aasmtai;
  247. {$ifdef MEMDEBUG}
  248. var
  249. memasmsymbols,
  250. memasmcfi,
  251. memasmlists : TMemDebug;
  252. {$endif MEMDEBUG}
  253. {*****************************************************************************
  254. TAsmCFI
  255. *****************************************************************************}
  256. constructor TAsmCFI.create;
  257. begin
  258. end;
  259. destructor TAsmCFI.destroy;
  260. begin
  261. end;
  262. procedure TAsmCFI.generate_code(list:TAsmList);
  263. begin
  264. end;
  265. procedure TAsmCFI.start_frame(list:TAsmList);
  266. begin
  267. end;
  268. procedure TAsmCFI.end_frame(list:TAsmList);
  269. begin
  270. end;
  271. procedure TAsmCFI.outmost_frame(list: TAsmList);
  272. begin
  273. end;
  274. procedure TAsmCFI.cfa_offset(list:TAsmList;reg:tregister;ofs:longint);
  275. begin
  276. end;
  277. procedure TAsmCFI.cfa_restore(list:TAsmList;reg:tregister);
  278. begin
  279. end;
  280. procedure TAsmCFI.cfa_def_cfa(list:TAsmList;reg:tregister;ofs:longint);
  281. begin
  282. end;
  283. procedure TAsmCFI.cfa_def_cfa_register(list:TAsmList;reg:tregister);
  284. begin
  285. end;
  286. procedure TAsmCFI.cfa_def_cfa_offset(list:TAsmList;ofs:longint);
  287. begin
  288. end;
  289. function TAsmCFI.get_frame_start: TAsmLabel;
  290. begin
  291. Result:=nil;
  292. end;
  293. function TAsmCFI.get_cfa_list: TAsmList;
  294. begin
  295. Result:=nil;
  296. end;
  297. {*****************************************************************************
  298. TTCInitItem
  299. *****************************************************************************}
  300. constructor TTCInitItem.Create(asym: tsym; aoffset: aint; alabel: TAsmSymbol; alabeldef: tdef);
  301. begin
  302. inherited Create;
  303. sym:=asym;
  304. offset:=aoffset;
  305. datalabel:=alabel;
  306. datadef:=alabeldef;
  307. end;
  308. {*****************************************************************************
  309. TAsmList
  310. *****************************************************************************}
  311. constructor TAsmList.create;
  312. begin
  313. inherited create;
  314. end;
  315. function TAsmList.getlasttaifilepos : pfileposinfo;
  316. var
  317. hp : tlinkedlistitem;
  318. begin
  319. getlasttaifilepos := nil;
  320. if assigned(last) then
  321. begin
  322. { find the last file information record }
  323. if not (tai(last).typ in SkipLineInfo) then
  324. getlasttaifilepos:=@tailineinfo(last).fileinfo
  325. else
  326. { go through list backwards to find the first entry
  327. with line information
  328. }
  329. begin
  330. hp:=tai(last);
  331. while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
  332. hp:=hp.Previous;
  333. { found entry }
  334. if assigned(hp) then
  335. getlasttaifilepos:=@tailineinfo(hp).fileinfo
  336. end;
  337. end;
  338. end;
  339. procedure TAsmList.insertList(p : TLinkedList);
  340. begin
  341. inherited insertList(p);
  342. inc(section_count,TAsmList(p).section_count);
  343. TAsmList(p).section_count:=0;
  344. end;
  345. procedure TAsmList.insertListBefore(Item : TLinkedListItem; p : TLinkedList);
  346. begin
  347. inherited insertListBefore(Item,p);
  348. inc(section_count,TAsmList(p).section_count);
  349. TAsmList(p).section_count:=0;
  350. end;
  351. procedure TAsmList.insertListAfter(Item : TLinkedListItem; p : TLinkedList);
  352. begin
  353. inherited insertListAfter(Item,p);
  354. inc(section_count,TAsmList(p).section_count);
  355. TAsmList(p).section_count:=0;
  356. end;
  357. procedure TAsmList.concatList(p : TLinkedList);
  358. begin
  359. inherited concatList(p);
  360. inc(section_count,TAsmList(p).section_count);
  361. TAsmList(p).section_count:=0;
  362. end;
  363. procedure TAsmList.insertListcopy(p : TLinkedList);
  364. begin
  365. inherited insertListcopy(p);
  366. inc(section_count,TAsmList(p).section_count);
  367. end;
  368. procedure TAsmList.concatListcopy(p : TLinkedList);
  369. begin
  370. inherited concatListcopy(p);
  371. inc(section_count,TAsmList(p).section_count);
  372. end;
  373. procedure TAsmList.RemoveAll;
  374. begin
  375. inherited RemoveAll;
  376. section_count:=0;
  377. end;
  378. {****************************************************************************
  379. TAsmData
  380. ****************************************************************************}
  381. function TAsmData.GetConstPools(APoolType: TConstPoolType): THashSet;
  382. begin
  383. if FConstPools[APoolType] = nil then
  384. case APoolType of
  385. sp_ansistr: FConstPools[APoolType] := TTagHashSet.Create(64, True, False);
  386. else
  387. FConstPools[APoolType] := THashSet.Create(64, True, False);
  388. end;
  389. Result := FConstPools[APoolType];
  390. end;
  391. function TAsmData.DefineAsmSymbolByClassBase(symclass: TAsmSymbolClass; const s: TSymStr; _bind: TAsmSymBind; _typ: Tasmsymtype; def: tdef; out wasdefined: boolean): TAsmSymbol;
  392. var
  393. hp : TAsmSymbol;
  394. namestr : TSymStr;
  395. begin
  396. { this difference is only necessary to determine whether we always need
  397. indirect references or not }
  398. if _typ in [AT_DATA_FORCEINDIRECT,AT_DATA_NOINDIRECT] then
  399. _typ:=AT_DATA;
  400. namestr:=s;
  401. if _bind in asmsymbindindirect then
  402. namestr:=namestr+suffix_indirect;
  403. hp:=TAsmSymbol(FAsmSymbolDict.Find(namestr));
  404. if assigned(hp) then
  405. begin
  406. { Redefine is allowed, but the types must be the same. The redefine
  407. is needed for Darwin where the labels are first allocated }
  408. wasdefined:=not(hp.bind in [AB_EXTERNAL,AB_WEAK_EXTERNAL]);
  409. if wasdefined then
  410. begin
  411. if (hp.bind<>_bind) and
  412. (hp.typ<>_typ) then
  413. internalerror(200603261);
  414. end;
  415. hp.typ:=_typ;
  416. { Changing bind from AB_GLOBAL to AB_LOCAL is wrong
  417. if bind is already AB_GLOBAL or AB_EXTERNAL,
  418. GOT might have been used, so change might be harmful. }
  419. if (_bind<>hp.bind) and (hp.getrefs>0) then
  420. begin
  421. {$ifdef extdebug}
  422. { the changes that matter must become internalerrors, the rest
  423. should be ignored; a used cannot change anything about this,
  424. so printing a warning/hint is not useful }
  425. if (_bind=AB_LOCAL) then
  426. Message3(asmw_w_changing_bind_type,namestr,asmsymbindname[hp.bind],asmsymbindname[_bind])
  427. else
  428. Message3(asmw_h_changing_bind_type,namestr,asmsymbindname[hp.bind],asmsymbindname[_bind]);
  429. {$endif extdebug}
  430. end;
  431. hp.bind:=_bind;
  432. end
  433. else
  434. begin
  435. wasdefined:=false;
  436. { Not found, insert it. }
  437. hp:=symclass.create(AsmSymbolDict,namestr,_bind,_typ);
  438. end;
  439. result:=hp;
  440. end;
  441. constructor TAsmData.create(n:pshortstring);
  442. var
  443. alt : TAsmLabelType;
  444. hal : TAsmListType;
  445. begin
  446. inherited create;
  447. name:=n;
  448. { symbols }
  449. FAsmSymbolDict:=TFPHashObjectList.create(true);
  450. FAltSymbolList:=TFPObjectList.Create(false);
  451. { labels }
  452. FNextAltNr:=1;
  453. for alt:=low(TAsmLabelType) to high(TAsmLabelType) do
  454. FNextLabelNr[alt]:=1;
  455. { AsmLists }
  456. CurrAsmList:=TAsmList.create;
  457. for hal:=low(TAsmListType) to high(TAsmListType) do
  458. AsmLists[hal]:=TAsmList.create;
  459. WideInits :=TAsmList.create;
  460. ResStrInits:=TAsmList.create;
  461. { CFI }
  462. FAsmCFI:=CAsmCFI.Create;
  463. end;
  464. destructor TAsmData.destroy;
  465. var
  466. hal : TAsmListType;
  467. hp : TConstPoolType;
  468. begin
  469. { Symbols }
  470. {$ifdef MEMDEBUG}
  471. memasmsymbols.start;
  472. {$endif}
  473. FAltSymbolList.free;
  474. FAsmSymbolDict.free;
  475. {$ifdef MEMDEBUG}
  476. memasmsymbols.stop;
  477. {$endif}
  478. { CFI }
  479. {$ifdef MEMDEBUG}
  480. memasmcfi.start;
  481. {$endif}
  482. FAsmCFI.free;
  483. {$ifdef MEMDEBUG}
  484. memasmcfi.stop;
  485. {$endif}
  486. { Lists }
  487. {$ifdef MEMDEBUG}
  488. memasmlists.start;
  489. {$endif}
  490. ResStrInits.free;
  491. WideInits.free;
  492. for hal:=low(TAsmListType) to high(TAsmListType) do
  493. AsmLists[hal].free;
  494. CurrAsmList.free;
  495. {$ifdef MEMDEBUG}
  496. memasmlists.stop;
  497. {$endif}
  498. for hp := low(TConstPoolType) to high(TConstPoolType) do
  499. FConstPools[hp].Free;
  500. end;
  501. function TAsmData.DefineAsmSymbolByClass(symclass: TAsmSymbolClass; const s: TSymStr; _bind: TAsmSymBind; _typ: Tasmsymtype; def: tdef): TAsmSymbol;
  502. var
  503. wasdefined: boolean;
  504. begin
  505. result:=DefineAsmSymbolByClassBase(symclass,s,_bind,_typ,def,wasdefined);
  506. end;
  507. function TAsmData.DefineAsmSymbol(const s: TSymStr; _bind: TAsmSymBind; _typ: Tasmsymtype; def: tdef): TAsmSymbol;
  508. begin
  509. result:=DefineAsmSymbolByClass(TAsmSymbol,s,_bind,_typ,def);
  510. end;
  511. function TAsmData.DefineProcAsmSymbol(pd: tdef; const s: TSymStr; global: boolean): TAsmSymbol;
  512. begin
  513. { The condition to use global or local symbol must match
  514. the code written in hlcg.gen_proc_symbol to
  515. avoid change from AB_LOCAL to AB_GLOBAL, which generates
  516. erroneous code (at least for targets using GOT) }
  517. if global or
  518. (cs_profile in current_settings.moduleswitches) then
  519. result:=DefineAsmSymbol(s,AB_GLOBAL,AT_FUNCTION,pd)
  520. else if tf_supports_hidden_symbols in target_info.flags then
  521. result:=DefineAsmSymbol(s,AB_PRIVATE_EXTERN,AT_FUNCTION,pd)
  522. else
  523. result:=DefineAsmSymbol(s,AB_LOCAL,AT_FUNCTION,pd);
  524. end;
  525. function TAsmData.RefAsmSymbol(const s : TSymStr;_typ:Tasmsymtype;indirect:boolean) : TAsmSymbol;
  526. var
  527. namestr : TSymStr;
  528. bind : tasmsymbind;
  529. begin
  530. namestr:=s;
  531. if indirect then
  532. begin
  533. namestr:=namestr+suffix_indirect;
  534. bind:=AB_EXTERNAL_INDIRECT;
  535. end
  536. else
  537. begin
  538. bind:=AB_EXTERNAL;
  539. end;
  540. result:=TAsmSymbol(FAsmSymbolDict.Find(namestr));
  541. if not assigned(result) then
  542. result:=TAsmSymbol.create(AsmSymbolDict,namestr,bind,_typ)
  543. { one normal reference removes the "weak" character of a symbol }
  544. else if (result.bind=AB_WEAK_EXTERNAL) then
  545. result.bind:=bind;
  546. end;
  547. function TAsmData.WeakRefAsmSymbol(const s : TSymStr;_typ:Tasmsymtype) : TAsmSymbol;
  548. begin
  549. result:=TAsmSymbol(FAsmSymbolDict.Find(s));
  550. if not assigned(result) then
  551. result:=TAsmSymbol.create(AsmSymbolDict,s,AB_WEAK_EXTERNAL,_typ);
  552. end;
  553. function TAsmData.GetAsmSymbol(const s : TSymStr) : TAsmSymbol;
  554. begin
  555. result:=TAsmSymbol(FAsmSymbolDict.Find(s));
  556. end;
  557. procedure TAsmData.GenerateAltSymbol(p:TAsmSymbol);
  558. begin
  559. if not assigned(p.altsymbol) then
  560. begin
  561. p.altsymbol:=p.getaltcopy(AsmSymbolDict,FNextAltNr);
  562. FAltSymbolList.Add(p);
  563. end;
  564. end;
  565. procedure TAsmData.ResetAltSymbols;
  566. var
  567. i : longint;
  568. begin
  569. for i:=0 to FAltSymbolList.Count-1 do
  570. TAsmSymbol(FAltSymbolList[i]).altsymbol:=nil;
  571. FAltSymbolList.Clear;
  572. end;
  573. procedure TAsmData.getlabel(out l : TAsmLabel;alt:TAsmLabeltype);
  574. begin
  575. if (target_info.system in (systems_linux + systems_bsd + systems_android)) and
  576. { the next condition was
  577. (cs_create_smart in current_settings.moduleswitches) and
  578. but if we create_smartlink_sections, this is useless }
  579. (create_smartlink_library) and
  580. (alt = alt_dbgline) then
  581. l:=TAsmLabel.createglobal(AsmSymbolDict,name^,FNextLabelNr[alt],alt)
  582. else
  583. l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt],alt);
  584. inc(FNextLabelNr[alt]);
  585. end;
  586. procedure TAsmData.getjumplabel(out l : TAsmLabel);
  587. begin
  588. l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt_jump],alt_jump);
  589. inc(FNextLabelNr[alt_jump]);
  590. end;
  591. procedure TAsmData.getglobaljumplabel(out l : TAsmLabel);
  592. begin
  593. l:=TAsmLabel.createglobal(AsmSymbolDict,name^,FNextLabelNr[alt_jump],alt_jump);
  594. inc(FNextLabelNr[alt_jump]);
  595. end;
  596. procedure TAsmData.getglobaldatalabel(out l : TAsmLabel);
  597. begin
  598. l:=TAsmLabel.createglobal(AsmSymbolDict,name^,FNextLabelNr[alt_data],alt_data);
  599. inc(FNextLabelNr[alt_data]);
  600. end;
  601. procedure TAsmData.getstaticdatalabel(out l : TAsmLabel);
  602. begin
  603. l:=TAsmLabel.createstatic(AsmSymbolDict,FNextLabelNr[alt_data],alt_data);
  604. inc(FNextLabelNr[alt_data]);
  605. end;
  606. procedure TAsmData.getlocaldatalabel(out l: TAsmLabel);
  607. begin
  608. l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt_data],alt_data);
  609. inc(FNextLabelNr[alt_data]);
  610. end;
  611. procedure TAsmData.getaddrlabel(out l : TAsmLabel);
  612. begin
  613. l:=TAsmLabel.createlocal(AsmSymbolDict,FNextLabelNr[alt_addr],alt_addr);
  614. inc(FNextLabelNr[alt_addr]);
  615. end;
  616. initialization
  617. {$ifdef MEMDEBUG}
  618. memasmsymbols:=TMemDebug.create('AsmSymbols');
  619. memasmsymbols.stop;
  620. memasmcfi:=TMemDebug.create('AsmCFI');
  621. memasmcfi.stop;
  622. memasmlists:=TMemDebug.create('AsmLists');
  623. memasmlists.stop;
  624. {$endif MEMDEBUG}
  625. if not(assigned(CAsmCFI)) then
  626. CAsmCFI:=TAsmCFI;
  627. finalization
  628. {$ifdef MEMDEBUG}
  629. memasmsymbols.free;
  630. memasmcfi.free;
  631. memasmlists.free;
  632. {$endif MEMDEBUG}
  633. end.