aasm.pas 31 KB

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