aasmbase.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  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. function newasmlabel(nr:longint;is_addr,is_data:boolean) : tasmlabel;
  167. {# create a new assembler label }
  168. procedure getlabel(var l : tasmlabel);
  169. { make l as a new label and flag is_addr }
  170. procedure getaddrlabel(var l : tasmlabel);
  171. { make l as a new label and flag is_data }
  172. procedure getdatalabel(var l : tasmlabel);
  173. {# return a label number }
  174. procedure getlabelnr(var l : longint);
  175. procedure CreateUsedAsmSymbolList;
  176. procedure DestroyUsedAsmSymbolList;
  177. procedure UsedAsmSymbolListInsert(p:tasmsymbol);
  178. { generate an alternative (duplicate) symbol }
  179. procedure GenerateAltSymbol(p:tasmsymbol);
  180. { reset alternative symbol information }
  181. procedure UsedAsmSymbolListResetAltSym;
  182. procedure UsedAsmSymbolListReset;
  183. procedure UsedAsmSymbolListCheckUndefined;
  184. end;
  185. var
  186. objectlibrary : tasmlibrarydata;
  187. implementation
  188. uses
  189. {$ifdef delphi}
  190. sysutils,
  191. {$else}
  192. strings,
  193. {$endif}
  194. fmodule,verbose;
  195. const
  196. symbolsgrow = 100;
  197. {*****************************************************************************
  198. TAsmSymbol
  199. *****************************************************************************}
  200. constructor tasmsymbol.create(const s:string;_bind:TAsmsymbind;_typ:Tasmsymtype);
  201. begin;
  202. inherited createname(s);
  203. reset;
  204. defbind:=_bind;
  205. typ:=_typ;
  206. inusedlist:=false;
  207. pass:=255;
  208. ppuidx:=-1;
  209. { mainly used to remove unused labels from the codesegment }
  210. refs:=0;
  211. end;
  212. procedure tasmsymbol.reset;
  213. begin
  214. { reset section info }
  215. section:=sec_none;
  216. address:=0;
  217. size:=0;
  218. indexnr:=-1;
  219. pass:=255;
  220. currbind:=AB_EXTERNAL;
  221. proclocal:=false;
  222. end;
  223. function tasmsymbol.is_used:boolean;
  224. begin
  225. is_used:=(refs>0);
  226. end;
  227. procedure tasmsymbol.setaddress(_pass:byte;sec:TSection;offset,len:longint);
  228. begin
  229. if (_pass=pass) then
  230. begin
  231. Message1(asmw_e_duplicate_label,name);
  232. exit;
  233. end;
  234. pass:=_pass;
  235. section:=sec;
  236. address:=offset;
  237. size:=len;
  238. { when the bind was reset to External, set it back to the default
  239. bind it got when defined }
  240. if (currbind=AB_EXTERNAL) and (defbind<>AB_NONE) then
  241. currbind:=defbind;
  242. end;
  243. {*****************************************************************************
  244. TAsmLabel
  245. *****************************************************************************}
  246. constructor tasmlabel.create(nr:longint);
  247. begin;
  248. labelnr:=nr;
  249. inherited create(target_asm.labelprefix+tostr(labelnr),AB_LOCAL,AT_FUNCTION);
  250. proclocal:=true;
  251. is_set:=false;
  252. is_addr := false;
  253. end;
  254. constructor tasmlabel.createdata(nr:longint);
  255. begin;
  256. labelnr:=nr;
  257. if (cs_create_smart in aktmoduleswitches) or
  258. target_asm.labelprefix_only_inside_procedure then
  259. inherited create('_$'+current_module.modulename^+'$_L'+tostr(labelnr),AB_GLOBAL,AT_DATA)
  260. else
  261. inherited create(target_asm.labelprefix+tostr(labelnr),AB_LOCAL,AT_DATA);
  262. is_set:=false;
  263. is_addr := false;
  264. proclocal := false;
  265. { write it always }
  266. refs:=1;
  267. end;
  268. constructor tasmlabel.createaddr(nr:longint);
  269. begin;
  270. create(nr);
  271. is_addr := true;
  272. end;
  273. function tasmlabel.getname:string;
  274. begin
  275. getname:=inherited getname;
  276. inc(refs);
  277. end;
  278. {****************************************************************************
  279. TAsmObjectAlloc
  280. ****************************************************************************}
  281. constructor TAsmObjectAlloc.create;
  282. begin
  283. end;
  284. destructor TAsmObjectAlloc.destroy;
  285. begin
  286. end;
  287. procedure TAsmObjectAlloc.seTSection(sec:TSection);
  288. begin
  289. currsec:=sec;
  290. end;
  291. procedure TAsmObjectAlloc.reseTSections;
  292. begin
  293. FillChar(secsize,sizeof(secsize),0);
  294. end;
  295. procedure TAsmObjectAlloc.sectionalloc(l:longint);
  296. begin
  297. inc(secsize[currsec],l);
  298. end;
  299. procedure TAsmObjectAlloc.sectionalign(l:longint);
  300. begin
  301. if (secsize[currsec] mod l)<>0 then
  302. inc(secsize[currsec],l-(secsize[currsec] mod l));
  303. end;
  304. procedure TAsmObjectAlloc.staballoc(p:pchar);
  305. begin
  306. inc(secsize[sec_stab]);
  307. if assigned(p) and (p[0]<>#0) then
  308. inc(secsize[sec_stabstr],strlen(p)+1);
  309. end;
  310. function TAsmObjectAlloc.sectionsize:longint;
  311. begin
  312. sectionsize:=secsize[currsec];
  313. end;
  314. {****************************************************************************
  315. TAsmRelocation
  316. ****************************************************************************}
  317. constructor TAsmRelocation.CreateSymbol(Aaddress:longint;s:Tasmsymbol;Atyp:TAsmRelocationType);
  318. begin
  319. Address:=Aaddress;
  320. Symbol:=s;
  321. OrgSize:=0;
  322. Section:=Sec_none;
  323. Typ:=Atyp;
  324. end;
  325. constructor TAsmRelocation.CreateSymbolSize(Aaddress:longint;s:Tasmsymbol;Aorgsize:longint;Atyp:TAsmRelocationType);
  326. begin
  327. Address:=Aaddress;
  328. Symbol:=s;
  329. OrgSize:=Aorgsize;
  330. Section:=Sec_none;
  331. Typ:=Atyp;
  332. end;
  333. constructor TAsmRelocation.CreateSection(Aaddress:longint;sec:TSection;Atyp:TAsmRelocationType);
  334. begin
  335. Address:=Aaddress;
  336. Symbol:=nil;
  337. OrgSize:=0;
  338. Section:=sec;
  339. Typ:=Atyp;
  340. end;
  341. {****************************************************************************
  342. TAsmSection
  343. ****************************************************************************}
  344. constructor TAsmSection.create(const Aname:string;Aalign:longint;alloconly:boolean);
  345. begin
  346. inherited create;
  347. name:=Aname;
  348. secsymidx:=0;
  349. addralign:=Aalign;
  350. { data }
  351. datasize:=0;
  352. datapos:=0;
  353. if alloconly then
  354. data:=nil
  355. else
  356. Data:=TDynamicArray.Create(8192);
  357. { position }
  358. mempos:=0;
  359. memsize:=0;
  360. { relocation }
  361. relocations:=TLinkedList.Create;
  362. end;
  363. destructor TAsmSection.destroy;
  364. begin
  365. if assigned(Data) then
  366. Data.Free;
  367. relocations.free;
  368. end;
  369. function TAsmSection.write(var d;l:longint):longint;
  370. begin
  371. write:=datasize;
  372. if not assigned(Data) then
  373. Internalerror(3334441);
  374. Data.write(d,l);
  375. inc(datasize,l);
  376. end;
  377. function TAsmSection.writestr(const s:string):longint;
  378. begin
  379. writestr:=datasize;
  380. if not assigned(Data) then
  381. Internalerror(3334441);
  382. Data.write(s[1],length(s));
  383. inc(datasize,length(s));
  384. end;
  385. procedure TAsmSection.writealign(l:longint);
  386. var
  387. i : longint;
  388. empty : array[0..63] of char;
  389. begin
  390. { no alignment needed for 0 or 1 }
  391. if l<=1 then
  392. exit;
  393. i:=datasize mod l;
  394. if i>0 then
  395. begin
  396. if assigned(data) then
  397. begin
  398. fillchar(empty,sizeof(empty),0);
  399. Data.write(empty,l-i);
  400. end;
  401. inc(datasize,l-i);
  402. end;
  403. end;
  404. function TAsmSection.aligneddatasize:longint;
  405. begin
  406. aligneddatasize:=align(datasize,addralign);
  407. end;
  408. procedure TAsmSection.alignsection;
  409. begin
  410. writealign(addralign);
  411. end;
  412. procedure TAsmSection.alloc(l:longint);
  413. begin
  414. if assigned(Data) then
  415. Internalerror(3334442);
  416. inc(datasize,l);
  417. end;
  418. procedure TAsmSection.addsymreloc(ofs:longint;p:tasmsymbol;relative:TAsmRelocationType);
  419. var
  420. r : TAsmRelocation;
  421. begin
  422. r:=TAsmRelocation.Create;
  423. r.address:=ofs;
  424. r.orgsize:=0;
  425. r.symbol:=p;
  426. r.section:=sec_none;
  427. r.typ:=relative;
  428. relocations.concat(r);
  429. end;
  430. procedure TAsmSection.addsectionreloc(ofs:longint;sec:TSection;relative:TAsmRelocationType);
  431. var
  432. r : TAsmRelocation;
  433. begin
  434. r:=TAsmRelocation.Create;
  435. r.address:=ofs;
  436. r.symbol:=nil;
  437. r.orgsize:=0;
  438. r.section:=sec;
  439. r.typ:=relative;
  440. relocations.concat(r);
  441. end;
  442. {****************************************************************************
  443. TAsmObjectData
  444. ****************************************************************************}
  445. constructor TAsmObjectData.create(const n:string);
  446. begin
  447. inherited create;
  448. name:=n;
  449. { sections }
  450. FillChar(Sects,sizeof(Sects),0);
  451. { symbols }
  452. symbols:=tindexarray.create(symbolsgrow);
  453. symbols.noclear:=true;
  454. end;
  455. destructor TAsmObjectData.destroy;
  456. var
  457. sec : TSection;
  458. begin
  459. { free memory }
  460. for sec:=low(TSection) to high(TSection) do
  461. if assigned(sects[sec]) then
  462. sects[sec].free;
  463. symbols.free;
  464. end;
  465. procedure TAsmObjectData.createsection(sec:TSection);
  466. begin
  467. sects[sec]:=TAsmSection.create(target_asm.secnames[sec],1,(sec=sec_bss));
  468. end;
  469. function TAsmObjectData.sectionsize(s:TSection):longint;
  470. begin
  471. if assigned(sects[s]) then
  472. sectionsize:=sects[s].datasize
  473. else
  474. sectionsize:=0;
  475. end;
  476. function TAsmObjectData.currsectionsize:longint;
  477. begin
  478. if assigned(sects[currsec]) then
  479. currsectionsize:=sects[currsec].datasize
  480. else
  481. currsectionsize:=0;
  482. end;
  483. procedure TAsmObjectData.seTSectionsizes(var s:TAsmSectionSizes);
  484. begin
  485. end;
  486. procedure TAsmObjectData.defaulTSection(sec:TSection);
  487. begin
  488. currsec:=sec;
  489. end;
  490. procedure TAsmObjectData.writebytes(var data;len:longint);
  491. begin
  492. if not assigned(sects[currsec]) then
  493. createsection(currsec);
  494. sects[currsec].write(data,len);
  495. end;
  496. procedure TAsmObjectData.alloc(len:longint);
  497. begin
  498. if not assigned(sects[currsec]) then
  499. createsection(currsec);
  500. sects[currsec].alloc(len);
  501. end;
  502. procedure TAsmObjectData.allocalign(len:longint);
  503. var
  504. modulo : longint;
  505. begin
  506. if not assigned(sects[currsec]) then
  507. createsection(currsec);
  508. modulo:=sects[currsec].datasize mod len;
  509. if modulo > 0 then
  510. sects[currsec].alloc(len-modulo);
  511. end;
  512. procedure TAsmObjectData.fixuprelocs;
  513. begin
  514. { no relocation support by default }
  515. end;
  516. {****************************************************************************
  517. TAsmLibraryData
  518. ****************************************************************************}
  519. constructor TAsmLibraryData.create(const n:string);
  520. begin
  521. inherited create;
  522. name:=n;
  523. { symbols }
  524. symbolsearch:=tdictionary.create;
  525. symbolsearch.usehash;
  526. { labels }
  527. nextaltnr:=1;
  528. nextlabelnr:=1;
  529. { ppu }
  530. asmsymbolppuidx:=0;
  531. asmsymbolidx:=nil;
  532. end;
  533. destructor TAsmLibraryData.destroy;
  534. begin
  535. symbolsearch.free;
  536. Freeasmsymbolidx;
  537. end;
  538. procedure TAsmLibraryData.Freeasmsymbolidx;
  539. begin
  540. if assigned(asmsymbolidx) then
  541. begin
  542. Freemem(asmsymbolidx);
  543. asmsymbolidx:=nil;
  544. end;
  545. end;
  546. procedure TAsmLibraryData.DerefAsmsymbol(var s:tasmsymbol);
  547. begin
  548. if assigned(s) then
  549. begin
  550. if not assigned(asmsymbolidx) then
  551. internalerror(200208072);
  552. if (longint(pointer(s))<1) or (longint(pointer(s))>asmsymbolppuidx) then
  553. internalerror(200208073);
  554. s:=asmsymbolidx^[longint(pointer(s))-1];
  555. end;
  556. end;
  557. function TAsmLibraryData.newasmsymbol(const s : string) : tasmsymbol;
  558. var
  559. hp : tasmsymbol;
  560. begin
  561. hp:=tasmsymbol(symbolsearch.search(s));
  562. if not assigned(hp) then
  563. begin
  564. { Not found, insert it as an External }
  565. hp:=tasmsymbol.create(s,AB_EXTERNAL,AT_FUNCTION);
  566. symbolsearch.insert(hp);
  567. end;
  568. newasmsymbol:=hp;
  569. end;
  570. function TAsmLibraryData.newasmsymboltype(const s : string;_bind:TAsmSymBind;_typ:Tasmsymtype) : tasmsymbol;
  571. var
  572. hp : tasmsymbol;
  573. begin
  574. hp:=tasmsymbol(symbolsearch.search(s));
  575. if assigned(hp) then
  576. hp.defbind:=_bind
  577. else
  578. begin
  579. { Not found, insert it as an External }
  580. hp:=tasmsymbol.create(s,_bind,_typ);
  581. symbolsearch.insert(hp);
  582. end;
  583. newasmsymboltype:=hp;
  584. end;
  585. function TAsmLibraryData.getasmsymbol(const s : string) : tasmsymbol;
  586. begin
  587. getasmsymbol:=tasmsymbol(symbolsearch.search(s));
  588. end;
  589. function TAsmLibraryData.renameasmsymbol(const sold, snew : string):tasmsymbol;
  590. begin
  591. renameasmsymbol:=tasmsymbol(symbolsearch.rename(sold,snew));
  592. end;
  593. procedure TAsmLibraryData.CreateUsedAsmSymbolList;
  594. begin
  595. if assigned(usedasmsymbollist) then
  596. internalerror(78455782);
  597. usedasmsymbollist:=TSingleList.create;
  598. end;
  599. procedure TAsmLibraryData.DestroyUsedAsmSymbolList;
  600. begin
  601. usedasmsymbollist.destroy;
  602. usedasmsymbollist:=nil;
  603. end;
  604. procedure TAsmLibraryData.UsedAsmSymbolListInsert(p:tasmsymbol);
  605. begin
  606. if not p.inusedlist then
  607. usedasmsymbollist.insert(p);
  608. p.inusedlist:=true;
  609. end;
  610. procedure TAsmLibraryData.GenerateAltSymbol(p:tasmsymbol);
  611. begin
  612. if not assigned(p.altsymbol) then
  613. begin
  614. p.altsymbol:=tasmsymbol.create(name+'_'+tostr(nextaltnr),p.defbind,p.typ);
  615. { also copy the amount of references }
  616. p.altsymbol.refs:=p.refs;
  617. inc(nextaltnr);
  618. { add to the usedasmsymbollist, that list is used to reset the
  619. altsymbol }
  620. if not p.inusedlist then
  621. usedasmsymbollist.insert(p);
  622. p.inusedlist:=true;
  623. end;
  624. end;
  625. procedure TAsmLibraryData.UsedAsmSymbolListReset;
  626. var
  627. hp : tasmsymbol;
  628. begin
  629. hp:=tasmsymbol(usedasmsymbollist.first);
  630. while assigned(hp) do
  631. begin
  632. with hp do
  633. begin
  634. reset;
  635. inusedlist:=false;
  636. end;
  637. hp:=tasmsymbol(hp.listnext);
  638. end;
  639. end;
  640. procedure TAsmLibraryData.UsedAsmSymbolListResetAltSym;
  641. var
  642. hp : tasmsymbol;
  643. begin
  644. hp:=tasmsymbol(usedasmsymbollist.first);
  645. while assigned(hp) do
  646. begin
  647. with hp do
  648. begin
  649. altsymbol:=nil;
  650. inusedlist:=false;
  651. end;
  652. hp:=tasmsymbol(hp.listnext);
  653. end;
  654. end;
  655. procedure TAsmLibraryData.UsedAsmSymbolListCheckUndefined;
  656. var
  657. hp : tasmsymbol;
  658. begin
  659. hp:=tasmsymbol(usedasmsymbollist.first);
  660. while assigned(hp) do
  661. begin
  662. with hp do
  663. begin
  664. if (refs>0) and
  665. (section=Sec_none) and
  666. not(currbind in [AB_EXTERNAL,AB_COMMON]) then
  667. Message1(asmw_e_undefined_label,name);
  668. end;
  669. hp:=tasmsymbol(hp.listnext);
  670. end;
  671. end;
  672. function TAsmLibraryData.newasmlabel(nr:longint;is_addr,is_data:boolean) : tasmlabel;
  673. var
  674. hp : tasmlabel;
  675. begin
  676. if is_addr then
  677. hp:=tasmlabel.createaddr(nr)
  678. else if is_data then
  679. hp:=tasmlabel.createdata(nr)
  680. else
  681. hp:=tasmlabel.create(nr);
  682. symbolsearch.insert(hp);
  683. newasmlabel:=hp;
  684. end;
  685. procedure TAsmLibraryData.getlabel(var l : tasmlabel);
  686. begin
  687. l:=tasmlabel.create(nextlabelnr);
  688. inc(nextlabelnr);
  689. symbolsearch.insert(l);
  690. end;
  691. procedure TAsmLibraryData.getdatalabel(var l : tasmlabel);
  692. begin
  693. l:=tasmlabel.createdata(nextlabelnr);
  694. inc(nextlabelnr);
  695. symbolsearch.insert(l);
  696. end;
  697. procedure TAsmLibraryData.getaddrlabel(var l : tasmlabel);
  698. begin
  699. l:=tasmlabel.createaddr(nextlabelnr);
  700. inc(nextlabelnr);
  701. symbolsearch.insert(l);
  702. end;
  703. procedure TAsmLibraryData.getlabelnr(var l : longint);
  704. begin
  705. l:=nextlabelnr;
  706. inc(nextlabelnr);
  707. end;
  708. end.
  709. {
  710. $Log$
  711. Revision 1.8 2002-08-19 19:36:42 peter
  712. * More fixes for cross unit inlining, all tnodes are now implemented
  713. * Moved pocall_internconst to po_internconst because it is not a
  714. calling type at all and it conflicted when inlining of these small
  715. functions was requested
  716. Revision 1.7 2002/08/18 20:06:23 peter
  717. * inlining is now also allowed in interface
  718. * renamed write/load to ppuwrite/ppuload
  719. * tnode storing in ppu
  720. * nld,ncon,nbas are already updated for storing in ppu
  721. Revision 1.6 2002/08/12 15:08:39 carl
  722. + stab register indexes for powerpc (moved from gdb to cpubase)
  723. + tprocessor enumeration moved to cpuinfo
  724. + linker in target_info is now a class
  725. * many many updates for m68k (will soon start to compile)
  726. - removed some ifdef or correct them for correct cpu
  727. Revision 1.5 2002/08/11 14:32:25 peter
  728. * renamed current_library to objectlibrary
  729. Revision 1.4 2002/08/11 13:24:10 peter
  730. * saving of asmsymbols in ppu supported
  731. * asmsymbollist global is removed and moved into a new class
  732. tasmlibrarydata that will hold the info of a .a file which
  733. corresponds with a single module. Added librarydata to tmodule
  734. to keep the library info stored for the module. In the future the
  735. objectfiles will also be stored to the tasmlibrarydata class
  736. * all getlabel/newasmsymbol and friends are moved to the new class
  737. Revision 1.3 2002/07/10 07:24:40 jonas
  738. * memory leak fixes from Sergey Korshunoff
  739. Revision 1.2 2002/07/07 09:52:32 florian
  740. * powerpc target fixed, very simple units can be compiled
  741. * some basic stuff for better callparanode handling, far from being finished
  742. Revision 1.1 2002/07/01 18:46:20 peter
  743. * internal linker
  744. * reorganized aasm layer
  745. }