aasmbase.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements an abstract asmoutput class for all processor types
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. { @abstract(This unit implements an abstract asm output class for all processor types)
  19. This unit implements an abstract assembler output class for all processors, these
  20. are then overriden for each assembler writer to actually write the data in these
  21. classes to an assembler file.
  22. }
  23. unit aasmbase;
  24. {$i fpcdefs.inc}
  25. interface
  26. uses
  27. cutils,cclasses,
  28. globtype,globals,systems;
  29. { asm symbol functions }
  30. type
  31. TAsmsymbind=(AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL);
  32. TAsmsymtype=(AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION);
  33. TAsmRelocationType = (RELOC_ABSOLUTE,RELOC_RELATIVE,RELOC_RVA);
  34. TAsmSectionSizes = array[TSection] of longint;
  35. TAsmSymbol = class(TNamedIndexItem)
  36. defbind,
  37. currbind : TAsmsymbind;
  38. typ : TAsmsymtype;
  39. { the next fields are filled in the binary writer }
  40. section : TSection;
  41. address,
  42. size : longint;
  43. { this need to be incremented with every symbol loading into the
  44. paasmoutput, thus in loadsym/loadref/const_symbol (PFV) }
  45. refs : longint;
  46. {# Alternate symbol which can be used for 'renaming' needed for
  47. inlining }
  48. altsymbol : tasmsymbol;
  49. objectdata : pointer;
  50. {# TRUE if the symbol is local for a procedure/function }
  51. proclocal : boolean;
  52. {# Is the symbol in the used list }
  53. inusedlist : boolean;
  54. { assembler pass label is set, used for detecting multiple labels }
  55. pass : byte;
  56. ppuidx : longint;
  57. constructor create(const s:string;_bind:TAsmsymbind;_typ:Tasmsymtype);
  58. procedure reset;
  59. function is_used:boolean;
  60. procedure setaddress(_pass:byte;sec:TSection;offset,len:longint);
  61. end;
  62. TAsmLabel = class(TAsmSymbol)
  63. { this is set by the tai_label.Init }
  64. is_set,
  65. { is the label only there for getting an address (e.g. for i/o }
  66. { checks -> true) or is it a jump target (false) }
  67. is_addr : boolean;
  68. labelnr : longint;
  69. constructor create(nr:longint);
  70. constructor createdata(nr:longint);
  71. constructor createaddr(nr:longint);
  72. function getname:string;override;
  73. end;
  74. TAsmRelocation = class(TLinkedListItem)
  75. address,
  76. orgsize : longint; { original size of the symbol to relocate, required for COFF }
  77. symbol : tasmsymbol;
  78. section : TSection; { only used if symbol=nil }
  79. typ : TAsmRelocationType;
  80. constructor CreateSymbol(Aaddress:longint;s:Tasmsymbol;Atyp:TAsmRelocationType);
  81. constructor CreateSymbolSize(Aaddress:longint;s:Tasmsymbol;Aorgsize:longint;Atyp:TAsmRelocationType);
  82. constructor CreateSection(Aaddress:longint;sec:TSection;Atyp:TAsmRelocationType);
  83. end;
  84. TAsmSection = class(TLinkedListItem)
  85. name : string[32];
  86. secsymidx : longint; { index for the section in symtab }
  87. addralign : longint; { alignment of the section }
  88. flags : cardinal; { section flags }
  89. { size of the data and in the file }
  90. dataalignbytes : longint;
  91. data : TDynamicArray;
  92. datasize : longint;
  93. datapos : longint;
  94. { size and position in memory, set by seTSectionsize }
  95. memsize,
  96. mempos : longint;
  97. { relocation }
  98. relocations : TLinkedList;
  99. constructor create(const Aname:string;Aalign:longint;alloconly:boolean);
  100. destructor destroy;override;
  101. function write(var d;l:longint):longint;
  102. function writestr(const s:string):longint;
  103. procedure writealign(l:longint);
  104. function aligneddatasize:longint;
  105. procedure alignsection;
  106. procedure alloc(l:longint);
  107. procedure addsymreloc(ofs:longint;p:tasmsymbol;relative:TAsmRelocationType);
  108. procedure addsectionreloc(ofs:longint;sec:TSection;relative:TAsmRelocationType);
  109. end;
  110. TAsmObjectAlloc = class
  111. currsec : TSection;
  112. secsize : TAsmSectionSizes;
  113. constructor create;
  114. destructor destroy;override;
  115. procedure seTSection(sec:TSection);
  116. function sectionsize:longint;
  117. procedure sectionalloc(l:longint);
  118. procedure sectionalign(l:longint);
  119. procedure staballoc(p:pchar);
  120. procedure resetSections;
  121. end;
  122. TAsmObjectData = class(TLinkedListItem)
  123. public
  124. name : string[80];
  125. currsec : TSection;
  126. sects : array[TSection] of TAsmSection;
  127. symbols : tindexarray; { contains symbols that will be defined in object file }
  128. constructor create(const n:string);
  129. destructor destroy;override;
  130. procedure createsection(sec:TSection);virtual;
  131. procedure defaulTSection(sec:TSection);
  132. function sectionsize(s:TSection):longint;
  133. function currsectionsize:longint;
  134. procedure setsectionsizes(var s:TAsmSectionSizes);virtual;
  135. procedure alloc(len:longint);
  136. procedure allocalign(len:longint);
  137. procedure writebytes(var data;len:longint);
  138. procedure writereloc(data,len:longint;p:tasmsymbol;relative:TAsmRelocationType);virtual;abstract;
  139. procedure writesymbol(p:tasmsymbol);virtual;abstract;
  140. procedure writestabs(section:TSection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual;abstract;
  141. procedure writesymstabs(section:TSection;offset:longint;p:pchar;ps:tasmsymbol;nidx,nother,line:longint;reloc:boolean);virtual;abstract;
  142. procedure fixuprelocs;virtual;
  143. end;
  144. tasmsymbolidxarr = array[0..$7fffffff div sizeof(pointer)] of tasmsymbol;
  145. pasmsymbolidxarr = ^tasmsymbolidxarr;
  146. TAsmLibraryData = class(TLinkedListItem)
  147. private
  148. nextaltnr : longint;
  149. nextlabelnr : longint;
  150. public
  151. name : string[80];
  152. symbolsearch : tdictionary; { contains ALL assembler symbols }
  153. usedasmsymbollist : tsinglelist;
  154. { ppu }
  155. asmsymbolppuidx : longint;
  156. asmsymbolidx : pasmsymbolidxarr; { used for translating ppu index->asmsymbol }
  157. constructor create(const n:string);
  158. destructor destroy;override;
  159. procedure Freeasmsymbolidx;
  160. procedure DerefAsmsymbol(var s:tasmsymbol);
  161. { asmsymbol }
  162. function newasmsymbol(const s : string) : tasmsymbol;
  163. function newasmsymboltype(const s : string;_bind:TAsmSymBind;_typ:TAsmsymtype) : tasmsymbol;
  164. function getasmsymbol(const s : string) : tasmsymbol;
  165. function renameasmsymbol(const sold, snew : string):tasmsymbol;
  166. {# create a new assembler label }
  167. procedure getlabel(var l : tasmlabel);
  168. { make l as a new label and flag is_addr }
  169. procedure getaddrlabel(var l : tasmlabel);
  170. { make l as a new label and flag is_data }
  171. procedure getdatalabel(var l : tasmlabel);
  172. {# return a label number }
  173. procedure getlabelnr(var l : longint);
  174. procedure CreateUsedAsmSymbolList;
  175. procedure DestroyUsedAsmSymbolList;
  176. procedure UsedAsmSymbolListInsert(p:tasmsymbol);
  177. { generate an alternative (duplicate) symbol }
  178. procedure GenerateAltSymbol(p:tasmsymbol);
  179. { reset alternative symbol information }
  180. procedure UsedAsmSymbolListResetAltSym;
  181. procedure UsedAsmSymbolListReset;
  182. procedure UsedAsmSymbolListCheckUndefined;
  183. end;
  184. var
  185. objectlibrary : tasmlibrarydata;
  186. implementation
  187. uses
  188. {$ifdef delphi}
  189. sysutils,
  190. {$else}
  191. strings,
  192. {$endif}
  193. fmodule,verbose;
  194. const
  195. symbolsgrow = 100;
  196. {*****************************************************************************
  197. TAsmSymbol
  198. *****************************************************************************}
  199. constructor tasmsymbol.create(const s:string;_bind:TAsmsymbind;_typ:Tasmsymtype);
  200. begin;
  201. inherited createname(s);
  202. reset;
  203. defbind:=_bind;
  204. typ:=_typ;
  205. inusedlist:=false;
  206. pass:=255;
  207. ppuidx:=-1;
  208. { mainly used to remove unused labels from the codesegment }
  209. refs:=0;
  210. end;
  211. procedure tasmsymbol.reset;
  212. begin
  213. { reset section info }
  214. section:=sec_none;
  215. address:=0;
  216. size:=0;
  217. indexnr:=-1;
  218. pass:=255;
  219. currbind:=AB_EXTERNAL;
  220. proclocal:=false;
  221. end;
  222. function tasmsymbol.is_used:boolean;
  223. begin
  224. is_used:=(refs>0);
  225. end;
  226. procedure tasmsymbol.setaddress(_pass:byte;sec:TSection;offset,len:longint);
  227. begin
  228. if (_pass=pass) then
  229. begin
  230. Message1(asmw_e_duplicate_label,name);
  231. exit;
  232. end;
  233. pass:=_pass;
  234. section:=sec;
  235. address:=offset;
  236. size:=len;
  237. { when the bind was reset to External, set it back to the default
  238. bind it got when defined }
  239. if (currbind=AB_EXTERNAL) and (defbind<>AB_NONE) then
  240. currbind:=defbind;
  241. end;
  242. {*****************************************************************************
  243. TAsmLabel
  244. *****************************************************************************}
  245. constructor tasmlabel.create(nr:longint);
  246. begin;
  247. labelnr:=nr;
  248. inherited create(target_asm.labelprefix+tostr(labelnr),AB_LOCAL,AT_FUNCTION);
  249. proclocal:=true;
  250. is_set:=false;
  251. is_addr := false;
  252. end;
  253. constructor tasmlabel.createdata(nr:longint);
  254. begin;
  255. labelnr:=nr;
  256. if (cs_create_smart in aktmoduleswitches) or
  257. target_asm.labelprefix_only_inside_procedure then
  258. inherited create('_$'+current_module.modulename^+'$_L'+tostr(labelnr),AB_GLOBAL,AT_DATA)
  259. else
  260. inherited create(target_asm.labelprefix+tostr(labelnr),AB_LOCAL,AT_DATA);
  261. is_set:=false;
  262. is_addr := false;
  263. proclocal := false;
  264. { write it always }
  265. refs:=1;
  266. end;
  267. constructor tasmlabel.createaddr(nr:longint);
  268. begin;
  269. create(nr);
  270. is_addr := true;
  271. end;
  272. function tasmlabel.getname:string;
  273. begin
  274. getname:=inherited getname;
  275. inc(refs);
  276. end;
  277. {****************************************************************************
  278. TAsmObjectAlloc
  279. ****************************************************************************}
  280. constructor TAsmObjectAlloc.create;
  281. begin
  282. end;
  283. destructor TAsmObjectAlloc.destroy;
  284. begin
  285. end;
  286. procedure TAsmObjectAlloc.seTSection(sec:TSection);
  287. begin
  288. currsec:=sec;
  289. end;
  290. procedure TAsmObjectAlloc.reseTSections;
  291. begin
  292. FillChar(secsize,sizeof(secsize),0);
  293. end;
  294. procedure TAsmObjectAlloc.sectionalloc(l:longint);
  295. begin
  296. inc(secsize[currsec],l);
  297. end;
  298. procedure TAsmObjectAlloc.sectionalign(l:longint);
  299. begin
  300. if (secsize[currsec] mod l)<>0 then
  301. inc(secsize[currsec],l-(secsize[currsec] mod l));
  302. end;
  303. procedure TAsmObjectAlloc.staballoc(p:pchar);
  304. begin
  305. inc(secsize[sec_stab]);
  306. if assigned(p) and (p[0]<>#0) then
  307. inc(secsize[sec_stabstr],strlen(p)+1);
  308. end;
  309. function TAsmObjectAlloc.sectionsize:longint;
  310. begin
  311. sectionsize:=secsize[currsec];
  312. end;
  313. {****************************************************************************
  314. TAsmRelocation
  315. ****************************************************************************}
  316. constructor TAsmRelocation.CreateSymbol(Aaddress:longint;s:Tasmsymbol;Atyp:TAsmRelocationType);
  317. begin
  318. Address:=Aaddress;
  319. Symbol:=s;
  320. OrgSize:=0;
  321. Section:=Sec_none;
  322. Typ:=Atyp;
  323. end;
  324. constructor TAsmRelocation.CreateSymbolSize(Aaddress:longint;s:Tasmsymbol;Aorgsize:longint;Atyp:TAsmRelocationType);
  325. begin
  326. Address:=Aaddress;
  327. Symbol:=s;
  328. OrgSize:=Aorgsize;
  329. Section:=Sec_none;
  330. Typ:=Atyp;
  331. end;
  332. constructor TAsmRelocation.CreateSection(Aaddress:longint;sec:TSection;Atyp:TAsmRelocationType);
  333. begin
  334. Address:=Aaddress;
  335. Symbol:=nil;
  336. OrgSize:=0;
  337. Section:=sec;
  338. Typ:=Atyp;
  339. end;
  340. {****************************************************************************
  341. TAsmSection
  342. ****************************************************************************}
  343. constructor TAsmSection.create(const Aname:string;Aalign:longint;alloconly:boolean);
  344. begin
  345. inherited create;
  346. name:=Aname;
  347. secsymidx:=0;
  348. addralign:=Aalign;
  349. { data }
  350. datasize:=0;
  351. datapos:=0;
  352. if alloconly then
  353. data:=nil
  354. else
  355. Data:=TDynamicArray.Create(8192);
  356. { position }
  357. mempos:=0;
  358. memsize:=0;
  359. { relocation }
  360. relocations:=TLinkedList.Create;
  361. end;
  362. destructor TAsmSection.destroy;
  363. begin
  364. if assigned(Data) then
  365. Data.Free;
  366. relocations.free;
  367. end;
  368. function TAsmSection.write(var d;l:longint):longint;
  369. begin
  370. write:=datasize;
  371. if not assigned(Data) then
  372. Internalerror(3334441);
  373. Data.write(d,l);
  374. inc(datasize,l);
  375. end;
  376. function TAsmSection.writestr(const s:string):longint;
  377. begin
  378. writestr:=datasize;
  379. if not assigned(Data) then
  380. Internalerror(3334441);
  381. Data.write(s[1],length(s));
  382. inc(datasize,length(s));
  383. end;
  384. procedure TAsmSection.writealign(l:longint);
  385. var
  386. i : longint;
  387. empty : array[0..63] of char;
  388. begin
  389. { no alignment needed for 0 or 1 }
  390. if l<=1 then
  391. exit;
  392. i:=datasize mod l;
  393. if i>0 then
  394. begin
  395. if assigned(data) then
  396. begin
  397. fillchar(empty,sizeof(empty),0);
  398. Data.write(empty,l-i);
  399. end;
  400. inc(datasize,l-i);
  401. end;
  402. end;
  403. function TAsmSection.aligneddatasize:longint;
  404. begin
  405. aligneddatasize:=align(datasize,addralign);
  406. end;
  407. procedure TAsmSection.alignsection;
  408. begin
  409. writealign(addralign);
  410. end;
  411. procedure TAsmSection.alloc(l:longint);
  412. begin
  413. if assigned(Data) then
  414. Internalerror(3334442);
  415. inc(datasize,l);
  416. end;
  417. procedure TAsmSection.addsymreloc(ofs:longint;p:tasmsymbol;relative:TAsmRelocationType);
  418. var
  419. r : TAsmRelocation;
  420. begin
  421. r:=TAsmRelocation.Create;
  422. r.address:=ofs;
  423. r.orgsize:=0;
  424. r.symbol:=p;
  425. r.section:=sec_none;
  426. r.typ:=relative;
  427. relocations.concat(r);
  428. end;
  429. procedure TAsmSection.addsectionreloc(ofs:longint;sec:TSection;relative:TAsmRelocationType);
  430. var
  431. r : TAsmRelocation;
  432. begin
  433. r:=TAsmRelocation.Create;
  434. r.address:=ofs;
  435. r.symbol:=nil;
  436. r.orgsize:=0;
  437. r.section:=sec;
  438. r.typ:=relative;
  439. relocations.concat(r);
  440. end;
  441. {****************************************************************************
  442. TAsmObjectData
  443. ****************************************************************************}
  444. constructor TAsmObjectData.create(const n:string);
  445. begin
  446. inherited create;
  447. name:=n;
  448. { sections }
  449. FillChar(Sects,sizeof(Sects),0);
  450. { symbols }
  451. symbols:=tindexarray.create(symbolsgrow);
  452. symbols.noclear:=true;
  453. end;
  454. destructor TAsmObjectData.destroy;
  455. var
  456. sec : TSection;
  457. begin
  458. { free memory }
  459. for sec:=low(TSection) to high(TSection) do
  460. if assigned(sects[sec]) then
  461. sects[sec].free;
  462. symbols.free;
  463. end;
  464. procedure TAsmObjectData.createsection(sec:TSection);
  465. begin
  466. sects[sec]:=TAsmSection.create(target_asm.secnames[sec],1,(sec=sec_bss));
  467. end;
  468. function TAsmObjectData.sectionsize(s:TSection):longint;
  469. begin
  470. if assigned(sects[s]) then
  471. sectionsize:=sects[s].datasize
  472. else
  473. sectionsize:=0;
  474. end;
  475. function TAsmObjectData.currsectionsize:longint;
  476. begin
  477. if assigned(sects[currsec]) then
  478. currsectionsize:=sects[currsec].datasize
  479. else
  480. currsectionsize:=0;
  481. end;
  482. procedure TAsmObjectData.seTSectionsizes(var s:TAsmSectionSizes);
  483. begin
  484. end;
  485. procedure TAsmObjectData.defaulTSection(sec:TSection);
  486. begin
  487. currsec:=sec;
  488. end;
  489. procedure TAsmObjectData.writebytes(var data;len:longint);
  490. begin
  491. if not assigned(sects[currsec]) then
  492. createsection(currsec);
  493. sects[currsec].write(data,len);
  494. end;
  495. procedure TAsmObjectData.alloc(len:longint);
  496. begin
  497. if not assigned(sects[currsec]) then
  498. createsection(currsec);
  499. sects[currsec].alloc(len);
  500. end;
  501. procedure TAsmObjectData.allocalign(len:longint);
  502. var
  503. modulo : longint;
  504. begin
  505. if not assigned(sects[currsec]) then
  506. createsection(currsec);
  507. modulo:=sects[currsec].datasize mod len;
  508. if modulo > 0 then
  509. sects[currsec].alloc(len-modulo);
  510. end;
  511. procedure TAsmObjectData.fixuprelocs;
  512. begin
  513. { no relocation support by default }
  514. end;
  515. {****************************************************************************
  516. TAsmLibraryData
  517. ****************************************************************************}
  518. constructor TAsmLibraryData.create(const n:string);
  519. begin
  520. inherited create;
  521. name:=n;
  522. { symbols }
  523. symbolsearch:=tdictionary.create;
  524. symbolsearch.usehash;
  525. { labels }
  526. nextaltnr:=1;
  527. nextlabelnr:=1;
  528. { ppu }
  529. asmsymbolppuidx:=0;
  530. asmsymbolidx:=nil;
  531. end;
  532. destructor TAsmLibraryData.destroy;
  533. begin
  534. symbolsearch.free;
  535. Freeasmsymbolidx;
  536. end;
  537. procedure TAsmLibraryData.Freeasmsymbolidx;
  538. begin
  539. if assigned(asmsymbolidx) then
  540. begin
  541. Freemem(asmsymbolidx);
  542. asmsymbolidx:=nil;
  543. end;
  544. end;
  545. procedure TAsmLibraryData.DerefAsmsymbol(var s:tasmsymbol);
  546. begin
  547. if not assigned(asmsymbolidx) then
  548. internalerror(200208072);
  549. if longint(pointer(s))>=asmsymbolppuidx then
  550. internalerror(200208073);
  551. s:=asmsymbolidx^[longint(pointer(s))];
  552. end;
  553. function TAsmLibraryData.newasmsymbol(const s : string) : tasmsymbol;
  554. var
  555. hp : tasmsymbol;
  556. begin
  557. hp:=tasmsymbol(symbolsearch.search(s));
  558. if not assigned(hp) then
  559. begin
  560. { Not found, insert it as an External }
  561. hp:=tasmsymbol.create(s,AB_EXTERNAL,AT_FUNCTION);
  562. symbolsearch.insert(hp);
  563. end;
  564. newasmsymbol:=hp;
  565. end;
  566. function TAsmLibraryData.newasmsymboltype(const s : string;_bind:TAsmSymBind;_typ:Tasmsymtype) : tasmsymbol;
  567. var
  568. hp : tasmsymbol;
  569. begin
  570. hp:=tasmsymbol(symbolsearch.search(s));
  571. if assigned(hp) then
  572. hp.defbind:=_bind
  573. else
  574. begin
  575. { Not found, insert it as an External }
  576. hp:=tasmsymbol.create(s,_bind,_typ);
  577. symbolsearch.insert(hp);
  578. end;
  579. newasmsymboltype:=hp;
  580. end;
  581. function TAsmLibraryData.getasmsymbol(const s : string) : tasmsymbol;
  582. begin
  583. getasmsymbol:=tasmsymbol(symbolsearch.search(s));
  584. end;
  585. function TAsmLibraryData.renameasmsymbol(const sold, snew : string):tasmsymbol;
  586. begin
  587. renameasmsymbol:=tasmsymbol(symbolsearch.rename(sold,snew));
  588. end;
  589. procedure TAsmLibraryData.CreateUsedAsmSymbolList;
  590. begin
  591. if assigned(usedasmsymbollist) then
  592. internalerror(78455782);
  593. usedasmsymbollist:=TSingleList.create;
  594. end;
  595. procedure TAsmLibraryData.DestroyUsedAsmSymbolList;
  596. begin
  597. usedasmsymbollist.destroy;
  598. usedasmsymbollist:=nil;
  599. end;
  600. procedure TAsmLibraryData.UsedAsmSymbolListInsert(p:tasmsymbol);
  601. begin
  602. if not p.inusedlist then
  603. usedasmsymbollist.insert(p);
  604. p.inusedlist:=true;
  605. end;
  606. procedure TAsmLibraryData.GenerateAltSymbol(p:tasmsymbol);
  607. begin
  608. if not assigned(p.altsymbol) then
  609. begin
  610. p.altsymbol:=tasmsymbol.create(name+'_'+tostr(nextaltnr),p.defbind,p.typ);
  611. { also copy the amount of references }
  612. p.altsymbol.refs:=p.refs;
  613. inc(nextaltnr);
  614. { add to the usedasmsymbollist, that list is used to reset the
  615. altsymbol }
  616. if not p.inusedlist then
  617. usedasmsymbollist.insert(p);
  618. p.inusedlist:=true;
  619. end;
  620. end;
  621. procedure TAsmLibraryData.UsedAsmSymbolListReset;
  622. var
  623. hp : tasmsymbol;
  624. begin
  625. hp:=tasmsymbol(usedasmsymbollist.first);
  626. while assigned(hp) do
  627. begin
  628. with hp do
  629. begin
  630. reset;
  631. inusedlist:=false;
  632. end;
  633. hp:=tasmsymbol(hp.listnext);
  634. end;
  635. end;
  636. procedure TAsmLibraryData.UsedAsmSymbolListResetAltSym;
  637. var
  638. hp : tasmsymbol;
  639. begin
  640. hp:=tasmsymbol(usedasmsymbollist.first);
  641. while assigned(hp) do
  642. begin
  643. with hp do
  644. begin
  645. altsymbol:=nil;
  646. inusedlist:=false;
  647. end;
  648. hp:=tasmsymbol(hp.listnext);
  649. end;
  650. end;
  651. procedure TAsmLibraryData.UsedAsmSymbolListCheckUndefined;
  652. var
  653. hp : tasmsymbol;
  654. begin
  655. hp:=tasmsymbol(usedasmsymbollist.first);
  656. while assigned(hp) do
  657. begin
  658. with hp do
  659. begin
  660. if (refs>0) and
  661. (section=Sec_none) and
  662. not(currbind in [AB_EXTERNAL,AB_COMMON]) then
  663. Message1(asmw_e_undefined_label,name);
  664. end;
  665. hp:=tasmsymbol(hp.listnext);
  666. end;
  667. end;
  668. procedure TAsmLibraryData.getlabel(var l : tasmlabel);
  669. begin
  670. l:=tasmlabel.create(nextlabelnr);
  671. inc(nextlabelnr);
  672. symbolsearch.insert(l);
  673. end;
  674. procedure TAsmLibraryData.getdatalabel(var l : tasmlabel);
  675. begin
  676. l:=tasmlabel.createdata(nextlabelnr);
  677. inc(nextlabelnr);
  678. symbolsearch.insert(l);
  679. end;
  680. procedure TAsmLibraryData.getaddrlabel(var l : tasmlabel);
  681. begin
  682. l:=tasmlabel.createaddr(nextlabelnr);
  683. inc(nextlabelnr);
  684. symbolsearch.insert(l);
  685. end;
  686. procedure TAsmLibraryData.getlabelnr(var l : longint);
  687. begin
  688. l:=nextlabelnr;
  689. inc(nextlabelnr);
  690. end;
  691. end.
  692. {
  693. $Log$
  694. Revision 1.6 2002-08-12 15:08:39 carl
  695. + stab register indexes for powerpc (moved from gdb to cpubase)
  696. + tprocessor enumeration moved to cpuinfo
  697. + linker in target_info is now a class
  698. * many many updates for m68k (will soon start to compile)
  699. - removed some ifdef or correct them for correct cpu
  700. Revision 1.5 2002/08/11 14:32:25 peter
  701. * renamed current_library to objectlibrary
  702. Revision 1.4 2002/08/11 13:24:10 peter
  703. * saving of asmsymbols in ppu supported
  704. * asmsymbollist global is removed and moved into a new class
  705. tasmlibrarydata that will hold the info of a .a file which
  706. corresponds with a single module. Added librarydata to tmodule
  707. to keep the library info stored for the module. In the future the
  708. objectfiles will also be stored to the tasmlibrarydata class
  709. * all getlabel/newasmsymbol and friends are moved to the new class
  710. Revision 1.3 2002/07/10 07:24:40 jonas
  711. * memory leak fixes from Sergey Korshunoff
  712. Revision 1.2 2002/07/07 09:52:32 florian
  713. * powerpc target fixed, very simple units can be compiled
  714. * some basic stuff for better callparanode handling, far from being finished
  715. Revision 1.1 2002/07/01 18:46:20 peter
  716. * internal linker
  717. * reorganized aasm layer
  718. }