aasmbase.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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. current_library : 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. { write it always }
  264. refs:=1;
  265. end;
  266. constructor tasmlabel.createaddr(nr:longint);
  267. begin;
  268. create(nr);
  269. is_addr := true;
  270. end;
  271. function tasmlabel.getname:string;
  272. begin
  273. getname:=inherited getname;
  274. inc(refs);
  275. end;
  276. {****************************************************************************
  277. TAsmObjectAlloc
  278. ****************************************************************************}
  279. constructor TAsmObjectAlloc.create;
  280. begin
  281. end;
  282. destructor TAsmObjectAlloc.destroy;
  283. begin
  284. end;
  285. procedure TAsmObjectAlloc.seTSection(sec:TSection);
  286. begin
  287. currsec:=sec;
  288. end;
  289. procedure TAsmObjectAlloc.reseTSections;
  290. begin
  291. FillChar(secsize,sizeof(secsize),0);
  292. end;
  293. procedure TAsmObjectAlloc.sectionalloc(l:longint);
  294. begin
  295. inc(secsize[currsec],l);
  296. end;
  297. procedure TAsmObjectAlloc.sectionalign(l:longint);
  298. begin
  299. if (secsize[currsec] mod l)<>0 then
  300. inc(secsize[currsec],l-(secsize[currsec] mod l));
  301. end;
  302. procedure TAsmObjectAlloc.staballoc(p:pchar);
  303. begin
  304. inc(secsize[sec_stab]);
  305. if assigned(p) and (p[0]<>#0) then
  306. inc(secsize[sec_stabstr],strlen(p)+1);
  307. end;
  308. function TAsmObjectAlloc.sectionsize:longint;
  309. begin
  310. sectionsize:=secsize[currsec];
  311. end;
  312. {****************************************************************************
  313. TAsmRelocation
  314. ****************************************************************************}
  315. constructor TAsmRelocation.CreateSymbol(Aaddress:longint;s:Tasmsymbol;Atyp:TAsmRelocationType);
  316. begin
  317. Address:=Aaddress;
  318. Symbol:=s;
  319. OrgSize:=0;
  320. Section:=Sec_none;
  321. Typ:=Atyp;
  322. end;
  323. constructor TAsmRelocation.CreateSymbolSize(Aaddress:longint;s:Tasmsymbol;Aorgsize:longint;Atyp:TAsmRelocationType);
  324. begin
  325. Address:=Aaddress;
  326. Symbol:=s;
  327. OrgSize:=Aorgsize;
  328. Section:=Sec_none;
  329. Typ:=Atyp;
  330. end;
  331. constructor TAsmRelocation.CreateSection(Aaddress:longint;sec:TSection;Atyp:TAsmRelocationType);
  332. begin
  333. Address:=Aaddress;
  334. Symbol:=nil;
  335. OrgSize:=0;
  336. Section:=sec;
  337. Typ:=Atyp;
  338. end;
  339. {****************************************************************************
  340. TAsmSection
  341. ****************************************************************************}
  342. constructor TAsmSection.create(const Aname:string;Aalign:longint;alloconly:boolean);
  343. begin
  344. inherited create;
  345. name:=Aname;
  346. secsymidx:=0;
  347. addralign:=Aalign;
  348. { data }
  349. datasize:=0;
  350. datapos:=0;
  351. if alloconly then
  352. data:=nil
  353. else
  354. Data:=TDynamicArray.Create(8192);
  355. { position }
  356. mempos:=0;
  357. memsize:=0;
  358. { relocation }
  359. relocations:=TLinkedList.Create;
  360. end;
  361. destructor TAsmSection.destroy;
  362. begin
  363. if assigned(Data) then
  364. Data.Free;
  365. relocations.free;
  366. end;
  367. function TAsmSection.write(var d;l:longint):longint;
  368. begin
  369. write:=datasize;
  370. if not assigned(Data) then
  371. Internalerror(3334441);
  372. Data.write(d,l);
  373. inc(datasize,l);
  374. end;
  375. function TAsmSection.writestr(const s:string):longint;
  376. begin
  377. writestr:=datasize;
  378. if not assigned(Data) then
  379. Internalerror(3334441);
  380. Data.write(s[1],length(s));
  381. inc(datasize,length(s));
  382. end;
  383. procedure TAsmSection.writealign(l:longint);
  384. var
  385. i : longint;
  386. empty : array[0..63] of char;
  387. begin
  388. { no alignment needed for 0 or 1 }
  389. if l<=1 then
  390. exit;
  391. i:=datasize mod l;
  392. if i>0 then
  393. begin
  394. if assigned(data) then
  395. begin
  396. fillchar(empty,sizeof(empty),0);
  397. Data.write(empty,l-i);
  398. end;
  399. inc(datasize,l-i);
  400. end;
  401. end;
  402. function TAsmSection.aligneddatasize:longint;
  403. begin
  404. aligneddatasize:=align(datasize,addralign);
  405. end;
  406. procedure TAsmSection.alignsection;
  407. begin
  408. writealign(addralign);
  409. end;
  410. procedure TAsmSection.alloc(l:longint);
  411. begin
  412. if assigned(Data) then
  413. Internalerror(3334442);
  414. inc(datasize,l);
  415. end;
  416. procedure TAsmSection.addsymreloc(ofs:longint;p:tasmsymbol;relative:TAsmRelocationType);
  417. var
  418. r : TAsmRelocation;
  419. begin
  420. r:=TAsmRelocation.Create;
  421. r.address:=ofs;
  422. r.orgsize:=0;
  423. r.symbol:=p;
  424. r.section:=sec_none;
  425. r.typ:=relative;
  426. relocations.concat(r);
  427. end;
  428. procedure TAsmSection.addsectionreloc(ofs:longint;sec:TSection;relative:TAsmRelocationType);
  429. var
  430. r : TAsmRelocation;
  431. begin
  432. r:=TAsmRelocation.Create;
  433. r.address:=ofs;
  434. r.symbol:=nil;
  435. r.orgsize:=0;
  436. r.section:=sec;
  437. r.typ:=relative;
  438. relocations.concat(r);
  439. end;
  440. {****************************************************************************
  441. TAsmObjectData
  442. ****************************************************************************}
  443. constructor TAsmObjectData.create(const n:string);
  444. begin
  445. inherited create;
  446. name:=n;
  447. { sections }
  448. FillChar(Sects,sizeof(Sects),0);
  449. { symbols }
  450. symbols:=tindexarray.create(symbolsgrow);
  451. symbols.noclear:=true;
  452. end;
  453. destructor TAsmObjectData.destroy;
  454. var
  455. sec : TSection;
  456. begin
  457. { free memory }
  458. for sec:=low(TSection) to high(TSection) do
  459. if assigned(sects[sec]) then
  460. sects[sec].free;
  461. symbols.free;
  462. end;
  463. procedure TAsmObjectData.createsection(sec:TSection);
  464. begin
  465. sects[sec]:=TAsmSection.create(target_asm.secnames[sec],1,(sec=sec_bss));
  466. end;
  467. function TAsmObjectData.sectionsize(s:TSection):longint;
  468. begin
  469. if assigned(sects[s]) then
  470. sectionsize:=sects[s].datasize
  471. else
  472. sectionsize:=0;
  473. end;
  474. function TAsmObjectData.currsectionsize:longint;
  475. begin
  476. if assigned(sects[currsec]) then
  477. currsectionsize:=sects[currsec].datasize
  478. else
  479. currsectionsize:=0;
  480. end;
  481. procedure TAsmObjectData.seTSectionsizes(var s:TAsmSectionSizes);
  482. begin
  483. end;
  484. procedure TAsmObjectData.defaulTSection(sec:TSection);
  485. begin
  486. currsec:=sec;
  487. end;
  488. procedure TAsmObjectData.writebytes(var data;len:longint);
  489. begin
  490. if not assigned(sects[currsec]) then
  491. createsection(currsec);
  492. sects[currsec].write(data,len);
  493. end;
  494. procedure TAsmObjectData.alloc(len:longint);
  495. begin
  496. if not assigned(sects[currsec]) then
  497. createsection(currsec);
  498. sects[currsec].alloc(len);
  499. end;
  500. procedure TAsmObjectData.allocalign(len:longint);
  501. var
  502. modulo : longint;
  503. begin
  504. if not assigned(sects[currsec]) then
  505. createsection(currsec);
  506. modulo:=sects[currsec].datasize mod len;
  507. if modulo > 0 then
  508. sects[currsec].alloc(len-modulo);
  509. end;
  510. procedure TAsmObjectData.fixuprelocs;
  511. begin
  512. { no relocation support by default }
  513. end;
  514. {****************************************************************************
  515. TAsmLibraryData
  516. ****************************************************************************}
  517. constructor TAsmLibraryData.create(const n:string);
  518. begin
  519. inherited create;
  520. name:=n;
  521. { symbols }
  522. symbolsearch:=tdictionary.create;
  523. symbolsearch.usehash;
  524. { labels }
  525. nextaltnr:=1;
  526. nextlabelnr:=1;
  527. { ppu }
  528. asmsymbolppuidx:=0;
  529. asmsymbolidx:=nil;
  530. end;
  531. destructor TAsmLibraryData.destroy;
  532. begin
  533. symbolsearch.free;
  534. Freeasmsymbolidx;
  535. end;
  536. procedure TAsmLibraryData.Freeasmsymbolidx;
  537. begin
  538. if assigned(asmsymbolidx) then
  539. begin
  540. Freemem(asmsymbolidx);
  541. asmsymbolidx:=nil;
  542. end;
  543. end;
  544. procedure TAsmLibraryData.DerefAsmsymbol(var s:tasmsymbol);
  545. begin
  546. if not assigned(asmsymbolidx) then
  547. internalerror(200208072);
  548. if longint(pointer(s))>=asmsymbolppuidx then
  549. internalerror(200208073);
  550. s:=asmsymbolidx^[longint(pointer(s))];
  551. end;
  552. function TAsmLibraryData.newasmsymbol(const s : string) : tasmsymbol;
  553. var
  554. hp : tasmsymbol;
  555. begin
  556. hp:=tasmsymbol(symbolsearch.search(s));
  557. if not assigned(hp) then
  558. begin
  559. { Not found, insert it as an External }
  560. hp:=tasmsymbol.create(s,AB_EXTERNAL,AT_FUNCTION);
  561. symbolsearch.insert(hp);
  562. end;
  563. newasmsymbol:=hp;
  564. end;
  565. function TAsmLibraryData.newasmsymboltype(const s : string;_bind:TAsmSymBind;_typ:Tasmsymtype) : tasmsymbol;
  566. var
  567. hp : tasmsymbol;
  568. begin
  569. hp:=tasmsymbol(symbolsearch.search(s));
  570. if assigned(hp) then
  571. hp.defbind:=_bind
  572. else
  573. begin
  574. { Not found, insert it as an External }
  575. hp:=tasmsymbol.create(s,_bind,_typ);
  576. symbolsearch.insert(hp);
  577. end;
  578. newasmsymboltype:=hp;
  579. end;
  580. function TAsmLibraryData.getasmsymbol(const s : string) : tasmsymbol;
  581. begin
  582. getasmsymbol:=tasmsymbol(symbolsearch.search(s));
  583. end;
  584. function TAsmLibraryData.renameasmsymbol(const sold, snew : string):tasmsymbol;
  585. begin
  586. renameasmsymbol:=tasmsymbol(symbolsearch.rename(sold,snew));
  587. end;
  588. procedure TAsmLibraryData.CreateUsedAsmSymbolList;
  589. begin
  590. if assigned(usedasmsymbollist) then
  591. internalerror(78455782);
  592. usedasmsymbollist:=TSingleList.create;
  593. end;
  594. procedure TAsmLibraryData.DestroyUsedAsmSymbolList;
  595. begin
  596. usedasmsymbollist.destroy;
  597. usedasmsymbollist:=nil;
  598. end;
  599. procedure TAsmLibraryData.UsedAsmSymbolListInsert(p:tasmsymbol);
  600. begin
  601. if not p.inusedlist then
  602. usedasmsymbollist.insert(p);
  603. p.inusedlist:=true;
  604. end;
  605. procedure TAsmLibraryData.GenerateAltSymbol(p:tasmsymbol);
  606. begin
  607. if not assigned(p.altsymbol) then
  608. begin
  609. p.altsymbol:=tasmsymbol.create(name+'_'+tostr(nextaltnr),p.defbind,p.typ);
  610. { also copy the amount of references }
  611. p.altsymbol.refs:=p.refs;
  612. inc(nextaltnr);
  613. { add to the usedasmsymbollist, that list is used to reset the
  614. altsymbol }
  615. if not p.inusedlist then
  616. usedasmsymbollist.insert(p);
  617. p.inusedlist:=true;
  618. end;
  619. end;
  620. procedure TAsmLibraryData.UsedAsmSymbolListReset;
  621. var
  622. hp : tasmsymbol;
  623. begin
  624. hp:=tasmsymbol(usedasmsymbollist.first);
  625. while assigned(hp) do
  626. begin
  627. with hp do
  628. begin
  629. reset;
  630. inusedlist:=false;
  631. end;
  632. hp:=tasmsymbol(hp.listnext);
  633. end;
  634. end;
  635. procedure TAsmLibraryData.UsedAsmSymbolListResetAltSym;
  636. var
  637. hp : tasmsymbol;
  638. begin
  639. hp:=tasmsymbol(usedasmsymbollist.first);
  640. while assigned(hp) do
  641. begin
  642. with hp do
  643. begin
  644. altsymbol:=nil;
  645. inusedlist:=false;
  646. end;
  647. hp:=tasmsymbol(hp.listnext);
  648. end;
  649. end;
  650. procedure TAsmLibraryData.UsedAsmSymbolListCheckUndefined;
  651. var
  652. hp : tasmsymbol;
  653. begin
  654. hp:=tasmsymbol(usedasmsymbollist.first);
  655. while assigned(hp) do
  656. begin
  657. with hp do
  658. begin
  659. if (refs>0) and
  660. (section=Sec_none) and
  661. not(currbind in [AB_EXTERNAL,AB_COMMON]) then
  662. Message1(asmw_e_undefined_label,name);
  663. end;
  664. hp:=tasmsymbol(hp.listnext);
  665. end;
  666. end;
  667. procedure TAsmLibraryData.getlabel(var l : tasmlabel);
  668. begin
  669. l:=tasmlabel.create(nextlabelnr);
  670. inc(nextlabelnr);
  671. symbolsearch.insert(l);
  672. end;
  673. procedure TAsmLibraryData.getdatalabel(var l : tasmlabel);
  674. begin
  675. l:=tasmlabel.createdata(nextlabelnr);
  676. inc(nextlabelnr);
  677. symbolsearch.insert(l);
  678. end;
  679. procedure TAsmLibraryData.getaddrlabel(var l : tasmlabel);
  680. begin
  681. l:=tasmlabel.createaddr(nextlabelnr);
  682. inc(nextlabelnr);
  683. symbolsearch.insert(l);
  684. end;
  685. procedure TAsmLibraryData.getlabelnr(var l : longint);
  686. begin
  687. l:=nextlabelnr;
  688. inc(nextlabelnr);
  689. end;
  690. end.
  691. {
  692. $Log$
  693. Revision 1.4 2002-08-11 13:24:10 peter
  694. * saving of asmsymbols in ppu supported
  695. * asmsymbollist global is removed and moved into a new class
  696. tasmlibrarydata that will hold the info of a .a file which
  697. corresponds with a single module. Added librarydata to tmodule
  698. to keep the library info stored for the module. In the future the
  699. objectfiles will also be stored to the tasmlibrarydata class
  700. * all getlabel/newasmsymbol and friends are moved to the new class
  701. Revision 1.3 2002/07/10 07:24:40 jonas
  702. * memory leak fixes from Sergey Korshunoff
  703. Revision 1.2 2002/07/07 09:52:32 florian
  704. * powerpc target fixed, very simple units can be compiled
  705. * some basic stuff for better callparanode handling, far from being finished
  706. Revision 1.1 2002/07/01 18:46:20 peter
  707. * internal linker
  708. * reorganized aasm layer
  709. }