aasm.pas 31 KB

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