aasmdata.pas 23 KB

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