aasm.pas 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. {
  2. $Id$
  3. Copyright (c) 1996-98 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. unit aasm;
  19. interface
  20. uses
  21. globtype,systems,cobjects,files,globals;
  22. type
  23. tait = (
  24. ait_none,
  25. ait_direct,
  26. ait_string,
  27. ait_label,
  28. ait_comment,
  29. ait_instruction,
  30. ait_datablock,
  31. ait_symbol,
  32. ait_const_32bit,
  33. ait_const_16bit,
  34. ait_const_8bit,
  35. ait_const_symbol,
  36. ait_real_80bit,
  37. ait_real_64bit,
  38. ait_real_32bit,
  39. ait_comp_64bit,
  40. ait_align,
  41. ait_section,
  42. { the following is only used by the win32 version of the compiler }
  43. { and only the GNU AS Win32 is able to write it }
  44. ait_const_rva,
  45. ait_stabn,
  46. ait_stabs,
  47. ait_force_line,
  48. ait_stab_function_name,
  49. ait_cut, { used to split into tiny assembler files }
  50. ait_regalloc, { for register,temp allocation debugging }
  51. ait_tempalloc,
  52. ait_marker,
  53. { never used, makes insertation of new ait_ easier to type }
  54. ait_dummy);
  55. { asm symbol functions }
  56. type
  57. TAsmsymtype=(AS_EXTERNAL,AS_LOCAL,AS_GLOBAL);
  58. pasmsymbol = ^tasmsymbol;
  59. tasmsymbol = object(tnamedindexobject)
  60. typ : TAsmsymtype;
  61. { this need te incremented with every symbol loading into the
  62. paasmoutput, thus in loadsym/loadref/const_symbol (PFV) }
  63. refs : longint;
  64. { the next fields are filled in the binary writer }
  65. idx : longint;
  66. section : tsection;
  67. address,
  68. size : longint;
  69. constructor init(const s:string;_typ:TAsmsymtype);
  70. procedure reset;
  71. function is_used:boolean;
  72. procedure setaddress(sec:tsection;offset,len:longint);
  73. end;
  74. pasmlabel = ^tasmlabel;
  75. tasmlabel = object(tasmsymbol)
  76. labelnr : longint;
  77. { this is set by the pai_label.init }
  78. is_set : boolean;
  79. constructor init;
  80. constructor initdata;
  81. function name:string;virtual;
  82. end;
  83. pasmsymbollist = ^tasmsymbollist;
  84. tasmsymbollist = object(tdictionary)
  85. end;
  86. { the short name makes typing easier }
  87. pai = ^tai;
  88. tai = object(tlinkedlist_item)
  89. typ : tait;
  90. { pointer to record with optimizer info about this tai object }
  91. optinfo : pointer;
  92. fileinfo : tfileposinfo;
  93. constructor init;
  94. end;
  95. pai_string = ^tai_string;
  96. tai_string = object(tai)
  97. str : pchar;
  98. { extra len so the string can contain an \0 }
  99. len : longint;
  100. constructor init(const _str : string);
  101. constructor init_pchar(_str : pchar);
  102. constructor init_length_pchar(_str : pchar;length : longint);
  103. destructor done;virtual;
  104. end;
  105. { generates a common label }
  106. pai_symbol = ^tai_symbol;
  107. tai_symbol = object(tai)
  108. sym : pasmsymbol;
  109. is_global : boolean;
  110. constructor init(_sym:PAsmSymbol);
  111. constructor initname(const _name : string);
  112. constructor initname_global(const _name : string);
  113. end;
  114. pai_label = ^tai_label;
  115. tai_label = object(tai)
  116. l : pasmlabel;
  117. is_global : boolean;
  118. constructor init(_l : pasmlabel);
  119. end;
  120. pai_direct = ^tai_direct;
  121. tai_direct = object(tai)
  122. str : pchar;
  123. constructor init(_str : pchar);
  124. destructor done; virtual;
  125. end;
  126. { to insert a comment into the generated assembler file }
  127. pai_asm_comment = ^tai_asm_comment;
  128. tai_asm_comment = object(tai)
  129. str : pchar;
  130. constructor init(_str : pchar);
  131. destructor done; virtual;
  132. end;
  133. { alignment for operator }
  134. pai_align = ^tai_align;
  135. tai_align = object(tai)
  136. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  137. fillsize : byte; { real size to fill }
  138. fillop : byte; { value to fill with - optional }
  139. use_op : boolean;
  140. constructor init(b:byte);
  141. constructor init_op(b: byte; _op: byte);
  142. end;
  143. { Insert a section/segment directive }
  144. pai_section = ^tai_section;
  145. tai_section = object(tai)
  146. sec : tsection;
  147. constructor init(s : tsection);
  148. end;
  149. { generates an uninitializised data block }
  150. pai_datablock = ^tai_datablock;
  151. tai_datablock = object(tai)
  152. sym : pasmsymbol;
  153. size : longint;
  154. is_global : boolean;
  155. constructor init(const _name : string;_size : longint);
  156. constructor init_global(const _name : string;_size : longint);
  157. end;
  158. { generates a long integer (32 bit) }
  159. pai_const = ^tai_const;
  160. tai_const = object(tai)
  161. value : longint;
  162. constructor init_32bit(_value : longint);
  163. constructor init_16bit(_value : word);
  164. constructor init_8bit(_value : byte);
  165. end;
  166. pai_const_symbol = ^tai_const_symbol;
  167. tai_const_symbol = object(tai)
  168. sym : pasmsymbol;
  169. offset : longint;
  170. constructor init(_sym:PAsmSymbol);
  171. constructor init_offset(_sym:PAsmSymbol;ofs:longint);
  172. constructor init_rva(_sym:PAsmSymbol);
  173. constructor initname(const name:string);
  174. constructor initname_offset(const name:string;ofs:longint);
  175. constructor initname_rva(const name:string);
  176. end;
  177. { generates a single (32 bit real) }
  178. pai_real_32bit = ^tai_real_32bit;
  179. tai_real_32bit = object(tai)
  180. value : ts32real;
  181. constructor init(_value : ts32real);
  182. end;
  183. { generates a double (64 bit real) }
  184. pai_real_64bit = ^tai_real_64bit;
  185. tai_real_64bit = object(tai)
  186. value : ts64real;
  187. constructor init(_value : ts64real);
  188. end;
  189. { generates an extended (80 bit real) }
  190. pai_real_80bit = ^tai_real_80bit;
  191. tai_real_80bit = object(tai)
  192. value : ts80real;
  193. constructor init(_value : ts80real);
  194. end;
  195. { generates an comp (integer over 64 bits) }
  196. pai_comp_64bit = ^tai_comp_64bit;
  197. tai_comp_64bit = object(tai)
  198. value : ts64comp;
  199. constructor init(_value : ts64comp);
  200. end;
  201. { insert a cut to split into several smaller files }
  202. pai_cut = ^tai_cut;
  203. tai_cut = object(tai)
  204. endname : boolean;
  205. constructor init;
  206. constructor init_end;
  207. end;
  208. TMarker = (NoPropInfoStart, NoPropInfoEnd, AsmBlockStart, AsmBlockEnd);
  209. pai_marker = ^tai_marker;
  210. tai_marker = object(tai)
  211. Kind: TMarker;
  212. Constructor init(_Kind: TMarker);
  213. end;
  214. { for each processor define the best precision }
  215. { bestreal is defined in globals }
  216. {$ifdef i386}
  217. const
  218. ait_bestreal = ait_real_80bit;
  219. type
  220. pai_bestreal = pai_real_80bit;
  221. tai_bestreal = tai_real_80bit;
  222. {$endif i386}
  223. {$ifdef m68k}
  224. const
  225. ait_bestreal = ait_real_32bit;
  226. type
  227. pai_bestreal = pai_real_32bit;
  228. tai_bestreal = tai_real_32bit;
  229. {$endif m68k}
  230. paasmoutput = ^taasmoutput;
  231. taasmoutput = object(tlinkedlist)
  232. function getlasttaifilepos : pfileposinfo;
  233. end;
  234. const
  235. { maximum of aasmoutput lists there will be }
  236. maxoutputlists = 10;
  237. var
  238. { temporary lists }
  239. exprasmlist,
  240. { default lists }
  241. datasegment,codesegment,bsssegment,
  242. debuglist,consts,
  243. importssection,exportssection,
  244. resourcesection,rttilist,
  245. resourcestringlist : paasmoutput;
  246. { asm symbol list }
  247. asmsymbollist : pasmsymbollist;
  248. const
  249. nextlabelnr : longint = 1;
  250. countlabelref : boolean = true;
  251. { make l as a new label }
  252. procedure getlabel(var l : pasmlabel);
  253. { make l as a new label and flag is_data }
  254. procedure getdatalabel(var l : pasmlabel);
  255. { free a label }
  256. procedure freelabel(var l : pasmlabel);
  257. {just get a label number }
  258. procedure getlabelnr(var l : longint);
  259. function newasmsymbol(const s : string) : pasmsymbol;
  260. function newasmsymboltyp(const s : string;_typ:TAsmSymType) : pasmsymbol;
  261. function getasmsymbol(const s : string) : pasmsymbol;
  262. function renameasmsymbol(const sold, snew : string):pasmsymbol;
  263. procedure ResetAsmsymbolList;
  264. implementation
  265. uses
  266. strings,verbose;
  267. {****************************************************************************
  268. TAI
  269. ****************************************************************************}
  270. constructor tai.init;
  271. begin
  272. optinfo := nil;
  273. fileinfo:=aktfilepos;
  274. end;
  275. {****************************************************************************
  276. TAI_SECTION
  277. ****************************************************************************}
  278. constructor tai_section.init(s : tsection);
  279. begin
  280. inherited init;
  281. typ:=ait_section;
  282. sec:=s;
  283. end;
  284. {****************************************************************************
  285. TAI_DATABLOCK
  286. ****************************************************************************}
  287. constructor tai_datablock.init(const _name : string;_size : longint);
  288. begin
  289. inherited init;
  290. typ:=ait_datablock;
  291. sym:=newasmsymboltyp(_name,AS_LOCAL);
  292. size:=_size;
  293. is_global:=false;
  294. end;
  295. constructor tai_datablock.init_global(const _name : string;_size : longint);
  296. begin
  297. inherited init;
  298. typ:=ait_datablock;
  299. sym:=newasmsymboltyp(_name,AS_GLOBAL);
  300. size:=_size;
  301. is_global:=true;
  302. end;
  303. {****************************************************************************
  304. TAI_SYMBOL
  305. ****************************************************************************}
  306. constructor tai_symbol.init(_sym:PAsmSymbol);
  307. begin
  308. inherited init;
  309. typ:=ait_symbol;
  310. sym:=_sym;
  311. end;
  312. constructor tai_symbol.initname(const _name : string);
  313. begin
  314. inherited init;
  315. typ:=ait_symbol;
  316. sym:=newasmsymboltyp(_name,AS_LOCAL);
  317. is_global:=false;
  318. end;
  319. constructor tai_symbol.initname_global(const _name : string);
  320. begin
  321. inherited init;
  322. typ:=ait_symbol;
  323. sym:=newasmsymboltyp(_name,AS_GLOBAL);
  324. is_global:=true;
  325. end;
  326. {****************************************************************************
  327. TAI_CONST
  328. ****************************************************************************}
  329. constructor tai_const.init_32bit(_value : longint);
  330. begin
  331. inherited init;
  332. typ:=ait_const_32bit;
  333. value:=_value;
  334. end;
  335. constructor tai_const.init_16bit(_value : word);
  336. begin
  337. inherited init;
  338. typ:=ait_const_16bit;
  339. value:=_value;
  340. end;
  341. constructor tai_const.init_8bit(_value : byte);
  342. begin
  343. inherited init;
  344. typ:=ait_const_8bit;
  345. value:=_value;
  346. end;
  347. {****************************************************************************
  348. TAI_CONST_SYMBOL_OFFSET
  349. ****************************************************************************}
  350. constructor tai_const_symbol.init(_sym:PAsmSymbol);
  351. begin
  352. inherited init;
  353. typ:=ait_const_symbol;
  354. sym:=_sym;
  355. offset:=0;
  356. { update sym info }
  357. inc(sym^.refs);
  358. end;
  359. constructor tai_const_symbol.init_offset(_sym:PAsmSymbol;ofs:longint);
  360. begin
  361. inherited init;
  362. typ:=ait_const_symbol;
  363. sym:=_sym;
  364. offset:=ofs;
  365. { update sym info }
  366. inc(sym^.refs);
  367. end;
  368. constructor tai_const_symbol.init_rva(_sym:PAsmSymbol);
  369. begin
  370. inherited init;
  371. typ:=ait_const_rva;
  372. sym:=_sym;
  373. offset:=0;
  374. { update sym info }
  375. inc(sym^.refs);
  376. end;
  377. constructor tai_const_symbol.initname(const name:string);
  378. begin
  379. inherited init;
  380. typ:=ait_const_symbol;
  381. sym:=newasmsymbol(name);
  382. offset:=0;
  383. { update sym info }
  384. inc(sym^.refs);
  385. end;
  386. constructor tai_const_symbol.initname_offset(const name:string;ofs:longint);
  387. begin
  388. inherited init;
  389. typ:=ait_const_symbol;
  390. sym:=newasmsymbol(name);
  391. offset:=ofs;
  392. { update sym info }
  393. inc(sym^.refs);
  394. end;
  395. constructor tai_const_symbol.initname_rva(const name:string);
  396. begin
  397. inherited init;
  398. typ:=ait_const_rva;
  399. sym:=newasmsymbol(name);
  400. offset:=0;
  401. { update sym info }
  402. inc(sym^.refs);
  403. end;
  404. {****************************************************************************
  405. TAI_real_32bit
  406. ****************************************************************************}
  407. constructor tai_real_32bit.init(_value : ts32real);
  408. begin
  409. inherited init;
  410. typ:=ait_real_32bit;
  411. value:=_value;
  412. end;
  413. {****************************************************************************
  414. TAI_real_64bit
  415. ****************************************************************************}
  416. constructor tai_real_64bit.init(_value : ts64real);
  417. begin
  418. inherited init;
  419. typ:=ait_real_64bit;
  420. value:=_value;
  421. end;
  422. {****************************************************************************
  423. TAI_real_80bit
  424. ****************************************************************************}
  425. constructor tai_real_80bit.init(_value : ts80real);
  426. begin
  427. inherited init;
  428. typ:=ait_real_80bit;
  429. value:=_value;
  430. end;
  431. {****************************************************************************
  432. Tai_comp_64bit
  433. ****************************************************************************}
  434. constructor tai_comp_64bit.init(_value : ts64comp);
  435. begin
  436. inherited init;
  437. typ:=ait_comp_64bit;
  438. value:=_value;
  439. end;
  440. {****************************************************************************
  441. TAI_STRING
  442. ****************************************************************************}
  443. constructor tai_string.init(const _str : string);
  444. begin
  445. inherited init;
  446. typ:=ait_string;
  447. getmem(str,length(_str)+1);
  448. strpcopy(str,_str);
  449. len:=length(_str);
  450. end;
  451. constructor tai_string.init_pchar(_str : pchar);
  452. begin
  453. inherited init;
  454. typ:=ait_string;
  455. str:=_str;
  456. len:=strlen(_str);
  457. end;
  458. constructor tai_string.init_length_pchar(_str : pchar;length : longint);
  459. begin
  460. inherited init;
  461. typ:=ait_string;
  462. str:=_str;
  463. len:=length;
  464. end;
  465. destructor tai_string.done;
  466. begin
  467. { you can have #0 inside the strings so }
  468. if str<>nil then
  469. freemem(str,len+1);
  470. inherited done;
  471. end;
  472. {****************************************************************************
  473. TAI_LABEL
  474. ****************************************************************************}
  475. constructor tai_label.init(_l : pasmlabel);
  476. begin
  477. inherited init;
  478. typ:=ait_label;
  479. l:=_l;
  480. l^.is_set:=true;
  481. is_global:=(l^.typ=AS_GLOBAL);
  482. end;
  483. {****************************************************************************
  484. TAI_DIRECT
  485. ****************************************************************************}
  486. constructor tai_direct.init(_str : pchar);
  487. begin
  488. inherited init;
  489. typ:=ait_direct;
  490. str:=_str;
  491. end;
  492. destructor tai_direct.done;
  493. begin
  494. strdispose(str);
  495. inherited done;
  496. end;
  497. {****************************************************************************
  498. TAI_ASM_COMMENT comment to be inserted in the assembler file
  499. ****************************************************************************}
  500. constructor tai_asm_comment.init(_str : pchar);
  501. begin
  502. inherited init;
  503. typ:=ait_comment;
  504. str:=_str;
  505. end;
  506. destructor tai_asm_comment.done;
  507. begin
  508. strdispose(str);
  509. inherited done;
  510. end;
  511. {****************************************************************************
  512. TAI_ALIGN
  513. ****************************************************************************}
  514. constructor tai_align.init(b: byte);
  515. begin
  516. inherited init;
  517. typ:=ait_align;
  518. if b in [1,2,4,8,16] then
  519. aligntype := b
  520. else
  521. aligntype := 1;
  522. fillsize:=0;
  523. fillop:=0;
  524. use_op:=false;
  525. end;
  526. constructor tai_align.init_op(b: byte; _op: byte);
  527. begin
  528. inherited init;
  529. typ:=ait_align;
  530. if b in [1,2,4,8,16] then
  531. aligntype := b
  532. else
  533. aligntype := 1;
  534. fillsize:=0;
  535. fillop:=_op;
  536. use_op:=true;
  537. end;
  538. {****************************************************************************
  539. TAI_CUT
  540. ****************************************************************************}
  541. constructor tai_cut.init;
  542. begin
  543. inherited init;
  544. typ:=ait_cut;
  545. endname:=false;
  546. end;
  547. constructor tai_cut.init_end;
  548. begin
  549. inherited init;
  550. typ:=ait_cut;
  551. endname:=true;
  552. end;
  553. {****************************************************************************
  554. Tai_Marker
  555. ****************************************************************************}
  556. Constructor Tai_Marker.Init(_Kind: TMarker);
  557. Begin
  558. Inherited Init;
  559. typ := ait_marker;
  560. Kind := _Kind;
  561. End;
  562. {*****************************************************************************
  563. AsmSymbol
  564. *****************************************************************************}
  565. constructor tasmsymbol.init(const s:string;_typ:TAsmsymtype);
  566. begin;
  567. inherited initname(s);
  568. reset;
  569. typ:=_typ;
  570. end;
  571. procedure tasmsymbol.reset;
  572. begin
  573. section:=sec_none;
  574. address:=0;
  575. size:=0;
  576. idx:=-1;
  577. typ:=AS_EXTERNAL;
  578. { mainly used to remove unused labels from the codesegment }
  579. refs:=0;
  580. end;
  581. function tasmsymbol.is_used:boolean;
  582. begin
  583. is_used:=(refs>0);
  584. end;
  585. procedure tasmsymbol.setaddress(sec:tsection;offset,len:longint);
  586. begin
  587. section:=sec;
  588. address:=offset;
  589. size:=len;
  590. end;
  591. {*****************************************************************************
  592. AsmLabel
  593. *****************************************************************************}
  594. constructor tasmlabel.init;
  595. begin;
  596. labelnr:=nextlabelnr;
  597. inc(nextlabelnr);
  598. inherited init(target_asm.labelprefix+tostr(labelnr),AS_LOCAL);
  599. is_set:=false;
  600. end;
  601. constructor tasmlabel.initdata;
  602. begin;
  603. labelnr:=nextlabelnr;
  604. inc(nextlabelnr);
  605. if (cs_smartlink in aktmoduleswitches) then
  606. inherited init('_$'+current_module^.modulename^+'$_L'+tostr(labelnr),AS_GLOBAL)
  607. else
  608. inherited init(target_asm.labelprefix+tostr(labelnr),AS_LOCAL);
  609. is_set:=false;
  610. { write it always }
  611. refs:=1;
  612. end;
  613. function tasmlabel.name:string;
  614. begin
  615. name:=inherited name;
  616. inc(refs);
  617. end;
  618. {*****************************************************************************
  619. AsmSymbolList helpers
  620. *****************************************************************************}
  621. function newasmsymbol(const s : string) : pasmsymbol;
  622. var
  623. hp : pasmsymbol;
  624. begin
  625. hp:=pasmsymbol(asmsymbollist^.search(s));
  626. if assigned(hp) then
  627. begin
  628. newasmsymbol:=hp;
  629. exit;
  630. end;
  631. { Not found, insert it as an External }
  632. hp:=new(pasmsymbol,init(s,AS_EXTERNAL));
  633. asmsymbollist^.insert(hp);
  634. newasmsymbol:=hp;
  635. end;
  636. function newasmsymboltyp(const s : string;_typ:TAsmSymType) : pasmsymbol;
  637. var
  638. hp : pasmsymbol;
  639. begin
  640. hp:=pasmsymbol(asmsymbollist^.search(s));
  641. if assigned(hp) then
  642. begin
  643. hp^.typ:=_typ;
  644. newasmsymboltyp:=hp;
  645. exit;
  646. end;
  647. { Not found, insert it as an External }
  648. hp:=new(pasmsymbol,init(s,_typ));
  649. asmsymbollist^.insert(hp);
  650. newasmsymboltyp:=hp;
  651. end;
  652. function getasmsymbol(const s : string) : pasmsymbol;
  653. begin
  654. getasmsymbol:=pasmsymbol(asmsymbollist^.search(s));
  655. end;
  656. { renames an asmsymbol }
  657. function renameasmsymbol(const sold, snew : string):pasmsymbol;
  658. {$ifdef nodictonaryrename}
  659. var
  660. hpold,hpnew : pasmsymbol;
  661. begin
  662. hpnew:=pasmsymbol(asmsymbollist^.search(snew));
  663. if assigned(hpnew) then
  664. internalerror(405405);
  665. hpold:=pasmsymbol(asmsymbollist^.search(sold));
  666. if not assigned(hpold) then
  667. internalerror(405406);
  668. hpnew:=new(pasmsymbol,init(sold));
  669. { replace the old one }
  670. { WARNING this heavily depends on the
  671. feature that tdictionnary.insert does not delete
  672. the tree element that it replaces !! }
  673. asmsymbollist^.replace_existing:=true;
  674. asmsymbollist^.insert(hpnew);
  675. asmsymbollist^.replace_existing:=false;
  676. { restore the tree }
  677. hpnew^.left:=hpold^.left;
  678. hpnew^.right:=hpold^.right;
  679. stringdispose(hpold^._name);
  680. hpold^._name:=stringdup(snew);
  681. hpold^.speedvalue:=getspeedvalue(snew);
  682. { now reinsert it at right location !! }
  683. asmsymbollist^.insert(hpold);
  684. renameasmsymbol:=hpold;
  685. end;
  686. {$else}
  687. begin
  688. renameasmsymbol:=pasmsymbol(asmsymbollist^.rename(sold,snew));
  689. end;
  690. {$endif}
  691. procedure ResetAsmSym(p:Pnamedindexobject);{$ifndef FPC}far;{$endif}
  692. begin
  693. pasmsymbol(p)^.reset;
  694. end;
  695. procedure ResetAsmsymbolList;
  696. begin
  697. asmsymbollist^.foreach({$ifndef TP}@{$endif}resetasmsym);
  698. end;
  699. {*****************************************************************************
  700. Label Helpers
  701. *****************************************************************************}
  702. procedure getlabel(var l : pasmlabel);
  703. begin
  704. l:=new(pasmlabel,init);
  705. asmsymbollist^.insert(l);
  706. end;
  707. procedure getdatalabel(var l : pasmlabel);
  708. begin
  709. l:=new(pasmlabel,initdata);
  710. asmsymbollist^.insert(l);
  711. end;
  712. procedure freelabel(var l : pasmlabel);
  713. begin
  714. { nothing to do, the dispose of the asmsymbollist will do it }
  715. l:=nil;
  716. end;
  717. procedure getlabelnr(var l : longint);
  718. begin
  719. l:=nextlabelnr;
  720. inc(nextlabelnr);
  721. end;
  722. {*****************************************************************************
  723. TAAsmOutput
  724. *****************************************************************************}
  725. function taasmoutput.getlasttaifilepos : pfileposinfo;
  726. begin
  727. if assigned(last) then
  728. getlasttaifilepos:=@pai(last)^.fileinfo
  729. else
  730. getlasttaifilepos:=nil;
  731. end;
  732. end.
  733. {
  734. $Log$
  735. Revision 1.53 1999-07-22 09:37:28 florian
  736. + resourcestring implemented
  737. + start of longstring support
  738. Revision 1.52 1999/07/03 00:26:01 peter
  739. * ag386bin doesn't destroy the aasmoutput lists anymore
  740. Revision 1.51 1999/06/02 22:43:57 pierre
  741. * previous wrong log corrected
  742. Revision 1.50 1999/06/02 22:25:24 pierre
  743. * changed $ifdef FPC @ into $ifndef TP
  744. Revision 1.49 1999/06/01 14:45:41 peter
  745. * @procvar is now always needed for FPC
  746. Revision 1.48 1999/05/28 09:11:39 peter
  747. * also count ref when asmlabel^.name is used
  748. Revision 1.47 1999/05/27 19:43:55 peter
  749. * removed oldasm
  750. * plabel -> pasmlabel
  751. * -a switches to source writing automaticly
  752. * assembler readers OOPed
  753. * asmsymbol automaticly external
  754. * jumptables and other label fixes for asm readers
  755. Revision 1.46 1999/05/21 13:54:38 peter
  756. * NEWLAB for label as symbol
  757. Revision 1.45 1999/05/20 22:18:51 pierre
  758. * fix from Peter for double bug reported 20/05/1999
  759. Revision 1.44 1999/05/12 00:19:34 peter
  760. * removed R_DEFAULT_SEG
  761. * uniform float names
  762. Revision 1.43 1999/05/08 20:38:02 jonas
  763. * seperate OPTimizer INFO pointer field in tai object
  764. Revision 1.42 1999/05/06 09:05:05 peter
  765. * generic write_float and str_float
  766. * fixed constant float conversions
  767. Revision 1.41 1999/05/02 22:41:46 peter
  768. * moved section names to systems
  769. * fixed nasm,intel writer
  770. Revision 1.40 1999/04/21 09:43:28 peter
  771. * storenumber works
  772. * fixed some typos in double_checksum
  773. + incompatible types type1 and type2 message (with storenumber)
  774. Revision 1.39 1999/04/16 11:49:36 peter
  775. + tempalloc
  776. + -at to show temp alloc info in .s file
  777. Revision 1.38 1999/04/14 09:14:44 peter
  778. * first things to store the symbol/def number in the ppu
  779. Revision 1.37 1999/03/10 13:25:42 pierre
  780. section order changed to get closer output from coff writer
  781. Revision 1.36 1999/03/08 14:51:04 peter
  782. + smartlinking for ag386bin
  783. Revision 1.35 1999/03/05 13:09:48 peter
  784. * first things for tai_cut support for ag386bin
  785. Revision 1.34 1999/03/03 11:59:27 pierre
  786. + getasmsymbol to search for existing assembler symbol only
  787. Revision 1.33 1999/03/02 02:56:08 peter
  788. + stabs support for binary writers
  789. * more fixes and missing updates from the previous commit :(
  790. Revision 1.32 1999/03/01 13:31:59 pierre
  791. * external used before implemented problem fixed
  792. Revision 1.31 1999/02/25 21:02:16 peter
  793. * ag386bin updates
  794. + coff writer
  795. Revision 1.30 1999/02/17 10:16:24 peter
  796. * small fixes for the binary writer
  797. Revision 1.29 1998/12/29 18:48:24 jonas
  798. + optimize pascal code surrounding assembler blocks
  799. Revision 1.28 1998/12/16 00:27:16 peter
  800. * removed some obsolete version checks
  801. Revision 1.27 1998/12/11 00:02:37 peter
  802. + globtype,tokens,version unit splitted from globals
  803. Revision 1.26 1998/12/01 23:36:31 pierre
  804. * zero padded alignment was buggy
  805. Revision 1.25 1998/11/30 09:42:52 pierre
  806. * some range check bugs fixed (still not working !)
  807. + added DLL writing support for win32 (also accepts variables)
  808. + TempAnsi for code that could be used for Temporary ansi strings
  809. handling
  810. Revision 1.24 1998/11/12 11:19:30 pierre
  811. * fix for first line of function break
  812. Revision 1.23 1998/10/14 15:56:37 pierre
  813. * all references to comp suppressed for m68k
  814. Revision 1.22 1998/10/12 12:20:38 pierre
  815. + added tai_const_symbol_offset
  816. for r : pointer = @var.field;
  817. * better message for different arg names on implementation
  818. of function
  819. Revision 1.21 1998/10/08 17:17:07 pierre
  820. * current_module old scanner tagged as invalid if unit is recompiled
  821. + added ppheap for better info on tracegetmem of heaptrc
  822. (adds line column and file index)
  823. * several memory leaks removed ith help of heaptrc !!
  824. Revision 1.20 1998/10/06 17:16:31 pierre
  825. * some memory leaks fixed (thanks to Peter for heaptrc !)
  826. Revision 1.19 1998/10/01 20:19:11 jonas
  827. + ait_marker support
  828. Revision 1.18 1998/09/20 17:11:25 jonas
  829. * released REGALLOC
  830. Revision 1.17 1998/09/07 18:33:31 peter
  831. + smartlinking for win95 imports
  832. Revision 1.16 1998/09/03 17:08:37 pierre
  833. * better lines for stabs
  834. (no scroll back to if before else part
  835. no return to case line at jump outside case)
  836. + source lines also if not in order
  837. Revision 1.15 1998/08/11 15:31:36 peter
  838. * write extended to ppu file
  839. * new version 0.99.7
  840. Revision 1.14 1998/08/10 23:56:03 peter
  841. * fixed extended writing
  842. Revision 1.13 1998/08/10 14:49:33 peter
  843. + localswitches, moduleswitches, globalswitches splitting
  844. Revision 1.12 1998/07/14 14:46:36 peter
  845. * released NEWINPUT
  846. Revision 1.11 1998/07/07 11:19:50 peter
  847. + NEWINPUT for a better inputfile and scanner object
  848. Revision 1.10 1998/06/08 22:59:41 peter
  849. * smartlinking works for win32
  850. * some defines to exclude some compiler parts
  851. Revision 1.9 1998/06/04 23:51:26 peter
  852. * m68k compiles
  853. + .def file creation moved to gendef.pas so it could also be used
  854. for win32
  855. Revision 1.8 1998/05/23 01:20:53 peter
  856. + aktasmmode, aktoptprocessor, aktoutputformat
  857. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  858. + $LIBNAME to set the library name where the unit will be put in
  859. * splitted cgi386 a bit (codeseg to large for bp7)
  860. * nasm, tasm works again. nasm moved to ag386nsm.pas
  861. Revision 1.7 1998/05/07 00:16:59 peter
  862. * smartlinking for sets
  863. + consts labels are now concated/generated in hcodegen
  864. * moved some cpu code to cga and some none cpu depended code from cga
  865. to tree and hcodegen and cleanup of hcodegen
  866. * assembling .. output reduced for smartlinking ;)
  867. Revision 1.6 1998/05/06 18:36:53 peter
  868. * tai_section extended with code,data,bss sections and enumerated type
  869. * ident 'compiled by FPC' moved to pmodules
  870. * small fix for smartlink
  871. Revision 1.5 1998/05/01 07:43:52 florian
  872. + basics for rtti implemented
  873. + switch $m (generate rtti for published sections)
  874. Revision 1.4 1998/04/29 10:33:40 pierre
  875. + added some code for ansistring (not complete nor working yet)
  876. * corrected operator overloading
  877. * corrected nasm output
  878. + started inline procedures
  879. + added starstarn : use ** for exponentiation (^ gave problems)
  880. + started UseTokenInfo cond to get accurate positions
  881. Revision 1.3 1998/04/27 23:10:27 peter
  882. + new scanner
  883. * $makelib -> if smartlink
  884. * small filename fixes pmodule.setfilename
  885. * moved import from files.pas -> import.pas
  886. Revision 1.2 1998/04/09 15:46:37 florian
  887. + register allocation tracing stuff added
  888. }