aasmbase.pas 26 KB

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