aasm.pas 31 KB

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