aasmdata.pas 23 KB

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