aasmbase.pas 27 KB

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